qc-ui-lit 0.2.6 → 0.3.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.
@@ -0,0 +1,151 @@
1
+ import { r as e } from "../AMap/AMap.js";
2
+ import { LitElement as t, css as n, html as r } from "lit";
3
+ import { customElement as i, property as a, state as o } from "lit/decorators.js";
4
+ import { classMap as s } from "lit/directives/class-map.js";
5
+ //#region src/tools/clipboard/index.ts
6
+ async function c(e, t) {
7
+ try {
8
+ if (navigator.clipboard && window.isSecureContext) {
9
+ await navigator.clipboard.writeText(e), t?.onSuccess?.();
10
+ return;
11
+ }
12
+ let n = document.createElement("textarea");
13
+ n.value = e, n.style.cssText = "position:fixed;left:-9999px;top:-9999px;opacity:0", document.body.appendChild(n), n.focus(), n.select();
14
+ let r = document.execCommand("copy");
15
+ if (document.body.removeChild(n), r) t?.onSuccess?.();
16
+ else throw Error("execCommand(\"copy\") failed");
17
+ } catch (e) {
18
+ throw t?.onError?.(e), e;
19
+ }
20
+ }
21
+ async function l() {
22
+ if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.readText();
23
+ throw Error("Clipboard API not available");
24
+ }
25
+ var u = {
26
+ writeText: c,
27
+ readText: l
28
+ };
29
+ //#endregion
30
+ //#region src/tools/document/domSelect/index.ts
31
+ function d(e) {
32
+ return e ? typeof e == "string" ? document.querySelector(e) : e : null;
33
+ }
34
+ function f(e, t) {
35
+ if (e.nodeType === Node.TEXT_NODE) {
36
+ t.push(e);
37
+ return;
38
+ }
39
+ if (e.nodeType !== Node.ELEMENT_NODE) return;
40
+ let n = e;
41
+ if (n.tagName === "SLOT") {
42
+ n.assignedNodes({ flatten: !0 }).forEach((e) => f(e, t));
43
+ return;
44
+ }
45
+ Array.from(n.childNodes).forEach((e) => f(e, t));
46
+ }
47
+ function p(e) {
48
+ let t = d(e);
49
+ if (!t) return !1;
50
+ let n = window.getSelection();
51
+ if (!n) return !1;
52
+ n.removeAllRanges();
53
+ let r = [];
54
+ if (f(t, r), r.length === 0) {
55
+ let e = document.createRange();
56
+ return e.selectNodeContents(t), n.addRange(e), n.toString().length > 0;
57
+ }
58
+ let i = document.createRange(), a = r[0], o = r[r.length - 1];
59
+ return i.setStart(a, 0), i.setEnd(o, o.textContent?.length || 0), n.addRange(i), n.toString().length > 0;
60
+ }
61
+ function m() {
62
+ let e = window.getSelection();
63
+ e && e.removeAllRanges();
64
+ }
65
+ function h() {
66
+ let e = window.getSelection();
67
+ return e ? e.toString() : "";
68
+ }
69
+ function g() {
70
+ let e = window.getSelection();
71
+ return !!e && e.toString().length > 0;
72
+ }
73
+ function _(e) {
74
+ let t = d(e);
75
+ return t ? t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement ? (t.focus(), t.select(), !0) : p(t) : !1;
76
+ }
77
+ var v = {
78
+ select: p,
79
+ clear: m,
80
+ getText: h,
81
+ hasSelection: g,
82
+ selectInput: _
83
+ };
84
+ //#endregion
85
+ //#region src/tools/document/getDomText/index.ts
86
+ function y(e) {
87
+ if (console.log("🚀 ~ getNodeText ~ node.nodeType:", e.nodeType), e.nodeType === Node.TEXT_NODE) return e.textContent || "";
88
+ if (e.nodeType === Node.ELEMENT_NODE) {
89
+ let t = e;
90
+ return t.tagName === "SLOT" ? t.assignedNodes({ flatten: !0 }).map(y).join("") : Array.from(t.childNodes).map(y).join("");
91
+ }
92
+ return "";
93
+ }
94
+ function b(e) {
95
+ let t = typeof e == "string" ? document.querySelector(e) : e;
96
+ return t ? y(t).replace(/\s+/g, "") : "";
97
+ }
98
+ //#endregion
99
+ //#region src/components/Replicable/qc-replicable.ts
100
+ var x = class extends t {
101
+ constructor(...e) {
102
+ super(...e), this.success = !1, this.classes = {
103
+ "qc-replicable": !0,
104
+ "qc-replicable-success": !1
105
+ };
106
+ }
107
+ willUpdate(e) {
108
+ e.has("success") && (this.classes["qc-replicable-success"] = this.success);
109
+ }
110
+ addSuccessClass() {
111
+ this.success = !0, setTimeout(() => {
112
+ this.success = !1;
113
+ }, 800);
114
+ }
115
+ copy() {
116
+ if (!this.shadowRoot) return;
117
+ let e = this.shadowRoot.querySelector("slot"), t = b(e);
118
+ this.addSuccessClass(), u.writeText(t), v.select(e);
119
+ }
120
+ render() {
121
+ return r`<span class=${s(this.classes)} @click=${this.copy}>
122
+ <slot></slot>
123
+ </span>`;
124
+ }
125
+ static {
126
+ this.styles = n`
127
+ .qc-replicable {
128
+ cursor: copy;
129
+ user-select: auto;
130
+ position: relative;
131
+ }
132
+ .qc-replicable-success::after {
133
+ content: '文本已复制到剪切板';
134
+ display: block;
135
+ position: absolute;
136
+ top: 0%;
137
+ left: 50%;
138
+ color: #fff;
139
+ background-color: rgba(0, 0, 0, 0.5);
140
+ padding: 2px 4px;
141
+ border-radius: 4px;
142
+ transform: translate(-50%, -100%);
143
+ white-space: nowrap;
144
+ font-size: 12px;
145
+ }
146
+ `;
147
+ }
148
+ };
149
+ e([a({ type: Boolean })], x.prototype, "success", void 0), e([o()], x.prototype, "classes", void 0), x = e([i("qc-replicable")], x);
150
+ //#endregion
151
+ export { g as a, l as c, h as i, c as l, b as n, _ as o, m as r, p as s, x as t };
@@ -0,0 +1,18 @@
1
+ import { LitElement } from 'lit';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'qc-replicable': QCReplicable;
5
+ }
6
+ }
7
+ export declare class QCReplicable extends LitElement {
8
+ success: boolean;
9
+ classes: {
10
+ 'qc-replicable': boolean;
11
+ 'qc-replicable-success': boolean;
12
+ };
13
+ willUpdate(changedProperties: Map<string, any>): void;
14
+ addSuccessClass(): void;
15
+ copy(): void;
16
+ protected render(): import("lit-html").TemplateResult<1>;
17
+ static styles: import("lit").CSSResult;
18
+ }
@@ -3,3 +3,4 @@ export * from './AMap/a-map';
3
3
  export * from './ECharts/qc-ECharts';
