Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clipboard-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipboard-polyfill - npm Package Compare versions

Comparing version 4.0.0-rc6 to 4.0.0-rc7

6

dist/es5/overwrite-globals/clipboard-polyfill.overwrite-globals.es5.js

@@ -348,9 +348,7 @@ "use strict";

if (originalNavigatorClipboardWrite && originalWindowClipboardItem) {
var originalNavigatorClipboardWriteReference = originalNavigatorClipboardWrite;
var originalNavigatorClipboardWriteCached = originalNavigatorClipboardWrite;
debugLog("Using `navigator.clipboard.write()`.");
return promiseConstructor.all(data.map(clipboardItemToGlobalClipboardItem)).then(
function(globalClipboardItems) {
return originalNavigatorClipboardWriteReference(
globalClipboardItems
).then(truePromiseFn).catch(function(e) {
return originalNavigatorClipboardWriteCached(globalClipboardItems).then(truePromiseFn).catch(function(e) {
if (!hasItemWithType(data, TEXT_PLAIN) && !hasItemWithType(data, TEXT_HTML)) {

@@ -357,0 +355,0 @@ throw e;

@@ -282,3 +282,4 @@ "use strict";

// src/clipboard-polyfill/promise/set-promise-polyfill-if-needed.ts
window.Promise || setPromiseConstructor(PromisePolyfillConstructor);
var _a2;
((_a2 = originalWindow) == null ? void 0 : _a2.Promise) || setPromiseConstructor(PromisePolyfillConstructor);

@@ -288,20 +289,20 @@ // src/clipboard-polyfill/builtins/builtin-globals.ts

var originalNavigatorClipboard = originalNavigator == null ? void 0 : originalNavigator.clipboard;
var _a2;
var originalNavigatorClipboardRead = (_a2 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.read) == null ? void 0 : _a2.bind(
originalNavigatorClipboard
);
var _a3;
var originalNavigatorClipboardReadText = (_a3 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.readText) == null ? void 0 : _a3.bind(
var originalNavigatorClipboardRead = (_a3 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.read) == null ? void 0 : _a3.bind(
originalNavigatorClipboard
);
var _a4;
var originalNavigatorClipboardWrite = (_a4 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.write) == null ? void 0 : _a4.bind(
var originalNavigatorClipboardReadText = (_a4 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.readText) == null ? void 0 : _a4.bind(
originalNavigatorClipboard
);
var _a5;
var originalNavigatorClipboardWriteText = (_a5 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.writeText) == null ? void 0 : _a5.bind(
var originalNavigatorClipboardWrite = (_a5 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.write) == null ? void 0 : _a5.bind(
originalNavigatorClipboard
);
var _a6;
var originalWindowClipboardItem = (_a6 = originalWindow) == null ? void 0 : _a6.ClipboardItem;
var originalNavigatorClipboardWriteText = (_a6 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.writeText) == null ? void 0 : _a6.bind(
originalNavigatorClipboard
);
var _a7;
var originalWindowClipboardItem = (_a7 = originalWindow) == null ? void 0 : _a7.ClipboardItem;
var promiseConstructor = getPromiseConstructor();

@@ -541,3 +542,3 @@

function ClipboardItemPolyfillImpl(items, options) {
var _a7;
var _a8;
var types = Object.keys(items);

@@ -553,3 +554,3 @@ var _items = {};

}
var presentationStyle = (_a7 = options == null ? void 0 : options.presentationStyle) != null ? _a7 : "unspecified";
var presentationStyle = (_a8 = options == null ? void 0 : options.presentationStyle) != null ? _a8 : "unspecified";
function getType(type2) {

@@ -617,9 +618,7 @@ return promiseConstructor.resolve(_items[type2]);

if (originalNavigatorClipboardWrite && originalWindowClipboardItem) {
var originalNavigatorClipboardWriteReference = originalNavigatorClipboardWrite;
var originalNavigatorClipboardWriteCached = originalNavigatorClipboardWrite;
debugLog("Using `navigator.clipboard.write()`.");
return promiseConstructor.all(data.map(clipboardItemToGlobalClipboardItem)).then(
function(globalClipboardItems) {
return originalNavigatorClipboardWriteReference(
globalClipboardItems
).then(truePromiseFn).catch(function(e) {
return originalNavigatorClipboardWriteCached(globalClipboardItems).then(truePromiseFn).catch(function(e) {
if (!hasItemWithType(data, TEXT_PLAIN) && !hasItemWithType(data, TEXT_HTML)) {

@@ -626,0 +625,0 @@ throw e;

@@ -354,9 +354,7 @@ "use strict";

if (originalNavigatorClipboardWrite && originalWindowClipboardItem) {
var originalNavigatorClipboardWriteReference = originalNavigatorClipboardWrite;
var originalNavigatorClipboardWriteCached = originalNavigatorClipboardWrite;
debugLog("Using `navigator.clipboard.write()`.");
return promiseConstructor.all(data.map(clipboardItemToGlobalClipboardItem)).then(
function(globalClipboardItems) {
return originalNavigatorClipboardWriteReference(
globalClipboardItems
).then(truePromiseFn).catch(function(e) {
return originalNavigatorClipboardWriteCached(globalClipboardItems).then(truePromiseFn).catch(function(e) {
if (!hasItemWithType(data, TEXT_PLAIN) && !hasItemWithType(data, TEXT_HTML)) {

@@ -363,0 +361,0 @@ throw e;

@@ -282,3 +282,4 @@ "use strict";

// src/clipboard-polyfill/promise/set-promise-polyfill-if-needed.ts
window.Promise || setPromiseConstructor(PromisePolyfillConstructor);
var _a2;
((_a2 = originalWindow) == null ? void 0 : _a2.Promise) || setPromiseConstructor(PromisePolyfillConstructor);

@@ -288,20 +289,20 @@ // src/clipboard-polyfill/builtins/builtin-globals.ts

var originalNavigatorClipboard = originalNavigator == null ? void 0 : originalNavigator.clipboard;
var _a2;
var originalNavigatorClipboardRead = (_a2 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.read) == null ? void 0 : _a2.bind(
originalNavigatorClipboard
);
var _a3;
var originalNavigatorClipboardReadText = (_a3 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.readText) == null ? void 0 : _a3.bind(
var originalNavigatorClipboardRead = (_a3 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.read) == null ? void 0 : _a3.bind(
originalNavigatorClipboard
);
var _a4;
var originalNavigatorClipboardWrite = (_a4 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.write) == null ? void 0 : _a4.bind(
var originalNavigatorClipboardReadText = (_a4 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.readText) == null ? void 0 : _a4.bind(
originalNavigatorClipboard
);
var _a5;
var originalNavigatorClipboardWriteText = (_a5 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.writeText) == null ? void 0 : _a5.bind(
var originalNavigatorClipboardWrite = (_a5 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.write) == null ? void 0 : _a5.bind(
originalNavigatorClipboard
);
var _a6;
var originalWindowClipboardItem = (_a6 = originalWindow) == null ? void 0 : _a6.ClipboardItem;
var originalNavigatorClipboardWriteText = (_a6 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.writeText) == null ? void 0 : _a6.bind(
originalNavigatorClipboard
);
var _a7;
var originalWindowClipboardItem = (_a7 = originalWindow) == null ? void 0 : _a7.ClipboardItem;
var promiseConstructor = getPromiseConstructor();

@@ -392,3 +393,3 @@

function ClipboardItemPolyfillImpl(items, options) {
var _a7;
var _a8;
var types = Object.keys(items);

@@ -404,3 +405,3 @@ var _items = {};

}
var presentationStyle = (_a7 = options == null ? void 0 : options.presentationStyle) != null ? _a7 : "unspecified";
var presentationStyle = (_a8 = options == null ? void 0 : options.presentationStyle) != null ? _a8 : "unspecified";
function getType(type2) {

@@ -623,9 +624,7 @@ return promiseConstructor.resolve(_items[type2]);

if (originalNavigatorClipboardWrite && originalWindowClipboardItem) {
var originalNavigatorClipboardWriteReference = originalNavigatorClipboardWrite;
var originalNavigatorClipboardWriteCached = originalNavigatorClipboardWrite;
debugLog("Using `navigator.clipboard.write()`.");
return promiseConstructor.all(data.map(clipboardItemToGlobalClipboardItem)).then(
function(globalClipboardItems) {
return originalNavigatorClipboardWriteReference(
globalClipboardItems
).then(truePromiseFn).catch(function(e) {
return originalNavigatorClipboardWriteCached(globalClipboardItems).then(truePromiseFn).catch(function(e) {
if (!hasItemWithType(data, TEXT_PLAIN) && !hasItemWithType(data, TEXT_HTML)) {

@@ -632,0 +631,0 @@ throw e;

@@ -1,22 +0,263 @@

import {
TEXT_HTML,
TEXT_PLAIN,
debugLog,
falsePromise,
originalNavigatorClipboardRead,
originalNavigatorClipboardWrite,
originalWindowClipboardItem,
promiseConstructor,
promiseRecordMap,
readText,
rejectThrownErrors,
setDebugLog,
shouldShowWarnings,
suppressWarnings,
truePromiseFn,
voidPromise,
writeFallback,
writeText
} from "./chunk-ZMZD3ZPV.js";
// src/clipboard-polyfill/ClipboardItem/data-types.ts
var TEXT_PLAIN = "text/plain";
var TEXT_HTML = "text/html";
// src/clipboard-polyfill/debug.ts
var debugLogImpl = (s) => {
};
function debugLog(s) {
debugLogImpl(s);
}
function setDebugLog(logFn) {
debugLogImpl = logFn;
}
var showWarnings = true;
function suppressWarnings() {
showWarnings = false;
}
function shouldShowWarnings() {
return showWarnings;
}
function warnOrLog() {
(console.warn || console.log).apply(console, arguments);
}
var warn = warnOrLog.bind("[clipboard-polyfill]");
// src/clipboard-polyfill/builtins/window-globalThis.ts
var originalWindow = typeof window === "undefined" ? void 0 : window;
var originalGlobalThis = typeof globalThis === "undefined" ? void 0 : globalThis;
// src/clipboard-polyfill/builtins/promise-constructor.ts
var _a, _b, _c;
var promiseConstructorImpl = (_c = (_a = originalWindow) == null ? void 0 : _a.Promise) != null ? _c : (_b = originalGlobalThis) == null ? void 0 : _b.Promise;
function getPromiseConstructor() {
if (!promiseConstructorImpl) {
throw new Error(
"No `Promise` implementation available for `clipboard-polyfill`. Consider using: https://github.com/lgarron/clipboard-polyfill#flat-file-version-with-promise-included"
);
}
return promiseConstructorImpl;
}
// src/clipboard-polyfill/builtins/builtin-globals.ts
var originalNavigator = typeof navigator === "undefined" ? void 0 : navigator;
var originalNavigatorClipboard = originalNavigator == null ? void 0 : originalNavigator.clipboard;
var _a2;
var originalNavigatorClipboardRead = (_a2 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.read) == null ? void 0 : _a2.bind(
originalNavigatorClipboard
);
var _a3;
var originalNavigatorClipboardReadText = (_a3 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.readText) == null ? void 0 : _a3.bind(
originalNavigatorClipboard
);
var _a4;
var originalNavigatorClipboardWrite = (_a4 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.write) == null ? void 0 : _a4.bind(
originalNavigatorClipboard
);
var _a5;
var originalNavigatorClipboardWriteText = (_a5 = originalNavigatorClipboard == null ? void 0 : originalNavigatorClipboard.writeText) == null ? void 0 : _a5.bind(
originalNavigatorClipboard
);
var _a6;
var originalWindowClipboardItem = (_a6 = originalWindow) == null ? void 0 : _a6.ClipboardItem;
var promiseConstructor = getPromiseConstructor();
// src/clipboard-polyfill/strategies/internet-explorer.ts
var ieWindow = originalWindow;
function seemToBeInIE() {
return typeof ClipboardEvent === "undefined" && typeof (ieWindow == null ? void 0 : ieWindow.clipboardData) !== "undefined" && typeof (ieWindow == null ? void 0 : ieWindow.clipboardData.setData) !== "undefined";
}
function writeTextIE(text) {
var success = ieWindow.clipboardData.setData("Text", text);
if (success) {
debugLog("writeTextIE worked");
}
return success;
}
function readTextIE() {
var text = ieWindow.clipboardData.getData("Text");
if (text === "") {
throw new Error(
"Empty clipboard or could not read plain text from clipboard"
);
}
return text;
}
// src/clipboard-polyfill/strategies/dom.ts
function copyListener(tracker, data, e) {
debugLog("listener called");
tracker.success = true;
for (var type in data) {
var value = data[type];
var clipboardData = e.clipboardData;
clipboardData.setData(type, value);
if (type === TEXT_PLAIN && clipboardData.getData(type) !== value) {
debugLog("setting text/plain failed");
tracker.success = false;
}
}
e.preventDefault();
}
function execCopy(data) {
var tracker = { success: false };
var listener = copyListener.bind(this, tracker, data);
document.addEventListener("copy", listener);
try {
document.execCommand("copy");
} finally {
document.removeEventListener("copy", listener);
}
return tracker.success;
}
function copyUsingTempSelection(e, data) {
selectionSet(e);
var success = execCopy(data);
selectionClear();
return success;
}
function copyUsingTempElem(data) {
var tempElem = document.createElement("div");
tempElem.setAttribute("style", "-webkit-user-select: text !important");
tempElem.textContent = "temporary element";
document.body.appendChild(tempElem);
var success = copyUsingTempSelection(tempElem, data);
document.body.removeChild(tempElem);
return success;
}
function copyTextUsingDOM(str) {
debugLog("copyTextUsingDOM");
var tempElem = document.createElement("div");
tempElem.setAttribute("style", "-webkit-user-select: text !important");
var spanParent = tempElem;
if (tempElem.attachShadow) {
debugLog("Using shadow DOM.");
spanParent = tempElem.attachShadow({ mode: "open" });
}
var span = document.createElement("span");
span.innerText = str;
spanParent.appendChild(span);
document.body.appendChild(tempElem);
selectionSet(span);
var result = document.execCommand("copy");
selectionClear();
document.body.removeChild(tempElem);
return result;
}
function selectionSet(elem) {
var sel = document.getSelection();
if (sel) {
var range = document.createRange();
range.selectNodeContents(elem);
sel.removeAllRanges();
sel.addRange(range);
}
}
function selectionClear() {
var sel = document.getSelection();
if (sel) {
sel.removeAllRanges();
}
}
// src/clipboard-polyfill/implementations/write-fallback.ts
function writeFallback(stringItem) {
var hasTextPlain = TEXT_PLAIN in stringItem;
if (seemToBeInIE()) {
if (!hasTextPlain) {
throw new Error("No `text/plain` value was specified.");
}
if (writeTextIE(stringItem[TEXT_PLAIN])) {
return true;
} else {
throw new Error("Copying failed, possibly because the user rejected it.");
}
}
if (execCopy(stringItem)) {
debugLog("regular execCopy worked");
return true;
}
if (navigator.userAgent.indexOf("Edge") > -1) {
debugLog('UA "Edge" => assuming success');
return true;
}
if (copyUsingTempSelection(document.body, stringItem)) {
debugLog("copyUsingTempSelection worked");
return true;
}
if (copyUsingTempElem(stringItem)) {
debugLog("copyUsingTempElem worked");
return true;
}
if (copyTextUsingDOM(stringItem[TEXT_PLAIN])) {
debugLog("copyTextUsingDOM worked");
return true;
}
return false;
}
// src/clipboard-polyfill/promise/promise-compat.ts
function promiseRecordMap(keys, f) {
var promiseList = [];
for (var i in keys) {
var key = keys[i];
promiseList.push(f(key));
}
return promiseConstructor.all(promiseList).then((vList) => {
var dataOut = {};
for (var i2 = 0; i2 < keys.length; i2++) {
dataOut[keys[i2]] = vList[i2];
}
return dataOut;
});
}
var voidPromise = promiseConstructor.resolve();
var truePromiseFn = () => promiseConstructor.resolve(true);
var falsePromise = promiseConstructor.resolve(false);
function rejectThrownErrors(executor) {
return new promiseConstructor((resolve, reject) => {
try {
resolve(executor());
} catch (e) {
reject(e);
}
});
}
// src/clipboard-polyfill/implementations/text.ts
function stringToStringItem(s) {
var stringItem = {};
stringItem[TEXT_PLAIN] = s;
return stringItem;
}
function writeText(s) {
return rejectThrownErrors(() => {
if (originalNavigatorClipboardWriteText) {
debugLog("Using `navigator.clipboard.writeText()`.");
return originalNavigatorClipboardWriteText(s).catch(
writeTextStringFallback
);
}
return promiseConstructor.resolve(writeTextStringFallback(s));
});
}
function writeTextStringFallback(s) {
if (!writeFallback(stringToStringItem(s))) {
throw new Error("writeText() failed");
}
}
function readText() {
return rejectThrownErrors(() => {
if (originalNavigatorClipboardReadText) {
debugLog("Using `navigator.clipboard.readText()`.");
return originalNavigatorClipboardReadText();
}
if (seemToBeInIE()) {
var result = readTextIE();
return promiseConstructor.resolve(result);
}
throw new Error("Read is not supported in your browser.");
});
}
// src/clipboard-polyfill/ClipboardItem/check.ts

@@ -35,3 +276,3 @@ function hasItemWithType(clipboardItems, typeName) {

function ClipboardItemPolyfillImpl(items, options) {
var _a;
var _a7;
var types = Object.keys(items);

@@ -47,3 +288,3 @@ var _items = {};

}
var presentationStyle = (_a = options == null ? void 0 : options.presentationStyle) != null ? _a : "unspecified";
var presentationStyle = (_a7 = options == null ? void 0 : options.presentationStyle) != null ? _a7 : "unspecified";
function getType(type2) {

@@ -111,9 +352,7 @@ return promiseConstructor.resolve(_items[type2]);

if (originalNavigatorClipboardWrite && originalWindowClipboardItem) {
var originalNavigatorClipboardWriteReference = originalNavigatorClipboardWrite;
var originalNavigatorClipboardWriteCached = originalNavigatorClipboardWrite;
debugLog("Using `navigator.clipboard.write()`.");
return promiseConstructor.all(data.map(clipboardItemToGlobalClipboardItem)).then(
(globalClipboardItems) => {
return originalNavigatorClipboardWriteReference(
globalClipboardItems
).then(truePromiseFn).catch((e) => {
return originalNavigatorClipboardWriteCached(globalClipboardItems).then(truePromiseFn).catch((e) => {
if (!hasItemWithType(data, TEXT_PLAIN) && !hasItemWithType(data, TEXT_HTML)) {

@@ -120,0 +359,0 @@ throw e;

{
"name": "clipboard-polyfill",
"version": "4.0.0-rc6",
"version": "4.0.0-rc7",
"description": "A polyfill for the asynchronous clipboard API",

@@ -47,3 +47,3 @@ "type": "module",

"mock-test": "./script/mock-test.bash",
"test-no-es6-browser-globals": "node dist/es6/clipboard-polyfill.es6.js && node dist/es6/clipboard-polyfill.text.es6.js",
"test-no-es6-browser-globals": "node dist/es6/clipboard-polyfill.es6.js",
"dev": "node script/dev.js",

@@ -66,8 +66,4 @@ "lint": "npx rome check ./script ./src",

"types": "./dist/types/entries/es5/overwrite-globals.d.ts"
},
"./text": {
"import": "./dist/es6/clipboard-polyfill.text.es6.js",
"types": "./dist/types/entries/es6/clipboard-polyfill.text.es6.d.ts"
}
}
}

@@ -7,5 +7,4 @@ ![Logo for clipboard-polyfill: an icon of a clipboard fading into a drafting paper grid.](clipboard-polyfill-logo.svg)

Note: As of 2020, you can use `navigator.clipboard.writeText(...)` [in the stable versions of all major browsers](https://caniuse.com/mdn-api_clipboard_writetext). This library will only be useful to you if you want to:
Note: As of 2021, you can use `navigator.clipboard.writeText(...)` [in the stable versions of all major browsers](https://caniuse.com/mdn-api_clipboard_writetext). This library will only be useful to you if you want to:
- target older browsers (see below for compatibility) for text copy,

@@ -16,24 +15,4 @@ - copy `text/html` in Firefox,

| Browser | First version supporting<br>`navigator.clipboard.writeText(...)` | Release Date |
| ------- | ------------------------------------------------------------- | ------------ |
| Chrome | 66+ | April 2018 |
| Firefox | 53+ | October 2018 |
| Edge | 79+ (first Chromium-based release) | January 2020 |
| Safari | 13.1+ | March 2020 |
See the "Compatibility" section below for more details.
See the "Compatibility" section below for more details. If you believe you have a use case that warrants continued maintenance, please [file an issue](https://github.com/lgarron/clipboard-polyfill/issues/new)!
### A brief history
This project dates from a time when clipboard access in JS was barely becoming possible, and [ergonomic clipboard API efforts were stalling](https://lists.w3.org/Archives/Public/public-webapps/2015JulSep/0235.html). (See [this presentation](https://docs.google.com/presentation/d/1Ix2rYi67hbZoIQsd85kspkUPLi8Q-PZopy_AtfafHW0/) for a bit more context.) Fortunately, [an ergonomic API with the same functionality](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) is now available in all modern browsers since 2020:
- 2015: Browsers [start supporting](https://caniuse.com/mdn-api_document_execcommand_copy) the [defunct](https://w3c.github.io/editing/docs/execCommand/) `document.execCommand("copy")` call (with [many, many issues](./experiment/Conclusions.md)).
- 2015: Started this project as `clipboard.js` (half a year before @zenorocha picked [the same name](https://github.com/zenorocha/clipboard.js) 😛).
- 2016: Renewed discussions about an async clipboard API (e.g. [proposal doc](https://docs.google.com/document/d/1QI5rKJSiYeD9ekP2NyCYJuOnivduC9-tqEOn-GsCGS4/edit#), [`crbug.com/593475`](https://bugs.chromium.org/p/chromium/issues/detail?id=593475)).
- 2017: Renamed this project to `clipboard-polyfill` to reflect a `v2` API overhaul aligned with the draft spec.
- 2018: Browsers [start supporting](https://caniuse.com/mdn-api_clipboard_writetext) `navigator.clipboard.writeText()`.
- 2020: Browsers [start supporting](https://caniuse.com/mdn-api_clipboard_write) `navigator.clipboard.write()` (including `text/html` support).
Thanks to Gary Kacmarcik, Hallvord Steen, and others for helping to bring the [async clipboard API](https://w3c.github.io/clipboard-apis/) to life!
---

@@ -62,14 +41,8 @@

```js
// Using the `clipboard/text` build saves code size.
// This is recommended if you only need to copy text.
import * as clipboard from "clipboard-polyfill/text";
import * as clipboard from "clipboard-polyfill";
function handler() {
clipboard.writeText("This text is plain.").then(
() => {
console.log("success!");
},
() => {
console.log("error!");
}
() => { console.log("success!"); },
() => { console.log("error!"); }
);

@@ -93,3 +66,3 @@ }

```js
import * as clipboard from "clipboard-polyfill/text";
import * as clipboard from "clipboard-polyfill";

@@ -192,9 +165,20 @@ async function handler() {

### Minification
### Bundling / tree shaking / minification / CommonJS
Builds are not minified. To minify code, pass it through your bundler of choice. If you want to get a minified version of an ES5 build, you can run:
Thanks to the conveniences of the modern JS ecosystem, we do not provide tree shaken, minified, or CommonJS builds anymore. To get such builds without losing compatibility, pass `clipboard-polyfill` builds through `esbuild`. For example:
```shell
curl --location https://unpkg.com/clipboard-polyfill/dist/es5/window-var/clipboard-polyfill.window-var.promise.es5.js \
| npx esbuild --target=es5 --minify
mkdir temp && cd temp && npm install clipboard-polyfill esbuild
# Minify the ES6 build:
echo 'export * from "clipboard-polyfill";' | npx esbuild --format=esm --target=es6 --bundle --minify
# Include just the `writeText()` export and minify:
echo 'export { writeText } from "clipboard-polyfill";' | npx esbuild --format=esm --target=es6 --bundle --minify
# Minify an ES5 build:
cat node_modules/clipboard-polyfill/dist/es5/window-var/clipboard-polyfill.window-var.promise.es5.js | npx esbuild --format=esm --target=es5 --bundle --minify
# Get a CommonJS build:
echo 'export * from "clipboard-polyfill";' | npx esbuild --format=cjs --target=es6 --bundle
```

@@ -246,2 +230,26 @@

### History
## Browser history
| Browser | First version supporting<br>`navigator.clipboard.writeText(...)` | Release Date |
| ------- | ------------------------------------------------------------- | ------------ |
| Chrome | 66+ | April 2018 |
| Firefox | 53+ | October 2018 |
| Edge | 79+ (first Chromium-based release) | January 2020 |
| Safari | 13.1+ | March 2020 |
### Project history
This project dates from a time when clipboard access in JS was barely becoming possible, and [ergonomic clipboard API efforts were stalling](https://lists.w3.org/Archives/Public/public-webapps/2015JulSep/0235.html). (See [this presentation](https://docs.google.com/presentation/d/1Ix2rYi67hbZoIQsd85kspkUPLi8Q-PZopy_AtfafHW0/) for a bit more context.) Fortunately, [an ergonomic API with the same functionality](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) is now available in all modern browsers since 2020:
- 2015: Browsers [start supporting](https://caniuse.com/mdn-api_document_execcommand_copy) the [defunct](https://w3c.github.io/editing/docs/execCommand/) `document.execCommand("copy")` call (with [many, many issues](./experiment/Conclusions.md)).
- 2015: Started this project as `clipboard.js` (half a year before @zenorocha picked [the same name](https://github.com/zenorocha/clipboard.js) 😛).
- 2016: Renewed discussions about an async clipboard API (e.g. [proposal doc](https://docs.google.com/document/d/1QI5rKJSiYeD9ekP2NyCYJuOnivduC9-tqEOn-GsCGS4/edit#), [`crbug.com/593475`](https://bugs.chromium.org/p/chromium/issues/detail?id=593475)).
- 2017: Renamed this project to `clipboard-polyfill` to reflect a `v2` API overhaul aligned with the draft spec.
- 2018: Browsers [start supporting](https://caniuse.com/mdn-api_clipboard_writetext) `navigator.clipboard.writeText()`.
- 2020: Browsers [start supporting](https://caniuse.com/mdn-api_clipboard_write) `navigator.clipboard.write()` (including `text/html` support).
Thanks to Gary Kacmarcik, Hallvord Steen, and others for helping to bring the [async clipboard API](https://w3c.github.io/clipboard-apis/) to life!
## This is way too complicated!

@@ -248,0 +256,0 @@

@@ -32,3 +32,3 @@ import { hasItemWithType } from "../ClipboardItem/check";

// TODO: This reference is a workaround for TypeScript inference.
var originalNavigatorClipboardWriteReference =
var originalNavigatorClipboardWriteCached =
originalNavigatorClipboardWrite;

@@ -42,5 +42,3 @@ debugLog("Using `navigator.clipboard.write()`.");

): Promise<boolean> => {
return originalNavigatorClipboardWriteReference(
globalClipboardItems,
)
return originalNavigatorClipboardWriteCached(globalClipboardItems)
.then(truePromiseFn)

@@ -47,0 +45,0 @@ .catch((e: Error): Promise<boolean> => {

import { setPromiseConstructor } from "../builtins/promise-constructor";
import { originalWindow } from "../builtins/window-globalThis";
import { PromisePolyfillConstructor } from "./polyfill";
(window as any).Promise || setPromiseConstructor(PromisePolyfillConstructor);
originalWindow?.Promise || setPromiseConstructor(PromisePolyfillConstructor);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc