@cmstops/pro-compo 0.3.13 → 0.3.14

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.
@@ -6,6 +6,7 @@ import _sfc_main$4 from "../imageCrop/component.js";
6
6
  import _sfc_main$1 from "./components/card.js";
7
7
  import _sfc_main$2 from "./components/colorPalette.js";
8
8
  import { DEFAULT_BASE_API } from "../config.js";
9
+ import { getThemeColor } from "../utils/index.js";
9
10
  const _hoisted_1 = {
10
11
  key: 0,
11
12
  class: "star"
@@ -279,9 +280,27 @@ const _sfc_main = defineComponent({
279
280
  styleData.value.data = temp;
280
281
  } else if (thumbBannerModel.value === "banner") {
281
282
  styleData.value.banner_url = data[0].url;
283
+ const getColors = getThemeColor(BASE_API, data[0].url);
284
+ getColors.then((themes) => {
285
+ styleData.value.banner_colorList = JSON.parse(JSON.stringify(themes));
286
+ styleData.value.banner_theme_color = `rgb(${themes[1]})`;
287
+ callback(styleData.value);
288
+ }).catch((e) => {
289
+ styleData.value.banner_theme_color = `rgb(255, 255, 255)`;
290
+ callback(styleData.value);
291
+ });
282
292
  } else {
283
293
  styleData.value.top_image_url = data[0].url;
284
294
  styleData.value.pc_banner_url = data[0].url;
295
+ const getColors = getThemeColor(BASE_API, data[0].url);
296
+ getColors.then((themes) => {
297
+ styleData.value.top_colorList = JSON.parse(JSON.stringify(themes));
298
+ styleData.value.top_theme_color = `rgb(${themes[1]})`;
299
+ callback(styleData.value);
300
+ }).catch((e) => {
301
+ styleData.value.top_theme_color = `rgb(255, 255, 255)`;
302
+ callback(styleData.value);
303
+ });
285
304
  }
286
305
  callback(styleData.value);
287
306
  dialogMediaSelectionShow.value = false;
@@ -11,3 +11,5 @@ export declare function replaceSuffix(str: string, insert: string): string;
11
11
  export declare const noCoverText: (item: any) => any;
12
12
  export declare const timeFormat: (value: any) => string;
13
13
  export declare const validateForm: (formRef: any) => Promise<unknown>;
14
+ export declare function getRealUrl(BASE_API: string, url: string): Promise<unknown>;
15
+ export declare function getThemeColor(BASE_API: string, src: string): Promise<unknown>;
package/es/utils/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import dayjs from "dayjs";
2
+ import ColorThief from "colorthief";
3
+ import { getFileRealUrl } from "../imageCrop/script/api.js";
4
+ import { DEFAULT_UPLOAD_URL } from "../config.js";
2
5
  const dateYYYYDDMMHHmm = (date) => {
3
6
  if (!date)
4
7
  return "--";
@@ -60,4 +63,48 @@ const validateForm = (formRef) => {
60
63
  }
61
64
  });
62
65
  };
63
- export { dateYYYYDDMMHHmm, generateUUID, noCoverText, replaceSuffix, timeFormat, to, validateForm };
66
+ function getRealUrl(BASE_API, url) {
67
+ return new Promise((resove, reject) => {
68
+ try {
69
+ const flag = !url.includes("/poplar/v2");
70
+ const cape = url.includes("cape/v1/upload");
71
+ const extented = !url.includes(BASE_API) && !url.includes(DEFAULT_UPLOAD_URL);
72
+ if (flag || extented || cape) {
73
+ resove(url);
74
+ } else {
75
+ getFileRealUrl(BASE_API, url).then((res) => {
76
+ resove(res.message);
77
+ });
78
+ }
79
+ } catch (e) {
80
+ reject(e);
81
+ }
82
+ });
83
+ }
84
+ function getThemeColor(BASE_API, src) {
85
+ return new Promise((resolve, reject) => {
86
+ const getUrl = getRealUrl(BASE_API, src);
87
+ getUrl.then((url) => {
88
+ const colorThief = new ColorThief();
89
+ const img = document.createElement("img");
90
+ img.crossOrigin = "Anonymous";
91
+ img.setAttribute("src", `${url}?t=${+new Date()}`);
92
+ img.onload = () => {
93
+ let themeColors = [];
94
+ const getResult = colorThief.getPalette(img);
95
+ if (getResult) {
96
+ themeColors = getResult.slice(0, 6);
97
+ } else {
98
+ themeColors = [[255, 255, 255]];
99
+ }
100
+ resolve(themeColors);
101
+ };
102
+ img.onerror = (e) => {
103
+ reject(e);
104
+ };
105
+ }).catch((e) => {
106
+ reject(e);
107
+ });
108
+ });
109
+ }
110
+ export { dateYYYYDDMMHHmm, generateUUID, getRealUrl, getThemeColor, noCoverText, replaceSuffix, timeFormat, to, validateForm };
@@ -7,6 +7,7 @@ var component$1 = require("../imageCrop/component.js");
7
7
  var card = require("./components/card.js");
