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/markdown.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
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
|
|
1
|
+
|
|
2
|
+
import { n as copyFailure } from "./chunks/errors-9h8sdFFX.js";
|
|
3
|
+
import { t as parseInertHtml } from "./chunks/inert-html-D75NyVvT.js";
|
|
4
|
+
import { i as safeUrl, n as DEFAULT_LINK_PROTOCOLS, r as linkDestination, t as DEFAULT_IMAGE_PROTOCOLS } from "./chunks/url-vJaFPbNL.js";
|
|
5
|
+
import { n as insertText, t as asTextField } from "./chunks/text-field-DUvrMMaK.js";
|
|
31
6
|
//#region src/markdown/escape.ts
|
|
32
7
|
/**
|
|
33
8
|
* CommonMark escaping. Pasted text must render as the same text, never as
|
|
@@ -69,59 +44,6 @@ function escapeLineStart(text) {
|
|
|
69
44
|
function escapeMarkdown(text) {
|
|
70
45
|
return text.split(/\r\n|\r|\n/).map((line) => escapeLineStart(escapeInline(line.replace(/^[ \t]+/, "")))).join("\n");
|
|
71
46
|
}
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/markdown/url.ts
|
|
74
|
-
/**
|
|
75
|
-
* URL safety for pasted links and images. Only absolute URLs with an allowed
|
|
76
|
-
* scheme survive; everything else (`javascript:`, `data:`, `vbscript:`,
|
|
77
|
-
* relative links without a base, malformed URLs) is dropped and the visible
|
|
78
|
-
* text is kept. Parsing uses the WHATWG URL parser, the same one the browser
|
|
79
|
-
* uses when the link is clicked, so tricks like `java\tscript:` are seen as
|
|
80
|
-
* `javascript:`.
|
|
81
|
-
*/
|
|
82
|
-
const DEFAULT_LINK_PROTOCOLS = [
|
|
83
|
-
"http:",
|
|
84
|
-
"https:",
|
|
85
|
-
"mailto:"
|
|
86
|
-
];
|
|
87
|
-
const DEFAULT_IMAGE_PROTOCOLS = ["https:", "http:"];
|
|
88
|
-
function parse(raw, base) {
|
|
89
|
-
try {
|
|
90
|
-
return new URL(raw.trim(), base);
|
|
91
|
-
} catch {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Click-tracking redirects that pasted links often carry: Google (Docs,
|
|
97
|
-
* Search, Gmail) and Outlook Safe Links. Unwrapped only to an http(s) target.
|
|
98
|
-
*/
|
|
99
|
-
function unwrapRedirect(url) {
|
|
100
|
-
const host = url.hostname.toLowerCase();
|
|
101
|
-
const param = /(^|\.)google\.[a-z.]+$/.test(host) && url.pathname === "/url" ? url.searchParams.get("q") ?? url.searchParams.get("url") : host.endsWith(".safelinks.protection.outlook.com") ? url.searchParams.get("url") : null;
|
|
102
|
-
if (param === null) return url;
|
|
103
|
-
const target = parse(param, void 0);
|
|
104
|
-
return target !== null && (target.protocol === "https:" || target.protocol === "http:") ? target : url;
|
|
105
|
-
}
|
|
106
|
-
/** The normalised URL, or `null` when it is not absolute or its scheme is not allowed. */
|
|
107
|
-
function safeUrl(raw, protocols, base) {
|
|
108
|
-
const parsed = parse(raw, base);
|
|
109
|
-
if (parsed === null) return null;
|
|
110
|
-
const url = unwrapRedirect(parsed);
|
|
111
|
-
return protocols.includes(url.protocol) ? url.href : null;
|
|
112
|
-
}
|
|
113
|
-
/** `href` comes from the URL serialiser, which already percent-encodes every non-ASCII character. */
|
|
114
|
-
const percent = (char) => `%${char.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`;
|
|
115
|
-
/**
|
|
116
|
-
* A Markdown link destination. ASCII whitespace, `<`, `>` and controls are
|
|
117
|
-
* percent-encoded (opaque URLs such as `mailto:` keep them otherwise),
|
|
118
|
-
* backslashes too so they can't act as escapes, and parentheses are kept
|
|
119
|
-
* exact by using the `<…>` form.
|
|
120
|
-
*/
|
|
121
|
-
function linkDestination(href) {
|
|
122
|
-
const encoded = href.replace(/[ <>\\\u0000-\u001f\u007f]/g, percent);
|
|
123
|
-
return /[()]/.test(encoded) ? `<${encoded}>` : encoded;
|
|
124
|
-
}
|
|
125
47
|
/** Outermost first: a style lower in the list is always nested inside the ones above it. */
|
|
126
48
|
const ORDER = [
|
|
127
49
|
[4, "~~"],
|
|
@@ -1239,7 +1161,7 @@ function htmlToMarkdown(source, options = {}) {
|
|
|
1239
1161
|
function parseHtml(html, resolved) {
|
|
1240
1162
|
if (typeof DOMParser === "undefined") throw copyFailure("unsupported", "htmlToMarkdown needs DOMParser to read an HTML string; pass a DOM node instead.");
|
|
1241
1163
|
return {
|
|
1242
|
-
body:
|
|
1164
|
+
body: parseInertHtml(html.slice(0, resolved.maxLength)).body,
|
|
1243
1165
|
truncated: html.length > resolved.maxLength
|
|
1244
1166
|
};
|
|
1245
1167
|
}
|
|
@@ -1259,68 +1181,6 @@ function convert(root, resolved, truncated) {
|
|
|
1259
1181
|
};
|
|
1260
1182
|
}
|
|
1261
1183
|
//#endregion
|
|
1262
|
-
//#region src/core/text-field.ts
|
|
1263
|
-
const TEXT_INPUTS = /* @__PURE__ */ new Set([
|
|
1264
|
-
"text",
|
|
1265
|
-
"search",
|
|
1266
|
-
"url",
|
|
1267
|
-
"tel",
|
|
1268
|
-
"password"
|
|
1269
|
-
]);
|
|
1270
|
-
function asTextField(target) {
|
|
1271
|
-
if (typeof target !== "object" || target === null) return null;
|
|
1272
|
-
const element = target;
|
|
1273
|
-
if (element.nodeName === "TEXTAREA") return target;
|
|
1274
|
-
if (element.nodeName === "INPUT" && typeof element.type === "string" && TEXT_INPUTS.has(element.type)) return target;
|
|
1275
|
-
return null;
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* Inserts text at the cursor of a `<textarea>` or text `<input>`, replacing the
|
|
1279
|
-
* selection, as typing or pasting would: the browser's undo (Ctrl/⌘+Z) still
|
|
1280
|
-
* works, `input` events fire (so React and other frameworks see the change),
|
|
1281
|
-
* and `maxlength` is respected. Returns `false` for disabled or read-only fields.
|
|
1282
|
-
*/
|
|
1283
|
-
function insertText(field, text) {
|
|
1284
|
-
if (field.disabled || field.readOnly) return false;
|
|
1285
|
-
const value = field.nodeName === "INPUT" ? text.replace(/[ \t]*(?:\r\n|\r|\n)+[ \t]*/g, " ") : text;
|
|
1286
|
-
const doc = field.ownerDocument;
|
|
1287
|
-
field.focus();
|
|
1288
|
-
const start = field.selectionStart;
|
|
1289
|
-
const end = field.selectionEnd;
|
|
1290
|
-
try {
|
|
1291
|
-
if (start !== null && end !== null) field.setSelectionRange(start, end);
|
|
1292
|
-
if (doc.activeElement === field && doc.execCommand("insertText", false, value)) return true;
|
|
1293
|
-
} catch {}
|
|
1294
|
-
const from = start ?? field.value.length;
|
|
1295
|
-
const to = end ?? from;
|
|
1296
|
-
let insert = value;
|
|
1297
|
-
if (field.maxLength >= 0) {
|
|
1298
|
-
const room = Math.max(0, field.maxLength - (field.value.length - (to - from)));
|
|
1299
|
-
insert = insert.slice(0, room);
|
|
1300
|
-
if (/[\ud800-\udbff]$/.test(insert)) insert = insert.slice(0, -1);
|
|
1301
|
-
}
|
|
1302
|
-
if (start === null) setNativeValue(field, field.value + insert);
|
|
1303
|
-
else field.setRangeText(insert, from, to, "end");
|
|
1304
|
-
const view = doc.defaultView;
|
|
1305
|
-
const event = view !== null && typeof view.InputEvent === "function" ? new view.InputEvent("input", {
|
|
1306
|
-
bubbles: true,
|
|
1307
|
-
inputType: "insertFromPaste",
|
|
1308
|
-
data: insert
|
|
1309
|
-
}) : new Event("input", { bubbles: true });
|
|
1310
|
-
field.dispatchEvent(event);
|
|
1311
|
-
return true;
|
|
1312
|
-
}
|
|
1313
|
-
/**
|
|
1314
|
-
* Sets a field's value through the prototype's setter. React tracks the value
|
|
1315
|
-
* set on the element itself; going around it lets React see the change and
|
|
1316
|
-
* call `onChange` for the `input` event that follows.
|
|
1317
|
-
*/
|
|
1318
|
-
function setNativeValue(field, next) {
|
|
1319
|
-
const setter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(field), "value")?.set;
|
|
1320
|
-
if (setter) setter.call(field, next);
|
|
1321
|
-
else field.value = next;
|
|
1322
|
-
}
|
|
1323
|
-
//#endregion
|
|
1324
1184
|
//#region src/markdown/paste.ts
|
|
1325
1185
|
const MONOSPACE_PRE = /white-space\s*:\s*pre/i;
|
|
1326
1186
|
const MONOSPACE_FONT = /font-family\s*:[^;]*\b(monospace|courier|consolas|menlo|monaco|mono)\b/i;
|