lyb-js 1.5.0 → 1.6.0
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/Browser/LibJsCopy.d.ts +5 -0
- package/Browser/LibJsCopy.js +22 -0
- package/README.md +10 -2
- package/libJs.d.ts +5 -0
- package/libJs.js +6 -0
- package/lyb.js +23 -1
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const fallbackCopy = (text) => {
|
|
2
|
+
const textarea = document.createElement("textarea");
|
|
3
|
+
textarea.value = text;
|
|
4
|
+
textarea.style.position = "fixed";
|
|
5
|
+
textarea.style.opacity = "0";
|
|
6
|
+
document.body.appendChild(textarea);
|
|
7
|
+
textarea.select();
|
|
8
|
+
document.execCommand("copy");
|
|
9
|
+
document.body.removeChild(textarea);
|
|
10
|
+
};
|
|
11
|
+
/** @description 复制文本到剪贴板
|
|
12
|
+
* @param text 要复制的文本
|
|
13
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCopy-复制文本到剪贴板
|
|
14
|
+
*/
|
|
15
|
+
export const libJsCopy = (text) => {
|
|
16
|
+
if (navigator.clipboard) {
|
|
17
|
+
navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
fallbackCopy(text);
|
|
21
|
+
}
|
|
22
|
+
};
|
package/README.md
CHANGED
|
@@ -81,6 +81,8 @@ console.log(t); //"string"
|
|
|
81
81
|
|
|
82
82
|
\- [LibJsObjToUrlParams-对象转Url参数](#LibJsObjToUrlParams-对象转Url参数)
|
|
83
83
|
|
|
84
|
+
\- [LibJsCopy-复制文本到剪贴板](#LibJsCopy-复制文本到剪贴板)
|
|
85
|
+
|
|
84
86
|
|
|
85
87
|
### Data-数据
|
|
86
88
|
|
|
@@ -264,6 +266,14 @@ libJsObjToParams({ name: "John", age: 30, active: true });
|
|
|
264
266
|
// "name=John&age=30&active=true"
|
|
265
267
|
```
|
|
266
268
|
|
|
269
|
+
### LibJsCopy-复制文本到剪贴板
|
|
270
|
+
|
|
271
|
+
> 内部做了兼容
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
libJsCopy("Hello World!")
|
|
275
|
+
```
|
|
276
|
+
|
|
267
277
|
## Data-数据
|
|
268
278
|
|
|
269
279
|
### LibJsChunkArray-数组拆分
|
|
@@ -601,8 +611,6 @@ $bus.off("stop");
|
|
|
601
611
|
```ts
|
|
602
612
|
import { LibJsClassObservable } from "@/utils/LibJsClassObservable";
|
|
603
613
|
|
|
604
|
-
export type WinTextType = "luck" | "win" | "reset";
|
|
605
|
-
|
|
606
614
|
interface Static {
|
|
607
615
|
/** 用户ID */
|
|
608
616
|
userID: number;
|
package/libJs.d.ts
CHANGED
|
@@ -57,6 +57,11 @@ export declare const Browser: {
|
|
|
57
57
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
|
|
58
58
|
*/
|
|
59
59
|
libJsObjToUrlParams: (params: Record<string, string | number | boolean>) => string;
|
|
60
|
+
/** @description 复制文本到剪贴板
|
|
61
|
+
* @param text 要复制的文本
|
|
62
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#libJsCopy-复制文本到剪贴板
|
|
63
|
+
*/
|
|
64
|
+
libJsCopy: (text: string) => void;
|
|
60
65
|
};
|
|
61
66
|
/** @description 数据相关方法 */
|
|
62
67
|
export declare const Data: {
|
package/libJs.js
CHANGED
|
@@ -41,6 +41,7 @@ import { LibJsEmitter } from "./Misc/LibJsEmitter";
|
|
|
41
41
|
import { LibJsLerp } from "./Math/LibJsLerp";
|
|
42
42
|
import { LibJsNormalizeInRange } from "./Math/LibJsNormalizeInRange";
|
|
43
43
|
import { LibJsClassObservable } from "./Misc/LibJsClassObservable";
|
|
44
|
+
import { libJsCopy } from "./Browser/LibJsCopy";
|
|
44
45
|
/** @description 基础方法 */
|
|
45
46
|
export const Base = {
|
|
46
47
|
/**
|
|
@@ -95,6 +96,11 @@ export const Browser = {
|
|
|
95
96
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
|
|
96
97
|
*/
|
|
97
98
|
libJsObjToUrlParams,
|
|
99
|
+
/** @description 复制文本到剪贴板
|
|
100
|
+
* @param text 要复制的文本
|
|
101
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#libJsCopy-复制文本到剪贴板
|
|
102
|
+
*/
|
|
103
|
+
libJsCopy,
|
|
98
104
|
};
|
|
99
105
|
/** @description 数据相关方法 */
|
|
100
106
|
export const Data = {
|
package/lyb.js
CHANGED
|
@@ -3490,6 +3490,23 @@ ${log3.label}:`, log3.value];
|
|
|
3490
3490
|
return v;
|
|
3491
3491
|
}
|
|
3492
3492
|
}
|
|
3493
|
+
const fallbackCopy = (text) => {
|
|
3494
|
+
const textarea = document.createElement("textarea");
|
|
3495
|
+
textarea.value = text;
|
|
3496
|
+
textarea.style.position = "fixed";
|
|
3497
|
+
textarea.style.opacity = "0";
|
|
3498
|
+
document.body.appendChild(textarea);
|
|
3499
|
+
textarea.select();
|
|
3500
|
+
document.execCommand("copy");
|
|
3501
|
+
document.body.removeChild(textarea);
|
|
3502
|
+
};
|
|
3503
|
+
const libJsCopy = (text) => {
|
|
3504
|
+
if (navigator.clipboard) {
|
|
3505
|
+
navigator.clipboard.writeText(text).catch(() => fallbackCopy(text));
|
|
3506
|
+
} else {
|
|
3507
|
+
fallbackCopy(text);
|
|
3508
|
+
}
|
|
3509
|
+
};
|
|
3493
3510
|
const Base = {
|
|
3494
3511
|
/**
|
|
3495
3512
|
* @description 返回数据类型
|
|
@@ -3541,7 +3558,12 @@ ${log3.label}:`, log3.value];
|
|
|
3541
3558
|
* @param params 对象参数
|
|
3542
3559
|
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
|
|
3543
3560
|
*/
|
|
3544
|
-
libJsObjToUrlParams
|
|
3561
|
+
libJsObjToUrlParams,
|
|
3562
|
+
/** @description 复制文本到剪贴板
|
|
3563
|
+
* @param text 要复制的文本
|
|
3564
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#libJsCopy-复制文本到剪贴板
|
|
3565
|
+
*/
|
|
3566
|
+
libJsCopy
|
|
3545
3567
|
};
|
|
3546
3568
|
const Data = {
|
|
3547
3569
|
/**
|