zartui 3.1.74 → 3.1.76

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/lib/zartui.cjs.js CHANGED
@@ -16081,6 +16081,7 @@ const mediaPickerProps = {
16081
16081
  disabled: Boolean,
16082
16082
  showTitle: Boolean,
16083
16083
  showDownload: Boolean,
16084
+ downloadAction: Function,
16084
16085
  useFileNameAsLabel: Boolean,
16085
16086
  title: makeStringProp("添加附件"),
16086
16087
  mediaList: makeArrayProp(),
@@ -16090,6 +16091,11 @@ const mediaPickerProps = {
16090
16091
  maxImageFileSize: makeNumberProp(1024),
16091
16092
  // 单个文件大小限制(本单位为KB,默认最大1M)
16092
16093
  maxFileSize: makeNumberProp(FILE_SIZE_LIMIT * 1024),
16094
+ // 是否保持原始文件类型(不转换为jpg)
16095
+ keepFileType: {
16096
+ type: Boolean,
16097
+ default: false
16098
+ },
16093
16099
  /**
16094
16100
  * {
16095
16101
  * maxImageSideLength,
@@ -16397,10 +16403,22 @@ var stdin_default$C = vue.defineComponent({
16397
16403
  }).finally(() => {
16398
16404
  });
16399
16405
  };
16406
+ const getExtensionFromMimeType = (mimeType) => {
16407
+ const mimeToExt = {
16408
+ "image/jpeg": "jpg",
16409
+ "image/jpg": "jpg",
16410
+ "image/png": "png",
16411
+ "image/gif": "gif",
16412
+ "image/webp": "webp",
16413
+ "image/bmp": "bmp",
16414
+ "image/svg+xml": "svg"
16415
+ };
16416
+ return mimeToExt[mimeType] || "jpg";
16417
+ };
16400
16418
  const transformImageFiles = (files) => {
16401
16419
  const promisesTodo = [];
16402
16420
  const resizeOptions = new appMediaUtils.ResizeOptions(props.maxImageSideLength);
16403
- const compressOptions = new appMediaUtils.CompressOptions(props.maxImageFileSize);
16421
+ const compressOptions = new appMediaUtils.CompressOptions(props.maxImageFileSize, props.keepFileType);
16404
16422
  for (let i = 0; i < files.length; i++) {
16405
16423
  const file = files[i];
16406
16424
  const watermarkEnabled = props.watermarkOptions && props.watermarkOptions.watermarkConfigString && appMediaUtils.checkWatermarkConfigSupported(props.watermarkOptions.watermarkConfigString);
@@ -16426,7 +16444,8 @@ var stdin_default$C = vue.defineComponent({
16426
16444
  return Promise.resolve(null);
16427
16445
  }
16428
16446
  return file2DataURL(f).then((base64) => {
16429
- const uniqueFileName = getUniqueFileName(f, "jpg");
16447
+ const ext = props.keepFileType ? getExtensionFromMimeType(f.type) : "jpg";
16448
+ const uniqueFileName = getUniqueFileName(f, ext);
16430
16449
  const media = {
16431
16450
  showSrc: base64,
16432
16451
  type: "photo",
@@ -16772,6 +16791,7 @@ var stdin_default$C = vue.defineComponent({
16772
16791
  url: image.url || image.showSrc || ""
16773
16792
  })),
16774
16793
  showDownload: props.showDownload,
16794
+ downloadAction: props.downloadAction,
16775
16795
  startPosition: imageIndex,
16776
16796
  closeable: true
16777
16797
  });
@@ -23497,7 +23517,7 @@ const Lazyload = {
23497
23517
  });
23498
23518
  }
23499
23519
  };
23500
- const version = "3.1.74";
23520
+ const version = "3.1.76";
23501
23521
  function install(app) {
23502
23522
  const components = [
23503
23523
  ActionSheet,
package/lib/zartui.es.js CHANGED
@@ -16079,6 +16079,7 @@ const mediaPickerProps = {
16079
16079
  disabled: Boolean,
16080
16080
  showTitle: Boolean,
16081
16081
  showDownload: Boolean,
16082
+ downloadAction: Function,
16082
16083
  useFileNameAsLabel: Boolean,
16083
16084
  title: makeStringProp("添加附件"),
16084
16085
  mediaList: makeArrayProp(),
@@ -16088,6 +16089,11 @@ const mediaPickerProps = {
16088
16089
  maxImageFileSize: makeNumberProp(1024),
16089
16090
  // 单个文件大小限制(本单位为KB,默认最大1M)
16090
16091
  maxFileSize: makeNumberProp(FILE_SIZE_LIMIT * 1024),
16092
+ // 是否保持原始文件类型(不转换为jpg)
16093
+ keepFileType: {
16094
+ type: Boolean,
16095
+ default: false
16096
+ },
16091
16097
  /**
16092
16098
  * {
16093
16099
  * maxImageSideLength,
@@ -16395,10 +16401,22 @@ var stdin_default$C = defineComponent({
16395
16401
  }).finally(() => {
16396
16402
  });
16397
16403
  };
16404
+ const getExtensionFromMimeType = (mimeType) => {
16405
+ const mimeToExt = {
16406
+ "image/jpeg": "jpg",
16407
+ "image/jpg": "jpg",
16408
+ "image/png": "png",
16409
+ "image/gif": "gif",
16410
+ "image/webp": "webp",
16411
+ "image/bmp": "bmp",
16412
+ "image/svg+xml": "svg"
16413
+ };
16414
+ return mimeToExt[mimeType] || "jpg";
16415
+ };
16398
16416
  const transformImageFiles = (files) => {
16399
16417
  const promisesTodo = [];
16400
16418
  const resizeOptions = new ResizeOptions(props.maxImageSideLength);
16401
- const compressOptions = new CompressOptions(props.maxImageFileSize);
16419
+ const compressOptions = new CompressOptions(props.maxImageFileSize, props.keepFileType);
16402
16420
  for (let i = 0; i < files.length; i++) {
16403
16421
  const file = files[i];
16404
16422
  const watermarkEnabled = props.watermarkOptions && props.watermarkOptions.watermarkConfigString && checkWatermarkConfigSupported(props.watermarkOptions.watermarkConfigString);
@@ -16424,7 +16442,8 @@ var stdin_default$C = defineComponent({
16424
16442
  return Promise.resolve(null);
16425
16443
  }
16426
16444
  return file2DataURL(f).then((base64) => {
16427
- const uniqueFileName = getUniqueFileName(f, "jpg");
16445
+ const ext = props.keepFileType ? getExtensionFromMimeType(f.type) : "jpg";
16446
+ const uniqueFileName = getUniqueFileName(f, ext);
16428
16447
  const media = {
16429
16448
  showSrc: base64,
16430
16449
  type: "photo",
@@ -16770,6 +16789,7 @@ var stdin_default$C = defineComponent({
16770
16789
  url: image.url || image.showSrc || ""
16771
16790
  })),
16772
16791
  showDownload: props.showDownload,
16792
+ downloadAction: props.downloadAction,
16773
16793
  startPosition: imageIndex,
16774
16794
  closeable: true
16775
16795
  });
@@ -23495,7 +23515,7 @@ const Lazyload = {
23495
23515
  });
23496
23516
  }
23497
23517
  };
23498
- const version = "3.1.74";
23518
+ const version = "3.1.76";
23499
23519
  function install(app) {
23500
23520
  const components = [
23501
23521
  ActionSheet,
package/lib/zartui.js CHANGED
@@ -15383,9 +15383,10 @@
15383
15383
  canvas.height = _height;
15384
15384
  const ctx = canvas.getContext("2d");
15385
15385
  if (ctx) {
15386
- ctx.fillStyle = "transparent";
15387
- if (type === "image/jpeg") {
15386
+ const needWhiteBackground = type === "image/jpeg" || type === "image/jpg" || type === "image/bmp";
15387
+ if (needWhiteBackground) {
15388
15388
  ctx.fillStyle = "#fff";
15389
+ ctx.fillRect(0, 0, _width, _height);
15389
15390
  }
15390
15391
  ctx.drawImage(img, 0, 0, _width, _height);
15391
15392
  return Promise.resolve(canvas);
@@ -15468,13 +15469,14 @@
15468
15469
  }
15469
15470
  };
15470
15471
  var CompressOptions = class {
15471
- // 图片大小限制,单位kb
15472
- constructor(photoFileSizeLimit) {
15472
+ // 是否保持原始文件类型
15473
+ constructor(photoFileSizeLimit, keepFileType = false) {
15473
15474
  if (checkIsUndefinedOrNull(photoFileSizeLimit)) {
15474
15475
  this.photoFileSizeLimit = PHOTO_FILE_SIZE_LIMIT;
15475
15476
  } else {
15476
15477
  this.photoFileSizeLimit = photoFileSizeLimit;
15477
15478
  }
15479
+ this.keepFileType = keepFileType;
15478
15480
  }
15479
15481
  };
15480
15482
  var ImageProcessor = class {
@@ -15488,12 +15490,15 @@
15488
15490
  process() {
15489
15491
  const filename = this.file.name;
15490
15492
  const { lastModified } = this.file;
15491
- let fileType = this.file.type;
15492
- if (this.file.size > this.compressOptions.photoFileSizeLimit * 1024) {
15493
- fileType = "image/jpeg";
15494
- }
15495
- if (fileType === "image/gif") {
15496
- fileType = "image/png";
15493
+ const originalFileType = this.file.type;
15494
+ let fileType = originalFileType;
15495
+ if (!this.compressOptions.keepFileType) {
15496
+ if (this.file.size > this.compressOptions.photoFileSizeLimit * 1024) {
15497
+ fileType = "image/jpeg";
15498
+ }
15499
+ if (fileType === "image/gif") {
15500
+ fileType = "image/png";
15501
+ }
15497
15502
  }
15498
15503
  return file2Image(this.file).then((img) => {
15499
15504
  return resize(img, {
@@ -15505,7 +15510,13 @@
15505
15510
  const canvas = result;
15506
15511
  return yield renderWatermark(canvas, this.watermarkOptions);
15507
15512
  })).then((canvas) => {
15508
- const exportFilename = filename.replace(/\./g, "-") + ".jpg";
15513
+ let exportFilename;
15514
+ if (this.compressOptions.keepFileType) {
15515
+ const ext = this.getExtensionFromMimeType(fileType);
15516
+ exportFilename = filename.replace(/\.[^.]+$/, "") + "." + ext;
15517
+ } else {
15518
+ exportFilename = filename.replace(/\./g, "-") + ".jpg";
15519
+ }
15509
15520
  return this.compress(
15510
15521
  canvas,
15511
15522
  exportFilename,
@@ -15515,6 +15526,21 @@
15515
15526
  );
15516
15527
  });
15517
15528
  }
15529
+ /**
15530
+ * 根据 MIME 类型获取文件扩展名
15531
+ */
15532
+ getExtensionFromMimeType(mimeType) {
15533
+ const mimeToExt = {
15534
+ "image/jpeg": "jpg",
15535
+ "image/jpg": "jpg",
15536
+ "image/png": "png",
15537
+ "image/gif": "gif",
15538
+ "image/webp": "webp",
15539
+ "image/bmp": "bmp",
15540
+ "image/svg+xml": "svg"
15541
+ };
15542
+ return mimeToExt[mimeType] || "jpg";
15543
+ }
15518
15544
  compress(canvas, filename, lastModified, type, quality, lastCompressFileSize = -1) {
15519
15545
  return canvas2File(canvas, filename, lastModified, type, quality).then(
15520
15546
  (file) => {
@@ -17857,6 +17883,7 @@
17857
17883
  disabled: Boolean,
17858
17884
  showTitle: Boolean,
17859
17885
  showDownload: Boolean,
17886
+ downloadAction: Function,
17860
17887
  useFileNameAsLabel: Boolean,
17861
17888
  title: makeStringProp("添加附件"),
17862
17889
  mediaList: makeArrayProp(),
@@ -17866,6 +17893,11 @@
17866
17893
  maxImageFileSize: makeNumberProp(1024),
17867
17894
  // 单个文件大小限制(本单位为KB,默认最大1M)
17868
17895
  maxFileSize: makeNumberProp(FILE_SIZE_LIMIT * 1024),
17896
+ // 是否保持原始文件类型(不转换为jpg)
17897
+ keepFileType: {
17898
+ type: Boolean,
17899
+ default: false
17900
+ },
17869
17901
  /**
17870
17902
  * {
17871
17903
  * maxImageSideLength,
@@ -18173,10 +18205,22 @@
18173
18205
  }).finally(() => {
18174
18206
  });
18175
18207
  };
18208
+ const getExtensionFromMimeType = (mimeType) => {
18209
+ const mimeToExt = {
18210
+ "image/jpeg": "jpg",
18211
+ "image/jpg": "jpg",
18212
+ "image/png": "png",
18213
+ "image/gif": "gif",
18214
+ "image/webp": "webp",
18215
+ "image/bmp": "bmp",
18216
+ "image/svg+xml": "svg"
18217
+ };
18218
+ return mimeToExt[mimeType] || "jpg";
18219
+ };
18176
18220
  const transformImageFiles = (files) => {
18177
18221
  const promisesTodo = [];
18178
18222
  const resizeOptions = new ResizeOptions(props.maxImageSideLength);
18179
- const compressOptions = new CompressOptions(props.maxImageFileSize);
18223
+ const compressOptions = new CompressOptions(props.maxImageFileSize, props.keepFileType);
18180
18224
  for (let i = 0; i < files.length; i++) {
18181
18225
  const file = files[i];
18182
18226
  const watermarkEnabled = props.watermarkOptions && props.watermarkOptions.watermarkConfigString && checkWatermarkConfigSupported(props.watermarkOptions.watermarkConfigString);
@@ -18202,7 +18246,8 @@
18202
18246
  return Promise.resolve(null);
18203
18247
  }
18204
18248
  return file2DataURL$1(f).then((base64) => {
18205
- const uniqueFileName = getUniqueFileName(f, "jpg");
18249
+ const ext = props.keepFileType ? getExtensionFromMimeType(f.type) : "jpg";
18250
+ const uniqueFileName = getUniqueFileName(f, ext);
18206
18251
  const media = {
18207
18252
  showSrc: base64,
18208
18253
  type: "photo",
@@ -18548,6 +18593,7 @@
18548
18593
  url: image2.url || image2.showSrc || ""
18549
18594
  })),
18550
18595
  showDownload: props.showDownload,
18596
+ downloadAction: props.downloadAction,
18551
18597
  startPosition: imageIndex,
18552
18598
  closeable: true
18553
18599
  });
@@ -27557,7 +27603,7 @@
27557
27603
  });
27558
27604
  }
27559
27605
  };
27560
- const version = "3.1.74";
27606
+ const version = "3.1.76";
27561
27607
  function install(app) {
27562
27608
  const components = [
27563
27609
  ActionSheet,