This commit is contained in:
NoryiE
2025-02-16 14:12:49 +00:00
parent c6a89e5b35
commit e0aeb9b06e
2737 changed files with 5220 additions and 1039045 deletions

View File

@@ -1,25 +0,0 @@
export namespace defaults {
let position: string;
let target: string;
let message: string;
let label: null;
let classes: string;
let preferSibling: string;
}
declare const _default: import("vue").DefineComponent<{}, {
label: string;
position: string;
target: string;
message: string;
classes: string;
content: string;
$props: {
readonly label?: string | undefined;
readonly position?: string | undefined;
readonly target?: string | undefined;
readonly message?: string | undefined;
readonly classes?: string | undefined;
readonly content?: string | undefined;
};
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
export default _default;

View File

@@ -1 +0,0 @@
export default function copyToClipboard(text: any): Promise<void>;

View File

@@ -1,18 +0,0 @@
import CopyButton from './components/CopyButton.vue';
export default CopyButton;
export declare const defaultSettings: import("vue").DefineComponent<{}, {
label: string;
position: string;
target: string;
message: string;
classes: string;
content: string;
$props: {
readonly label?: string | undefined;
readonly position?: string | undefined;
readonly target?: string | undefined;
readonly message?: string | undefined;
readonly classes?: string | undefined;
readonly content?: string | undefined;
};
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;

View File

@@ -1 +0,0 @@
.copy-btn[data-v-32f61984]{position:relative;vertical-align:middle;border:1px solid var(--vp-code-copy-code-border-color);border-radius:4px;display:inline-block;width:18px;height:18px;background-color:var(--vp-code-copy-code-bg);cursor:pointer;background-image:var(--vp-icon-copy);background-position:50%;background-size:20px;background-repeat:no-repeat;line-height:1}.copy-btn[data-v-32f61984].copy-btn-beforeend[data-v-32f61984]{margin-left:5px}.copy-btn[data-v-32f61984].copy-btn-afterbegin[data-v-32f61984]{margin-right:5px}.copy-btn[data-v-32f61984][data-label][data-v-32f61984]{width:auto;padding-left:22px;padding-right:4px;background-position-x:2px;padding-top:0}.copy-btn[data-v-32f61984][data-label][data-v-32f61984][data-v-32f61984]:after{content:attr(data-label);line-height:1.3}.copy-btn[data-v-32f61984][data-message].copied[data-v-32f61984]:before{content:attr(data-message);position:absolute;top:0;left:50%;color:var(--vp-c-text-1);opacity:0;animation:toast-32f61984 1s ease-out;border:1px solid var(--vp-code-copy-code-border-color);border-radius:4px;padding:2px 4px;font-size:small;display:inline-block;background-color:var(--vp-code-copy-code-bg);white-space:nowrap;line-height:1}@keyframes toast-32f61984{0%{opacity:0;transform:translate(-50%,-100%)}50%{opacity:1;transform:translate(-50%,-150%)}to{opacity:0;transform:translate(-50%,-200%)}}

View File

@@ -1,98 +0,0 @@
import { useSlots as h, ref as c, computed as b, onMounted as k, openBlock as _, createElementBlock as S, normalizeClass as A, unref as B } from "vue";
async function L(l) {
try {
return navigator.clipboard.writeText(l);
} catch {
const e = document.createElement("textarea"), a = document.activeElement;
e.value = l, e.setAttribute("readonly", ""), e.style.contain = "strict", e.style.position = "absolute", e.style.left = "-9999px", e.style.fontSize = "12pt";
const t = document.getSelection(), n = t ? t.rangeCount > 0 && t.getRangeAt(0) : null;
document.body.appendChild(e), e.select(), e.selectionStart = 0, e.selectionEnd = l.length, document.execCommand("copy"), document.body.removeChild(e), t && n && (t.removeAllRanges(), t.addRange(n)), a && a.focus();
}
}
const N = (l, e) => {
const a = l.__vccOpts || l;
for (const [t, n] of e)
a[t] = n;
return a;
}, $ = ["data-message", "data-label"], M = ["innerHTML"], d = {
position: "auto",
target: "auto",
message: "copied",
label: null,
classes: "copy-btn",
preferSibling: "previous"
}, O = {
__name: "CopyButton",
props: {
position: {
// start, end, auto
type: String,
default: () => d.position
},
target: {
// previous, next, auto
type: String,
default: () => d.target
},
message: {
type: String,
default: () => d.message
},
label: {
type: String,
default: () => d.label
},
classes: {
type: String,
default: () => d.classes
},
content: {
type: String,
default: null
}
},
setup(l) {
var v, g;
const e = l, a = h(), t = c(null), n = c(null), p = c(!0), f = c(null), r = c(null), C = e.label ? e.label : (g = (v = a.default) == null ? void 0 : v.call(a)[0]) == null ? void 0 : g.children, E = b(() => `<!-- Button not rendered: ${f.value} -->`), x = b(() => e.message.replace("$CONTENT", r.value));
k(() => {
var m, y;
const s = ((m = t.value.previousElementSibling) == null ? void 0 : m.tagName) === "CODE" ? t.value.previousElementSibling : null, i = ((y = t.value.nextElementSibling) == null ? void 0 : y.tagName) === "CODE" ? t.value.nextElementSibling : null;
if (!s && !i && !e.content) {
p.value = !1, f.value = "No code element found and no content prop given";
return;
}
if (e.content) {
r.value = e.content;
return;
}
let o = e.position;
if (e.target === "auto" ? s && i ? (n.value = s, o === "auto" && (o = "end")) : n.value = s || i : e.target === "previous" ? (n.value = s, o === "auto" && (o = "end")) : e.target === "next" && (n.value = i, o === "auto" && (o = "start")), !n.value) {
f.value = "Failed to select code node";
return;
}
let u = "beforeend";
o === "auto" ? s ? u = "beforeend" : i && (u = "afterbegin") : o === "start" ? u = "afterbegin" : o === "end" && (u = "beforeend"), r.value = n.value.innerText, n.value.innerText = "", n.value.insertAdjacentHTML("beforeend", `<span>${r.value}</span>`), n.value.insertAdjacentElement(u, t.value), t.value.classList.add(`copy-btn-${u}`);
});
async function T() {
await L(r.value), t.value.classList.add("copied"), setTimeout(() => {
t.value.classList.remove("copied");
}, 1e3);
}
return (s, i) => p.value ? (_(), S("span", {
key: 0,
class: A(l.classes),
ref_key: "btn",
ref: t,
onClick: T,
"data-message": x.value,
"data-label": B(C)
}, null, 10, $)) : (_(), S("span", {
key: 1,
innerHTML: E.value
}, null, 8, M));
}
}, R = /* @__PURE__ */ N(O, [["__scopeId", "data-v-32f61984"]]), H = R;
export {
R as default,
H as defaultSettings
};

View File

@@ -1 +0,0 @@
(function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.VitepressCopyHelper={},i.Vue))})(this,function(i,t){"use strict";async function S(o){try{return navigator.clipboard.writeText(o)}catch{const e=document.createElement("textarea"),a=document.activeElement;e.value=o,e.setAttribute("readonly",""),e.style.contain="strict",e.style.position="absolute",e.style.left="-9999px",e.style.fontSize="12pt";const n=document.getSelection(),l=n?n.rangeCount>0&&n.getRangeAt(0):null;document.body.appendChild(e),e.select(),e.selectionStart=0,e.selectionEnd=o.length,document.execCommand("copy"),document.body.removeChild(e),n&&l&&(n.removeAllRanges(),n.addRange(l)),a&&a.focus()}}const L="",C=(o,e)=>{const a=o.__vccOpts||o;for(const[n,l]of e)a[n]=l;return a},E=["data-message","data-label"],T=["innerHTML"],d={position:"auto",target:"auto",message:"copied",label:null,classes:"copy-btn",preferSibling:"previous"},m=C({__name:"CopyButton",props:{position:{type:String,default:()=>d.position},target:{type:String,default:()=>d.target},message:{type:String,default:()=>d.message},label:{type:String,default:()=>d.label},classes:{type:String,default:()=>d.classes},content:{type:String,default:null}},setup(o){var v,y;const e=o,a=t.useSlots(),n=t.ref(null),l=t.ref(null),g=t.ref(!0),p=t.ref(null),f=t.ref(null),x=e.label?e.label:(y=(v=a.default)==null?void 0:v.call(a)[0])==null?void 0:y.children,k=t.computed(()=>`<!-- Button not rendered: ${p.value} -->`),B=t.computed(()=>e.message.replace("$CONTENT",f.value));t.onMounted(()=>{var b,_;const r=((b=n.value.previousElementSibling)==null?void 0:b.tagName)==="CODE"?n.value.previousElementSibling:null,c=((_=n.value.nextElementSibling)==null?void 0:_.tagName)==="CODE"?n.value.nextElementSibling:null;if(!r&&!c&&!e.content){g.value=!1,p.value="No code element found and no content prop given";return}if(e.content){f.value=e.content;return}let s=e.position;if(e.target==="auto"?r&&c?(l.value=r,s==="auto"&&(s="end")):l.value=r||c:e.target==="previous"?(l.value=r,s==="auto"&&(s="end")):e.target==="next"&&(l.value=c,s==="auto"&&(s="start")),!l.value){p.value="Failed to select code node";return}let u="beforeend";s==="auto"?r?u="beforeend":c&&(u="afterbegin"):s==="start"?u="afterbegin":s==="end"&&(u="beforeend"),f.value=l.value.innerText,l.value.innerText="",l.value.insertAdjacentHTML("beforeend",`<span>${f.value}</span>`),l.value.insertAdjacentElement(u,n.value),n.value.classList.add(`copy-btn-${u}`)});async function A(){await S(f.value),n.value.classList.add("copied"),setTimeout(()=>{n.value.classList.remove("copied")},1e3)}return(r,c)=>g.value?(t.openBlock(),t.createElementBlock("span",{key:0,class:t.normalizeClass(o.classes),ref_key:"btn",ref:n,onClick:A,"data-message":B.value,"data-label":t.unref(x)},null,10,E)):(t.openBlock(),t.createElementBlock("span",{key:1,innerHTML:k.value},null,8,T))}},[["__scopeId","data-v-32f61984"]]),h=m;i.default=m,i.defaultSettings=h,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});