8
8
  var colorPalette = require("./components/colorPalette.js");
9
9
  var config = require("../config.js");
10
+ var index = require("../utils/index.js");
10
11
  const _hoisted_1 = {
11
12
  key: 0,
12
13
  class: "star"
@@ -236,14 +237,14 @@ const _sfc_main = vue.defineComponent({
236
237
  tempThumbFiles.value.push(data);
237
238
  submitCallback(tempThumbFiles.value);
238
239
  };
239
- const changeThumbType = (type, index) => {
240
+ const changeThumbType = (type, index2) => {
240
241
  tempThumbFiles.value = [];
241
242
  thumbBannerModel.value = type;
242
- thumbOptionIndex.value = index;
243
+ thumbOptionIndex.value = index2;
243
244
  };
244
- const openDialogMediaSelection = (type, index) => {
245
+ const openDialogMediaSelection = (type, index2) => {
245
246
  thumbBannerModel.value = type || "thumb";
246
- thumbOptionIndex.value = index || 0;
247
+ thumbOptionIndex.value = index2 || 0;
247
248
  dialogMediaSelectionShow.value = true;
248
249
  };
249
250
  const docSeriesShowTopThemeColor = vue.computed(() => {
@@ -280,9 +281,27 @@ const _sfc_main = vue.defineComponent({
280
281
  styleData.value.data = temp;
281
282
  } else if (thumbBannerModel.value === "banner") {
282
283
  styleData.value.banner_url = data[0].url;
284
+ const getColors = index.getThemeColor(BASE_API, data[0].url);
285
+ getColors.then((themes) => {
286
+ styleData.value.banner_colorList = JSON.parse(JSON.stringify(themes));
287
+ styleData.value.banner_theme_color = `rgb(${themes[1]})`;
288
+ callback(styleData.value);
289
+ }).catch((e) => {
290
+ styleData.value.banner_theme_color = `rgb(255, 255, 255)`;
291
+ callback(styleData.value);
292
+ });
283
293
  } else {
284
294
  styleData.value.top_image_url = data[0].url;
285
295
  styleData.value.pc_banner_url = data[0].url;
296
+ const getColors = index.getThemeColor(BASE_API, data[0].url);
297
+ getColors.then((themes) => {
298
+ styleData.value.top_colorList = JSON.parse(JSON.stringify(themes));
299
+ styleData.value.top_theme_color = `rgb(${themes[1]})`;
300
+ callback(styleData.value);
301
+ }).catch((e) => {
302
+ styleData.value.top_theme_color = `rgb(255, 255, 255)`;
303
+ callback(styleData.value);
304
+ });
286
305
  }
287
306
  callback(styleData.value);
288
307
  dialogMediaSelectionShow.value = false;
@@ -390,40 +409,40 @@ const _sfc_main = vue.defineComponent({
390
409
  ], 4)) : vue.createCommentVNode("v-if", true),
391
410
  vue.createElementVNode("div", _hoisted_3, [
392
411
  ["thumbs"].includes(_ctx.mode) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_4, [
393
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(thumbsLengthList.value, (item, index) => {
412
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(thumbsLengthList.value, (item, index2) => {
394
413
  return vue.openBlock(), vue.createBlock(card, {
395
- key: index,
396
- id: `thumb-card-${index}`,
397
- data: thumbList.value[index],
398
- "onUpdate:data": ($event) => thumbList.value[index] = $event,
414
+ key: index2,
415
+ id: `thumb-card-${index2}`,
416
+ data: thumbList.value[index2],
417
+ "onUpdate:data": ($event) => thumbList.value[index2] = $event,
399
418
  parentRef: selectThumbRef.value,
400
- idx: index,
419
+ idx: index2,
401
420
  "preview-list": previewList.value,
402
421
  "thumb-model": "thumb",
403
422
  onFileForShowThumb: fileForShowThumb,
404
423
  onChangeThumbType: changeThumbType,
405
424
  onUploadLocal: _cache[0] || (_cache[0] = (cb) => _ctx.$emit("upload", cb)),
406
- onOpen: ($event) => openDialogMediaSelection($event, index)
425
+ onOpen: ($event) => openDialogMediaSelection($event, index2)
407
426
  }, null, 8, ["id", "data", "onUpdate:data", "parentRef", "idx", "preview-list", "onOpen"]);
408
427
  }), 128))
409
428
  ])) : currentModel.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 1 }, [
410
429
  vue.createCommentVNode(" \u5C01\u9762\u56FEcard "),
411
430
  vue.createElementVNode("div", _hoisted_5, [
412
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(currentModel.value.maxLength, (item, index) => {
431
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(currentModel.value.maxLength, (item, index2) => {
413
432
  return vue.openBlock(), vue.createBlock(card, {
414
- key: index,
415
- id: `thumb-card-${index}`,
416
- data: thumbList.value[index],
417
- "onUpdate:data": ($event) => thumbList.value[index] = $event,
433
+ key: index2,
434
+ id: `thumb-card-${index2}`,
435
+ data: thumbList.value[index2],
436
+ "onUpdate:data": ($event) => thumbList.value[index2] = $event,
418
437
  parentRef: selectThumbRef.value,
419
438
  model: model.value,
420
- idx: index,
439
+ idx: index2,
421
440
  "preview-list": previewList.value,
422
441
  "thumb-model": "thumb",
423
442
  onFileForShowThumb: fileForShowThumb,
424
443
  onChangeThumbType: changeThumbType,
425
444
  onUploadLocal: _cache[1] || (_cache[1] = (cb) => _ctx.$emit("upload", cb)),
426
- onOpen: ($event) => openDialogMediaSelection($event, index)
445
+ onOpen: ($event) => openDialogMediaSelection($event, index2)
427
446
  }, null, 8, ["id", "data", "onUpdate:data", "parentRef", "model", "idx", "preview-list", "onOpen"]);
428
447
  }), 128))
429
448
  ])
@@ -443,9 +462,9 @@ const _sfc_main = vue.defineComponent({
443
462
  onChange: modelChange
444
463
  }, {
445
464
  default: vue.withCtx(() => [
446
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(modelList.value, (item, index) => {
465
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(modelList.value, (item, index2) => {
447
466
  return vue.openBlock(), vue.createBlock(vue.unref(webVue.Radio), {
448
- key: index,
467
+ key: index2,
449
468
  value: item.value
450
469
  }, {
451
470
  default: vue.withCtx(() => [
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
3
  var dayjs = require("dayjs");
4
+ var ColorThief = require("colorthief");
5
+ var api = require("../imageCrop/script/api.js");
6
+ var config = require("../config.js");
4
7
  function _interopDefaultLegacy(e) {
5
8
  return e && typeof e === "object" && "default" in e ? e : { "default": e };
6
9
  }
7
10
  var dayjs__default = /* @__PURE__ */ _interopDefaultLegacy(dayjs);
11
+ var ColorThief__default = /* @__PURE__ */ _interopDefaultLegacy(ColorThief);
8
12
  const dateYYYYDDMMHHmm = (date) => {
9
13
  if (!date)
10
14
  return "--";
@@ -66,8 +70,54 @@ const validateForm = (formRef) => {
66
70
  }
67
71
  });
68
72
  };
73
+ function getRealUrl(BASE_API, url) {
74
+ return new Promise((resove, reject) => {
75
+ try {
76
+ const flag = !url.includes("/poplar/v2");
77
+ const cape = url.includes("cape/v1/upload");
78
+ const extented = !url.includes(BASE_API) && !url.includes(config.DEFAULT_UPLOAD_URL);
79
+ if (flag || extented || cape) {
80
+ resove(url);
81
+ } else {
82
+ api.getFileRealUrl(BASE_API, url).then((res) => {
83
+ resove(res.message);
84
+ });
85
+ }
86
+ } catch (e) {
87
+ reject(e);
88
+ }
89
+ });
90
+ }
91
+ function getThemeColor(BASE_API, src) {
92
+ return new Promise((resolve, reject) => {
93
+ const getUrl = getRealUrl(BASE_API, src);
94
+ getUrl.then((url) => {
95
+ const colorThief = new ColorThief__default["default"]();
96
+ const img = document.createElement("img");
97
+ img.crossOrigin = "Anonymous";
98
+ img.setAttribute("src", `${url}?t=${+new Date()}`);
99
+ img.onload = () => {
100
+ let themeColors = [];
101
+ const getResult = colorThief.getPalette(img);
102
+ if (getResult) {
103
+ themeColors = getResult.slice(0, 6);
104
+ } else {
105
+ themeColors = [[255, 255, 255]];
106
+ }
107
+ resolve(themeColors);
108
+ };
109
+ img.onerror = (e) => {
110
+ reject(e);
111
+ };
112
+ }).catch((e) => {
113
+ reject(e);
114
+ });
115
+ });
116
+ }
69
117
  exports.dateYYYYDDMMHHmm = dateYYYYDDMMHHmm;
70
118
  exports.generateUUID = generateUUID;
119
+ exports.getRealUrl = getRealUrl;
120
+ exports.getThemeColor = getThemeColor;
71
121
  exports.noCoverText = noCoverText;
72
122
  exports.replaceSuffix = replaceSuffix;
73
123
  exports.timeFormat = timeFormat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmstops/pro-compo",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vue",