react-smart-copy 1.17.2 → 1.19.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/README.md +86 -5
- package/dist/capture.cjs +30 -153
- package/dist/capture.cjs.map +1 -1
- package/dist/capture.d.cts +2 -25
- package/dist/capture.d.ts +2 -25
- package/dist/capture.js +5 -128
- package/dist/capture.js.map +1 -1
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs +102 -0
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs.map +1 -0
- package/dist/chunks/clipboard-adapter-CtH4VELE.d.cts +43 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js +97 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js.map +1 -0
- package/dist/chunks/clipboard-adapter-Ds0irroN.d.ts +43 -0
- package/dist/chunks/contrast-C6CVklEI.cjs +842 -0
- package/dist/chunks/contrast-C6CVklEI.cjs.map +1 -0
- package/dist/chunks/contrast-DpK2JIVu.js +789 -0
- package/dist/chunks/contrast-DpK2JIVu.js.map +1 -0
- package/dist/chunks/copy-interceptor-C6NABy1l.d.ts +141 -0
- package/dist/chunks/copy-interceptor-CZWzGOkL.d.cts +141 -0
- package/dist/chunks/core-Cp2HSpaz.js +1035 -0
- package/dist/chunks/core-Cp2HSpaz.js.map +1 -0
- package/dist/chunks/core-DYf_Lhbe.cjs +1142 -0
- package/dist/chunks/core-DYf_Lhbe.cjs.map +1 -0
- package/dist/chunks/deadline-C29AlS_Q.js +46 -0
- package/dist/chunks/deadline-C29AlS_Q.js.map +1 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs +51 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs.map +1 -0
- package/dist/chunks/errors-9h8sdFFX.js +120 -0
- package/dist/chunks/errors-9h8sdFFX.js.map +1 -0
- package/dist/chunks/errors-BwOF6T_M.cjs +167 -0
- package/dist/chunks/errors-BwOF6T_M.cjs.map +1 -0
- package/dist/chunks/index-mr7sSAgP.d.ts +426 -0
- package/dist/chunks/index-vz0iW5V2.d.cts +426 -0
- package/dist/chunks/inert-html-D75NyVvT.js +34 -0
- package/dist/chunks/inert-html-D75NyVvT.js.map +1 -0
- package/dist/chunks/inert-html-DyxjWDok.cjs +39 -0
- package/dist/chunks/inert-html-DyxjWDok.cjs.map +1 -0
- package/dist/chunks/mime--LB7kdqG.cjs +153 -0
- package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
- package/dist/chunks/mime-aa-HA2dm.js +100 -0
- package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
- package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
- package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
- package/dist/chunks/payload-CUymxwim.cjs +100 -0
- package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
- package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
- package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
- package/dist/chunks/payload-DGw-JOo7.js +71 -0
- package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
- package/dist/chunks/payload-DI5AorDz.js +103 -0
- package/dist/chunks/payload-DI5AorDz.js.map +1 -0
- package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
- package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
- package/dist/chunks/share-Bop47Znn.js +208 -0
- package/dist/chunks/share-Bop47Znn.js.map +1 -0
- package/dist/chunks/share-C0esXvRK.d.cts +115 -0
- package/dist/chunks/share-ayDz974N.cjs +231 -0
- package/dist/chunks/share-ayDz974N.cjs.map +1 -0
- package/dist/chunks/share-e7FenIr2.d.ts +115 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
- package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
- package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
- package/dist/chunks/text-field-DUvrMMaK.js +66 -0
- package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
- package/dist/chunks/url-B9jdFGQy.cjs +86 -0
- package/dist/chunks/url-B9jdFGQy.cjs.map +1 -0
- package/dist/chunks/url-BcMYVCXQ.js +135 -0
- package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
- package/dist/chunks/url-D4PGsRm8.cjs +164 -0
- package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
- package/dist/chunks/url-DWdElCT3.d.cts +43 -0
- package/dist/chunks/url-DWdElCT3.d.ts +43 -0
- package/dist/chunks/url-vJaFPbNL.js +57 -0
- package/dist/chunks/url-vJaFPbNL.js.map +1 -0
- package/dist/code.cjs +22 -113
- package/dist/code.cjs.map +1 -1
- package/dist/code.d.cts +4 -28
- package/dist/code.d.ts +4 -28
- package/dist/code.js +5 -96
- package/dist/code.js.map +1 -1
- package/dist/color.cjs +21 -893
- package/dist/color.cjs.map +1 -1
- package/dist/color.d.cts +4 -28
- package/dist/color.d.ts +4 -28
- package/dist/color.js +4 -876
- package/dist/color.js.map +1 -1
- package/dist/core.cjs +52 -1659
- package/dist/core.d.cts +8 -878
- package/dist/core.d.ts +8 -878
- package/dist/core.js +7 -1614
- package/dist/image.cjs +23 -94
- package/dist/image.cjs.map +1 -1
- package/dist/image.d.cts +1 -0
- package/dist/image.d.ts +1 -0
- package/dist/image.js +3 -74
- package/dist/image.js.map +1 -1
- package/dist/index.cjs +74 -2072
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -978
- package/dist/index.d.ts +8 -978
- package/dist/index.js +7 -2005
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +26 -339
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +5 -83
- package/dist/link.d.ts +5 -83
- package/dist/link.js +7 -320
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +19 -159
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -16
- package/dist/markdown.d.ts +3 -16
- package/dist/markdown.js +6 -146
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +1123 -940
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +101 -91
- package/dist/rich.d.ts +101 -91
- package/dist/rich.js +1099 -919
- package/dist/rich.js.map +1 -1
- package/dist/share.cjs +5 -640
- package/dist/share.d.cts +3 -248
- package/dist/share.d.ts +3 -248
- package/dist/share.js +1 -637
- package/dist/structured.cjs +13 -95
- package/dist/structured.cjs.map +1 -1
- package/dist/structured.d.cts +2 -11
- package/dist/structured.d.ts +2 -11
- package/dist/structured.js +4 -86
- package/dist/structured.js.map +1 -1
- package/dist/table.cjs +13 -40
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +2 -12
- package/dist/table.d.ts +2 -12
- package/dist/table.js +4 -31
- package/dist/table.js.map +1 -1
- package/dist/testing.cjs +10 -43
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +6 -181
- package/dist/testing.d.ts +6 -181
- package/dist/testing.js +3 -36
- package/dist/testing.js.map +1 -1
- package/package.json +37 -5
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/share.cjs.map +0 -1
- package/dist/share.js.map +0 -1
package/dist/link.d.cts
CHANGED
|
@@ -1,70 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** Required plain-text fallback for targets that don't understand HTML. */
|
|
6
|
-
readonly text: string;
|
|
7
|
-
}
|
|
8
|
-
interface MultiPayloadItem {
|
|
9
|
-
/**
|
|
10
|
-
* The MIME type, or a web custom format (`web application/vnd.acme+json`).
|
|
11
|
-
* Web custom formats are only written by the async Clipboard API; copy and drag
|
|
12
|
-
* events skip them.
|
|
13
|
-
*/
|
|
14
|
-
readonly mimeType: string;
|
|
15
|
-
readonly data: string | Blob;
|
|
16
|
-
/**
|
|
17
|
-
* Skip this item, instead of failing the copy, when the browser cannot write its type.
|
|
18
|
-
* An optional item is only written when `ClipboardItem.supports()` confirms the type.
|
|
19
|
-
* At least one item must be written.
|
|
20
|
-
*/
|
|
21
|
-
readonly optional?: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface MultiPayload {
|
|
24
|
-
readonly kind: 'multi';
|
|
25
|
-
readonly items: readonly MultiPayloadItem[];
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/link/url.d.ts
|
|
29
|
-
/** Schemes a copied or pasted link may use by default. Never `javascript:`, `data:`, `vbscript:` or `file:`. */
|
|
30
|
-
export declare const DEFAULT_LINK_PROTOCOLS: readonly string[];
|
|
31
|
-
/**
|
|
32
|
-
* Query parameters that only track where a click came from: the defaults of
|
|
33
|
-
* {@link cleanLinkUrl}. `utm_` matches every parameter starting with it.
|
|
34
|
-
*/
|
|
35
|
-
export declare const TRACKING_PARAMETERS: readonly string[];
|
|
36
|
-
interface CleanLinkOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Parameters to remove: exact names, names ending in `_` (a prefix, like
|
|
39
|
-
* `utm_`), or regular expressions tested against the name. Default {@link TRACKING_PARAMETERS}.
|
|
40
|
-
*/
|
|
41
|
-
readonly params?: readonly (string | RegExp)[];
|
|
42
|
-
/** Parameters never removed, even when `params` matches them. */
|
|
43
|
-
readonly keep?: readonly string[];
|
|
44
|
-
}
|
|
45
|
-
interface LinkUrlOptions {
|
|
46
|
-
/** Resolves relative links. Default: the page's address in a browser; required elsewhere for relative links. */
|
|
47
|
-
readonly base?: string | URL;
|
|
48
|
-
/** Allowed schemes, with the colon. Default {@link DEFAULT_LINK_PROTOCOLS}. */
|
|
49
|
-
readonly protocols?: readonly string[];
|
|
50
|
-
/** Remove tracking parameters: `true` for {@link TRACKING_PARAMETERS}, or your own list. Default `false`. */
|
|
51
|
-
readonly clean?: boolean | CleanLinkOptions;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The link as an absolute, safe URL string, or a typed `invalid-payload` error:
|
|
55
|
-
* relative links are resolved, the scheme must be allowed, user names and
|
|
56
|
-
* passwords are always removed, and tracking parameters optionally.
|
|
57
|
-
*/
|
|
58
|
-
export declare function resolveLinkUrl(input: string | URL, options?: LinkUrlOptions): string;
|
|
59
|
-
/**
|
|
60
|
-
* Removes tracking parameters (`utm_*`, `fbclid`, `gclid`, ...) from a link, keeping
|
|
61
|
-
* everything else, including the fragment. Also validates it like every link here.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* cleanLinkUrl('https://shop.example/p/42?utm_source=news&color=red'); // 'https://shop.example/p/42?color=red'
|
|
65
|
-
*/
|
|
66
|
-
export declare function cleanLinkUrl(url: string | URL, options?: CleanLinkOptions & Omit<LinkUrlOptions, 'clean'>): string;
|
|
67
|
-
//#endregion
|
|
1
|
+
|
|
2
|
+
import { o as HtmlPayload, u as MultiPayload } from "./chunks/payload-CcwKJ_bU.cjs";
|
|
3
|
+
import { t as insertText } from "./chunks/text-field-C0SGmvvR.cjs";
|
|
4
|
+
import { a as cleanLinkUrl, i as TRACKING_PARAMETERS, n as DEFAULT_LINK_PROTOCOLS, o as resolveLinkUrl, r as LinkUrlOptions, t as CleanLinkOptions } from "./chunks/url-DWdElCT3.cjs";
|
|
68
5
|
//#region src/link/payload.d.ts
|
|
69
6
|
/** A link with an optional title. */
|
|
70
7
|
interface Link {
|
|
@@ -240,20 +177,5 @@ interface SelectionLinkOptions extends TextFragmentOptions {
|
|
|
240
177
|
*/
|
|
241
178
|
export declare function selectionLink(options?: SelectionLinkOptions): SelectionLink | null;
|
|
242
179
|
//#endregion
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Text-field helpers shared by the paste handlers of the opt-in entry points.
|
|
246
|
-
* Internal: not part of `react-smart-copy/core`'s public API.
|
|
247
|
-
*/
|
|
248
|
-
/** Text fields `setRangeText` and `execCommand('insertText')` both support. */
|
|
249
|
-
type TextField = HTMLTextAreaElement | HTMLInputElement;
|
|
250
|
-
/**
|
|
251
|
-
* Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
|
|
252
|
-
* selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
|
|
253
|
-
* works, `input` events fire (so React and other frameworks see the change),
|
|
254
|
-
* and `maxlength` is respected. Returns `false` for disabled or read-only fields.
|
|
255
|
-
*/
|
|
256
|
-
export declare function insertText(field: TextField, text: string): boolean;
|
|
257
|
-
//#endregion
|
|
258
|
-
export type { CleanLinkOptions, Link, LinkDragPayloadOptions, LinkPasteEvent, LinkPasteSource, LinkPayloadOptions, LinkSource, LinkTextFormat, LinkUrlOptions, PasteAsLinkOptions, ResolvedLink, SelectionLink, SelectionLinkOptions, TextFragment, TextFragmentOptions };
|
|
180
|
+
export { type CleanLinkOptions, DEFAULT_LINK_PROTOCOLS, type Link, type LinkDragPayloadOptions, type LinkPasteEvent, type LinkPasteSource, type LinkPayloadOptions, type LinkSource, type LinkTextFormat, type LinkUrlOptions, type PasteAsLinkOptions, type ResolvedLink, type SelectionLink, type SelectionLinkOptions, TRACKING_PARAMETERS, type TextFragment, type TextFragmentOptions, cleanLinkUrl, insertText, resolveLinkUrl };
|
|
259
181
|
//# sourceMappingURL=link.d.cts.map
|
package/dist/link.d.ts
CHANGED
|
@@ -1,70 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** Required plain-text fallback for targets that don't understand HTML. */
|
|
6
|
-
readonly text: string;
|
|
7
|
-
}
|
|
8
|
-
interface MultiPayloadItem {
|
|
9
|
-
/**
|
|
10
|
-
* The MIME type, or a web custom format (`web application/vnd.acme+json`).
|
|
11
|
-
* Web custom formats are only written by the async Clipboard API; copy and drag
|
|
12
|
-
* events skip them.
|
|
13
|
-
*/
|
|
14
|
-
readonly mimeType: string;
|
|
15
|
-
readonly data: string | Blob;
|
|
16
|
-
/**
|
|
17
|
-
* Skip this item, instead of failing the copy, when the browser cannot write its type.
|
|
18
|
-
* An optional item is only written when `ClipboardItem.supports()` confirms the type.
|
|
19
|
-
* At least one item must be written.
|
|
20
|
-
*/
|
|
21
|
-
readonly optional?: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface MultiPayload {
|
|
24
|
-
readonly kind: 'multi';
|
|
25
|
-
readonly items: readonly MultiPayloadItem[];
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/link/url.d.ts
|
|
29
|
-
/** Schemes a copied or pasted link may use by default. Never `javascript:`, `data:`, `vbscript:` or `file:`. */
|
|
30
|
-
export declare const DEFAULT_LINK_PROTOCOLS: readonly string[];
|
|
31
|
-
/**
|
|
32
|
-
* Query parameters that only track where a click came from: the defaults of
|
|
33
|
-
* {@link cleanLinkUrl}. `utm_` matches every parameter starting with it.
|
|
34
|
-
*/
|
|
35
|
-
export declare const TRACKING_PARAMETERS: readonly string[];
|
|
36
|
-
interface CleanLinkOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Parameters to remove: exact names, names ending in `_` (a prefix, like
|
|
39
|
-
* `utm_`), or regular expressions tested against the name. Default {@link TRACKING_PARAMETERS}.
|
|
40
|
-
*/
|
|
41
|
-
readonly params?: readonly (string | RegExp)[];
|
|
42
|
-
/** Parameters never removed, even when `params` matches them. */
|
|
43
|
-
readonly keep?: readonly string[];
|
|
44
|
-
}
|
|
45
|
-
interface LinkUrlOptions {
|
|
46
|
-
/** Resolves relative links. Default: the page's address in a browser; required elsewhere for relative links. */
|
|
47
|
-
readonly base?: string | URL;
|
|
48
|
-
/** Allowed schemes, with the colon. Default {@link DEFAULT_LINK_PROTOCOLS}. */
|
|
49
|
-
readonly protocols?: readonly string[];
|
|
50
|
-
/** Remove tracking parameters: `true` for {@link TRACKING_PARAMETERS}, or your own list. Default `false`. */
|
|
51
|
-
readonly clean?: boolean | CleanLinkOptions;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The link as an absolute, safe URL string, or a typed `invalid-payload` error:
|
|
55
|
-
* relative links are resolved, the scheme must be allowed, user names and
|
|
56
|
-
* passwords are always removed, and tracking parameters optionally.
|
|
57
|
-
*/
|
|
58
|
-
export declare function resolveLinkUrl(input: string | URL, options?: LinkUrlOptions): string;
|
|
59
|
-
/**
|
|
60
|
-
* Removes tracking parameters (`utm_*`, `fbclid`, `gclid`, ...) from a link, keeping
|
|
61
|
-
* everything else, including the fragment. Also validates it like every link here.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* cleanLinkUrl('https://shop.example/p/42?utm_source=news&color=red'); // 'https://shop.example/p/42?color=red'
|
|
65
|
-
*/
|
|
66
|
-
export declare function cleanLinkUrl(url: string | URL, options?: CleanLinkOptions & Omit<LinkUrlOptions, 'clean'>): string;
|
|
67
|
-
//#endregion
|
|
1
|
+
|
|
2
|
+
import { o as HtmlPayload, u as MultiPayload } from "./chunks/payload-Cl_8hCI5.js";
|
|
3
|
+
import { t as insertText } from "./chunks/text-field-C0SGmvvR.js";
|
|
4
|
+
import { a as cleanLinkUrl, i as TRACKING_PARAMETERS, n as DEFAULT_LINK_PROTOCOLS, o as resolveLinkUrl, r as LinkUrlOptions, t as CleanLinkOptions } from "./chunks/url-DWdElCT3.js";
|
|
68
5
|
//#region src/link/payload.d.ts
|
|
69
6
|
/** A link with an optional title. */
|
|
70
7
|
interface Link {
|
|
@@ -240,20 +177,5 @@ interface SelectionLinkOptions extends TextFragmentOptions {
|
|
|
240
177
|
*/
|
|
241
178
|
export declare function selectionLink(options?: SelectionLinkOptions): SelectionLink | null;
|
|
242
179
|
//#endregion
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Text-field helpers shared by the paste handlers of the opt-in entry points.
|
|
246
|
-
* Internal: not part of `react-smart-copy/core`'s public API.
|
|
247
|
-
*/
|
|
248
|
-
/** Text fields `setRangeText` and `execCommand('insertText')` both support. */
|
|
249
|
-
type TextField = HTMLTextAreaElement | HTMLInputElement;
|
|
250
|
-
/**
|
|
251
|
-
* Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
|
|
252
|
-
* selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
|
|
253
|
-
* works, `input` events fire (so React and other frameworks see the change),
|
|
254
|
-
* and `maxlength` is respected. Returns `false` for disabled or read-only fields.
|
|
255
|
-
*/
|
|
256
|
-
export declare function insertText(field: TextField, text: string): boolean;
|
|
257
|
-
//#endregion
|
|
258
|
-
export type { CleanLinkOptions, Link, LinkDragPayloadOptions, LinkPasteEvent, LinkPasteSource, LinkPayloadOptions, LinkSource, LinkTextFormat, LinkUrlOptions, PasteAsLinkOptions, ResolvedLink, SelectionLink, SelectionLinkOptions, TextFragment, TextFragmentOptions };
|
|
180
|
+
export { type CleanLinkOptions, DEFAULT_LINK_PROTOCOLS, type Link, type LinkDragPayloadOptions, type LinkPasteEvent, type LinkPasteSource, type LinkPayloadOptions, type LinkSource, type LinkTextFormat, type LinkUrlOptions, type PasteAsLinkOptions, type ResolvedLink, type SelectionLink, type SelectionLinkOptions, TRACKING_PARAMETERS, type TextFragment, type TextFragmentOptions, cleanLinkUrl, insertText, resolveLinkUrl };
|
|
259
181
|
//# sourceMappingURL=link.d.ts.map
|
package/dist/link.js
CHANGED
|
@@ -1,260 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type,
|
|
8
|
-
message,
|
|
9
|
-
cause
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Branded (not `instanceof`) so failures stay recognisable even when the core
|
|
14
|
-
* is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
|
|
15
|
-
*/
|
|
16
|
-
const COPY_FAILURE_BRAND = Symbol.for("react-smart-copy.CopyFailure");
|
|
17
|
-
/** Error thrown by adapters to carry a fully classified {@link CopyError}. */
|
|
18
|
-
var CopyFailure = class extends Error {
|
|
19
|
-
constructor(copyError) {
|
|
20
|
-
super(copyError.message);
|
|
21
|
-
this[COPY_FAILURE_BRAND] = true;
|
|
22
|
-
this.name = "CopyFailure";
|
|
23
|
-
this.copyError = copyError;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
/** Shorthand for throwing a classified failure. */
|
|
27
|
-
function copyFailure(type, message, cause) {
|
|
28
|
-
return new CopyFailure(createCopyError(type, message, cause));
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/link/url.ts
|
|
32
|
-
/** Schemes a copied or pasted link may use by default. Never `javascript:`, `data:`, `vbscript:` or `file:`. */
|
|
33
|
-
const DEFAULT_LINK_PROTOCOLS = /* @__PURE__ */ Object.freeze([
|
|
34
|
-
"https:",
|
|
35
|
-
"http:",
|
|
36
|
-
"mailto:",
|
|
37
|
-
"tel:"
|
|
38
|
-
]);
|
|
39
|
-
/**
|
|
40
|
-
* Query parameters that only track where a click came from: the defaults of
|
|
41
|
-
* {@link cleanLinkUrl}. `utm_` matches every parameter starting with it.
|
|
42
|
-
*/
|
|
43
|
-
const TRACKING_PARAMETERS = /* @__PURE__ */ Object.freeze([
|
|
44
|
-
"utm_",
|
|
45
|
-
"fbclid",
|
|
46
|
-
"gclid",
|
|
47
|
-
"gclsrc",
|
|
48
|
-
"dclid",
|
|
49
|
-
"gbraid",
|
|
50
|
-
"wbraid",
|
|
51
|
-
"msclkid",
|
|
52
|
-
"yclid",
|
|
53
|
-
"twclid",
|
|
54
|
-
"ttclid",
|
|
55
|
-
"li_fat_id",
|
|
56
|
-
"igshid",
|
|
57
|
-
"igsh",
|
|
58
|
-
"mc_cid",
|
|
59
|
-
"mc_eid",
|
|
60
|
-
"_hsenc",
|
|
61
|
-
"_hsmi",
|
|
62
|
-
"mkt_tok",
|
|
63
|
-
"oly_anon_id",
|
|
64
|
-
"oly_enc_id",
|
|
65
|
-
"vero_id",
|
|
66
|
-
"wickedid",
|
|
67
|
-
"_gl"
|
|
68
|
-
]);
|
|
69
|
-
const invalid$2 = (message) => copyFailure("invalid-payload", message);
|
|
70
|
-
function baseUrl(base) {
|
|
71
|
-
if (base !== void 0) {
|
|
72
|
-
if (typeof base === "string" || base instanceof URL) return String(base);
|
|
73
|
-
throw invalid$2("`base` must be a string or a URL.");
|
|
74
|
-
}
|
|
75
|
-
return typeof location === "undefined" ? void 0 : location.href;
|
|
76
|
-
}
|
|
77
|
-
function protocolSet(protocols) {
|
|
78
|
-
const list = protocols ?? DEFAULT_LINK_PROTOCOLS;
|
|
79
|
-
const valid = (protocol) => typeof protocol === "string" && /^[a-z][a-z\d+.-]*:$/i.test(protocol);
|
|
80
|
-
if (!Array.isArray(list) || list.length === 0 || !list.every(valid)) throw invalid$2("`protocols` must be a non-empty list of schemes with their colon, like \"https:\".");
|
|
81
|
-
return new Set(list.map((protocol) => protocol.toLowerCase()));
|
|
82
|
-
}
|
|
83
|
-
function matcher(params) {
|
|
84
|
-
const list = params ?? TRACKING_PARAMETERS;
|
|
85
|
-
if (!Array.isArray(list) || !list.every((param) => typeof param === "string" || param instanceof RegExp)) throw invalid$2("`clean.params` must be a list of strings and regular expressions.");
|
|
86
|
-
return (name) => {
|
|
87
|
-
const lower = name.toLowerCase();
|
|
88
|
-
return list.some((param) => {
|
|
89
|
-
if (typeof param !== "string") return new RegExp(param.source, param.flags.replace(/[gy]/g, "")).test(name);
|
|
90
|
-
const wanted = param.toLowerCase();
|
|
91
|
-
return wanted.endsWith("_") ? lower.startsWith(wanted) : lower === wanted;
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/** The cleaning step `clean` asks for, or `null`. Throws for an invalid option. */
|
|
96
|
-
function cleaner(option) {
|
|
97
|
-
const cleaning = option ?? false;
|
|
98
|
-
if (cleaning === false) return null;
|
|
99
|
-
if (cleaning !== true && (typeof cleaning !== "object" || cleaning === null)) throw invalid$2("`clean` must be a boolean or an options object.");
|
|
100
|
-
const settings = cleaning === true ? {} : cleaning;
|
|
101
|
-
const tracking = matcher(settings.params);
|
|
102
|
-
const keep = settings.keep ?? [];
|
|
103
|
-
if (!Array.isArray(keep) || !keep.every((name) => typeof name === "string")) throw invalid$2("`clean.keep` must be a list of strings.");
|
|
104
|
-
const kept = new Set(keep.map((name) => name.toLowerCase()));
|
|
105
|
-
return (url) => {
|
|
106
|
-
for (const name of [...new Set(url.searchParams.keys())]) if (tracking(name) && !kept.has(name.toLowerCase())) url.searchParams.delete(name);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Validates `options` once (throwing a typed `invalid-payload` error for invalid
|
|
111
|
-
* ones) and returns a resolver that throws only for invalid links.
|
|
112
|
-
* @internal
|
|
113
|
-
*/
|
|
114
|
-
function linkUrlResolver(options = {}) {
|
|
115
|
-
const protocols = protocolSet(options.protocols);
|
|
116
|
-
const base = baseUrl(options.base);
|
|
117
|
-
const clean = cleaner(options.clean);
|
|
118
|
-
return (input) => {
|
|
119
|
-
if (typeof input !== "string" && !(input instanceof URL)) throw invalid$2("A link must be a string or a URL.");
|
|
120
|
-
const raw = String(input).trim();
|
|
121
|
-
if (raw === "") throw invalid$2("A link must not be empty.");
|
|
122
|
-
let url;
|
|
123
|
-
try {
|
|
124
|
-
url = new URL(raw, base);
|
|
125
|
-
} catch (cause) {
|
|
126
|
-
throw copyFailure("invalid-payload", `Not a valid link: ${JSON.stringify(raw.slice(0, 200))}.`, cause);
|
|
127
|
-
}
|
|
128
|
-
if (!protocols.has(url.protocol)) throw invalid$2(`Links with the scheme "${url.protocol}" are not allowed (allowed: ${[...protocols].join(", ")}).`);
|
|
129
|
-
url.username = "";
|
|
130
|
-
url.password = "";
|
|
131
|
-
clean?.(url);
|
|
132
|
-
return url.href;
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* The link as an absolute, safe URL string, or a typed `invalid-payload` error:
|
|
137
|
-
* relative links are resolved, the scheme must be allowed, user names and
|
|
138
|
-
* passwords are always removed, and tracking parameters optionally.
|
|
139
|
-
*/
|
|
140
|
-
function resolveLinkUrl(input, options = {}) {
|
|
141
|
-
return linkUrlResolver(options)(input);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Removes tracking parameters (`utm_*`, `fbclid`, `gclid`, ...) from a link, keeping
|
|
145
|
-
* everything else, including the fragment. Also validates it like every link here.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* cleanLinkUrl('https://shop.example/p/42?utm_source=news&color=red'); // 'https://shop.example/p/42?color=red'
|
|
149
|
-
*/
|
|
150
|
-
function cleanLinkUrl(url, options = {}) {
|
|
151
|
-
const { params, keep, ...rest } = options;
|
|
152
|
-
return resolveLinkUrl(url, {
|
|
153
|
-
...rest,
|
|
154
|
-
clean: {
|
|
155
|
-
...params === void 0 ? {} : { params },
|
|
156
|
-
...keep === void 0 ? {} : { keep }
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/link/payload.ts
|
|
162
|
-
const DEFAULT_LINK_TITLE_LENGTH = 300;
|
|
163
|
-
const invalid$1 = (message) => copyFailure("invalid-payload", message);
|
|
164
|
-
/**
|
|
165
|
-
* Characters a title never keeps: controls, bidi overrides and isolates (which can
|
|
166
|
-
* make a title read differently), and zero-width characters.
|
|
167
|
-
*/
|
|
168
|
-
const HIDDEN = /[\0-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f\u061C\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g;
|
|
169
|
-
/** A title as one clean line: hidden characters removed, whitespace collapsed, length capped. */
|
|
170
|
-
function cleanTitle(title, maxLength) {
|
|
171
|
-
const clean = title.replace(HIDDEN, "").replace(/\s+/g, " ").trim();
|
|
172
|
-
if (clean.length <= maxLength) return clean;
|
|
173
|
-
return `${Array.from(clean).slice(0, maxLength - 1).join("").trimEnd()}\u2026`;
|
|
174
|
-
}
|
|
175
|
-
function maxTitle(value) {
|
|
176
|
-
if (value === void 0) return 300;
|
|
177
|
-
if (Number.isInteger(value) && value >= 1) return value;
|
|
178
|
-
throw invalid$1(`\`maxTitleLength\` must be a positive integer (received ${String(value)}).`);
|
|
179
|
-
}
|
|
180
|
-
function isAnchor(source) {
|
|
181
|
-
return typeof source === "object" && source !== null && source.nodeName === "A" && typeof source.href === "string";
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Validates a link and its title: see {@link resolveLinkUrl} for the URL rules.
|
|
185
|
-
* An `<a>` element gives its `href` and its text (or `title` attribute).
|
|
186
|
-
*/
|
|
187
|
-
function resolveLink(source, options = {}) {
|
|
188
|
-
let url;
|
|
189
|
-
let title;
|
|
190
|
-
if (typeof source === "string" || source instanceof URL) url = source;
|
|
191
|
-
else if (isAnchor(source)) {
|
|
192
|
-
url = source.getAttribute("href") ?? "";
|
|
193
|
-
title = source.textContent.trim() !== "" ? source.textContent : source.getAttribute("title") ?? void 0;
|
|
194
|
-
if (url !== "" && options.base === void 0) url = source.href;
|
|
195
|
-
} else if (typeof source === "object" && source !== null && "url" in source) {
|
|
196
|
-
url = source.url;
|
|
197
|
-
title = source.title;
|
|
198
|
-
} else throw invalid$1("A link must be a URL, a { url, title } object or an <a> element.");
|
|
199
|
-
if (title !== void 0 && typeof title !== "string") throw invalid$1("A link title must be a string.");
|
|
200
|
-
const href = resolveLinkUrl(url, options);
|
|
201
|
-
const clean = title === void 0 ? "" : cleanTitle(title, maxTitle(options.maxTitleLength));
|
|
202
|
-
return {
|
|
203
|
-
url: href,
|
|
204
|
-
title: clean === "" ? href : clean,
|
|
205
|
-
titled: clean !== ""
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
const escapeHtml = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
209
|
-
/** `[title](url)`, safe in every CommonMark renderer: brackets and backslashes escaped, parentheses and spaces encoded. */
|
|
210
|
-
function markdownLink(link) {
|
|
211
|
-
return `[${link.title.replace(/[\\[\]]/g, "\\$&")}](${link.url.replace(/[()<> ]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)})`;
|
|
212
|
-
}
|
|
213
|
-
function plainText(link, format) {
|
|
214
|
-
switch (format) {
|
|
215
|
-
case "url": return link.url;
|
|
216
|
-
case "title": return link.title;
|
|
217
|
-
case "title-and-url": return link.titled ? `${link.title}\n${link.url}` : link.url;
|
|
218
|
-
case "markdown": return markdownLink(link);
|
|
219
|
-
default: throw invalid$1(`\`text\` must be "url", "title", "title-and-url" or "markdown" (received ${JSON.stringify(format)}).`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function linkPayload(source, options = {}) {
|
|
223
|
-
const target = options.target ?? "clipboard";
|
|
224
|
-
if (target !== "drag" && target !== "clipboard") throw invalid$1("`target` must be \"clipboard\" or \"drag\".");
|
|
225
|
-
const link = resolveLink(source, options);
|
|
226
|
-
const text = plainText(link, options.text ?? "url");
|
|
227
|
-
const html = `<a href="${escapeHtml(link.url)}">${escapeHtml(link.title)}</a>`;
|
|
228
|
-
if (target === "clipboard") return {
|
|
229
|
-
kind: "html",
|
|
230
|
-
html,
|
|
231
|
-
text
|
|
232
|
-
};
|
|
233
|
-
return {
|
|
234
|
-
kind: "multi",
|
|
235
|
-
items: [
|
|
236
|
-
{
|
|
237
|
-
mimeType: "text/plain",
|
|
238
|
-
data: text
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
mimeType: "text/html",
|
|
242
|
-
data: html
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
mimeType: "text/uri-list",
|
|
246
|
-
data: link.url,
|
|
247
|
-
optional: true
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
mimeType: "text/x-moz-url",
|
|
251
|
-
data: `${link.url}\n${link.title}`,
|
|
252
|
-
optional: true
|
|
253
|
-
}
|
|
254
|
-
]
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
//#endregion
|
|
1
|
+
|
|
2
|
+
import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
|
|
3
|
+
import { a as resolveLinkUrl, i as linkUrlResolver, n as TRACKING_PARAMETERS, r as cleanLinkUrl, t as DEFAULT_LINK_PROTOCOLS } from "./chunks/url-BcMYVCXQ.js";
|
|
4
|
+
import { a as resolveLink, i as markdownLink, n as cleanTitle, r as linkPayload, t as DEFAULT_LINK_TITLE_LENGTH } from "./chunks/payload-DI5AorDz.js";
|
|
5
|
+
import { t as parseInertHtml } from "./chunks/inert-html-D75NyVvT.js";
|
|
6
|
+
import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
|
|
258
7
|
//#region src/link/fragment.ts
|
|
259
8
|
const invalid = (message) => copyFailure("invalid-payload", message);
|
|
260
9
|
const collapse = (text) => text.replace(/\s+/g, " ").trim();
|
|
@@ -435,68 +184,6 @@ function supportsTextFragments() {
|
|
|
435
184
|
return typeof document !== "undefined" && "fragmentDirective" in document;
|
|
436
185
|
}
|
|
437
186
|
//#endregion
|
|
438
|
-
//#region src/core/text-field.ts
|
|
439
|
-
const TEXT_INPUTS = /* @__PURE__ */ new Set([
|
|
440
|
-
"text",
|
|
441
|
-
"search",
|
|
442
|
-
"url",
|
|
443
|
-
"tel",
|
|
444
|
-
"password"
|
|
445
|
-
]);
|
|
446
|
-
function asTextField(target) {
|
|
447
|
-
if (typeof target !== "object" || target === null) return null;
|
|
448
|
-
const element = target;
|
|
449
|
-
if (element.nodeName === "TEXTAREA") return target;
|
|
450
|
-
if (element.nodeName === "INPUT" && typeof element.type === "string" && TEXT_INPUTS.has(element.type)) return target;
|
|
451
|
-
return null;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
|
|
455
|
-
* selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
|
|
456
|
-
* works, `input` events fire (so React and other frameworks see the change),
|
|
457
|
-
* and `maxlength` is respected. Returns `false` for disabled or read-only fields.
|
|
458
|
-
*/
|
|
459
|
-
function insertText(field, text) {
|
|
460
|
-
if (field.disabled || field.readOnly) return false;
|
|
461
|
-
const value = field.nodeName === "INPUT" ? text.replace(/[ \t]*(?:\r\n|\r|\n)+[ \t]*/g, " ") : text;
|
|
462
|
-
const doc = field.ownerDocument;
|
|
463
|
-
field.focus();
|
|
464
|
-
const start = field.selectionStart;
|
|
465
|
-
const end = field.selectionEnd;
|
|
466
|
-
try {
|
|
467
|
-
if (start !== null && end !== null) field.setSelectionRange(start, end);
|
|
468
|
-
if (doc.activeElement === field && doc.execCommand("insertText", false, value)) return true;
|
|
469
|
-
} catch {}
|
|
470
|
-
const from = start ?? field.value.length;
|
|
471
|
-
const to = end ?? from;
|
|
472
|
-
let insert = value;
|
|
473
|
-
if (field.maxLength >= 0) {
|
|
474
|
-
const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));
|
|
475
|
-
insert = insert.slice(0, room);
|
|
476
|
-
if (/[\ud800-\udbff]$/.test(insert)) insert = insert.slice(0, -1);
|
|
477
|
-
}
|
|
478
|
-
if (start === null) setNativeValue(field, field.value + insert);
|
|
479
|
-
else field.setRangeText(insert, from, to, "end");
|
|
480
|
-
const view = doc.defaultView;
|
|
481
|
-
const event = view !== null && typeof view.InputEvent === "function" ? new view.InputEvent("input", {
|
|
482
|
-
bubbles: true,
|
|
483
|
-
inputType: "insertFromPaste",
|
|
484
|
-
data: insert
|
|
485
|
-
}) : new Event("input", { bubbles: true });
|
|
486
|
-
field.dispatchEvent(event);
|
|
487
|
-
return true;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Sets a field's value through the prototype's setter. React tracks the value
|
|
491
|
-
* set on the element itself; going around it lets React see the change and
|
|
492
|
-
* call `onChange` for the `input` event that follows.
|
|
493
|
-
*/
|
|
494
|
-
function setNativeValue(field, next) {
|
|
495
|
-
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field), "value")?.set;
|
|
496
|
-
if (setter) setter.call(field, next);
|
|
497
|
-
else field.value = next;
|
|
498
|
-
}
|
|
499
|
-
//#endregion
|
|
500
187
|
//#region src/link/paste.ts
|
|
501
188
|
/** One URL with no spaces, as a whole pasted text (surrounding whitespace allowed). */
|
|
502
189
|
const SINGLE_URL = /^\s*<?([a-z][a-z\d+.-]*:[^\s<>]+?)>?\s*$/i;
|
|
@@ -515,7 +202,7 @@ function fromUriList(list, resolve) {
|
|
|
515
202
|
/** The single link in pasted HTML (one `<a href>` and nothing else visible besides its text), parsed inertly. */
|
|
516
203
|
function fromHtml(html, resolve) {
|
|
517
204
|
if (typeof DOMParser === "undefined" || html.trim() === "") return null;
|
|
518
|
-
const body =
|
|
205
|
+
const body = parseInertHtml(html.slice(0, 1e5)).body;
|
|
519
206
|
const anchors = body.querySelectorAll("a[href]");
|
|
520
207
|
if (anchors.length !== 1) return null;
|
|
521
208
|
const anchor = anchors[0];
|