View File

@@ -1,48 +0,0 @@
{
"name": "vitepress-copy-helper",
"version": "0.0.3",
"description": "customizable, easy-to-use copy buttons for single-backtick code blocks and general purpose copy helper for vitepress",
"type": "module",
"keywords": [
"vue",
"vitepress",
"vitepress-plugin",
"copy-and-paste",
"copy"
],
"license": "MIT",
"homepage": "https://github.com/Mtillmann/vitepress-copy-helper",
"author": "Martin Tillmann<mtillmann@gmail.com>",
"bugs": {
"url": "https://github.com/Mtillmann/vitepress-copy-helper/issues"
},
"files": [
"dist"
],
"main": "./dist/vitepress-copy-helper.umd.cjs",
"module": "./dist/vitepress-copy-helper.js",
"exports": {
".": {
"import": "./dist/vitepress-copy-helper.js",
"require": "./dist/vitepress-copy-helper.umd.cjs"
},
"./style.css": "./dist/style.css"
},
"dependencies": {
"vue": "^3.2.47"
},
"types": "./dist/index.d.ts",
"scripts": {
"dev": "vite",
"build": "vite build && vue-tsc --emitDeclarationOnly",
"types": "vue-tsc ",
"preview": "vite preview"
},
"devDependencies": {
"@types/node": "^20.2.5",
"@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.0.2",
"vite": "^4.3.9",
"vue-tsc": "^1.4.2"
}
}

