vue-editify 0.0.1 → 0.0.12

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/editify.es.js CHANGED
@@ -1322,6 +1322,98 @@ const file$1 = {
1322
1322
  return new File([u8arr], fileName, {
1323
1323
  type: mime
1324
1324
  });
1325
+ },
1326
+ /**
1327
+ * 图片压缩方法
1328
+ * @param {*} file 需要压缩的图片File文件
1329
+ * @param {*} opts 压缩参数
1330
+ */
1331
+ compressImage(file2, opts) {
1332
+ const options = {
1333
+ //压缩图片的宽,单位px,如果不设置默认为原图宽
1334
+ width: null,
1335
+ //压缩图片质量,默认为原图的0.8
1336
+ quality: 0.8,
1337
+ //图片类型,jpeg或者webp,默认为jpeg
1338
+ mimeType: "jpeg",
1339
+ //压缩后的最大值,单位kb,默认为0表示不设置此值
1340
+ maxSize: 0,
1341
+ //小于该大小的图片不进行压缩,单位kb,默认为0表示任何图片都要压缩
1342
+ minSize: 0
1343
+ };
1344
+ if (common$1.isObject(opts)) {
1345
+ if (number$1.isNumber(opts.width)) {
1346
+ options.width = opts.width;
1347
+ }
1348
+ if (number$1.isNumber(opts.quality) && opts.quality >= 0 && opts.quality <= 1) {
1349
+ options.quality = opts.quality;
1350
+ }
1351
+ if (opts.mimeType == "jpeg" || opts.mimeType == "webp") {
1352
+ options.mimeType = opts.mimeType;
1353
+ }
1354
+ if (number$1.isNumber(opts.maxSize)) {
1355
+ options.maxSize = opts.maxSize;
1356
+ }
1357
+ if (number$1.isNumber(opts.minSize)) {
1358
+ options.minSize = opts.minSize;
1359
+ }
1360
+ }
1361
+ const createFile = (canvas, fileName, quality) => {
1362
+ let url2 = canvas.toDataURL("image/" + options.mimeType, quality);
1363
+ let file3 = this.dataBase64toFile(url2, fileName);
1364
+ if (options.maxSize > 0 && file3.size > options.maxSize * 1024) {
1365
+ quality = quality <= 0 ? 0 : Number((quality - 0.01).toFixed(2));
1366
+ const res = createFile(canvas, fileName, quality);
1367
+ url2 = res.url;
1368
+ file3 = res.file;
1369
+ quality = res.quality;
1370
+ }
1371
+ return {
1372
+ file: file3,
1373
+ url: url2,
1374
+ quality
1375
+ };
1376
+ };
1377
+ return new Promise((resolve, reject) => {
1378
+ let reader = new FileReader();
1379
+ reader.readAsDataURL(file2);
1380
+ reader.onload = () => {
1381
+ let url2 = reader.result;
1382
+ let img = new Image();
1383
+ img.src = url2;
1384
+ img.onload = () => {
1385
+ if (options.minSize > 0 && file2.size <= options.minSize * 1024) {
1386
+ resolve({
1387
+ file: file2,
1388
+ url: url2,
1389
+ quality: 1,
1390
+ width: img.width,
1391
+ height: img.height
1392
+ });
1393
+ return;
1394
+ }
1395
+ let canvas = document.createElement("canvas");
1396
+ let context = canvas.getContext("2d");
1397
+ canvas.width = options.width || img.width;
1398
+ canvas.height = options.width ? options.width / (img.width / img.height) : img.height;
1399
+ context.drawImage(img, 0, 0, canvas.width, canvas.height);
1400
+ let index = file2.name.lastIndexOf(".");
1401
+ const fileName = file2.name.substring(0, index) + "." + options.mimeType;
1402
+ let res = createFile(canvas, fileName, options.quality);
1403
+ resolve({
1404
+ ...res,
1405
+ width: canvas.width,
1406
+ height: canvas.height
1407
+ });
1408
+ };
1409
+ img.onerror = () => {
1410
+ reject(new Error("Failed to load image file"));
1411
+ };
1412
+ };
1413
+ reader.onerror = () => {
1414
+ reject(new Error("Failed to load image file"));
1415
+ };
1416
+ });
1325
1417
  }
1326
1418
  };
