tiny-essentials 1.17.0 → 1.18.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/v1/TinyBasicsEs.js +336 -45
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClipboard.js +459 -0
- package/dist/v1/TinyClipboard.min.js +1 -0
- package/dist/v1/TinyDragger.js +336 -45
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +1218 -45
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +336 -45
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +336 -45
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.js +497 -0
- package/dist/v1/TinyTextRangeEditor.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +338 -45
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/build/TinyClipboard.cjs +7 -0
- package/dist/v1/build/TinyClipboard.d.mts +3 -0
- package/dist/v1/build/TinyClipboard.mjs +2 -0
- package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
- package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
- package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyClipboard.cjs +420 -0
- package/dist/v1/libs/TinyClipboard.d.mts +155 -0
- package/dist/v1/libs/TinyClipboard.mjs +398 -0
- package/dist/v1/libs/TinyHtml.cjs +336 -45
- package/dist/v1/libs/TinyHtml.d.mts +238 -27
- package/dist/v1/libs/TinyHtml.mjs +320 -47
- package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
- package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
- package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/libs/TinyClipboard.md +213 -0
- package/docs/v1/libs/TinyHtml.md +211 -15
- package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
- package/package.json +1 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ "use strict";
|
|
3
|
+
/******/ // The require scope
|
|
4
|
+
/******/ var __webpack_require__ = {};
|
|
5
|
+
/******/
|
|
6
|
+
/************************************************************************/
|
|
7
|
+
/******/ /* webpack/runtime/define property getters */
|
|
8
|
+
/******/ (() => {
|
|
9
|
+
/******/ // define getter functions for harmony exports
|
|
10
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
11
|
+
/******/ for(var key in definition) {
|
|
12
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
13
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
14
|
+
/******/ }
|
|
15
|
+
/******/ }
|
|
16
|
+
/******/ };
|
|
17
|
+
/******/ })();
|
|
18
|
+
/******/
|
|
19
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
20
|
+
/******/ (() => {
|
|
21
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
22
|
+
/******/ })();
|
|
23
|
+
/******/
|
|
24
|
+
/************************************************************************/
|
|
25
|
+
var __webpack_exports__ = {};
|
|
26
|
+
|
|
27
|
+
// EXPORTS
|
|
28
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
29
|
+
TinyClipboard: () => (/* reexport */ libs_TinyClipboard)
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
;// ./src/v1/libs/TinyClipboard.mjs
|
|
33
|
+
/**
|
|
34
|
+
* Utility class to handle clipboard operations for text and blob data.
|
|
35
|
+
* Supports modern Clipboard API, custom platform, and legacy execCommand fallback.
|
|
36
|
+
*/
|
|
37
|
+
class TinyClipboard {
|
|
38
|
+
/**
|
|
39
|
+
* Indicates whether the legacy `document.execCommand()` API is available.
|
|
40
|
+
* Used as a fallback for clipboard operations when modern APIs are not supported.
|
|
41
|
+
*
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
*/
|
|
44
|
+
#existExecCommand = false;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Indicates whether the modern Clipboard API (`navigator.clipboard`) is available.
|
|
48
|
+
*
|
|
49
|
+
* @type {boolean}
|
|
50
|
+
*/
|
|
51
|
+
#existNavigator = false;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Function used to copy plain text to the clipboard.
|
|
55
|
+
* Can be overridden using `setCopyText()`.
|
|
56
|
+
*
|
|
57
|
+
* @type {((text: string) => Promise<void>) | null}
|
|
58
|
+
*/
|
|
59
|
+
#copyText = null;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Function used to copy a Blob (binary data) to the clipboard.
|
|
63
|
+
* Can be overridden using `setCopyBlob()`.
|
|
64
|
+
*
|
|
65
|
+
* @type {((blob: Blob) => Promise<void>) | null}
|
|
66
|
+
*/
|
|
67
|
+
#copyBlob = null;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Constructs a new TinyClipboard instance.
|
|
71
|
+
* Automatically detects and configures available clipboard APIs.
|
|
72
|
+
*/
|
|
73
|
+
constructor() {
|
|
74
|
+
// Whether the Clipboard API is available.
|
|
75
|
+
if (typeof navigator.clipboard !== 'undefined' && navigator.clipboard !== null) {
|
|
76
|
+
this.#existNavigator = true;
|
|
77
|
+
this.#copyText = (text) => navigator.clipboard.writeText(text);
|
|
78
|
+
this.#copyBlob = (blob) =>
|
|
79
|
+
navigator.clipboard.write([
|
|
80
|
+
new ClipboardItem({
|
|
81
|
+
[blob.type]: blob,
|
|
82
|
+
}),
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @type {boolean}
|
|
88
|
+
* Whether the legacy execCommand API is available.
|
|
89
|
+
*/
|
|
90
|
+
this.#existExecCommand =
|
|
91
|
+
typeof document.execCommand !== 'undefined' && document.execCommand !== null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Override the default text copy behavior.
|
|
96
|
+
* This allows you to provide your own clipboard implementation or
|
|
97
|
+
* integrate with external systems like Capacitor or Electron.
|
|
98
|
+
*
|
|
99
|
+
* @param {(text: string) => Promise<void>} callback - The function to use for copying text.
|
|
100
|
+
* @throws {TypeError} If the callback is not a function.
|
|
101
|
+
*/
|
|
102
|
+
setCopyText(callback) {
|
|
103
|
+
if (typeof callback !== 'function')
|
|
104
|
+
throw new TypeError('setCopyText expected a function that returns Promise<void>.');
|
|
105
|
+
this.#copyText = callback;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Override the default blob copy behavior.
|
|
110
|
+
* This allows you to provide a custom clipboard handling method for blob data.
|
|
111
|
+
*
|
|
112
|
+
* @param {(blob: Blob) => Promise<void>} callback - The function to use for copying blob data.
|
|
113
|
+
* @throws {TypeError} If the callback is not a function.
|
|
114
|
+
*/
|
|
115
|
+
setCopyBlob(callback) {
|
|
116
|
+
if (typeof callback !== 'function')
|
|
117
|
+
throw new TypeError('setCopyBlob expected a function that returns Promise<void>.');
|
|
118
|
+
this.#copyBlob = callback;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Copy a plain text string to the clipboard.
|
|
123
|
+
* Uses modern or legacy fallback.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} text - The text string to be copied.
|
|
126
|
+
* @returns {Promise<void>} A promise resolving when the text is copied or boolean for legacy.
|
|
127
|
+
*/
|
|
128
|
+
copyText(text) {
|
|
129
|
+
if (typeof text !== 'string') throw new TypeError('copyText expected a string.');
|
|
130
|
+
// Clipboard API
|
|
131
|
+
if (this.#copyText) return this.#copyText(text);
|
|
132
|
+
// Classic API
|
|
133
|
+
else if (this.#existExecCommand) {
|
|
134
|
+
const host = document.body;
|
|
135
|
+
const copyInput = document.createElement('input');
|
|
136
|
+
copyInput.style.position = 'fixed';
|
|
137
|
+
copyInput.style.opacity = '0';
|
|
138
|
+
copyInput.value = text;
|
|
139
|
+
host.append(copyInput);
|
|
140
|
+
|
|
141
|
+
copyInput.select();
|
|
142
|
+
copyInput.setSelectionRange(0, 99999);
|
|
143
|
+
document.execCommand('Copy');
|
|
144
|
+
copyInput.remove();
|
|
145
|
+
return new Promise((resolve) => resolve(undefined));
|
|
146
|
+
}
|
|
147
|
+
throw new Error('Clipboard API not found!');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Copy a Blob (binary data) to the clipboard.
|
|
152
|
+
*
|
|
153
|
+
* @param {Blob} blob - The blob object to copy.
|
|
154
|
+
* @returns {Promise<void>} A promise that resolves when the blob is copied or null on fallback.
|
|
155
|
+
*/
|
|
156
|
+
copyBlob(blob) {
|
|
157
|
+
if (!(blob instanceof Blob)) throw new TypeError('copyBlob expected a Blob instance.');
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
if (this.#copyBlob) {
|
|
160
|
+
return this.#copyBlob(blob).then(resolve).catch(reject);
|
|
161
|
+
}
|
|
162
|
+
throw new Error('Clipboard API not found!');
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Internal: Handle getting blob data from a clipboard item.
|
|
168
|
+
*
|
|
169
|
+
* @private
|
|
170
|
+
* @param {string} type - The MIME type to fetch.
|
|
171
|
+
* @param {ClipboardItem} clipboardItem - Clipboard item instance.
|
|
172
|
+
* @returns {Promise<Blob>} A promise that resolves with the Blob.
|
|
173
|
+
*/
|
|
174
|
+
_handleBlob(type, clipboardItem) {
|
|
175
|
+
return clipboardItem.getType(type);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Internal: Handle getting plain text from a clipboard item.
|
|
180
|
+
*
|
|
181
|
+
* @private
|
|
182
|
+
* @param {string} type - The MIME type (should be 'text/plain').
|
|
183
|
+
* @param {ClipboardItem} clipboardItem - Clipboard item instance.
|
|
184
|
+
* @returns {Promise<string>} A promise that resolves with the text content.
|
|
185
|
+
*/
|
|
186
|
+
_handleText(type, clipboardItem) {
|
|
187
|
+
return this._handleBlob(type, clipboardItem).then((blob) => blob.text());
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Read clipboard data based on filters like type, mime, index.
|
|
192
|
+
*
|
|
193
|
+
* @param {number|null} [index=0] - Item index or null for all.
|
|
194
|
+
* @param {'text'|'custom'|null} [type=null] - Data type to filter.
|
|
195
|
+
* @param {string|null} [mimeFormat=null] - MIME type or prefix.
|
|
196
|
+
* @param {boolean} [fixValue=false] - If true, exact match on MIME type.
|
|
197
|
+
* @returns {Promise<Blob|string|Array<Blob|string>|null>} A promise resolving with matching data.
|
|
198
|
+
*/
|
|
199
|
+
_readData(index = 0, type = null, mimeFormat = null, fixValue = false) {
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
this._read(index)
|
|
202
|
+
.then((items) => {
|
|
203
|
+
if (!items) return resolve(null);
|
|
204
|
+
/** @type {Array<Blob|string>} */
|
|
205
|
+
const finalResult = [];
|
|
206
|
+
|
|
207
|
+
// Complete task
|
|
208
|
+
let continueLoop = true;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @param {string} mimeType
|
|
212
|
+
* @param {ClipboardItem} item
|
|
213
|
+
*/
|
|
214
|
+
const completeTask = async (mimeType, item) => {
|
|
215
|
+
if (!continueLoop) return;
|
|
216
|
+
// Custom
|
|
217
|
+
if (
|
|
218
|
+
(type === null || type === 'custom') &&
|
|
219
|
+
typeof mimeFormat === 'string' &&
|
|
220
|
+
((!fixValue && mimeType.startsWith(mimeFormat)) ||
|
|
221
|
+
(fixValue && mimeType === mimeFormat))
|
|
222
|
+
) {
|
|
223
|
+
continueLoop = false;
|
|
224
|
+
const result = await this._handleBlob(mimeType, item);
|
|
225
|
+
if (result) finalResult.push(result);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Text
|
|
229
|
+
else if ((type === null || type === 'text') && mimeType === 'text/plain') {
|
|
230
|
+
continueLoop = false;
|
|
231
|
+
const result = await this._handleText(mimeType, item);
|
|
232
|
+
if (result) finalResult.push(result);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Blob
|
|
236
|
+
else if (type === null) {
|
|
237
|
+
continueLoop = false;
|
|
238
|
+
const result = await this._handleBlob(mimeType, item);
|
|
239
|
+
if (result) finalResult.push(result);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/** @type {Promise<void>[]} */
|
|
244
|
+
const promises = [];
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Read Item
|
|
248
|
+
* @param {ClipboardItem | ClipboardItems} item
|
|
249
|
+
*/
|
|
250
|
+
const readItem = (item) => {
|
|
251
|
+
if (!(item instanceof ClipboardItem))
|
|
252
|
+
throw new Error('Expected ClipboardItem when reading data.');
|
|
253
|
+
for (const tIndex in item.types) promises.push(completeTask(item.types[tIndex], item));
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// Specific Item
|
|
257
|
+
if (
|
|
258
|
+
typeof index === 'number' &&
|
|
259
|
+
!Number.isNaN(index) &&
|
|
260
|
+
Number.isFinite(index) &&
|
|
261
|
+
index > -1
|
|
262
|
+
) {
|
|
263
|
+
readItem(items);
|
|
264
|
+
Promise.all(promises)
|
|
265
|
+
.then(() => {
|
|
266
|
+
if (finalResult[0]) resolve(finalResult[0]);
|
|
267
|
+
else resolve(null);
|
|
268
|
+
})
|
|
269
|
+
.catch(reject);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// All
|
|
273
|
+
else if (Array.isArray(items)) {
|
|
274
|
+
for (const tIndex in items) readItem(items[tIndex]);
|
|
275
|
+
Promise.all(promises)
|
|
276
|
+
.then(() => resolve(finalResult))
|
|
277
|
+
.catch(reject);
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
// Fail
|
|
281
|
+
.catch(reject);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Read plain text from the clipboard (single item by index).
|
|
287
|
+
*
|
|
288
|
+
* @param {number} [index=0] - The index of the clipboard item to read.
|
|
289
|
+
* @returns {Promise<string|null>} A promise that resolves to the clipboard text or null.
|
|
290
|
+
*/
|
|
291
|
+
async readText(index = 0) {
|
|
292
|
+
const value = await this._readData(index, 'text');
|
|
293
|
+
if (typeof value !== 'string') throw new Error('Failed to read text: expected string result.');
|
|
294
|
+
return value;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Read custom clipboard data based on MIME type from a specific index.
|
|
299
|
+
*
|
|
300
|
+
* @param {string|null} [mimeFormat=null] - MIME prefix to match (e.g., "image/").
|
|
301
|
+
* @param {boolean} [fixValue=false] - If true, matches exact MIME instead of prefix.
|
|
302
|
+
* @param {number} [index=0] - Clipboard item index.
|
|
303
|
+
* @returns {Promise<Blob|null>} A promise resolving with a blob or null.
|
|
304
|
+
*/
|
|
305
|
+
async readCustom(mimeFormat = null, fixValue = false, index = 0) {
|
|
306
|
+
const value = await this._readData(index, 'custom', mimeFormat, fixValue);
|
|
307
|
+
if (!(value instanceof Blob)) throw new Error('Failed to read custom data: expected Blob.');
|
|
308
|
+
return value;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Read all available plain text entries from the clipboard.
|
|
313
|
+
*
|
|
314
|
+
* @returns {Promise<string[]>} A promise resolving to an array of strings or null.
|
|
315
|
+
*/
|
|
316
|
+
async readAllTexts() {
|
|
317
|
+
const values = await this._readData(null, 'text');
|
|
318
|
+
if (!Array.isArray(values))
|
|
319
|
+
throw new Error('Expected array of strings when reading all texts.');
|
|
320
|
+
if (!values.every((value) => typeof value === 'string'))
|
|
321
|
+
throw new Error('Some values returned were not strings.');
|
|
322
|
+
return values;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Read all clipboard data matching a specific custom MIME type.
|
|
327
|
+
*
|
|
328
|
+
* @param {string|null} [mimeFormat=null] - MIME prefix or exact type.
|
|
329
|
+
* @param {boolean} [fixValue=false] - Match prefix or exact MIME.
|
|
330
|
+
* @returns {Promise<Blob[]>} A promise resolving with array of Blobs or null.
|
|
331
|
+
*/
|
|
332
|
+
async readAllCustom(mimeFormat = null, fixValue = false) {
|
|
333
|
+
const values = await this._readData(null, 'custom', mimeFormat, fixValue);
|
|
334
|
+
if (!Array.isArray(values))
|
|
335
|
+
throw new Error('Expected array of blobs when reading all custom items.');
|
|
336
|
+
if (!values.every((value) => value instanceof Blob))
|
|
337
|
+
throw new Error('Some values returned were not Blob instances.');
|
|
338
|
+
return values;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Read all clipboard data as Blob or text depending on type.
|
|
343
|
+
*
|
|
344
|
+
* @param {'text'|'custom'|null} [type=null] - The type of data to retrieve.
|
|
345
|
+
* @param {string|null} [mimeFormat=null] - The MIME type or prefix to match.
|
|
346
|
+
* @returns {Promise<Array<Blob|string>>} A promise resolving with matching data array.
|
|
347
|
+
*/
|
|
348
|
+
async readAllData(type = null, mimeFormat = null) {
|
|
349
|
+
const value = await this._readData(null, type, mimeFormat);
|
|
350
|
+
if (!Array.isArray(value)) throw new Error('Expected array result when reading all data.');
|
|
351
|
+
return value;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Read clipboard data at a specific index or all if null.
|
|
356
|
+
*
|
|
357
|
+
* @param {number|null} index - Index of the item to retrieve or null to get all.
|
|
358
|
+
* @returns {Promise<ClipboardItem|ClipboardItems|null>} A promise resolving with a clipboard item or array of items.
|
|
359
|
+
*/
|
|
360
|
+
_read(index) {
|
|
361
|
+
return new Promise((resolve, reject) => {
|
|
362
|
+
if (!this.#existNavigator) reject(new Error('Clipboard API not found!'));
|
|
363
|
+
navigator.clipboard
|
|
364
|
+
.read()
|
|
365
|
+
.then((items) => {
|
|
366
|
+
// Index is number
|
|
367
|
+
if (typeof index === 'number') {
|
|
368
|
+
if (Number.isNaN(index) || !Number.isFinite(index) || index < 0)
|
|
369
|
+
throw new Error(`Invalid index value: ${index}`);
|
|
370
|
+
if (items[index]) resolve(items[index]);
|
|
371
|
+
// Not found
|
|
372
|
+
else resolve(null);
|
|
373
|
+
}
|
|
374
|
+
// Get All
|
|
375
|
+
resolve(items);
|
|
376
|
+
})
|
|
377
|
+
.catch(reject);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Read clipboard data at a specific index.
|
|
383
|
+
*
|
|
384
|
+
* @param {number} index - Index of the item to retrieve
|
|
385
|
+
* @returns {Promise<ClipboardItem|null>} A promise resolving with a clipboard item.
|
|
386
|
+
*/
|
|
387
|
+
async readIndex(index) {
|
|
388
|
+
const value = await this._read(index);
|
|
389
|
+
if (value !== null && !(value instanceof ClipboardItem))
|
|
390
|
+
throw new Error(`Value at index ${index} is not a ClipboardItem.`);
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Read all clipboard content without any filters.
|
|
396
|
+
*
|
|
397
|
+
* @returns {Promise<ClipboardItems>} A promise resolving with all clipboard items.
|
|
398
|
+
*/
|
|
399
|
+
async readAll() {
|
|
400
|
+
const value = await this._read(null);
|
|
401
|
+
if (!Array.isArray(value)) throw new Error('Expected array result from clipboard read.');
|
|
402
|
+
for (const item of value) {
|
|
403
|
+
if (!(item instanceof ClipboardItem))
|
|
404
|
+
throw new Error('Invalid item type found in clipboard result.');
|
|
405
|
+
}
|
|
406
|
+
return value;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Returns whether the legacy `document.execCommand()` API is available.
|
|
411
|
+
* This can be used to determine if a fallback clipboard method is usable.
|
|
412
|
+
*
|
|
413
|
+
* @returns {boolean} True if `document.execCommand` is available.
|
|
414
|
+
*/
|
|
415
|
+
isExecCommandAvailable() {
|
|
416
|
+
return this.#existExecCommand;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Returns whether the modern Clipboard API (`navigator.clipboard`) is available.
|
|
421
|
+
* Useful to know if full clipboard features can be accessed.
|
|
422
|
+
*
|
|
423
|
+
* @returns {boolean} True if `navigator.clipboard` is available.
|
|
424
|
+
*/
|
|
425
|
+
isNavigatorClipboardAvailable() {
|
|
426
|
+
return this.#existNavigator;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Returns the function used to copy plain text to the clipboard.
|
|
431
|
+
* This function may be built-in or set manually via `setCopyText`.
|
|
432
|
+
*
|
|
433
|
+
* @returns {((text: string) => Promise<void>) | null} The current text copy function or null if unavailable.
|
|
434
|
+
*/
|
|
435
|
+
getCopyTextFunc() {
|
|
436
|
+
return this.#copyText;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Returns the function used to copy Blob (binary data) to the clipboard.
|
|
441
|
+
* This function may be built-in or set manually via `setCopyBlob`.
|
|
442
|
+
*
|
|
443
|
+
* @returns {((blob: Blob) => Promise<void>) | null} The current blob copy function or null if unavailable.
|
|
444
|
+
*/
|
|
445
|
+
getCopyBlobFunc() {
|
|
446
|
+
return this.#copyBlob;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/* harmony default export */ const libs_TinyClipboard = (TinyClipboard);
|
|
451
|
+
|
|
452
|
+
;// ./src/v1/build/TinyClipboard.mjs
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
window.TinyClipboard = __webpack_exports__.TinyClipboard;
|
|
458
|
+
/******/ })()
|
|
459
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{TinyClipboard:()=>r});const r=class{#e=!1;#t=!1;#r=null;#o=null;constructor(){void 0!==navigator.clipboard&&null!==navigator.clipboard&&(this.#t=!0,this.#r=e=>navigator.clipboard.writeText(e),this.#o=e=>navigator.clipboard.write([new ClipboardItem({[e.type]:e})])),this.#e=void 0!==document.execCommand&&null!==document.execCommand}setCopyText(e){if("function"!=typeof e)throw new TypeError("setCopyText expected a function that returns Promise<void>.");this.#r=e}setCopyBlob(e){if("function"!=typeof e)throw new TypeError("setCopyBlob expected a function that returns Promise<void>.");this.#o=e}copyText(e){if("string"!=typeof e)throw new TypeError("copyText expected a string.");if(this.#r)return this.#r(e);if(this.#e){const t=document.body,r=document.createElement("input");return r.style.position="fixed",r.style.opacity="0",r.value=e,t.append(r),r.select(),r.setSelectionRange(0,99999),document.execCommand("Copy"),r.remove(),new Promise((e=>e(void 0)))}throw new Error("Clipboard API not found!")}copyBlob(e){if(!(e instanceof Blob))throw new TypeError("copyBlob expected a Blob instance.");return new Promise(((t,r)=>{if(this.#o)return this.#o(e).then(t).catch(r);throw new Error("Clipboard API not found!")}))}_handleBlob(e,t){return t.getType(e)}_handleText(e,t){return this._handleBlob(e,t).then((e=>e.text()))}_readData(e=0,t=null,r=null,o=!1){return new Promise(((n,a)=>{this._read(e).then((i=>{if(!i)return n(null);const s=[];let l=!0;const c=async(e,n)=>{if(l)if(null!==t&&"custom"!==t||"string"!=typeof r||!(!o&&e.startsWith(r)||o&&e===r))if(null!==t&&"text"!==t||"text/plain"!==e){if(null===t){l=!1;const t=await this._handleBlob(e,n);t&&s.push(t)}}else{l=!1;const t=await this._handleText(e,n);t&&s.push(t)}else{l=!1;const t=await this._handleBlob(e,n);t&&s.push(t)}},d=[],u=e=>{if(!(e instanceof ClipboardItem))throw new Error("Expected ClipboardItem when reading data.");for(const t in e.types)d.push(c(e.types[t],e))};if("number"==typeof e&&!Number.isNaN(e)&&Number.isFinite(e)&&e>-1)u(i),Promise.all(d).then((()=>{s[0]?n(s[0]):n(null)})).catch(a);else if(Array.isArray(i)){for(const e in i)u(i[e]);Promise.all(d).then((()=>n(s))).catch(a)}})).catch(a)}))}async readText(e=0){const t=await this._readData(e,"text");if("string"!=typeof t)throw new Error("Failed to read text: expected string result.");return t}async readCustom(e=null,t=!1,r=0){const o=await this._readData(r,"custom",e,t);if(!(o instanceof Blob))throw new Error("Failed to read custom data: expected Blob.");return o}async readAllTexts(){const e=await this._readData(null,"text");if(!Array.isArray(e))throw new Error("Expected array of strings when reading all texts.");if(!e.every((e=>"string"==typeof e)))throw new Error("Some values returned were not strings.");return e}async readAllCustom(e=null,t=!1){const r=await this._readData(null,"custom",e,t);if(!Array.isArray(r))throw new Error("Expected array of blobs when reading all custom items.");if(!r.every((e=>e instanceof Blob)))throw new Error("Some values returned were not Blob instances.");return r}async readAllData(e=null,t=null){const r=await this._readData(null,e,t);if(!Array.isArray(r))throw new Error("Expected array result when reading all data.");return r}_read(e){return new Promise(((t,r)=>{this.#t||r(new Error("Clipboard API not found!")),navigator.clipboard.read().then((r=>{if("number"==typeof e){if(Number.isNaN(e)||!Number.isFinite(e)||e<0)throw new Error(`Invalid index value: ${e}`);r[e]?t(r[e]):t(null)}t(r)})).catch(r)}))}async readIndex(e){const t=await this._read(e);if(null!==t&&!(t instanceof ClipboardItem))throw new Error(`Value at index ${e} is not a ClipboardItem.`);return t}async readAll(){const e=await this._read(null);if(!Array.isArray(e))throw new Error("Expected array result from clipboard read.");for(const t of e)if(!(t instanceof ClipboardItem))throw new Error("Invalid item type found in clipboard result.");return e}isExecCommandAvailable(){return this.#e}isNavigatorClipboardAvailable(){return this.#t}getCopyTextFunc(){return this.#r}getCopyBlobFunc(){return this.#o}};window.TinyClipboard=t.TinyClipboard})();
|