clipxjs 1.2.1 → 1.3.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/LICENSE.md CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 [Mr Akshay Shinde](https://github.com/mraxays)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 [Mr Akshay Shinde](https://github.com/mraxays)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,410 +1,410 @@
1
- ![License](https://img.shields.io/badge/License-MIT-ff932e)
2
- ![Release](https://img.shields.io/github/v/release/mraxays/clipxjs?color=ff7a5e)
3
-
4
- # ClipX.js -Maximize Clipboard Power with Minimal Size
5
-
6
- 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.
7
-
8
- ---
9
-
10
- ## Official Website
11
-
12
- For more information about this project, please visit our official website: [ClipX](https://clipx.dzr.app/)
13
-
14
- ---
15
-
16
- ## Table of Contents 📑
17
-
18
- 1. [Why Choose ClipX.js?](#why-choose-clipxjs)
19
- - [Lightweight & Fast](#lightweight--fast)
20
- - [Built-in Feedback](#built-in-feedback)
21
- - [Flexible Customization](#flexible-customization)
22
- - [Easy Integration](#easy-integration)
23
- - [Robust Error Handling](#robust-error-handling)
24
- 2. [Installation](#installation)
25
- - [Via NPM](#via-npm)
26
- - [Via CDN](#via-cdn)
27
- 3. [Initializing ClipX.js](#initializing-clipxjs)
28
- - [Basic Initialization](#basic-initialization)
29
- - [Configuration Options](#configuration-options)
30
- 4. [Attaching ClipX Functionality](#attaching-clipx-functionality)
31
- - [Example: Using Data Attributes](#example-using-data-attributes)
32
- - [Example: Using Class Names](#example-using-class-names)
33
- 5. [Attributes Overview](#attributes-overview)
34
- - [`data-clipx-target`](#data-clipx-target)
35
- - [`data-clipx-text`](#data-clipx-text)
36
- - [`data-clipx-cut`](#data-clipx-cut)
37
- - [`data-clipx-msg`](#data-clipx-msg)
38
- - [`data-clipx-toast`](#data-clipx-toast)
39
- - [`data-clipx-disable-msg`](#data-clipx-disable-msg)
40
- - [`data-clipx-disable-toast`](#data-clipx-disable-toast)
41
- - [`data-clipx-toast-position`](#data-clipx-toast-position)
42
- - [`data-clipx-duration`](#data-clipx-duration)
43
- 6. [Example](#example)
44
- 7. [Demo](#demo--get-start-code)
45
-
46
- ---
47
-
48
- ## Why Choose ClipX.js?
49
-
50
- ### Lightweight & Fast
51
-
52
- - At only 2KB, ClipX.js is smaller and faster than most clipboard libraries.
53
-
54
- ### Built-in Feedback
55
-
56
- - Includes customizable toast notifications for clipboard actions—no need for additional UI libraries.
57
-
58
- ### Flexible Customization
59
-
60
- - Easily style toasts, control message display, and integrate seamlessly with your app's design.
61
-
62
- ### Easy Integration
63
-
64
- - Simple API with minimal setup, ensuring broad compatibility across modern and older browsers.
65
-
66
- ### Robust Error Handling
67
-
68
- - Provides clear, customizable error feedback to enhance user experience and simplify debugging.
69
-
70
- ---
71
-
72
- ## Installation
73
-
74
- ### Via NPM
75
-
76
- ```bash
77
- npm i clipxjs
78
- ```
79
-
80
- ### Via CDN
81
-
82
- Use only one `CDN`
83
-
84
- **jsdelivr**
85
-
86
- ```html
87
- <script src="https://cdn.jsdelivr.net/npm/clipxjs/dist/clipx.min.js"></script>
88
- ```
89
-
90
- **OR**
91
-
92
- **unpkg**
93
-
94
- ```html
95
- <script src="https://unpkg.com/clipxjs/dist/clipx.min.js"></script>
96
- ```
97
-
98
- ---
99
-
100
- ## Initializing ClipX.js
101
-
102
- To get started with ClipX.js, follow these steps to set up and configure the library according to your needs:
103
-
104
- ## Basic Initialization
105
-
106
- ```javascript
107
- /* Initialize ClipX.js instance */
108
- var clipx = new clipx();
109
- ```
110
-
111
- ## Configuration Options
112
-
113
- ### 1. Disable Text Content Change Globally
114
-
115
- To prevent the text content of elements from changing globally, set the `msg` property to `true`. Otherwise, set it to `false` to enable text content change.
116
-
117
- ```javascript
118
- clipx.disable.msg = false; // Set to true to disable text content change globally
119
- ```
120
-
121
- ### 2. Disable Toast Notifications Globally
122
-
123
- To prevent toast notifications from showing globally, set the `toast` property to `true`. Otherwise, set it to `false` to enable toast notifications.
124
-
125
- ```javascript
126
- clipx.disable.toast = false; // Set to true to disable toast notifications globally
127
- ```
128
-
129
- ### 3. Set Custom Styles for Toast Notifications
130
-
131
- Customize the appearance of toast notifications by providing CSS styles. For example, the following configuration sets a dark background with white text, padding, and rounded corners.
132
-
133
- ```javascript
134
- clipx.setCustomStyles({
135
- toast:
136
- "background-color: #333; color: #fff; padding: 12px; border-radius: 5px;",
137
- });
138
- ```
139
-
140
- ### 4. Hide SVG Icon
141
-
142
- To hide Svg Icon from toast
143
-
144
- ```css
145
- .clipx-js-svg-icon {
146
- display: none;
147
- }
148
- ```
149
-
150
- ## Attaching ClipX Functionality
151
-
152
- To bind ClipX.js functionality to elements, use the `attach` method with appropriate selectors. This method will enable clipboard operations on elements with the specified attributes or classes.
153
-
154
- ### Example: Using Data Attributes
155
-
156
- Apply ClipX.js to elements with `data-clipx-text` or `data-clipx-target` attributes.
157
-
158
- ```javascript
159
- clipx.attach("[data-clipx-text], [data-clipx-target]");
160
- ```
161
-
162
- ### Example: Using Class Names
163
-
164
- Alternatively, apply ClipX.js to elements with specific classes.
165
-
166
- ```javascript
167
- clipx.attach(".clipx, .copy-btn, .your-class");
168
- ```
169
-
170
- ---
171
-
172
- ## Attributes Overview
173
-
174
- ### This All Are Attributes
175
-
176
- - **`data-clipx-target`**: Element selector for text source.
177
- - **`data-clipx-text`**: Static text to copy or cut.
178
- - **`data-clipx-cut`**: Toggle cut operation.
179
- - **`data-clipx-msg`**: Custom success message.
180
- - **`data-clipx-toast`**: Show only toast, no text change.
181
- - **`data-clipx-disable-msg`**: Disable element text change.
182
- - **`data-clipx-disable-toast`**: Disable toast notification.
183
- - **`data-clipx-toast-position`**: Position of the toast (top/bottom).
184
- - **`data-clipx-duration`**: Duration of toast visibility.
185
-
186
- ---
187
-
188
- ## Example
189
-
190
- ### `data-clipx-target`
191
-
192
- **Description:** Specifies the target element whose text will be copied to the clipboard when the button is clicked.
193
-
194
- **Example:**
195
-
196
- ```html
197
- <button class="copy-btn" data-clipx-target="#text-to-copy">Copy Text</button>
198
- <p id="text-to-copy">This is the text to be copied.</p>
199
- ```
200
-
201
- ### `data-clipx-text`
202
-
203
- **Description:** Defines a static text string that will be copied to the clipboard when the button is clicked.
204
-
205
- **Example:**
206
-
207
- ```html
208
- <button class="copy-btn" data-clipx-text="Static text to copy">
209
- Copy Static Text
210
- </button>
211
- ```
212
-
213
- ### `data-clipx-cut`
214
-
215
- **Description:** Cuts the text from the specified element, copying it to the clipboard and clearing the element's content.
216
-
217
- **Example:**
218
-
219
- ```html
220
- <textarea id="text-to-cut">This text will be cut.</textarea>
221
- <button class="copy-btn" data-clipx-target="#text-to-cut" data-clipx-cut>
222
- Cut Text
223
- </button>
224
- ```
225
-
226
- ### `data-clipx-msg`
227
-
228
- **Description:** Copies the specified text to the clipboard and shows a toast notification with a custom message.
229
-
230
- **Example:**
231
-
232
- ```html
233
- <button
234
- class="copy-btn"
235
- data-clipx-text="Another static text"
236
- data-clipx-msg="Text copied successfully!"
237
- >
238
- Copy with Custom Message
239
- </button>
240
- ```
241
-
242
- ### `data-clipx-toast`
243
-
244
- **Description:** Displays a toast notification with the copied text. The button text remains unchanged.
245
-
246
- **Example:**
247
-
248
- ```html
249
- <button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast>
250
- Copy with Toast Only
251
- </button>
252
- ```
253
-
254
- ### `data-clipx-disable-msg`
255
-
256
- **Description:** Shows a toast notification without changing the button's text content.
257
-
258
- **Example:**
259
-
260
- ```html
261
- <button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-msg>
262
- Copy with Toast Only, No Text Change
263
- </button>
264
- ```
265
-
266
- ### `USE data-clipx-disable-toast & data-clipx-disable-msg`
267
-
268
- **Description:** Copies the specified text to the clipboard without showing a toast notification And Changing Text Contents.
269
-
270
- **Example:**
271
-
272
- ```html
273
- <button
274
- class="copy-btn"
275
- data-clipx-text="Text to copy"
276
- data-clipx-disable-toast
277
- data-clipx-disable-msg
278
- >
279
- Copy without Toast & with Change Text
280
- </button>
281
- ```
282
-
283
- ### `data-clipx-disable-toast`
284
-
285
- **Description:** Copies the specified text to the clipboard without showing a toast notification.
286
-
287
- **Example:**
288
-
289
- ```html
290
- <button
291
- class="copy-btn"
292
- data-clipx-text="Text to copy"
293
- data-clipx-disable-toast
294
- >
295
- Copy without Toast
296
- </button>
297
- ```
298
-
299
- ### `data-clipx-toast-position`
300
-
301
- **Description:** Defines the position of the toast notification (top or bottom).
302
-
303
- **Example:**
304
-
305
- ```html
306
- <button
307
- class="copy-btn"
308
- data-clipx-text="Text to copy"
309
- data-clipx-toast
310
- data-clipx-toast-position="top"
311
- >
312
- Copy with Toast on Top
313
- </button>
314
- <button
315
- class="copy-btn"
316
- data-clipx-text="Text to copy"
317
- data-clipx-toast
318
- data-clipx-toast-position="bottom"
319
- >
320
- Copy with Toast on Bottom
321
- </button>
322
- ```
323
-
324
- ### `data-clipx-duration`
325
-
326
- **Description:** Sets the duration (in milliseconds) for which the toast notification is visible before it fades out.
327
-
328
- **Example:**
329
-
330
- ```html
331
- <button
332
- class="copy-btn"
333
- data-clipx-text="Text to copy"
334
- data-clipx-toast
335
- data-clipx-duration="3000"
336
- >
337
- Copy with 3 Seconds Toast
338
- </button>
339
- <button
340
- class="copy-btn"
341
- data-clipx-text="Text to copy"
342
- data-clipx-duration="3000"
343
- >
344
- Copy with 3 Seconds Toast & Content Change
345
- </button>
346
- <button
347
- class="copy-btn"
348
- data-clipx-text="Text to copy"
349
- data-clipx-disable-toast
350
- data-clipx-duration="3000"
351
- >
352
- Copy 3 sec Content Change
353
- </button>
354
- ```
355
-
356
- ---
357
-
358
- ## Demo || Get Start Code
359
-
360
- ```html
361
- <h1>ClipX.js Demo</h1>
362
-
363
- <button
364
- class="copy-btn"
365
- data-clipx-text="Static text to copy"
366
- data-clipx-msg="Static text copied!"
367
- >
368
- Copy Static Text
369
- </button>
370
-
371
- <button class="copy-btn" data-clipx-target="#text-to-copy" data-clipx-cut>
372
- Cut Text
373
- </button>
374
- <button class="copy-btn" data-clipx-target="#text-to-copy">Copy Text</button>
375
-
376
- <p id="text-to-copy">This text will be cut and copied to the clipboard.</p>
377
-
378
- <button
379
- class="copy-btn"
380
- data-clipx-text="Another static text"
381
- data-clipx-toast
382
- data-clipx-toast-position="bottom"
383
- >
384
- Copy with Toast Only
385
- </button>
386
-
387
- <button
388
- class="copy-btn"
389
- data-clipx-text="Text with 5 seconds toast"
390
- data-clipx-toast
391
- data-clipx-duration="5000"
392
- >
393
- Copy with 5 Seconds Toast
394
- </button>
395
-
396
- <script src="https://cdn.jsdelivr.net/npm/clipxjs/dist/clipx.min.js"></script>
397
- <script>
398
- // Initialize ClipX.js instance
399
- var clipx = new clipx();
400
-
401
- // Optional: Set custom styles for toast notifications
402
- clipx.setCustomStyles({
403
- toast:
404
- "background-color: #333; color: #fff; padding: 12px; border-radius: 5px;",
405
- });
406
-
407
- // Attach ClipX.js functionality to elements
408
- clipx.attach("[data-clipx-text], [data-clipx-target]");
409
- </script>
410
- ```
1
+ ![License](https://img.shields.io/badge/License-MIT-ff932e)
2
+ ![Release](https://img.shields.io/github/v/release/mraxays/clipxjs?color=ff7a5e)
3
+
4
+ # ClipX.js -Maximize Clipboard Power with Minimal Size
5
+
6
+ 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.
7
+
8
+ ---
9
+
10
+ ## Official Website
11
+
12
+ For more information about this project, please visit our official website: [ClipX](https://clipx.js.org/)
13
+
14
+ ---
15
+
16
+ ## Table of Contents 📑
17
+
18
+ 1. [Why Choose ClipX.js?](#why-choose-clipxjs)
19
+ - [Lightweight & Fast](#lightweight--fast)
20
+ - [Built-in Feedback](#built-in-feedback)
21
+ - [Flexible Customization](#flexible-customization)
22
+ - [Easy Integration](#easy-integration)
23
+ - [Robust Error Handling](#robust-error-handling)
24
+ 2. [Installation](#installation)
25
+ - [Via NPM](#via-npm)
26
+ - [Via CDN](#via-cdn)
27
+ 3. [Initializing ClipX.js](#initializing-clipxjs)
28
+ - [Basic Initialization](#basic-initialization)
29
+ - [Configuration Options](#configuration-options)
30
+ 4. [Attaching ClipX Functionality](#attaching-clipx-functionality)
31
+ - [Example: Using Data Attributes](#example-using-data-attributes)
32
+ - [Example: Using Class Names](#example-using-class-names)
33
+ 5. [Attributes Overview](#attributes-overview)
34
+ - [`data-clipx-target`](#data-clipx-target)
35
+ - [`data-clipx-text`](#data-clipx-text)
36
+ - [`data-clipx-cut`](#data-clipx-cut)
37
+ - [`data-clipx-msg`](#data-clipx-msg)
38
+ - [`data-clipx-toast`](#data-clipx-toast)
39
+ - [`data-clipx-disable-msg`](#data-clipx-disable-msg)
40
+ - [`data-clipx-disable-toast`](#data-clipx-disable-toast)
41
+ - [`data-clipx-toast-position`](#data-clipx-toast-position)
42
+ - [`data-clipx-duration`](#data-clipx-duration)
43
+ 6. [Example](#example)
44
+ 7. [Demo](#demo--get-start-code)
45
+
46
+ ---
47
+
48
+ ## Why Choose ClipX.js?
49
+
50
+ ### Lightweight & Fast
51
+
52
+ - At only 2KB, ClipX.js is smaller and faster than most clipboard libraries.
53
+
54
+ ### Built-in Feedback
55
+
56
+ - Includes customizable toast notifications for clipboard actions—no need for additional UI libraries.
57
+
58
+ ### Flexible Customization
59
+
60
+ - Easily style toasts, control message display, and integrate seamlessly with your app's design.
61
+
62
+ ### Easy Integration
63
+
64
+ - Simple API with minimal setup, ensuring broad compatibility across modern and older browsers.
65
+
66
+ ### Robust Error Handling
67
+
68
+ - Provides clear, customizable error feedback to enhance user experience and simplify debugging.
69
+
70
+ ---
71
+
72
+ ## Installation
73
+
74
+ ### Via NPM
75
+
76
+ ```bash
77
+ npm i clipxjs
78
+ ```
79
+
80
+ ### Via CDN
81
+
82
+ Use only one `CDN`
83
+
84
+ **jsdelivr**
85
+
86
+ ```html
87
+ <script src="https://cdn.jsdelivr.net/npm/clipxjs/dist/clipx.min.js"></script>
88
+ ```
89
+
90
+ **OR**
91
+
92
+ **unpkg**
93
+
94
+ ```html
95
+ <script src="https://unpkg.com/clipxjs/dist/clipx.min.js"></script>
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Initializing ClipX.js
101
+
102
+ To get started with ClipX.js, follow these steps to set up and configure the library according to your needs:
103
+
104
+ ## Basic Initialization
105
+
106
+ ```javascript
107
+ /* Initialize ClipX.js instance */
108
+ var clipx = new clipx();
109
+ ```
110
+
111
+ ## Configuration Options
112
+
113
+ ### 1. Disable Text Content Change Globally
114
+
115
+ To prevent the text content of elements from changing globally, set the `msg` property to `true`. Otherwise, set it to `false` to enable text content change.
116
+
117
+ ```javascript
118
+ clipx.disable.msg = false; // Set to true to disable text content change globally
119
+ ```
120
+
121
+ ### 2. Disable Toast Notifications Globally
122
+
123
+ To prevent toast notifications from showing globally, set the `toast` property to `true`. Otherwise, set it to `false` to enable toast notifications.
124
+
125
+ ```javascript
126
+ clipx.disable.toast = false; // Set to true to disable toast notifications globally
127
+ ```
128
+
129
+ ### 3. Set Custom Styles for Toast Notifications
130
+
131
+ Customize the appearance of toast notifications by providing CSS styles. For example, the following configuration sets a dark background with white text, padding, and rounded corners.
132
+
133
+ ```javascript
134
+ clipx.setCustomStyles({
135
+ toast:
136
+ "background-color: #333; color: #fff; padding: 12px; border-radius: 5px;",
137
+ });
138
+ ```
139
+
140
+ ### 4. Hide SVG Icon
141
+
142
+ To hide Svg Icon from toast
143
+
144
+ ```css
145
+ .clipx-js-svg-icon {
146
+ display: none;
147
+ }
148
+ ```
149
+
150
+ ## Attaching ClipX Functionality
151
+
152
+ To bind ClipX.js functionality to elements, use the `attach` method with appropriate selectors. This method will enable clipboard operations on elements with the specified attributes or classes.
153
+
154
+ ### Example: Using Data Attributes
155
+
156
+ Apply ClipX.js to elements with `data-clipx-text` or `data-clipx-target` attributes.
157
+
158
+ ```javascript
159
+ clipx.attach("[data-clipx-text], [data-clipx-target]");
160
+ ```
161
+
162
+ ### Example: Using Class Names
163
+
164
+ Alternatively, apply ClipX.js to elements with specific classes.
165
+
166
+ ```javascript
167
+ clipx.attach(".clipx, .copy-btn, .your-class");
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Attributes Overview
173
+
174
+ ### This All Are Attributes
175
+
176
+ - **`data-clipx-target`**: Element selector for text source.
177
+ - **`data-clipx-text`**: Static text to copy or cut.
178
+ - **`data-clipx-cut`**: Toggle cut operation.
179
+ - **`data-clipx-msg`**: Custom success message.
180
+ - **`data-clipx-toast`**: Show only toast, no text change.
181
+ - **`data-clipx-disable-msg`**: Disable element text change.
182
+ - **`data-clipx-disable-toast`**: Disable toast notification.
183
+ - **`data-clipx-toast-position`**: Position of the toast (top/bottom).
184
+ - **`data-clipx-duration`**: Duration of toast visibility.
185
+
186
+ ---
187
+
188
+ ## Example
189
+
190
+ ### `data-clipx-target`
191
+
192
+ **Description:** Specifies the target element whose text will be copied to the clipboard when the button is clicked.
193
+
194
+ **Example:**
195
+
196
+ ```html
197
+ <button class="copy-btn" data-clipx-target="#text-to-copy">Copy Text</button>
198
+ <p id="text-to-copy">This is the text to be copied.</p>
199
+ ```
200
+
201
+ ### `data-clipx-text`
202
+
203
+ **Description:** Defines a static text string that will be copied to the clipboard when the button is clicked.
204
+
205
+ **Example:**
206
+
207
+ ```html
208
+ <button class="copy-btn" data-clipx-text="Static text to copy">
209
+ Copy Static Text
210
+ </button>
211
+ ```
212
+
213
+ ### `data-clipx-cut`
214
+
215
+ **Description:** Cuts the text from the specified element, copying it to the clipboard and clearing the element's content.
216
+
217
+ **Example:**
218
+
219
+ ```html
220
+ <textarea id="text-to-cut">This text will be cut.</textarea>
221
+ <button class="copy-btn" data-clipx-target="#text-to-cut" data-clipx-cut>
222
+ Cut Text
223
+ </button>
224
+ ```
225
+
226
+ ### `data-clipx-msg`
227
+
228
+ **Description:** Copies the specified text to the clipboard and shows a toast notification with a custom message.
229
+
230
+ **Example:**
231
+
232
+ ```html
233
+ <button
234
+ class="copy-btn"
235
+ data-clipx-text="Another static text"
236
+ data-clipx-msg="Text copied successfully!"
237
+ >
238
+ Copy with Custom Message
239
+ </button>
240
+ ```
241
+
242
+ ### `data-clipx-toast`
243
+
244
+ **Description:** Displays a toast notification with the copied text. The button text remains unchanged.
245
+
246
+ **Example:**
247
+
248
+ ```html
249
+ <button class="copy-btn" data-clipx-text="Text to copy" data-clipx-toast>
250
+ Copy with Toast Only
251
+ </button>
252
+ ```
253
+
254
+ ### `data-clipx-disable-msg`
255
+
256
+ **Description:** Shows a toast notification without changing the button's text content.
257
+
258
+ **Example:**
259
+
260
+ ```html
261
+ <button class="copy-btn" data-clipx-text="Text to copy" data-clipx-disable-msg>
262
+ Copy with Toast Only, No Text Change
263
+ </button>
264
+ ```
265
+
266
+ ### `USE data-clipx-disable-toast & data-clipx-disable-msg`
267
+
268
+ **Description:** Copies the specified text to the clipboard without showing a toast notification And Changing Text Contents.
269
+
270
+ **Example:**
271
+
272
+ ```html
273
+ <button
274
+ class="copy-btn"
275
+ data-clipx-text="Text to copy"
276
+ data-clipx-disable-toast
277
+ data-clipx-disable-msg
278
+ >
279
+ Copy without Toast & with Change Text
280
+ </button>
281
+ ```
282
+
283
+ ### `data-clipx-disable-toast`
284
+
285
+ **Description:** Copies the specified text to the clipboard without showing a toast notification.
286
+
287
+ **Example:**
288
+
289
+ ```html
290
+ <button
291
+ class="copy-btn"
292
+ data-clipx-text="Text to copy"
293
+ data-clipx-disable-toast
294
+ >
295
+ Copy without Toast
296
+ </button>
297
+ ```
298
+
299
+ ### `data-clipx-toast-position`
300
+
301
+ **Description:** Defines the position of the toast notification (top or bottom).
302
+
303
+ **Example:**
304
+
305
+ ```html
306
+ <button
307
+ class="copy-btn"
308
+ data-clipx-text="Text to copy"
309
+ data-clipx-toast
310
+ data-clipx-toast-position="top"
311
+ >
312
+ Copy with Toast on Top
313
+ </button>
314
+ <button
315
+ class="copy-btn"
316
+ data-clipx-text="Text to copy"
317
+ data-clipx-toast
318
+ data-clipx-toast-position="bottom"
319
+ >
320
+ Copy with Toast on Bottom
321
+ </button>
322
+ ```
323
+
324
+ ### `data-clipx-duration`
325
+
326
+ **Description:** Sets the duration (in milliseconds) for which the toast notification is visible before it fades out.
327
+
328
+ **Example:**
329
+
330
+ ```html
331
+ <button
332
+ class="copy-btn"
333
+ data-clipx-text="Text to copy"
334
+ data-clipx-toast
335
+ data-clipx-duration="3000"
336
+ >
337
+ Copy with 3 Seconds Toast
338
+ </button>
339
+ <button
340
+ class="copy-btn"
341
+ data-clipx-text="Text to copy"
342
+ data-clipx-duration="3000"
343
+ >
344
+ Copy with 3 Seconds Toast & Content Change
345
+ </button>
346
+ <button
347
+ class="copy-btn"
348
+ data-clipx-text="Text to copy"
349
+ data-clipx-disable-toast
350
+ data-clipx-duration="3000"
351
+ >
352
+ Copy 3 sec Content Change
353
+ </button>
354
+ ```
355
+
356
+ ---
357
+
358
+ ## Demo || Get Start Code
359
+
360
+ ```html
361
+ <h1>ClipX.js Demo</h1>
362
+
363
+ <button
364
+ class="copy-btn"
365
+ data-clipx-text="Static text to copy"
366
+ data-clipx-msg="Static text copied!"
367
+ >
368
+ Copy Static Text
369
+ </button>
370
+
371
+ <button class="copy-btn" data-clipx-target="#text-to-copy" data-clipx-cut>
372
+ Cut Text
373
+ </button>
374
+ <button class="copy-btn" data-clipx-target="#text-to-copy">Copy Text</button>
375
+
376
+ <p id="text-to-copy">This text will be cut and copied to the clipboard.</p>
377
+
378
+ <button
379
+ class="copy-btn"
380
+ data-clipx-text="Another static text"
381
+ data-clipx-toast
382
+ data-clipx-toast-position="bottom"
383
+ >
384
+ Copy with Toast Only
385
+ </button>
386
+
387
+ <button
388
+ class="copy-btn"
389
+ data-clipx-text="Text with 5 seconds toast"
390
+ data-clipx-toast
391
+ data-clipx-duration="5000"
392
+ >
393
+ Copy with 5 Seconds Toast
394
+ </button>
395
+
396
+ <script src="https://cdn.jsdelivr.net/npm/clipxjs/dist/clipx.min.js"></script>
397
+ <script>
398
+ // Initialize ClipX.js instance
399
+ var clipx = new clipx();
400
+
401
+ // Optional: Set custom styles for toast notifications
402
+ clipx.setCustomStyles({
403
+ toast:
404
+ "background-color: #333; color: #fff; padding: 12px; border-radius: 5px;",
405
+ });
406
+
407
+ // Attach ClipX.js functionality to elements
408
+ clipx.attach("[data-clipx-text], [data-clipx-target]");
409
+ </script>
410
+ ```
package/dist/clipx.min.js CHANGED
@@ -1,9 +1,2 @@
1
- /*
2
- ClipX JS
3
- https://clipx.dzr.app
4
- GitHub: https://github.com/mraxays/clipxjs
5
- Version: 1.2.1
6
- Copyright (c) 2025 Mr Akshay Shinde
7
- Licensed under the MIT license
8
- */
9
- (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,n=t.getAttribute("data-clipx-target"),o=t.getAttribute("data-clipx-text"),i=t.hasAttribute("data-clipx-cut"),s=t.getAttribute("data-clipx-msg"),a=t.hasAttribute("data-clipx-toast"),r=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(n){var d=document.querySelector(n);d&&(e=i?this.cutFromElement(d):this.copyFromElement(d))}else o&&(e=i?this.cutText(o):this.copyText(o));e&&e.then(()=>this.onSuccess(t,s,a,r,c,l,p)).catch(e=>this.onError(t,e)).finally(()=>{this.isProcessing=!1})}}.bind(this))}.bind(this))},e.prototype.onSuccess=function(t,e,n,o,i,s,a){var r=t.textContent,c=e||"Copied !",l="top"===s?"clipx-toast top":"clipx-toast bottom";if(n||o||this.disable.msg||(t.textContent=c),i||this.disable.toast)setTimeout(function(){this.disable.msg||(t.textContent=r)}.bind(this),a);else{var p=document.createElement("div");p.className=l;var d='<svg class="clipx-js-svg-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="rgba(0,210,65,1)" fill="currentColor"><path d="M4 12C4 7.58172 7.58172 4 12 4C16.4183 4 20 7.58172 20 12C20 16.4183 16.4183 20 12 20C7.58172 20 4 16.4183 4 12ZM12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2ZM17.4571 9.45711L16.0429 8.04289L11 13.0858L8.20711 10.2929L6.79289 11.7071L11 15.9142L17.4571 9.45711Z"></path></svg>';p.innerHTML=d+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),n||o||this.disable.msg||(t.textContent=r)}.bind(this),a)}},e.prototype.onError=function(t,e){console.error("Failed to cut/copy text: ",e);var n=document.createElement("div");n.className="clipx-toast error";var o='<svg xmlns="http://www.w3.org/2000/svg" class="clipx-js-svg-icon" viewBox="0 0 24 24" width="16" height="16" fill="rgba(231,0,0,1)" fill="currentColor"><path d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11 15H13V17H11V15ZM11 7H13V13H11V7Z"></path></svg>';n.innerHTML=o+"Failed to copy!",n.setAttribute("role","alert"),n.setAttribute("aria-live","assertive"),n.style.cssText=this.customStyles.toast||"",document.body.appendChild(n),setTimeout(()=>{n.style.opacity=0,setTimeout(()=>document.body.removeChild(n),500)},1500)},e.prototype.setCustomStyles=function(t){this.customStyles=t},t.clipx=e;var n=document.createElement("style");n.textContent="\n .clipx-toast {\n font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n position: fixed;\n left: 50%;\n transform: translateX(-50%);\n background-color: #fff;\n color: #363636;\n padding: 8px 10px;\n border-radius: 8px;\n z-index: 9999;\n box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05);\n font-size: 14px;\n text-align: center;\n opacity: 0;\n animation: fadeIn 0.5s ease forwards;\n transition: opacity 0.5s ease;\n max-width: 90%; /* Ensure it fits well on smaller screens */\n width: auto; /* Ensure the width adjusts based on content */\n display: flex;\n align-items: center;\n gap: 5px;\n}\n\n.clipx-toast.top {\n top: 20px;\n bottom: auto;\n}\n\n.clipx-toast.bottom {\n bottom: 20px;\n}\n\n.clipx-toast.error {\n background-color: #f8d7da;\n color: #721c24;\n}\n\n@keyframes fadeIn {\n from {\n opacity: 0;\n transform: translateY(10px) translateX(-50%);\n }\n to {\n opacity: 1;\n transform: translateY(0) translateX(-50%);\n }\n}\n\n@keyframes fadeOut {\n from {\n opacity: 1;\n transform: translateY(0) translateX(-50%);\n }\n to {\n opacity: 0;\n transform: translateY(10px) translateX(-50%);\n }\n}",document.head.appendChild(n)})(this);
1
+ /*! ClipX JS v1.3.0 | MIT | https://clipx.js.org */
2
+ !function(){var t=function(){"use strict";var t="undefined"!=typeof document&&document,i="undefined"!=typeof navigator?navigator:{},o=(t,i)=>'<svg class="clipx-js-svg-icon" viewBox="0 0 24 24" width="16" height="16" fill="'+t+'" aria-hidden="true"><path fill-rule="evenodd" d="'+i+'"/></svg>',e={ok:o("#00d241","M12 2a10 10 0 100 20 10 10 0 000-20zm-1 14.4-4-4 1.4-1.4 2.6 2.6 5.6-5.6L18 9.4z"),err:o("#e70000","M12 2a10 10 0 100 20 10 10 0 000-20zm1 15h-2v-2h2zm0-4h-2V7h2z")},r=t=>t&&t.parentNode&&t.parentNode.removeChild(t),s=t=>/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName),n=t=>s(t)?t.value:t.textContent,a=(t,i,o)=>t.dispatchEvent(o?new CustomEvent(i,{bubbles:!0,detail:o}):new Event(i,{bubbles:!0})),c=(t,i)=>{s(t)?(t.value=i,a(t,"input"),a(t,"change")):t.textContent=i},p=i=>new Promise((o,e)=>{var s=t.activeElement,n=t.createElement("textarea"),a=!1;n.value=i,n.readOnly=!0,n.style.cssText="position:fixed;top:0;opacity:0",t.body.appendChild(n),n.select();try{n.setSelectionRange(0,i.length),a=t.execCommand("copy")}catch(t){}r(n),s&&s.focus&&s.focus(),a?o():e(Error("Copy failed"))}),h={trim:t=>t.trim(),uppercase:t=>t.toUpperCase(),lowercase:t=>t.toLowerCase(),capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),titlecase:t=>t.toLowerCase().replace(/(^|\s)\S/g,t=>t.toUpperCase()),collapse:t=>t.replace(/\s+/g," "),singleline:t=>t.replace(/\s*[\r\n]+\s*/g," "),striphtml:t=>t.replace(/<[^>]*>/g,"")};function l(){this.disable={msg:!1,toast:!1},this.customStyles={},this.formatters=Object.assign({},h),this._sel=[],this._fn=null,this.t={}}var u=l.prototype;return l.version="1.3.0",u.addFormatter=function(t,i){if("function"!=typeof i)throw new TypeError("Formatter must be a function");return this.formatters[String(t).toLowerCase()]=i,this},u.format=function(t,i){return t=null==t?"":String(t),(Array.isArray(i)?i:String(i||"").split(",")).forEach(i=>{i=String(i).trim().toLowerCase();var o=this.formatters[i];o?t=String(o(t)):i&&console.warn("ClipX: unknown format '"+i+"'")}),t},u.copyText=function(t){return t=null==t?"":String(t),i.clipboard&&i.clipboard.writeText?i.clipboard.writeText(t).catch(()=>p(t)):p(t)},u.cutText=function(t,i){return this.copyText(t).then(()=>{i&&c(i,"")})},u.copyFromElement=function(t,i){var o=this.format(n(t),i);return o?this.copyText(o):Promise.reject(Error("Nothing to copy."))},u.cutFromElement=function(t,i){var o=this.format(n(t),i);return o?this.cutText(o,t):Promise.reject(Error("Nothing to copy."))},u.pasteText=function(){return i.clipboard&&i.clipboard.readText?i.clipboard.readText():Promise.reject(Error("Paste is not supported here."))},u.pasteToElement=function(t,i){return this.pasteText().then(o=>(o=this.format(o,i),c(t,o),o))},u.attach=function(i){return t?(i=i||"[data-clipx-text],[data-clipx-target],[data-clipx-paste]",this._sel.indexOf(i)<0&&this._sel.push(i),this._fn||t.addEventListener("click",this._fn=t=>{var i=t.target;i&&1!=i.nodeType&&(i=i.parentElement),(i=i&&i.closest&&i.closest(this._sel.join(",")))&&this._run(i)}),this):this},u.detach=function(){return this._fn&&t.removeEventListener("click",this._fn),this._fn=null,this._sel=[],this},u._run=function(i){if(!i.__cx){var o,e,r=t=>i.getAttribute("data-clipx-"+t),s=t=>i.hasAttribute("data-clipx-"+t),n=r("format"),a=s("cut"),c="copy",p=parseInt(r("duration"),10);try{if(r("paste")){if(c="paste",!(e=t.querySelector(r("paste"))))throw Error("Paste target not found");o=this.pasteToElement(e,n)}else if(r("target")){if(!(e=t.querySelector(r("target"))))throw Error("Target not found");c=a?"cut":"copy",o=a?this.cutFromElement(e,n):this.copyFromElement(e,n)}else{if(!s("text"))throw Error("Add data-clipx-target, -text or -paste");if(!(e=this.format(r("text"),n)))throw Error("Nothing to copy.");o=this.copyText(e)}}catch(t){return this.onError(i,t)}i.__cx=1,o.then(()=>this.onSuccess(i,r("msg"),s("toast"),s("disable-msg"),s("disable-toast"),r("toast-position")||"bottom",p>0?p:1500,c),t=>this.onError(i,t)).then(()=>{i.__cx=0})}},u.onSuccess=function(t,i,o,e,r,s,n,c){i=i||("paste"==c?"Pasted!":"Copied!"),o||e||this.disable.msg||(void 0===t.__o&&(t.__o=t.innerHTML),t.textContent=i,clearTimeout(t.__t),t.__t=setTimeout(()=>{t.innerHTML=t.__o,t.__o=void 0},n)),r||this.disable.toast||this._toast(i,"ok",s,n),a(t,"clipx:success",{type:c||"copy"})},u.onError=function(t,i){console.error("ClipX:",i),this.disable.toast||this._toast(i&&"Nothing to copy."==i.message?i.message:"Failed to copy!","err","bottom",1500),a(t,"clipx:error",{error:i})},u._toast=function(i,o,s,n){if(!t.getElementById("clipx-js-styles")){var a=t.createElement("style");a.id="clipx-js-styles",a.textContent=".clipx-toast{font:14px system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;position:fixed;left:50%;transform:translateX(-50%);background:#fff;color:#363636;padding:8px 10px;border-radius:8px;z-index:9999;box-shadow:0 3px 10px rgba(0,0,0,.1),0 3px 3px rgba(0,0,0,.05);opacity:0;transition:opacity .3s;max-width:90%;display:flex;align-items:center;gap:5px;pointer-events:none}.clipx-show{opacity:1}.clipx-toast.top{top:20px}.clipx-toast.bottom{bottom:20px}.clipx-toast.error{background:#f8d7da;color:#721c24}@media(prefers-reduced-motion:reduce){.clipx-toast{transition:none}}",(t.head||t.documentElement).appendChild(a)}s="top"==s?"top":"bottom",r(this.t[s]);var c=t.createElement("div"),p=t.createElement("span");c.className="clipx-toast "+s+("err"==o?" error":""),c.setAttribute("role","err"==o?"alert":"status"),c.innerHTML=e[o],p.textContent=i,c.appendChild(p),c.style.cssText=(this.customStyles.toast||"")+";"+("err"==o&&this.customStyles.error||""),t.body.appendChild(c),this.t[s]=c,setTimeout(()=>c.classList.add("clipx-show"),10),setTimeout(()=>{c.classList.remove("clipx-show"),setTimeout(()=>{r(c),this.t[s]==c&&(this.t[s]=null)},300)},n)},u.setCustomStyles=function(t){return this.customStyles=t||{},this},l.ClipX=l,l}();"object"==typeof module&&module.exports&&(module.exports=t),"undefined"!=typeof window&&(window.clipx=window.ClipX=t)}();
package/package.json CHANGED
@@ -1,25 +1,39 @@
1
- {
2
- "name": "clipxjs",
3
- "version": "1.2.1",
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
- "main": "src/clipx.js",
6
- "scripts": {
7
- "build": "webpack --config bundler/webpack.config.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/mraxays/clipxjs.git"
12
- },
13
- "keywords": ["clipboard","copy","cut","paste","toast","notifications","clipx","clipxjs","lightweight","UI","customizable","performance","cross-browser","front-end"
14
- ],
15
- "author": "@mrakshayas",
16
- "files": [
17
- "dist",
18
- "src"
19
- ],
20
- "license": "MIT",
21
- "bugs": {
22
- "url": "https://github.com/mraxays/clipxjs/issues"
23
- },
24
- "homepage": "https://clipx.dzr.app/"
25
- }
1
+ {
2
+ "name": "clipxjs",
3
+ "version": "1.3.0",
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
+ "main": "src/clipx.js",
6
+ "scripts": {
7
+ "build": "webpack --config bundler/webpack.config.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/mraxays/clipxjs.git"
12
+ },
13
+ "keywords": [
14
+ "clipboard",
15
+ "copy",
16
+ "cut",
17
+ "paste",
18
+ "toast",
19
+ "notifications",
20
+ "clipx",
21
+ "clipxjs",
22
+ "lightweight",
23
+ "UI",
24
+ "customizable",
25
+ "performance",
26
+ "cross-browser",
27
+ "front-end"
28
+ ],
29
+ "author": "@mrakshayas",
30
+ "files": [
31
+ "dist",
32
+ "src"
33
+ ],
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/mraxays/clipxjs/issues"
37
+ },
38
+ "homepage": "https://clipx.js.org/"
39
+ }
@@ -0,0 +1 @@
1
+ (function(t,e){var o=e();"object"==typeof module&&module.exports&&(module.exports=o),"undefined"!=typeof window&&(window.clipx=window.ClipX=o)})(0,function(){"use strict";function t(){this.disable={msg:!1,toast:!1},this.customStyles={},this.formatters=Object.assign({},h),this._sel=[],this._fn=null,this._t={}}var e="undefined"!=typeof document&&document,o="undefined"!=typeof navigator?navigator:{},r="[data-clipx-text],[data-clipx-target],[data-clipx-paste]",s=(t,e)=>'<svg class="clipx-js-svg-icon" viewBox="0 0 24 24" width="16" height="16" fill="'+t+'" aria-hidden="true"><path fill-rule="evenodd" d="'+e+'"/></svg>',i={ok:s("#00d241","M12 2a10 10 0 100 20 10 10 0 000-20zm-1 14.4-4-4 1.4-1.4 2.6 2.6 5.6-5.6L18 9.4z"),err:s("#e70000","M12 2a10 10 0 100 20 10 10 0 000-20zm1 15h-2v-2h2zm0-4h-2V7h2z")},n=".clipx-toast{font:14px system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;position:fixed;left:50%;transform:translateX(-50%);background:#fff;color:#363636;padding:8px 10px;border-radius:8px;z-index:9999;box-shadow:0 3px 10px rgba(0,0,0,.1),0 3px 3px rgba(0,0,0,.05);opacity:0;transition:opacity .3s;max-width:90%;display:flex;align-items:center;gap:5px;pointer-events:none}.clipx-show{opacity:1}.clipx-toast.top{top:20px}.clipx-toast.bottom{bottom:20px}.clipx-toast.error{background:#f8d7da;color:#721c24}@media(prefers-reduced-motion:reduce){.clipx-toast{transition:none}}",a=t=>t&&t.parentNode&&t.parentNode.removeChild(t),c=t=>/^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName),l=t=>c(t)?t.value:t.textContent,p=(t,e,o)=>t.dispatchEvent(o?new CustomEvent(e,{bubbles:!0,detail:o}):new Event(e,{bubbles:!0})),d=(t,e)=>{c(t)?(t.value=e,p(t,"input"),p(t,"change")):t.textContent=e},u=t=>new Promise((o,r)=>{var s=e.activeElement,i=e.createElement("textarea"),n=!1;i.value=t,i.readOnly=!0,i.style.cssText="position:fixed;top:0;opacity:0",e.body.appendChild(i),i.select();try{i.setSelectionRange(0,t.length),n=e.execCommand("copy")}catch(t){}a(i),s&&s.focus&&s.focus(),n?o():r(Error("Copy failed"))}),h={trim:t=>t.trim(),uppercase:t=>t.toUpperCase(),lowercase:t=>t.toLowerCase(),capitalize:t=>t.charAt(0).toUpperCase()+t.slice(1),titlecase:t=>t.toLowerCase().replace(/(^|\s)\S/g,t=>t.toUpperCase()),collapse:t=>t.replace(/\s+/g," "),singleline:t=>t.replace(/\s*[\r\n]+\s*/g," "),striphtml:t=>t.replace(/<[^>]*>/g,"")},m=t.prototype;return t.version="1.3.0",m.addFormatter=function(t,e){if("function"!=typeof e)throw new TypeError("Formatter must be a function");return this.formatters[String(t).toLowerCase()]=e,this},m.format=function(t,e){return t=null==t?"":String(t),(Array.isArray(e)?e:String(e||"").split(",")).forEach(e=>{e=String(e).trim().toLowerCase();var o=this.formatters[e];o?t=String(o(t)):e&&console.warn("ClipX: unknown format '"+e+"'")}),t},m.copyText=function(t){return t=null==t?"":String(t),o.clipboard&&o.clipboard.writeText?o.clipboard.writeText(t).catch(()=>u(t)):u(t)},m.cutText=function(t,e){return this.copyText(t).then(()=>{e&&d(e,"")})},m.copyFromElement=function(t,e){var o=this.format(l(t),e);return o?this.copyText(o):Promise.reject(Error("Nothing to copy."))},m.cutFromElement=function(t,e){var o=this.format(l(t),e);return o?this.cutText(o,t):Promise.reject(Error("Nothing to copy."))},m.pasteText=function(){return o.clipboard&&o.clipboard.readText?o.clipboard.readText():Promise.reject(Error("Paste is not supported here."))},m.pasteToElement=function(t,e){return this.pasteText().then(o=>(o=this.format(o,e),d(t,o),o))},m.attach=function(t){return e?(t=t||r,this._sel.indexOf(t)<0&&this._sel.push(t),this._fn||e.addEventListener("click",this._fn=(t=>{var e=t.target;e&&1!=e.nodeType&&(e=e.parentElement),e=e&&e.closest&&e.closest(this._sel.join(",")),e&&this._run(e)})),this):this},m.detach=function(){return this._fn&&e.removeEventListener("click",this._fn),this._fn=null,this._sel=[],this},m._run=function(t){if(!t.__cx){var o,r,s=e=>t.getAttribute("data-clipx-"+e),i=e=>t.hasAttribute("data-clipx-"+e),n=s("format"),a=i("cut"),c="copy",l=parseInt(s("duration"),10);try{if(s("paste")){if(c="paste",!(r=e.querySelector(s("paste"))))throw Error("Paste target not found");o=this.pasteToElement(r,n)}else if(s("target")){if(!(r=e.querySelector(s("target"))))throw Error("Target not found");c=a?"cut":"copy",o=a?this.cutFromElement(r,n):this.copyFromElement(r,n)}else{if(!i("text"))throw Error("Add data-clipx-target, -text or -paste");if(!(r=this.format(s("text"),n)))throw Error("Nothing to copy.");o=this.copyText(r)}}catch(e){return this.onError(t,e)}t.__cx=1,o.then(()=>this.onSuccess(t,s("msg"),i("toast"),i("disable-msg"),i("disable-toast"),s("toast-position")||"bottom",l>0?l:1500,c),e=>this.onError(t,e)).then(()=>{t.__cx=0})}},m.onSuccess=function(t,e,o,r,s,i,n,a){e=e||("paste"==a?"Pasted!":"Copied!"),o||r||this.disable.msg||(void 0===t.__o&&(t.__o=t.innerHTML),t.textContent=e,clearTimeout(t.__t),t.__t=setTimeout(()=>{t.innerHTML=t.__o,t.__o=void 0},n)),s||this.disable.toast||this._toast(e,"ok",i,n),p(t,"clipx:success",{type:a||"copy"})},m.onError=function(t,e){console.error("ClipX:",e),this.disable.toast||this._toast(e&&"Nothing to copy."==e.message?e.message:"Failed to copy!","err","bottom",1500),p(t,"clipx:error",{error:e})},m._toast=function(t,o,r,s){if(!e.getElementById("clipx-js-styles")){var c=e.createElement("style");c.id="clipx-js-styles",c.textContent=n,(e.head||e.documentElement).appendChild(c)}r="top"==r?"top":"bottom",a(this._t[r]);var l=e.createElement("div"),p=e.createElement("span");l.className="clipx-toast "+r+("err"==o?" error":""),l.setAttribute("role","err"==o?"alert":"status"),l.innerHTML=i[o],p.textContent=t,l.appendChild(p),l.style.cssText=(this.customStyles.toast||"")+";"+("err"==o&&this.customStyles.error||""),e.body.appendChild(l),this._t[r]=l,setTimeout(()=>l.classList.add("clipx-show"),10),setTimeout(()=>{l.classList.remove("clipx-show"),setTimeout(()=>{a(l),this._t[r]==l&&(this._t[r]=null)},300)},s)},m.setCustomStyles=function(t){return this.customStyles=t||{},this},t.ClipX=t,t});
package/src/clipx.js DELETED
@@ -1,275 +0,0 @@
1
- (function (global) {
2
- // Constructor for the clipx object
3
- function clipx() {
4
- this.attach = this.attach.bind(this); // Bind the attach method to the instance
5
- this.isProcessing = false; // Flag to prevent multiple executions
6
- // Global flags to disable specific features
7
- this.disable = {
8
- msg: false,
9
- toast: false,
10
- };
11
- this.customStyles = {}; // Store custom styles for the toast notifications
12
- }
13
-
14
- // Method to copy text to clipboard
15
- clipx.prototype.copyText = function (text) {
16
- if (navigator.clipboard) {
17
- // Use the Clipboard API if available
18
- return navigator.clipboard.writeText(text);
19
- } else if (navigator.permissions) {
20
- // Check permissions if Clipboard API is not available
21
- return navigator.permissions
22
- .query({ name: "clipboard-write" })
23
- .then(function (permissionStatus) {
24
- if (
25
- permissionStatus.state === "granted" ||
26
- permissionStatus.state === "prompt"
27
- ) {
28
- return navigator.clipboard.writeText(text);
29
- } else {
30
- throw new Error("Clipboard write permission denied.");
31
- }
32
- });
33
- } else {
34
- // Fallback to using a temporary textarea element for older browsers
35
- var textArea = document.createElement("textarea");
36
- textArea.value = text;
37
- document.body.appendChild(textArea);
38
- textArea.select();
39
- document.execCommand("copy");
40
- document.body.removeChild(textArea);
41
- return Promise.resolve();
42
- }
43
- };
44
-
45
- // Method to cut (copy and then clear) text from an element
46
- clipx.prototype.cutText = function (text, element) {
47
- return this.copyText(text).then(function () {
48
- if (element) {
49
- element.value = ""; // Clear value for input elements
50
- element.textContent = ""; // Clear text content for non-input elements
51
- }
52
- });
53
- };
54
-
55
- // Method to copy text from an element
56
- clipx.prototype.copyFromElement = function (element) {
57
- var text = element.value || element.textContent; // Get text from input or non-input element
58
- return this.copyText(text);
59
- };
60
-
61
- // Method to cut (copy and then clear) text from an element
62
- clipx.prototype.cutFromElement = function (element) {
63
- var text = element.value || element.textContent; // Get text from input or non-input element
64
- return this.cutText(text, element);
65
- };
66
-
67
- // Method to attach event listeners to elements matching the selector
68
- clipx.prototype.attach = function (selector) {
69
- var elements = document.querySelectorAll(selector);
70
- elements.forEach(
71
- function (element) {
72
- element.addEventListener(
73
- "click",
74
- function () {
75
- if (this.isProcessing) return; // Prevent multiple executions
76
- this.isProcessing = true;
77
-
78
- var targetSelector = element.getAttribute("data-clipx-target");
79
- var text = element.getAttribute("data-clipx-text");
80
- var cut = element.hasAttribute("data-clipx-cut");
81
- var msgType = element.getAttribute("data-clipx-msg");
82
- var toastOnly = element.hasAttribute("data-clipx-toast");
83
- var disableMsg = element.hasAttribute("data-clipx-disable-msg");
84
- var disableToast = element.hasAttribute("data-clipx-disable-toast");
85
- var toastPosition =
86
- element.getAttribute("data-clipx-toast-position") || "bottom";
87
- var contentDuration =
88
- parseInt(element.getAttribute("data-clipx-duration"), 10) || 1500;
89
-
90
- var actionPromise;
91
-
92
- // Determine the action based on attributes
93
- if (targetSelector) {
94
- var targetElement = document.querySelector(targetSelector);
95
- if (targetElement) {
96
- actionPromise = cut
97
- ? this.cutFromElement(targetElement)
98
- : this.copyFromElement(targetElement);
99
- }
100
- } else if (text) {
101
- actionPromise = cut ? this.cutText(text) : this.copyText(text);
102
- }
103
-
104
- if (actionPromise) {
105
- actionPromise
106
- .then(() =>
107
- this.onSuccess(
108
- element,
109
- msgType,
110
- toastOnly,
111
- disableMsg,
112
- disableToast,
113
- toastPosition,
114
- contentDuration
115
- )
116
- )
117
- .catch((err) => this.onError(element, err))
118
- .finally(() => {
119
- this.isProcessing = false;
120
- });
121
- }
122
- }.bind(this)
123
- );
124
- }.bind(this)
125
- );
126
- };
127
-
128
- // Handle successful copy/cut operation
129
- clipx.prototype.onSuccess = function (
130
- element,
131
- msgType,
132
- toastOnly,
133
- disableMsg,
134
- disableToast,
135
- toastPosition,
136
- contentDuration
137
- ) {
138
- var originalText = element.textContent; // Store original text content
139
- var customMessage = msgType || "Copied !"; // Use provided message or default to "Copied!"
140
- var toastClass =
141
- toastPosition === "top" ? "clipx-toast top" : "clipx-toast bottom";
142
-
143
- if (!toastOnly && !disableMsg && !this.disable.msg) {
144
- element.textContent = customMessage; // Update element's text content
145
- }
146
-
147
- if (!disableToast && !this.disable.toast) {
148
- var toast = document.createElement("div");
149
- toast.className = toastClass;
150
- // Insert the success SVG icon along with the custom message
151
- var successSVG = `<svg class="clipx-js-svg-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16" fill="rgba(0,210,65,1)" fill="currentColor"><path d="M4 12C4 7.58172 7.58172 4 12 4C16.4183 4 20 7.58172 20 12C20 16.4183 16.4183 20 12 20C7.58172 20 4 16.4183 4 12ZM12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2ZM17.4571 9.45711L16.0429 8.04289L11 13.0858L8.20711 10.2929L6.79289 11.7071L11 15.9142L17.4571 9.45711Z"></path></svg>`;
152
- toast.innerHTML = successSVG + customMessage;
153
- toast.setAttribute("role", "alert");
154
- toast.setAttribute("aria-live", "assertive");
155
- toast.style.cssText = this.customStyles.toast || ""; // Apply custom styles if any
156
-
157
- document.body.appendChild(toast);
158
-
159
- // Fade-in and fade-out animation
160
- toast.style.opacity = 0;
161
- setTimeout(() => (toast.style.opacity = 1), 0);
162
-
163
- setTimeout(
164
- function () {
165
- toast.style.opacity = 0;
166
- setTimeout(() => document.body.removeChild(toast), 500);
167
-
168
- if (!toastOnly && !disableMsg && !this.disable.msg) {
169
- element.textContent = originalText; // Restore original text content
170
- }
171
- }.bind(this),
172
- contentDuration
173
- );
174
- } else {
175
- setTimeout(
176
- function () {
177
- if (!this.disable.msg) {
178
- element.textContent = originalText; // Restore original text content
179
- }
180
- }.bind(this),
181
- contentDuration
182
- );
183
- }
184
- };
185
-
186
- // Handle errors during copy/cut operation
187
- clipx.prototype.onError = function (element, err) {
188
- console.error("Failed to cut/copy text: ", err);
189
- var toast = document.createElement("div");
190
- toast.className = "clipx-toast error";
191
- // Insert the error SVG icon along with the error message
192
- var errorSVG = `<svg xmlns="http://www.w3.org/2000/svg" class="clipx-js-svg-icon" viewBox="0 0 24 24" width="16" height="16" fill="rgba(231,0,0,1)" fill="currentColor"><path d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11 15H13V17H11V15ZM11 7H13V13H11V7Z"></path></svg>`;
193
- toast.innerHTML = errorSVG + "Failed to copy!";
194
- toast.setAttribute("role", "alert");
195
- toast.setAttribute("aria-live", "assertive");
196
- toast.style.cssText = this.customStyles.toast || "";
197
-
198
- document.body.appendChild(toast);
199
- setTimeout(() => {
200
- toast.style.opacity = 0;
201
- setTimeout(() => document.body.removeChild(toast), 500);
202
- }, 1500);
203
- };
204
-
205
- // Method to set custom styles for toast notifications
206
- clipx.prototype.setCustomStyles = function (styles) {
207
- this.customStyles = styles;
208
- };
209
-
210
- // Expose the clipx constructor to the global object
211
- global.clipx = clipx;
212
-
213
- // Add default styles for toast notifications
214
- var style = document.createElement("style");
215
- style.textContent = `
216
- .clipx-toast {
217
- font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
218
- position: fixed;
219
- left: 50%;
220
- transform: translateX(-50%);
221
- background-color: #fff;
222
- color: #363636;
223
- padding: 8px 10px;
224
- border-radius: 8px;
225
- z-index: 9999;
226
- box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05);
227
- font-size: 14px;
228
- text-align: center;
229
- opacity: 0;
230
- animation: fadeIn 0.5s ease forwards;
231
- transition: opacity 0.5s ease;
232
- max-width: 90%; /* Ensure it fits well on smaller screens */
233
- width: auto; /* Ensure the width adjusts based on content */
234
- display: flex;
235
- align-items: center;
236
- gap: 5px;
237
- }
238
-
239
- .clipx-toast.top {
240
- top: 20px;
241
- bottom: auto;
242
- }
243
-
244
- .clipx-toast.bottom {
245
- bottom: 20px;
246
- }
247
-
248
- .clipx-toast.error {
249
- background-color: #f8d7da;
250
- color: #721c24;
251
- }
252
-
253
- @keyframes fadeIn {
254
- from {
255
- opacity: 0;
256
- transform: translateY(10px) translateX(-50%);
257
- }
258
- to {
259
- opacity: 1;
260
- transform: translateY(0) translateX(-50%);
261
- }
262
- }
263
-
264
- @keyframes fadeOut {
265
- from {
266
- opacity: 1;
267
- transform: translateY(0) translateX(-50%);
268
- }
269
- to {
270
- opacity: 0;
271
- transform: translateY(10px) translateX(-50%);
272
- }
273
- }`;
274
- document.head.appendChild(style);
275
- })(this);