@deot/vc-components 1.0.53 → 1.0.55

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/index.cjs CHANGED
@@ -75,6 +75,7 @@ const defaults$2 = {
75
75
  line: nil
76
76
  },
77
77
  Snapshot: {
78
+ options: nil,
78
79
  source: nil,
79
80
  download: nil
80
81
  }
@@ -10851,14 +10852,18 @@ const Upload$1 = vue.defineComponent({
10851
10852
  }
10852
10853
  let { enhancer } = VcInstance.options.Upload || {};
10853
10854
  enhancer = props.enhancer || enhancer || (() => false);
10854
- const allow = enhancer(instance);
10855
- if (allow && allow.then) {
10856
- allow.catch(() => {
10857
- el.click?.();
10855
+ const skip = enhancer(instance);
10856
+ if (skip && skip.then) {
10857
+ let skip$ = false;
10858
+ skip.then((v) => {
10859
+ skip$ = typeof v === "undefined" ? true : !!v;
10860
+ return v;
10861
+ }).finally(() => {
10862
+ skip$ || el.click?.();
10858
10863
  });
10859
10864
  return;
10860
10865
  }
10861
- allow || el.click();
10866
+ skip || el.click();
10862
10867
  };
10863
10868
  const handleChange = (e) => {
10864
10869
  uploadFiles(e.target.files);
@@ -12128,6 +12133,14 @@ const props$H = {
12128
12133
  },
12129
12134
  source: Function,
12130
12135
  download: Function,
12136
+ lazy: {
12137
+ type: Boolean,
12138
+ default: true
12139
+ },
12140
+ showLoading: {
12141
+ type: Boolean,
12142
+ default: true
12143
+ },
12131
12144
  // 传递给snap-dom的配置项
12132
12145
  options: {
12133
12146
  type: Object,
@@ -12147,62 +12160,71 @@ const Snapshot = /* @__PURE__ */ vue.defineComponent({
12147
12160
  slots,
12148
12161
  expose
12149
12162
  }) {
12163
+ let snapDOM;
12150
12164
  const instance = vue.getCurrentInstance();
12151
12165
  const current = vue.ref();
12152
- const snapdom = vue.ref();
12153
-
12154
- // 网络的图片如果没有加上crossOrigin,且没有放在第一个就会出现问题(Safari)
12166
+ const snapshot = vue.ref();
12155
12167
  const refresh = async () => {
12156
- if (!props.crossOrigin) return;
12157
- const transformSource = props.source || VcInstance.options.Snapshot?.source || (v => v);
12158
- return Promise.all(Array.from(current.value.querySelectorAll('img')).map(node => {
12159
- return new Promise(resolve => {
12160
- (async () => {
12161
- let url;
12162
- try {
12163
- url = await transformSource(node.src, 'image');
12164
- } catch (e) {
12165
- console.error(e);
12166
- }
12167
- const image = new Image();
12168
- image.crossOrigin = props.crossOrigin;
12169
- image.src = `${url}?=${new Date().getTime()}`; // 强制不缓存
12170
- image.onload = () => {
12171
- node.src = image.src;
12172
- resolve(1);
12173
- };
12174
- image.onerror = () => resolve(0);
12175
- })();
12176
- });
12177
- }));
12168
+ await vue.nextTick();
12169
+ snapshot.value = await snapDOM(current.value, {
12170
+ fast: false,
12171
+ // dom太大时会卡死一会儿
12172
+ ...VcInstance.options.Snapshot?.options,
12173
+ ...props.options
12174
+ });
12175
+ return snapshot.value;
12176
+ };
12177
+ const onLoad = () => {
12178
+ return props.showLoading && Message.loading('正在生成...');
12179
+ };
12180
+ const onLoaded = ctx => {
12181
+ ctx?.destroy?.();
12178
12182
  };
12179
12183
  const toDataURL = async () => {
12184
+ const loadContext = onLoad();
12185
+ try {
12186
+ await refresh();
12187
+ return snapshot.value.toRaw();
12188
+ } finally {
12189
+ onLoaded(loadContext);
12190
+ }
12191
+ };
12192
+ const downloadByDefault = async options => {
12180
12193
  await refresh();
12181
- return snapdom.value.toRaw();
12194
+ return snapshot.value.download(options);
12182
12195
  };
12183
12196
  const download = async options => {
12184
- await refresh();
12185
- const _download = props.download || VcInstance.options.Snapshot?.download || (() => false);
12186
- const allow = _download(instance, options);
12187
- if (allow && allow.then) {
12188
- allow.catch(() => {
12189
- snapdom.value.download(options);
12190
- });
12197
+ const loadContext = onLoad();
12198
+ const downloadByUser = props.download || VcInstance.options.Snapshot?.download || (() => false);
12199
+ const skip = downloadByUser(instance, options);
12200
+ const done = async v => {
12201
+ try {
12202
+ v || (await downloadByDefault(options));
12203
+ } finally {
12204
+ onLoaded(loadContext);
12205
+ }
12206
+ };
12207
+ if (skip && skip.then) {
12208
+ let skip$ = false;
12209
+ skip.then(v => {
12210
+ skip$ = typeof v === 'undefined' ? true : !!v;
12211
+ return v;
12212
+ }).finally(() => done(skip$));
12191
12213
  return;
12192
12214
  }
12193
- allow || snapdom.value.download(options);
12215
+ done(skip);
12194
12216
  };
12195
12217
  expose({
12196
- snapdom,
12218
+ snapshot,
12197
12219
  refresh,
12198
12220
  toDataURL,
12199
12221
  download
12200
12222
  });
12201
12223
  vue.onMounted(async () => {
12202
12224
  try {
12203
- let snapDOM = window.snapdom || (await import('@zumer/snapdom'));
12225
+ snapDOM = window.snapdom || (await import('@zumer/snapdom'));
12204
12226
  snapDOM = snapDOM.snapdom || snapDOM;
12205
- snapdom.value = await snapDOM(current.value, props.options);
12227
+ !props.lazy && (await refresh());
12206
12228
  emit('ready', {
12207
12229
  instance,
12208
12230
  dependencies: {
package/dist/index.d.ts CHANGED
@@ -8425,10 +8425,18 @@ default: string;
8425
8425
  crossOrigin: {
8426
8426
  type: StringConstructor;
8427
8427
  default: string;
8428
- validator: (v: any) => boolean;
8428
+ validator: (v: string) => boolean;
8429
8429
  };
8430
8430
  source: FunctionConstructor;
8431
8431
  download: FunctionConstructor;
8432
+ lazy: {
8433
+ type: BooleanConstructor;
8434
+ default: boolean;
8435
+ };
8436
+ showLoading: {
8437
+ type: BooleanConstructor;
8438
+ default: boolean;
8439
+ };
8432
8440
  options: {
8433
8441
  type: ObjectConstructor;
8434
8442
  default: () => {};
@@ -8441,10 +8449,18 @@ default: string;
8441
8449
  crossOrigin: {
8442
8450
  type: StringConstructor;
8443
8451
  default: string;
8444
- validator: (v: any) => boolean;
8452
+ validator: (v: string) => boolean;
8445
8453
  };
8446
8454
  source: FunctionConstructor;
8447
8455
  download: FunctionConstructor;
8456
+ lazy: {
8457
+ type: BooleanConstructor;
8458
+ default: boolean;
8459
+ };
8460
+ showLoading: {
8461
+ type: BooleanConstructor;
8462
+ default: boolean;
8463
+ };
8448
8464
  options: {
8449
8465
  type: ObjectConstructor;
8450
8466
  default: () => {};
@@ -8454,7 +8470,9 @@ onReady?: ((...args: any[]) => any) | undefined;
8454
8470
  }>, {
8455
8471
  tag: string;
8456
8472
  options: Record<string, any>;
8473
+ showLoading: boolean;
8457
8474
  crossOrigin: string;
8475
+ lazy: boolean;
8458
8476
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
8459
8477
 
8460
8478
  export declare const MSortList: DefineComponent<ExtractPropTypes< {
@@ -13308,10 +13326,18 @@ default: string;
13308
13326
  crossOrigin: {
13309
13327
  type: StringConstructor;
13310
13328
  default: string;
13311
- validator: (v: any) => boolean;
13329
+ validator: (v: string) => boolean;
13312
13330
  };
13313
13331
  source: FunctionConstructor;
13314
13332
  download: FunctionConstructor;
13333
+ lazy: {
13334
+ type: BooleanConstructor;
13335
+ default: boolean;
13336
+ };
13337
+ showLoading: {
13338
+ type: BooleanConstructor;
13339
+ default: boolean;
13340
+ };
13315
13341
  options: {
13316
13342
  type: ObjectConstructor;
13317
13343
  default: () => {};
@@ -13324,10 +13350,18 @@ default: string;
13324
13350
  crossOrigin: {
13325
13351
  type: StringConstructor;
13326
13352
  default: string;
13327
- validator: (v: any) => boolean;
13353
+ validator: (v: string) => boolean;
13328
13354
  };
13329
13355
  source: FunctionConstructor;
13330
13356
  download: FunctionConstructor;
13357
+ lazy: {
13358
+ type: BooleanConstructor;
13359
+ default: boolean;
13360
+ };
13361
+ showLoading: {
13362
+ type: BooleanConstructor;
13363
+ default: boolean;
13364
+ };
13331
13365
  options: {
13332
13366
  type: ObjectConstructor;
13333
13367
  default: () => {};
@@ -13337,7 +13371,9 @@ onReady?: ((...args: any[]) => any) | undefined;
13337
13371
  }>, {
13338
13372
  tag: string;
13339
13373
  options: Record<string, any>;
13374
+ showLoading: boolean;
13340
13375
  crossOrigin: string;
13376
+ lazy: boolean;
13341
13377
  }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
13342
13378
 
13343
13379
  export declare const SortList: DefineComponent<ExtractPropTypes< {
@@ -37,6 +37,7 @@ var VcComponents = (function (exports, vue) {
37
37
  line: nil
38
38
  },
39
39
  Snapshot: {
40
+ options: nil,
40
41
  source: nil,
41
42
  download: nil
42
43
  }
@@ -19262,14 +19263,18 @@ var VcComponents = (function (exports, vue) {
19262
19263
  }
19263
19264
  let { enhancer } = VcInstance.options.Upload || {};
19264
19265
  enhancer = props.enhancer || enhancer || (() => false);
19265
- const allow = enhancer(instance);
19266
- if (allow && allow.then) {
19267
- allow.catch(() => {
19268
- el.click?.();
19266
+ const skip = enhancer(instance);
19267
+ if (skip && skip.then) {
19268
+ let skip$ = false;
19269
+ skip.then((v) => {
19270
+ skip$ = typeof v === "undefined" ? true : !!v;
19271
+ return v;
19272
+ }).finally(() => {
19273
+ skip$ || el.click?.();
19269
19274
  });
19270
19275
  return;
19271
19276
  }
19272
- allow || el.click();
19277
+ skip || el.click();
19273
19278
  };
19274
19279
  const handleChange = (e) => {
19275
19280
  uploadFiles(e.target.files);
@@ -20671,6 +20676,14 @@ var VcComponents = (function (exports, vue) {
20671
20676
  },
20672
20677
  source: Function,
20673
20678
  download: Function,
20679
+ lazy: {
20680
+ type: Boolean,
20681
+ default: true
20682
+ },
20683
+ showLoading: {
20684
+ type: Boolean,
20685
+ default: true
20686
+ },
20674
20687
  // 传递给snap-dom的配置项
20675
20688
  options: {
20676
20689
  type: Object,
@@ -20690,62 +20703,71 @@ var VcComponents = (function (exports, vue) {
20690
20703
  slots,
20691
20704
  expose
20692
20705
  }) {
20706
+ let snapDOM;
20693
20707
  const instance = vue.getCurrentInstance();
20694
20708
  const current = vue.ref();
20695
- const snapdom = vue.ref();
20696
-
20697
- // 网络的图片如果没有加上crossOrigin,且没有放在第一个就会出现问题(Safari)
20709
+ const snapshot = vue.ref();
20698
20710
  const refresh = async () => {
20699
- if (!props.crossOrigin) return;
20700
- const transformSource = props.source || VcInstance.options.Snapshot?.source || (v => v);
20701
- return Promise.all(Array.from(current.value.querySelectorAll('img')).map(node => {
20702
- return new Promise(resolve => {
20703
- (async () => {
20704
- let url;
20705
- try {
20706
- url = await transformSource(node.src, 'image');
20707
- } catch (e) {
20708
- console.error(e);
20709
- }
20710
- const image = new Image();
20711
- image.crossOrigin = props.crossOrigin;
20712
- image.src = `${url}?=${new Date().getTime()}`; // 强制不缓存
20713
- image.onload = () => {
20714
- node.src = image.src;
20715
- resolve(1);
20716
- };
20717
- image.onerror = () => resolve(0);
20718
- })();
20719
- });
20720
- }));
20711
+ await vue.nextTick();
20712
+ snapshot.value = await snapDOM(current.value, {
20713
+ fast: false,
20714
+ // dom太大时会卡死一会儿
20715
+ ...VcInstance.options.Snapshot?.options,
20716
+ ...props.options
20717
+ });
20718
+ return snapshot.value;
20719
+ };
20720
+ const onLoad = () => {
20721
+ return props.showLoading && Message.loading('正在生成...');
20722
+ };
20723
+ const onLoaded = ctx => {
20724
+ ctx?.destroy?.();
20721
20725
  };
20722
20726
  const toDataURL = async () => {
20727
+ const loadContext = onLoad();
20728
+ try {
20729
+ await refresh();
20730
+ return snapshot.value.toRaw();
20731
+ } finally {
20732
+ onLoaded(loadContext);
20733
+ }
20734
+ };
20735
+ const downloadByDefault = async options => {
20723
20736
  await refresh();
20724
- return snapdom.value.toRaw();
20737
+ return snapshot.value.download(options);
20725
20738
  };
20726
20739
  const download = async options => {
20727
- await refresh();
20728
- const _download = props.download || VcInstance.options.Snapshot?.download || (() => false);
20729
- const allow = _download(instance, options);
20730
- if (allow && allow.then) {
20731
- allow.catch(() => {
20732
- snapdom.value.download(options);
20733
- });
20740
+ const loadContext = onLoad();
20741
+ const downloadByUser = props.download || VcInstance.options.Snapshot?.download || (() => false);
20742
+ const skip = downloadByUser(instance, options);
20743
+ const done = async v => {
20744
+ try {
20745
+ v || (await downloadByDefault(options));
20746
+ } finally {
20747
+ onLoaded(loadContext);
20748
+ }
20749
+ };
20750
+ if (skip && skip.then) {
20751
+ let skip$ = false;
20752
+ skip.then(v => {
20753
+ skip$ = typeof v === 'undefined' ? true : !!v;
20754
+ return v;
20755
+ }).finally(() => done(skip$));
20734
20756
  return;
20735
20757
  }
20736
- allow || snapdom.value.download(options);
20758
+ done(skip);
20737
20759
  };
20738
20760
  expose({
20739
- snapdom,
20761
+ snapshot,
20740
20762
  refresh,
20741
20763
  toDataURL,
20742
20764
  download
20743
20765
  });
20744
20766
  vue.onMounted(async () => {
20745
20767
  try {
20746
- let snapDOM = window.snapdom || (await Promise.resolve().then(() => snapdom$1));
20768
+ snapDOM = window.snapdom || (await Promise.resolve().then(() => snapdom$1));
20747
20769
  snapDOM = snapDOM.snapdom || snapDOM;
20748
- snapdom.value = await snapDOM(current.value, props.options);
20770
+ !props.lazy && (await refresh());
20749
20771
  emit('ready', {
20750
20772
  instance,
20751
20773
  dependencies: {
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ const defaults$2 = {
53
53
  line: nil
54
54
  },
55
55
  Snapshot: {
56
+ options: nil,
56
57
  source: nil,
57
58
  download: nil
58
59
  }
@@ -10829,14 +10830,18 @@ const Upload$1 = defineComponent({
10829
10830
  }
10830
10831
  let { enhancer } = VcInstance.options.Upload || {};
10831
10832
  enhancer = props.enhancer || enhancer || (() => false);
10832
- const allow = enhancer(instance);
10833
- if (allow && allow.then) {
10834
- allow.catch(() => {
10835
- el.click?.();
10833
+ const skip = enhancer(instance);
10834
+ if (skip && skip.then) {
10835
+ let skip$ = false;
10836
+ skip.then((v) => {
10837
+ skip$ = typeof v === "undefined" ? true : !!v;
10838
+ return v;
10839
+ }).finally(() => {
10840
+ skip$ || el.click?.();
10836
10841
  });
10837
10842
  return;
10838
10843
  }
10839
- allow || el.click();
10844
+ skip || el.click();
10840
10845
  };
10841
10846
  const handleChange = (e) => {
10842
10847
  uploadFiles(e.target.files);
@@ -12106,6 +12111,14 @@ const props$H = {
12106
12111
  },
12107
12112
  source: Function,
12108
12113
  download: Function,
12114
+ lazy: {
12115
+ type: Boolean,
12116
+ default: true
12117
+ },
12118
+ showLoading: {
12119
+ type: Boolean,
12120
+ default: true
12121
+ },
12109
12122
  // 传递给snap-dom的配置项
12110
12123
  options: {
12111
12124
  type: Object,
@@ -12125,62 +12138,71 @@ const Snapshot = /* @__PURE__ */ defineComponent({
12125
12138
  slots,
12126
12139
  expose
12127
12140
  }) {
12141
+ let snapDOM;
12128
12142
  const instance = getCurrentInstance();
12129
12143
  const current = ref();
12130
- const snapdom = ref();
12131
-
12132
- // 网络的图片如果没有加上crossOrigin,且没有放在第一个就会出现问题(Safari)
12144
+ const snapshot = ref();
12133
12145
  const refresh = async () => {
12134
- if (!props.crossOrigin) return;
12135
- const transformSource = props.source || VcInstance.options.Snapshot?.source || (v => v);
12136
- return Promise.all(Array.from(current.value.querySelectorAll('img')).map(node => {
12137
- return new Promise(resolve => {
12138
- (async () => {
12139
- let url;
12140
- try {
12141
- url = await transformSource(node.src, 'image');
12142
- } catch (e) {
12143
- console.error(e);
12144
- }
12145
- const image = new Image();
12146
- image.crossOrigin = props.crossOrigin;
12147
- image.src = `${url}?=${new Date().getTime()}`; // 强制不缓存
12148
- image.onload = () => {
12149
- node.src = image.src;
12150
- resolve(1);
12151
- };
12152
- image.onerror = () => resolve(0);
12153
- })();
12154
- });
12155
- }));
12146
+ await nextTick();
12147
+ snapshot.value = await snapDOM(current.value, {
12148
+ fast: false,
12149
+ // dom太大时会卡死一会儿
12150
+ ...VcInstance.options.Snapshot?.options,
12151
+ ...props.options
12152
+ });
12153
+ return snapshot.value;
12154
+ };
12155
+ const onLoad = () => {
12156
+ return props.showLoading && Message.loading('正在生成...');
12157
+ };
12158
+ const onLoaded = ctx => {
12159
+ ctx?.destroy?.();
12156
12160
  };
12157
12161
  const toDataURL = async () => {
12162
+ const loadContext = onLoad();
12163
+ try {
12164
+ await refresh();
12165
+ return snapshot.value.toRaw();
12166
+ } finally {
12167
+ onLoaded(loadContext);
12168
+ }
12169
+ };
12170
+ const downloadByDefault = async options => {
12158
12171
  await refresh();
12159
- return snapdom.value.toRaw();
12172
+ return snapshot.value.download(options);
12160
12173
  };
12161
12174
  const download = async options => {
12162
- await refresh();
12163
- const _download = props.download || VcInstance.options.Snapshot?.download || (() => false);
12164
- const allow = _download(instance, options);
12165
- if (allow && allow.then) {
12166
- allow.catch(() => {
12167
- snapdom.value.download(options);
12168
- });
12175
+ const loadContext = onLoad();
12176
+ const downloadByUser = props.download || VcInstance.options.Snapshot?.download || (() => false);
12177
+ const skip = downloadByUser(instance, options);
12178
+ const done = async v => {
12179
+ try {
12180
+ v || (await downloadByDefault(options));
12181
+ } finally {
12182
+ onLoaded(loadContext);
12183
+ }
12184
+ };
12185
+ if (skip && skip.then) {
12186
+ let skip$ = false;
12187
+ skip.then(v => {
12188
+ skip$ = typeof v === 'undefined' ? true : !!v;
12189
+ return v;
12190
+ }).finally(() => done(skip$));
12169
12191
  return;
12170
12192
  }
12171
- allow || snapdom.value.download(options);
12193
+ done(skip);
12172
12194
  };
12173
12195
  expose({
12174
- snapdom,
12196
+ snapshot,
12175
12197
  refresh,
12176
12198
  toDataURL,
12177
12199
  download
12178
12200
  });
12179
12201
  onMounted(async () => {
12180
12202
  try {
12181
- let snapDOM = window.snapdom || (await import('@zumer/snapdom'));
12203
+ snapDOM = window.snapdom || (await import('@zumer/snapdom'));
12182
12204
  snapDOM = snapDOM.snapdom || snapDOM;
12183
- snapdom.value = await snapDOM(current.value, props.options);
12205
+ !props.lazy && (await refresh());
12184
12206
  emit('ready', {
12185
12207
  instance,
12186
12208
  dependencies: {
@@ -40,6 +40,7 @@
40
40
  line: nil
41
41
  },
42
42
  Snapshot: {
43
+ options: nil,
43
44
  source: nil,
44
45
  download: nil
45
46
  }
@@ -19265,14 +19266,18 @@
19265
19266
  }
19266
19267
  let { enhancer } = VcInstance.options.Upload || {};
19267
19268
  enhancer = props.enhancer || enhancer || (() => false);
19268
- const allow = enhancer(instance);
19269
- if (allow && allow.then) {
19270
- allow.catch(() => {
19271
- el.click?.();
19269
+ const skip = enhancer(instance);
19270
+ if (skip && skip.then) {
19271
+ let skip$ = false;
19272
+ skip.then((v) => {
19273
+ skip$ = typeof v === "undefined" ? true : !!v;
19274
+ return v;
19275
+ }).finally(() => {
19276
+ skip$ || el.click?.();
19272
19277
  });
19273
19278
  return;
19274
19279
  }
19275
- allow || el.click();
19280
+ skip || el.click();
19276
19281
  };
19277
19282
  const handleChange = (e) => {
19278
19283
  uploadFiles(e.target.files);
@@ -20674,6 +20679,14 @@
20674
20679
  },
20675
20680
  source: Function,
20676
20681
  download: Function,
20682
+ lazy: {
20683
+ type: Boolean,
20684
+ default: true
20685
+ },
20686
+ showLoading: {
20687
+ type: Boolean,
20688
+ default: true
20689
+ },
20677
20690
  // 传递给snap-dom的配置项
20678
20691
  options: {
20679
20692
  type: Object,
@@ -20693,62 +20706,71 @@
20693
20706
  slots,
20694
20707
  expose
20695
20708
  }) {
20709
+ let snapDOM;
20696
20710
  const instance = vue.getCurrentInstance();
20697
20711
  const current = vue.ref();
20698
- const snapdom = vue.ref();
20699
-
20700
- // 网络的图片如果没有加上crossOrigin,且没有放在第一个就会出现问题(Safari)
20712
+ const snapshot = vue.ref();
20701
20713
  const refresh = async () => {
20702
- if (!props.crossOrigin) return;
20703
- const transformSource = props.source || VcInstance.options.Snapshot?.source || (v => v);
20704
- return Promise.all(Array.from(current.value.querySelectorAll('img')).map(node => {
20705
- return new Promise(resolve => {
20706
- (async () => {
20707
- let url;
20708
- try {
20709
- url = await transformSource(node.src, 'image');
20710
- } catch (e) {
20711
- console.error(e);
20712
- }
20713
- const image = new Image();
20714
- image.crossOrigin = props.crossOrigin;
20715
- image.src = `${url}?=${new Date().getTime()}`; // 强制不缓存
20716
- image.onload = () => {
20717
- node.src = image.src;
20718
- resolve(1);
20719
- };
20720
- image.onerror = () => resolve(0);
20721
- })();
20722
- });
20723
- }));
20714
+ await vue.nextTick();
20715
+ snapshot.value = await snapDOM(current.value, {
20716
+ fast: false,
20717
+ // dom太大时会卡死一会儿
20718
+ ...VcInstance.options.Snapshot?.options,
20719
+ ...props.options
20720
+ });
20721
+ return snapshot.value;
20722
+ };
20723
+ const onLoad = () => {
20724
+ return props.showLoading && Message.loading('正在生成...');
20725
+ };
20726
+ const onLoaded = ctx => {
20727
+ ctx?.destroy?.();
20724
20728
  };
20725
20729
  const toDataURL = async () => {
20730
+ const loadContext = onLoad();
20731
+ try {
20732
+ await refresh();
20733
+ return snapshot.value.toRaw();
20734
+ } finally {
20735
+ onLoaded(loadContext);
20736
+ }
20737
+ };
20738
+ const downloadByDefault = async options => {
20726
20739
  await refresh();
20727
- return snapdom.value.toRaw();
20740
+ return snapshot.value.download(options);
20728
20741
  };
20729
20742
  const download = async options => {
20730
- await refresh();
20731
- const _download = props.download || VcInstance.options.Snapshot?.download || (() => false);
20732
- const allow = _download(instance, options);
20733
- if (allow && allow.then) {
20734
- allow.catch(() => {
20735
- snapdom.value.download(options);
20736
- });
20743
+ const loadContext = onLoad();
20744
+ const downloadByUser = props.download || VcInstance.options.Snapshot?.download || (() => false);
20745
+ const skip = downloadByUser(instance, options);
20746
+ const done = async v => {
20747
+ try {
20748
+ v || (await downloadByDefault(options));
20749
+ } finally {
20750
+ onLoaded(loadContext);
20751
+ }
20752
+ };
20753
+ if (skip && skip.then) {
20754
+ let skip$ = false;
20755
+ skip.then(v => {
20756
+ skip$ = typeof v === 'undefined' ? true : !!v;
20757
+ return v;
20758
+ }).finally(() => done(skip$));
20737
20759
  return;
20738
20760
  }
20739
- allow || snapdom.value.download(options);
20761
+ done(skip);
20740
20762
  };
20741
20763
  expose({
20742
- snapdom,
20764
+ snapshot,
20743
20765
  refresh,
20744
20766
  toDataURL,
20745
20767
  download
20746
20768
  });
20747
20769
  vue.onMounted(async () => {
20748
20770
  try {
20749
- let snapDOM = window.snapdom || (await Promise.resolve().then(() => snapdom$1));
20771
+ snapDOM = window.snapdom || (await Promise.resolve().then(() => snapdom$1));
20750
20772
  snapDOM = snapDOM.snapdom || snapDOM;
20751
- snapdom.value = await snapDOM(current.value, props.options);
20773
+ !props.lazy && (await refresh());
20752
20774
  emit('ready', {
20753
20775
  instance,
20754
20776
  dependencies: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/vc-components",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",