View File

@@ -1,45 +0,0 @@
# vitepress-copy-helper
This plugin lets you add a copy button to your single-backtick-code-blocks and general purpose copy buttons.
## Installation
```bash
npm install --save-dev vitepress-copy-helper
```
## Usage
In `.vitepress/theme/index.js`:
```js
import CopyButton from 'vitepress-copy-helper';
import 'vitepress-copy-helper/style.css'
```
then, in the `enhanceApp` function, add:
```js
app.component('C', CopyButton),
```
`C` is the name of the component you will use in your markdown files, you can change it to whatever you want.
## Default Settings
To override the default settings, change the import to:
```js
import {default as CopyButton, defaultSettings} from 'vitepress-copy-helper'
import 'vitepress-copy-helper/style.css'
```
Just change the properties of `defaultSettings` to your liking:
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| position | string | 'auto' | The position of the button, relative to the target `code`-element. `auto`, `start`, `end` |
| message | string | 'copied' | The message that will be displayed when the button is clicked |
| label | string | null | The label of the button, if `null`, no label is rendered |
| classes | string | 'copy-btn' | The classes that will be added to the button |
| target | string | 'auto' | Controls which `code`-element the button attaches to when wedged between `code`-elements |
| preferSibling | string | 'previous' | Controls which `code`-element is picked when button is wedged and `target` is `auto`. `previous`, `next` |
## Examples
[Look here for usage examples](https://mtillmann.github.io/posts/simple-copy-button-helper-for-vitepress.html)