4
4
  export * from './Resize/qc-resize';
5
5
  export * from './Button/qc-button';
6
+ export * from './Replicable/qc-replicable';
package/dist/index.js CHANGED
@@ -3,12 +3,11 @@ import { t as n } from "./components/Loading/Loading.js";
3
3
  import { t as r } from "./components/ECharts/ECharts.js";
4
4
  import { n as i, t as a } from "./components/Resize/Resize.js";
5
5
  import { t as o } from "./components/Button/Button.js";
6
- import { t as s } from "./tools/throttle/throttle.js";
7
- import { t as c } from "./tools/date/date.js";
8
- import { t as l } from "./tools/deepClone/deepClone.js";
9
- import { n as u, t as d } from "./tools/clipboard/clipboard.js";
10
- import { a as f, i as p, n as m, o as h, r as g, t as _ } from "./tools/fullscreen/fullscreen.js";
11
- import { a as v, i as y, n as b, r as x, t as S } from "./tools/domSelect/domSelect.js";
12
- import { n as C, t as w } from "./tools/EventBus/EventBus.js";
13
- import { t as T } from "./tools/changeCoordinate/changeCoordinate.js";
14
- export { t as AMap, r as EChartsElement, w as EventBus, T as MapCorrect, o as QCButton, c as QCDate, n as QCLoading, a as QCResize, S as clearSelection, C as createEventBus, i as debounce, l as deepClone, _ as enterFullscreen, m as exitFullscreen, g as getFullscreenElement, b as getSelectedText, x as hasSelection, p as isFullscreen, e as loadAMap, f as onFullscreenChange, d as readText, y as selectInputText, v as selectText, s as throttle, h as toggleFullscreen, u as writeText };
6
+ import { a as s, c, i as l, l as u, n as d, o as f, r as p, s as m, t as h } from "./components/Replicable/Replicable.js";
7
+ import { t as g } from "./tools/throttle/throttle.js";
8
+ import { t as _ } from "./tools/date/date.js";
9
+ import { t as v } from "./tools/deepClone/deepClone.js";
10
+ import { a as y, i as b, n as x, o as S, r as C, t as w } from "./tools/fullscreen/fullscreen.js";
11
+ import { n as T, t as E } from "./tools/EventBus/EventBus.js";
12
+ import { t as D } from "./tools/changeCoordinate/changeCoordinate.js";
13
+ export { t as AMap, r as EChartsElement, E as EventBus, D as MapCorrect, o as QCButton, _ as QCDate, n as QCLoading, h as QCReplicable, a as QCResize, p as clearSelection, T as createEventBus, i as debounce, v as deepClone, w as enterFullscreen, x as exitFullscreen, d as getDomText, C as getFullscreenElement, l as getSelectedText, s as hasSelection, b as isFullscreen, e as loadAMap, y as onFullscreenChange, c as readText, f as selectInputText, m as selectText, g as throttle, S as toggleFullscreen, u as writeText };
@@ -1,6 +1,6 @@
1
1
  export type SelectTarget = string | HTMLElement | null | undefined;