1327
1419
  const platform$1 = {
@@ -6081,6 +6173,98 @@ const file = {
6081
6173
  return new File([u8arr], fileName, {
6082
6174
  type: mime
6083
6175
  });
6176
+ },
6177
+ /**
6178
+ * 图片压缩方法
6179
+ * @param {*} file 需要压缩的图片File文件
6180
+ * @param {*} opts 压缩参数
6181
+ */
6182
+ compressImage(file2, opts) {
6183
+ const options = {
6184
+ //压缩图片的宽,单位px,如果不设置默认为原图宽
6185
+ width: null,
6186
+ //压缩图片质量,默认为原图的0.8
6187
+ quality: 0.8,
6188
+ //图片类型,jpeg或者webp,默认为jpeg
6189
+ mimeType: "jpeg",
6190
+ //压缩后的最大值,单位kb,默认为0表示不设置此值
6191
+ maxSize: 0,
6192
+ //小于该大小的图片不进行压缩,单位kb,默认为0表示任何图片都要压缩
6193
+ minSize: 0
6194
+ };
6195
+ if (common.isObject(opts)) {
6196
+ if (number.isNumber(opts.width)) {
6197
+ options.width = opts.width;
6198
+ }
6199
+ if (number.isNumber(opts.quality) && opts.quality >= 0 && opts.quality <= 1) {
6200
+ options.quality = opts.quality;
6201
+ }
6202
+ if (opts.mimeType == "jpeg" || opts.mimeType == "webp") {
6203
+ options.mimeType = opts.mimeType;
6204
+ }
6205
+ if (number.isNumber(opts.maxSize)) {
6206
+ options.maxSize = opts.maxSize;
6207
+ }
6208
+ if (number.isNumber(opts.minSize)) {
6209
+ options.minSize = opts.minSize;
6210
+ }
6211
+ }
6212
+ const createFile = (canvas, fileName, quality) => {
6213
+ let url2 = canvas.toDataURL("image/" + options.mimeType, quality);
6214
+ let file3 = this.dataBase64toFile(url2, fileName);
6215
+ if (options.maxSize > 0 && file3.size > options.maxSize * 1024) {
6216
+ quality = quality <= 0 ? 0 : Number((quality - 0.01).toFixed(2));
6217
+ const res = createFile(canvas, fileName, quality);
6218
+ url2 = res.url;
6219
+ file3 = res.file;
6220
+ quality = res.quality;
6221
+ }
6222
+ return {
6223
+ file: file3,
6224
+ url: url2,
6225
+ quality
6226
+ };
6227
+ };
6228
+ return new Promise((resolve, reject) => {
6229
+ let reader = new FileReader();
6230
+ reader.readAsDataURL(file2);
6231
+ reader.onload = () => {
6232
+ let url2 = reader.result;
6233
+ let img = new Image();
6234
+ img.src = url2;
6235
+ img.onload = () => {
6236
+ if (options.minSize > 0 && file2.size <= options.minSize * 1024) {
6237
+ resolve({
6238
+ file: file2,
6239
+ url: url2,
6240
+ quality: 1,
6241
+ width: img.width,
6242
+ height: img.height
6243
+ });
6244
+ return;
6245
+ }
6246
+ let canvas = document.createElement("canvas");
6247
+ let context = canvas.getContext("2d");
6248
+ canvas.width = options.width || img.width;
6249
+ canvas.height = options.width ? options.width / (img.width / img.height) : img.height;
6250
+ context.drawImage(img, 0, 0, canvas.width, canvas.height);
6251
+ let index = file2.name.lastIndexOf(".");
6252
+ const fileName = file2.name.substring(0, index) + "." + options.mimeType;
6253
+ let res = createFile(canvas, fileName, options.quality);
6254
+ resolve({
6255
+ ...res,
6256
+ width: canvas.width,
6257
+ height: canvas.height
6258
+ });
6259
+ };
6260
+ img.onerror = () => {
6261
+ reject(new Error("Failed to load image file"));
6262
+ };
6263
+ };
6264
+ reader.onerror = () => {
6265
+ reject(new Error("Failed to load image file"));
6266
+ };
6267
+ });
6084
6268
  }
6085
6269
  };
6086
6270
  const platform = {
@@ -19562,7 +19746,7 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
19562
19746
  ]);
19563
19747
  }
19564
19748
  const InsertTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2], ["__scopeId", "data-v-0277a84c"]]);
