knt-shared 1.7.7 → 1.7.8

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.js CHANGED
@@ -9556,6 +9556,181 @@ const calcDiv = (a, b) => {
9556
9556
  const d = Number(b.toString().replace(".", ""));
9557
9557
  return calcMul(c / d, Math.pow(10, f - e));
9558
9558
  };
9559
+ function setObjToUrlParams(baseUrl, obj) {
9560
+ let parameters = "";
9561
+ for (const key in obj) {
9562
+ parameters += key + "=" + encodeURIComponent(obj[key]) + "&";
9563
+ }
9564
+ parameters = parameters.replace(/&$/, "");
9565
+ return /\?$/.test(baseUrl) ? baseUrl + parameters : baseUrl.replace(/\/?$/, "?") + parameters;
9566
+ }
9567
+ function openWindow(url, opt2) {
9568
+ const { target = "__blank", noopener = true, noreferrer = true } = opt2 || {};
9569
+ const feature = [];
9570
+ noopener && feature.push("noopener=yes");
9571
+ noreferrer && feature.push("noreferrer=yes");
9572
+ window.open(url, target, feature.join(","));
9573
+ }
9574
+ function dataURLtoBlob(base64Buf) {
9575
+ const arr = base64Buf.split(",");
9576
+ const typeItem = arr[0];
9577
+ const mime = typeItem.match(/:(.*?);/)[1];
9578
+ const bstr = window.atob(arr[1]);
9579
+ let n = bstr.length;
9580
+ const u8arr = new Uint8Array(n);
9581
+ while (n--) {
9582
+ u8arr[n] = bstr.charCodeAt(n);
9583
+ }
9584
+ return new Blob([u8arr], { type: mime });
9585
+ }
9586
+ function urlToBase64(url, mineType) {
9587
+ return new Promise((resolve, reject) => {
9588
+ let canvas = document.createElement("CANVAS");
9589
+ const ctx = canvas.getContext("2d");
9590
+ const img = new Image();
9591
+ img.crossOrigin = "anonymous";
9592
+ img.onload = function() {
9593
+ if (!canvas || !ctx) {
9594
+ return reject();
9595
+ }
9596
+ canvas.height = img.height;
9597
+ canvas.width = img.width;
9598
+ ctx.drawImage(img, 0, 0);
9599
+ const dataURL = canvas.toDataURL(mineType || "image/png");
9600
+ canvas = null;
9601
+ resolve(dataURL);
9602
+ };
9603
+ img.src = url;
9604
+ });
9605
+ }
9606
+ function downloadByOnlineUrl(url, filename, mime, bom) {
9607
+ urlToBase64(url).then((base64) => {
9608
+ downloadByBase64(base64, filename, mime, bom);
9609
+ });
9610
+ }
9611
+ function downloadByBase64(buf, filename, mime, bom) {
9612
+ const base64Buf = dataURLtoBlob(buf);
9613
+ downloadByData(base64Buf, filename, mime, bom);
9614
+ }
9615
+ function downloadByData(data, filename, mime, bom) {
9616
+ const blobData = typeof bom !== "undefined" ? [bom, data] : [data];
9617
+ const blob = new Blob(blobData, { type: mime || "application/octet-stream" });
9618
+ const blobURL = window.URL.createObjectURL(blob);
9619
+ const tempLink = document.createElement("a");
9620
+ tempLink.style.display = "none";
9621
+ tempLink.href = blobURL;
9622
+ tempLink.setAttribute("download", filename);
9623
+ if (typeof tempLink.download === "undefined") {
9624
+ tempLink.setAttribute("target", "_blank");
9625
+ }
9626
+ document.body.appendChild(tempLink);
9627
+ tempLink.click();
9628
+ document.body.removeChild(tempLink);
9629
+ window.URL.revokeObjectURL(blobURL);
9630
+ }
9631
+ function downloadByUrl({
9632
+ url,
9633
+ target = "_blank",
9634
+ fileName
9635
+ }) {
9636
+ const isChrome = window.navigator.userAgent.toLowerCase().indexOf("chrome") > -1;
9637
+ const isSafari = window.navigator.userAgent.toLowerCase().indexOf("safari") > -1;
9638
+ if (/(iP)/g.test(window.navigator.userAgent)) {
9639
+ console.error("Your browser does not support download!");
9640
+ return false;
9641
+ }
9642
+ if (isChrome || isSafari) {
9643
+ const link = document.createElement("a");
9644
+ link.href = url;
9645
+ link.target = target;
9646
+ if (link.download !== void 0) {
9647
+ link.download = fileName || url.substring(url.lastIndexOf("/") + 1, url.length);
9648
+ }
9649
+ if (document.createEvent) {
9650
+ const e = document.createEvent("MouseEvents");
9651
+ e.initEvent("click", true, true);
9652
+ link.dispatchEvent(e);
9653
+ return true;
9654
+ }
9655
+ }
9656
+ if (url.indexOf("?") === -1) {
9657
+ url += "?download";
9658
+ }
9659
+ openWindow(url, { target });
9660
+ return true;
9661
+ }
9662
+ function isHexColor(color) {
9663
+ const reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-f]{6})$/;
9664
+ return reg.test(color);
9665
+ }
9666
+ function rgbToHex(r, g, b) {
9667
+ const hex = (r << 16 | g << 8 | b).toString(16);
9668
+ return "#" + new Array(Math.abs(hex.length - 7)).join("0") + hex;
9669
+ }
9670
+ function hexToRGB(hex) {
9671
+ let sHex = hex.toLowerCase();
9672
+ if (isHexColor(hex)) {
9673
+ if (sHex.length === 4) {
9674
+ let sColorNew = "#";
9675
+ for (let i = 1; i < 4; i += 1) {
9676
+ sColorNew += sHex.slice(i, i + 1).concat(sHex.slice(i, i + 1));
9677
+ }
9678
+ sHex = sColorNew;
9679
+ }
9680
+ const sColorChange = [];
9681
+ for (let i = 1; i < 7; i += 2) {
9682
+ sColorChange.push(parseInt("0x" + sHex.slice(i, i + 2)));
9683
+ }
9684
+ return "RGB(" + sColorChange.join(",") + ")";
9685
+ }
9686
+ return sHex;
9687
+ }
9688
+ function colorIsDark(color) {
9689
+ if (!isHexColor(color)) return;
9690
+ const [r, g, b] = hexToRGB(color).replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",").map((item) => Number(item));
9691
+ return r * 0.299 + g * 0.578 + b * 0.114 < 192;
9692
+ }
9693
+ function darken(color, amount) {
9694
+ color = color.indexOf("#") >= 0 ? color.substring(1, color.length) : color;
9695
+ amount = Math.trunc(255 * amount / 100);
9696
+ return `#${subtractLight(color.substring(0, 2), amount)}${subtractLight(
9697
+ color.substring(2, 4),
9698
+ amount
9699
+ )}${subtractLight(color.substring(4, 6), amount)}`;
9700
+ }
9701
+ function lighten(color, amount) {
9702
+ color = color.indexOf("#") >= 0 ? color.substring(1, color.length) : color;
9703
+ amount = Math.trunc(255 * amount / 100);
9704
+ return `#${addLight(color.substring(0, 2), amount)}${addLight(
9705
+ color.substring(2, 4),
9706
+ amount
9707
+ )}${addLight(color.substring(4, 6), amount)}`;
9708
+ }
9709
+ function addLight(color, amount) {
9710
+ const cc = parseInt(color, 16) + amount;
9711
+ const c = cc > 255 ? 255 : cc;
9712
+ return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
9713
+ }
9714
+ function luminanace(r, g, b) {
9715
+ const a = [r, g, b].map((v) => {
9716
+ v /= 255;
9717
+ return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
9718
+ });
9719
+ return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
9720
+ }
9721
+ function contrast(rgb1, rgb2) {
9722
+ return (luminanace(~~rgb1[0], ~~rgb1[1], ~~rgb1[2]) + 0.05) / (luminanace(rgb2[0], rgb2[1], rgb2[2]) + 0.05);
9723
+ }
9724
+ function calculateBestTextColor(hexColor) {
9725
+ const rgbColor = hexToRGB(hexColor.substring(1));
9726
+ const contrastWithBlack = contrast(rgbColor.split(","), [0, 0, 0]);
9727
+ return contrastWithBlack >= 12 ? "#000000" : "#FFFFFF";
9728
+ }
9729
+ function subtractLight(color, amount) {
9730
+ const cc = parseInt(color, 16) - amount;
9731
+ const c = cc < 0 ? 0 : cc;
9732
+ return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
9733
+ }
9559
9734
  function useDebounce(value, delay = 300) {
9560
9735
  const debouncedValue = vue.ref(value.value);
9561
9736
  let timer = null;
@@ -9618,17 +9793,25 @@ exports.calcAdd = calcAdd;
9618
9793
  exports.calcDiv = calcDiv;
9619
9794
  exports.calcMul = calcMul;
9620
9795
  exports.calcSub = calcSub;
9796
+ exports.calculateBestTextColor = calculateBestTextColor;
9621
9797
  exports.classifyFiles = classifyFiles;
9622
9798
  exports.clearAllCache = clearAllCache;
9623
9799
  exports.clearApiCache = clearApiCache;
9800
+ exports.colorIsDark = colorIsDark;
9624
9801
  exports.compareObjects = compareObjects;
9625
9802
  exports.componentMap = componentMap;
9626
9803
  exports.copyToClipboard = copyToClipboard;
9627
9804
  exports.createFormSchema = createFormSchema;
9628
9805
  exports.createLoading = createLoading;
9629
9806
  exports.createTableColumns = createTableColumns;
9807
+ exports.darken = darken;
9808
+ exports.dataURLtoBlob = dataURLtoBlob;
9630
9809
  exports.debounce = debounce;
9631
9810
  exports.diffArrays = diffArrays;
9811
+ exports.downloadByBase64 = downloadByBase64;
9812
+ exports.downloadByData = downloadByData;
9813
+ exports.downloadByOnlineUrl = downloadByOnlineUrl;
9814
+ exports.downloadByUrl = downloadByUrl;
9632
9815
  exports.findAdded = findAdded;
9633
9816
  exports.findCascaderPath = findCascaderPath;
9634
9817
  exports.findDeleted = findDeleted;
@@ -9650,12 +9833,14 @@ exports.getLabelFromTreeData = getLabelFromTreeData;
9650
9833
  exports.getLabelsFromOptions = getLabelsFromOptions;
9651
9834
  exports.getLabelsFromTreeData = getLabelsFromTreeData;
9652
9835
  exports.getRenderer = getRenderer;
9836
+ exports.hexToRGB = hexToRGB;
9653
9837
  exports.isArray = isArray;
9654
9838
  exports.isBoolean = isBoolean;
9655
9839
  exports.isDef = isDef;
9656
9840
  exports.isEmpty = isEmpty;
9657
9841
  exports.isEmptyArray = isEmptyArray;
9658
9842
  exports.isFunction = isFunction;
9843
+ exports.isHexColor = isHexColor;
9659
9844
  exports.isImageFile = isImageFile;
9660
9845
  exports.isJSONStr = isJSONStr;
9661
9846
  exports.isNullOrUnDef = isNullOrUnDef;
@@ -9666,16 +9851,21 @@ exports.isValidEmail = isValidEmail;
9666
9851
  exports.isValidIdCard = isValidIdCard;
9667
9852
  exports.isValidPhone = isValidPhone;
9668
9853
  exports.isValidUrl = isValidUrl;
9854
+ exports.lighten = lighten;
9669
9855
  exports.mergeFormSchemas = mergeFormSchemas;
9670
9856
  exports.mergeTableColumns = mergeTableColumns;
9857
+ exports.openWindow = openWindow;
9671
9858
  exports.registerComponent = registerComponent;
9672
9859
  exports.rendererMap = rendererMap;
9860
+ exports.rgbToHex = rgbToHex;
9673
9861
  exports.safeToString = safeToString;
9862
+ exports.setObjToUrlParams = setObjToUrlParams;
9674
9863
  exports.throttle = throttle;
9675
9864
  exports.transFormUrlPath = transFormUrlPath;
9676
9865
  exports.transformBackUrl = transformBackUrl;
9677
9866
  exports.transformTree = transformTree;
9678
9867
  exports.transformUploadUrl = transformUploadUrl;
9868
+ exports.urlToBase64 = urlToBase64;
9679
9869
  exports.useApiRequest = useApiRequest;
9680
9870
  exports.useDebounce = useDebounce;
9681
9871
  exports.useDescription = useDescription;