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

copy-rich-text

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-rich-text - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

cjs/copy.d.ts

@@ -1,2 +0,2 @@

export declare type CopyOptions = {
export type CopyOptions = {
/**

@@ -3,0 +3,0 @@ * @description 当传入 string 时,复制原始 html 字符串。

@@ -10,11 +10,8 @@ 'use strict';

let dom;
if (typeof textOrElement === 'number') {
textOrElement = String(textOrElement);
}
if (typeof textOrElement === 'string') {
dom = document.createElement('div');
if (options != null && options.html) {
if (options?.html) {
// console.log('set innerText');

@@ -27,6 +24,5 @@ dom.innerText = textOrElement;

} else if (textOrElement instanceof HTMLElement) {
if (options != null && options.html) {
if (options?.html) {
return copy(textOrElement.innerHTML, options);
}
dom = textOrElement.cloneNode(true);

@@ -37,3 +33,2 @@ } else {

}
dom.style.whiteSpace = 'pre';

@@ -46,10 +41,8 @@ dom.style.left = '-9999px';

}
async function copyDomContent(dom) {
var _window$getSelection;
const text = select(dom); // console.log(dom, text);
const text = select(dom);
// console.log(dom, text);
if (typeof document.execCommand === 'function') {
document.execCommand('copy'); // console.log('copied by execCommand');
document.execCommand('copy');
// console.log('copied by execCommand');
} else if (navigator.clipboard) {

@@ -61,11 +54,9 @@ // todo 无法在普通input粘贴;带图片会报错

// console.log('copied by navigator.clipboard.write');
await navigator.clipboard.writeText(text); // console.log('copied by navigator.clipboard.writeText');
await navigator.clipboard.writeText(text);
// console.log('copied by navigator.clipboard.writeText');
}
(_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.removeAllRanges();
window.getSelection()?.removeAllRanges();
}
function select(element) {
let selectedText;
if (element instanceof HTMLSelectElement) {

@@ -76,14 +67,10 @@ element.focus();

const isReadOnly = element.hasAttribute('readonly');
if (!isReadOnly) {
element.setAttribute('readonly', '');
}
element.select();
element.setSelectionRange(0, element.value.length);
if (!isReadOnly) {
element.removeAttribute('readonly');
}
selectedText = element.value;

@@ -94,11 +81,8 @@ } else {

}
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
if (!selection) {
throw new Error('无法获取当前选择');
}
selection.removeAllRanges();

@@ -108,3 +92,2 @@ selection.addRange(range);

}
return selectedText;

@@ -111,0 +94,0 @@ }

@@ -1,2 +0,2 @@

declare const _default: import("vue").DefineComponent<{}, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
declare const _default: import("vue").DefineComponent<{}, () => any, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;

@@ -1,2 +0,2 @@

declare const _default: import("vue").DefineComponent<{}, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
declare const _default: import("vue").DefineComponent<{}, () => any, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;

@@ -1,3 +0,3 @@

export declare const version = "0.2.0";
export declare const version = "0.2.1";
export * from './copy';
export { copy as default } from './copy';

@@ -7,3 +7,3 @@ 'use strict';

const version = "0.2.0";
const version = "0.2.1";

@@ -10,0 +10,0 @@ exports.copy = copy.copy;

@@ -1,2 +0,2 @@

export declare type CopyOptions = {
export type CopyOptions = {
/**

@@ -3,0 +3,0 @@ * @description 当传入 string 时,复制原始 html 字符串。

@@ -6,11 +6,8 @@ /**

let dom;
if (typeof textOrElement === 'number') {
textOrElement = String(textOrElement);
}
if (typeof textOrElement === 'string') {
dom = document.createElement('div');
if (options != null && options.html) {
if (options?.html) {
// console.log('set innerText');

@@ -23,6 +20,5 @@ dom.innerText = textOrElement;

} else if (textOrElement instanceof HTMLElement) {
if (options != null && options.html) {
if (options?.html) {
return copy(textOrElement.innerHTML, options);
}
dom = textOrElement.cloneNode(true);

@@ -33,3 +29,2 @@ } else {

}
dom.style.whiteSpace = 'pre';

@@ -42,10 +37,8 @@ dom.style.left = '-9999px';

}
async function copyDomContent(dom) {
var _window$getSelection;
const text = select(dom); // console.log(dom, text);
const text = select(dom);
// console.log(dom, text);
if (typeof document.execCommand === 'function') {
document.execCommand('copy'); // console.log('copied by execCommand');
document.execCommand('copy');
// console.log('copied by execCommand');
} else if (navigator.clipboard) {

@@ -57,11 +50,9 @@ // todo 无法在普通input粘贴;带图片会报错

// console.log('copied by navigator.clipboard.write');
await navigator.clipboard.writeText(text); // console.log('copied by navigator.clipboard.writeText');
await navigator.clipboard.writeText(text);
// console.log('copied by navigator.clipboard.writeText');
}
(_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.removeAllRanges();
window.getSelection()?.removeAllRanges();
}
function select(element) {
let selectedText;
if (element instanceof HTMLSelectElement) {

@@ -72,14 +63,10 @@ element.focus();

const isReadOnly = element.hasAttribute('readonly');
if (!isReadOnly) {
element.setAttribute('readonly', '');
}
element.select();
element.setSelectionRange(0, element.value.length);
if (!isReadOnly) {
element.removeAttribute('readonly');
}
selectedText = element.value;

@@ -90,11 +77,8 @@ } else {

}
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
if (!selection) {
throw new Error('无法获取当前选择');
}
selection.removeAllRanges();

@@ -104,3 +88,2 @@ selection.addRange(range);

}
return selectedText;

@@ -107,0 +90,0 @@ }

@@ -1,2 +0,2 @@

declare const _default: import("vue").DefineComponent<{}, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
declare const _default: import("vue").DefineComponent<{}, () => any, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;

@@ -1,2 +0,2 @@

declare const _default: import("vue").DefineComponent<{}, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
declare const _default: import("vue").DefineComponent<{}, () => any, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;

@@ -1,3 +0,3 @@

export declare const version = "0.2.0";
export declare const version = "0.2.1";
export * from './copy';
export { copy as default } from './copy';
export { copy, copy as default } from './copy.js';
const version = "0.2.0";
const version = "0.2.1";
export { version };
{
"name": "copy-rich-text",
"version": "0.2.0",
"version": "0.2.1",
"description": "copy text or rich text to clipboard",

@@ -41,7 +41,2 @@ "main": "cjs/index.js",

],
"engines": {
"node": ">= 14.0.0",
"npm": "6 - 8",
"yarn": "^1.22.10"
},
"author": "bowen",

@@ -48,0 +43,0 @@ "license": "ISC",

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