19565
- const Menu_vue_vue_type_style_index_0_scoped_01d538d0_lang = "";
19749
+ const Menu_vue_vue_type_style_index_0_scoped_4c7850ff_lang = "";
19566
19750
  const _sfc_main$1 = {
19567
19751
  name: "Menu",
19568
19752
  props: {
@@ -20481,57 +20665,59 @@ const _sfc_main$1 = {
20481
20665
  }
20482
20666
  if (obj.common.isObject(this.$parent.config.extends)) {
20483
20667
  const configuration = this.$parent.config.extends[this.name];
20484
- return h(
20485
- Button,
20486
- {
20487
- ...props,
20488
- ref: "btn",
20489
- type: configuration.type || "default",
20490
- title: configuration.title || "",
20491
- leftBorder: configuration.leftBorder || false,
20492
- rightBorder: configuration.rightBorder || false,
20493
- disabled: configuration.disabled || this.disabled || this.$parent.disabled,
20494
- hideScroll: configuration.hideScroll || false,
20495
- active: configuration.active || false,
20496
- selectConfig: {
20497
- width: configuration.width,
20498
- maxHeight: configuration.maxHeight,
20499
- options: configuration.options
20500
- },
20501
- displayConfig: {
20502
- width: configuration.width,
20503
- maxHeight: configuration.maxHeight,
20504
- value: configuration.value,
20505
- options: configuration.options
20506
- },
20507
- color: this.$parent.color,
20508
- onLayerShow: () => {
20509
- if (typeof configuration.onLayerShow == "function") {
20510
- configuration.onLayerShow.apply(this.$parent.$parent, [this.name, this.$refs.btn]);
20511
- }
20512
- },
20513
- onLayerShown: () => {
20514
- if (typeof configuration.onLayerShown == "function") {
20515
- configuration.onLayerShown.apply(this.$parent.$parent, [this.name, this.$refs.btn]);
20516
- }
20517
- },
20518
- onLayerHidden: () => {
20519
- if (typeof configuration.onLayerHidden == "function") {
20520
- configuration.onLayerHidden.apply(this.$parent.$parent, [this.name, this.$refs.btn]);
20668
+ if (configuration) {
20669
+ return h(
20670
+ Button,
20671
+ {
20672
+ ...props,
20673
+ ref: "btn",
20674
+ type: configuration.type || "default",
20675
+ title: configuration.title || "",
20676
+ leftBorder: configuration.leftBorder || false,
20677
+ rightBorder: configuration.rightBorder || false,
20678
+ disabled: configuration.disabled || this.disabled || this.$parent.disabled,
20679
+ hideScroll: configuration.hideScroll || false,
20680
+ active: configuration.active || false,
20681
+ selectConfig: {
20682
+ width: configuration.width,
20683
+ maxHeight: configuration.maxHeight,
20684
+ options: configuration.options
20685
+ },
20686
+ displayConfig: {
20687
+ width: configuration.width,
20688
+ maxHeight: configuration.maxHeight,
20689
+ value: configuration.value,
20690
+ options: configuration.options
20691
+ },
20692
+ color: this.$parent.color,
20693
+ onLayerShow: () => {
20694
+ if (typeof configuration.onLayerShow == "function") {
20695
+ configuration.onLayerShow.apply(this.$parent.$parent, [this.name, this.$refs.btn]);
20696
+ }
20697
+ },
20698
+ onLayerShown: () => {
20699
+ if (typeof configuration.onLayerShown == "function") {
20700
+ configuration.onLayerShown.apply(this.$parent.$parent, [this.name, this.$refs.btn]);
20701
+ }
20702
+ },
20703
+ onLayerHidden: () => {
20704
+ if (typeof configuration.onLayerHidden == "function") {
20705
+ configuration.onLayerHidden.apply(this.$parent.$parent, [this.name, this.$refs.btn]);
20706
+ }
20707
+ },
20708
+ onOperate: (name, val) => {
20709
+ if (typeof configuration.onOperate == "function") {
20710
+ configuration.onOperate.apply(this.$parent.$parent, [name, val, this.$refs.btn]);
20711
+ }
20521
20712
  }
20522
20713
  },
20523
- onOperate: (name, val) => {
20524
- if (typeof configuration.onOperate == "function") {
20525
- configuration.onOperate.apply(this.$parent.$parent, [name, val, this.$refs.btn]);
20526
- }
20714
+ {
20715
+ default: configuration.default || null,
20716
+ layer: configuration.layer || null,
20717
+ option: configuration.option || null
20527
20718
  }
20528
- },
20529
- {
20530
- default: configuration.default || null,
20531
- layer: configuration.layer || null,
20532
- option: configuration.option || null
20533
- }
20534
- );
20719
+ );
20720
+ }
20535
20721
  }
20536
20722
  return null;
20537
20723
  }
@@ -20780,7 +20966,7 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
20780
20966
  }), 256))
20781
20967
  ], 14, _hoisted_1$1);
20782
20968
  }
20783
- const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-01d538d0"]]);
20969
+ const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-4c7850ff"]]);
20784
20970
  const Editify_vue_vue_type_style_index_0_scoped_be97ae51_lang = "";
20785
20971
  const _sfc_main = {
20786
20972
  name: "editify",
@@ -22439,7 +22625,7 @@ const i18n = (locale) => {
22439
22625
  return translations[locale][key];
22440
22626
  };
22441
22627
  };
22442
- const version = "0.0.1";
22628
+ const version = "0.0.11";
22443
22629
  const install = (app, props) => {
22444
22630
  const locale = (props ? props.locale : "zh_CN") || "zh_CN";
22445
22631
  app.provide("$editTrans", i18n(locale));