2
2
  /**
3
- * 选中元素内的所有文本
3
+ * 选中元素内的所有文本(支持 slot 内容)
4
4
  * @param target 目标元素(选择器字符串或 DOM 元素)
5
5
  * @returns boolean 是否选中成功
6
6
  */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 获取目标元素内所有文本(包含嵌套子元素及 slot 内容),并去除所有空格与换行
3
+ * @param target 目标元素或选择器
4
+ * @returns 纯文本字符串
5
+ */
6
+ export declare function getDomText(target: HTMLElement | string): string;
7
+ export default getDomText;
@@ -5,5 +5,6 @@ export * from './date';
5
5
  export * from './deepClone';
6
6
  export * from './clipboard';
7
7
  export * from './fullscreen';
8
- export * from './domSelect';
8
+ export * from './document/domSelect';
9
+ export * from './document/getDomText';
9
10
  export * from './EventBus';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qc-ui-lit",
3
- "version": "0.2.6",
3
+ "version": "0.3.0",
4
4
  "description": "基于 Lit 的 Web Components 组件库",
5
5
  "author": "",
6
6
  "license": "MIT",
@@ -1,22 +0,0 @@
1
- //#region src/tools/clipboard/index.ts
2
- async function e(e, t) {
3
- try {
4
- if (navigator.clipboard && window.isSecureContext) {
5
- await navigator.clipboard.writeText(e), t?.onSuccess?.();
6
- return;
7
- }
8
- let n = document.createElement("textarea");
9
- n.value = e, n.style.cssText = "position:fixed;left:-9999px;top:-9999px;opacity:0", document.body.appendChild(n), n.focus(), n.select();
10
- let r = document.execCommand("copy");
11
- if (document.body.removeChild(n), r) t?.onSuccess?.();
12
- else throw Error("execCommand(\"copy\") failed");
13
- } catch (e) {
14
- throw t?.onError?.(e), e;
15
- }
16
- }
17
- async function t() {
18
- if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.readText();
19
- throw Error("Clipboard API not available");
20
- }
21
- //#endregion
22
- export { e as n, t };
@@ -1,31 +0,0 @@
1
- //#region src/tools/domSelect/index.ts
2
- function e(e) {
3
- return e ? typeof e == "string" ? document.querySelector(e) : e : null;
4
- }
5
- function t(t) {
6
- let n = e(t);
7
- if (!n) return !1;
8
- let r = window.getSelection();
9
- if (!r) return !1;
10
- r.removeAllRanges();
11
- let i = document.createRange();
12
- return i.selectNodeContents(n), r.addRange(i), r.toString().length > 0;
13
- }
14
- function n() {
15
- let e = window.getSelection();
16
- e && e.removeAllRanges();
17
- }
18
- function r() {
19
- let e = window.getSelection();
20
- return e ? e.toString() : "";
21
- }
22
- function i() {
23
- let e = window.getSelection();
24
- return !!e && e.toString().length > 0;
25
- }
26
- function a(n) {
27
- let r = e(n);
28
- return r ? r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement ? (r.focus(), r.select(), !0) : t(r) : !1;
29
- }
30
- //#endregion
31
- export { t as a, a as i, r as n, i as r, n as t };