lyb-js 1.5.0 → 1.6.1

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.
@@ -0,0 +1,5 @@
1
+ /** @description 复制文本到剪贴板
2
+ * @param text 要复制的文本
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCopy-复制文本到剪贴板
4
+ */
5
+ export declare const libJsCopy: (text: string) => void;
@@ -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
+ };
@@ -1,4 +1,4 @@
1
1
  /** @description 获取浏览器地址栏参数
2
2
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
3
3
  */
4
- export declare const libJsPathParams: () => Record<string, string>;
4
+ export declare const libJsPathParams: (path?: string) => Record<string, string>;
@@ -1,8 +1,8 @@
1
1
  /** @description 获取浏览器地址栏参数
2
2
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
3
3
  */
4
- export const libJsPathParams = () => {
5
- const v = location.href;
4
+ export const libJsPathParams = (path) => {
5
+ const v = path || location.href;
6
6
  const url = v.split("?")[1];
7
7
  if (!url)
8
8
  return {};
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
@@ -39,7 +39,7 @@ export declare const Browser: {
39
39
  /** @description 获取浏览器地址栏参数
40
40
  * @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
41
41
  */
42
- libJsPathParams: () => Record<string, string>;
42
+ libJsPathParams: (path?: string) => Record<string, string>;
43
43
  /** @description 动态设置网站标题及图标
44
44
  * @param title 网站标题
45
45
  * @param url 网站图标地址
@@ -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
@@ -86,8 +86,8 @@ ${log3.label}:`, log3.value];
86
86
  const isTabletAspectRatio = aspectRatio >= 1.3 && aspectRatio <= 1.6;
87
87
  return isTabletUserAgent || isTabletWidth && isTabletAspectRatio;
88
88
  };
89
- const libJsPathParams = () => {
90
- const v = location.href;
89
+ const libJsPathParams = (path) => {
90
+ const v = path || location.href;
91
91
  const url = v.split("?")[1];
92
92
  if (!url)
93
93
  return {};
@@ -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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lyb-js",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "自用JS方法库",
5
5
  "license": "ISC",
6
6
  "type": "module",