clipxjs 1.0.0-beta.0-1 → 1.1.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/dist/clipx.min.js +7 -0
- package/package.json +1 -1
package/dist/clipx.min.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
ClipX JS
|
|
3
|
+
https://clipx.dzr.app
|
|
4
|
+
Version: 1.1.0
|
|
5
|
+
Copyright (c) 2024 Mr Akshay Shinde
|
|
6
|
+
Licensed under the MIT license
|
|
7
|
+
*/
|
|
1
8
|
(function(t){function e(){this.attach=this.attach.bind(this),this.isProcessing=!1,this.disable={msg:!1,toast:!1},this.customStyles={}}e.prototype.copyText=function(t){if(navigator.clipboard)return navigator.clipboard.writeText(t);if(navigator.permissions)return navigator.permissions.query({name:"clipboard-write"}).then(function(e){if("granted"===e.state||"prompt"===e.state)return navigator.clipboard.writeText(t);throw new Error("Clipboard write permission denied.")});var e=document.createElement("textarea");return e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),Promise.resolve()},e.prototype.cutText=function(t,e){return this.copyText(t).then(function(){e&&(e.value="",e.textContent="")})},e.prototype.copyFromElement=function(t){var e=t.value||t.textContent;return this.copyText(e)},e.prototype.cutFromElement=function(t){var e=t.value||t.textContent;return this.cutText(e,t)},e.prototype.attach=function(t){var e=document.querySelectorAll(t);e.forEach(function(t){t.addEventListener("click",function(){if(!this.isProcessing){this.isProcessing=!0;var e,o=t.getAttribute("data-clipx-target"),i=t.getAttribute("data-clipx-text"),a=t.hasAttribute("data-clipx-cut"),s=t.getAttribute("data-clipx-msg"),r=t.hasAttribute("data-clipx-toast"),n=t.hasAttribute("data-clipx-disable-msg"),c=t.hasAttribute("data-clipx-disable-toast"),l=t.getAttribute("data-clipx-toast-position")||"bottom",p=parseInt(t.getAttribute("data-clipx-duration"),10)||1500;if(o){var u=document.querySelector(o);u&&(e=a?this.cutFromElement(u):this.copyFromElement(u))}else i&&(e=a?this.cutText(i):this.copyText(i));e&&e.then(()=>this.onSuccess(t,s,r,n,c,l,p)).catch(e=>this.onError(t,e)).finally(()=>{this.isProcessing=!1})}}.bind(this))}.bind(this))},e.prototype.onSuccess=function(t,e,o,i,a,s,r){var n=t.textContent,c=e||"Copied !",l="top"===s?"clipx-toast top":"clipx-toast bottom";if(o||i||this.disable.msg||(t.textContent=c),a||this.disable.toast)setTimeout(function(){this.disable.msg||(t.textContent=n)}.bind(this),r);else{var p=document.createElement("div");p.className=l,p.textContent=c,p.setAttribute("role","alert"),p.setAttribute("aria-live","assertive"),p.style.cssText=this.customStyles.toast||"",document.body.appendChild(p),p.style.opacity=0,setTimeout(()=>p.style.opacity=1,0),setTimeout(function(){p.style.opacity=0,setTimeout(()=>document.body.removeChild(p),500),o||i||this.disable.msg||(t.textContent=n)}.bind(this),r)}},e.prototype.onError=function(t,e){console.error("Failed to cut/copy text: ",e);var o=document.createElement("div");o.className="clipx-toast error",o.textContent="Failed to copy!",o.setAttribute("role","alert"),o.setAttribute("aria-live","assertive"),o.style.cssText=this.customStyles.toast||"",document.body.appendChild(o),setTimeout(()=>{o.style.opacity=0,setTimeout(()=>document.body.removeChild(o),500)},1500)},e.prototype.setCustomStyles=function(t){this.customStyles=t},t.clipx=e;var o=document.createElement("style");o.textContent=" .clipx-toast{font-family:system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,'Open Sans','Helvetica Neue',sans-serif;position:fixed;left:50%;transform:translateX(-50%);background-color:#fff;color:#363636;padding:8px 10px;border-radius:8px;z-index:9999;box-shadow:0 3px 10px rgb(0 0 0 / .1),0 3px 3px rgb(0 0 0 / .05);font-size:14px;text-align:center;opacity:0;animation:fadeIn 0.5s ease forwards;transition:opacity 0.5s ease;max-width:90%;width:auto}.clipx-toast.top{top:20px;bottom:auto}.clipx-toast.bottom{bottom:20px}.clipx-toast.error{background-color:#f8d7da;color:#721c24}@keyframes fadeIn{from{opacity:0;transform:translateY(10px) translateX(-50%)}to{opacity:1;transform:translateY(0) translateX(-50%)}}@keyframes fadeOut{from{opacity:1;transform:translateY(0) translateX(-50%)}to{opacity:0;transform:translateY(10px) translateX(-50%)}}",document.head.appendChild(o)})(this);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clipxjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "ClipX.js is an ultra-light JavaScript library that simplifies clipboard tasks and enriches user feedback. It offers straightforward copy, cut, and paste capabilities, and built-in toast notifications that you can easily customize, providing a quick and efficient way to handle clipboard and notification needs. ——— The Smarter Clipboard Solution.",
|
|
5
5
|
"main": "src/clipx.js",
|
|
6
6
|
"scripts": {
|