@whitesev/utils 2.11.3 → 2.11.5
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.amd.js +54 -3
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +54 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +54 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +54 -3
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +54 -3
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +54 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +20 -0
- package/package.json +1 -1
- package/src/Utils.ts +73 -2
|
@@ -1620,6 +1620,26 @@ declare class Utils {
|
|
|
1620
1620
|
* @param timeout 超时时间,默认为`1500ms`
|
|
1621
1621
|
*/
|
|
1622
1622
|
hasWorkerCSP(timeout?: number): Promise<boolean>;
|
|
1623
|
+
/**
|
|
1624
|
+
* 计算两个坐标的直线距离
|
|
1625
|
+
* @param positionX 坐标x信息
|
|
1626
|
+
* @param positionY 坐标y信息
|
|
1627
|
+
* @param otherPositionX 坐标x信息
|
|
1628
|
+
* @param otherPositionY 坐标y信息
|
|
1629
|
+
*/
|
|
1630
|
+
calcPositionDistance(positionX: number | string, positionY: number | string, otherPositionX: number | string, otherPositionY: number | string): number;
|
|
1631
|
+
/**
|
|
1632
|
+
* 计算两个坐标的直线距离
|
|
1633
|
+
* @param position 坐标信息
|
|
1634
|
+
* @param otherPosition 坐标信息
|
|
1635
|
+
*/
|
|
1636
|
+
calcPositionDistance(position: {
|
|
1637
|
+
x: number | string;
|
|
1638
|
+
y: number | string;
|
|
1639
|
+
}, otherPosition: {
|
|
1640
|
+
x: number | string;
|
|
1641
|
+
y: number | string;
|
|
1642
|
+
}): number;
|
|
1623
1643
|
}
|
|
1624
1644
|
declare const utils: Utils;
|
|
1625
1645
|
export { utils as Utils };
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -2620,8 +2620,7 @@ class Utils {
|
|
|
2620
2620
|
}
|
|
2621
2621
|
async init() {
|
|
2622
2622
|
let copyStatus = false;
|
|
2623
|
-
|
|
2624
|
-
console.log(requestPermissionStatus);
|
|
2623
|
+
await this.requestClipboardPermission();
|
|
2625
2624
|
if (this.hasClipboard() && (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
2626
2625
|
try {
|
|
2627
2626
|
copyStatus = await this.copyDataByClipboard();
|
|
@@ -3959,6 +3958,78 @@ class Utils {
|
|
|
3959
3958
|
}
|
|
3960
3959
|
});
|
|
3961
3960
|
}
|
|
3961
|
+
/**
|
|
3962
|
+
* 计算两个坐标的直线距离
|
|
3963
|
+
* @param positionX 坐标x信息
|
|
3964
|
+
* @param positionY 坐标y信息
|
|
3965
|
+
* @param otherPositionX 坐标x信息
|
|
3966
|
+
* @param otherPositionY 坐标y信息
|
|
3967
|
+
*/
|
|
3968
|
+
calcPositionDistance(
|
|
3969
|
+
positionX: number | string,
|
|
3970
|
+
positionY: number | string,
|
|
3971
|
+
otherPositionX: number | string,
|
|
3972
|
+
otherPositionY: number | string
|
|
3973
|
+
): number;
|
|
3974
|
+
/**
|
|
3975
|
+
* 计算两个坐标的直线距离
|
|
3976
|
+
* @param position 坐标信息
|
|
3977
|
+
* @param otherPosition 坐标信息
|
|
3978
|
+
*/
|
|
3979
|
+
calcPositionDistance(
|
|
3980
|
+
position: { x: number | string; y: number | string },
|
|
3981
|
+
otherPosition: { x: number | string; y: number | string }
|
|
3982
|
+
): number;
|
|
3983
|
+
calcPositionDistance(...args: any[]) {
|
|
3984
|
+
let position = {
|
|
3985
|
+
x: 0,
|
|
3986
|
+
y: 0,
|
|
3987
|
+
};
|
|
3988
|
+
let otherPosition = {
|
|
3989
|
+
x: 0,
|
|
3990
|
+
y: 0,
|
|
3991
|
+
};
|
|
3992
|
+
if (typeof args[0] === "object" && args[0] != null && typeof args[1] === "object" && args[1] != null) {
|
|
3993
|
+
position = args[0];
|
|
3994
|
+
otherPosition = args[1];
|
|
3995
|
+
} else if (args.length === 4) {
|
|
3996
|
+
position = {
|
|
3997
|
+
x: args[0],
|
|
3998
|
+
y: args[1],
|
|
3999
|
+
};
|
|
4000
|
+
otherPosition = {
|
|
4001
|
+
x: args[2],
|
|
4002
|
+
y: args[3],
|
|
4003
|
+
};
|
|
4004
|
+
} else {
|
|
4005
|
+
throw new Error("Invalid arguments");
|
|
4006
|
+
}
|
|
4007
|
+
if (typeof position.x === "string") {
|
|
4008
|
+
position.x = Number(position.x);
|
|
4009
|
+
}
|
|
4010
|
+
if (isNaN(position.x)) {
|
|
4011
|
+
throw new Error(`Invalid x: ${position.x}`);
|
|
4012
|
+
}
|
|
4013
|
+
if (typeof position.y === "string") {
|
|
4014
|
+
position.y = Number(position.y);
|
|
4015
|
+
}
|
|
4016
|
+
if (isNaN(position.y)) {
|
|
4017
|
+
throw new Error(`Invalid y: ${position.y}`);
|
|
4018
|
+
}
|
|
4019
|
+
if (typeof otherPosition.x === "string") {
|
|
4020
|
+
otherPosition.x = Number(otherPosition.x);
|
|
4021
|
+
}
|
|
4022
|
+
if (isNaN(otherPosition.x)) {
|
|
4023
|
+
throw new Error(`Invalid x: ${otherPosition.x}`);
|
|
4024
|
+
}
|
|
4025
|
+
if (typeof otherPosition.y === "string") {
|
|
4026
|
+
otherPosition.y = Number(otherPosition.y);
|
|
4027
|
+
}
|
|
4028
|
+
if (isNaN(otherPosition.y)) {
|
|
4029
|
+
throw new Error(`Invalid y: ${otherPosition.y}`);
|
|
4030
|
+
}
|
|
4031
|
+
return Math.sqrt(Math.pow(otherPosition.x - position.x, 2) + Math.pow(otherPosition.y - position.y, 2));
|
|
4032
|
+
}
|
|
3962
4033
|
}
|
|
3963
4034
|
|
|
3964
4035
|
const utils = new Utils();
|