@dile/utils 3.2.0 → 3.2.1
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.
|
@@ -221,6 +221,90 @@ export class DileQrCode extends LitElement {
|
|
|
221
221
|
img.src = this.logo;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Downloads the QR code as a PNG image.
|
|
226
|
+
* @param {string} filename - Optional filename for the download. Defaults to 'qr-code.png'.
|
|
227
|
+
*/
|
|
228
|
+
download(filename = 'qr-code.png') {
|
|
229
|
+
const canvas = this.#getCanvas();
|
|
230
|
+
if (!canvas) {
|
|
231
|
+
console.warn('dile-qr-code: Canvas not found');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
canvas.toBlob((blob) => {
|
|
236
|
+
if (!blob) {
|
|
237
|
+
console.warn('dile-qr-code: Failed to create blob from canvas');
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const url = URL.createObjectURL(blob);
|
|
242
|
+
const link = document.createElement('a');
|
|
243
|
+
link.href = url;
|
|
244
|
+
link.download = filename;
|
|
245
|
+
document.body.appendChild(link);
|
|
246
|
+
link.click();
|
|
247
|
+
document.body.removeChild(link);
|
|
248
|
+
URL.revokeObjectURL(url);
|
|
249
|
+
|
|
250
|
+
this.dispatchEvent(
|
|
251
|
+
new CustomEvent('dile-qr-code-downloaded', {
|
|
252
|
+
bubbles: true,
|
|
253
|
+
composed: true,
|
|
254
|
+
detail: { filename },
|
|
255
|
+
})
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Copies the QR code as an image to the clipboard.
|
|
262
|
+
* Allows pasting the QR code directly into any application that accepts images.
|
|
263
|
+
*/
|
|
264
|
+
async copy() {
|
|
265
|
+
const canvas = this.#getCanvas();
|
|
266
|
+
if (!canvas) {
|
|
267
|
+
console.warn('dile-qr-code: Canvas not found');
|
|
268
|
+
this.dispatchEvent(
|
|
269
|
+
new CustomEvent('dile-qr-code-copy-error', {
|
|
270
|
+
bubbles: true,
|
|
271
|
+
composed: true,
|
|
272
|
+
detail: { error: 'Canvas not found' },
|
|
273
|
+
})
|
|
274
|
+
);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const blob = await new Promise((resolve) => {
|
|
280
|
+
canvas.toBlob(resolve);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
if (!blob) {
|
|
284
|
+
throw new Error('Failed to create blob from canvas');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const item = new ClipboardItem({ 'image/png': blob });
|
|
288
|
+
await navigator.clipboard.write([item]);
|
|
289
|
+
|
|
290
|
+
this.dispatchEvent(
|
|
291
|
+
new CustomEvent('dile-qr-code-copied', {
|
|
292
|
+
bubbles: true,
|
|
293
|
+
composed: true,
|
|
294
|
+
})
|
|
295
|
+
);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.warn('dile-qr-code: Error copying to clipboard', error);
|
|
298
|
+
this.dispatchEvent(
|
|
299
|
+
new CustomEvent('dile-qr-code-copy-error', {
|
|
300
|
+
bubbles: true,
|
|
301
|
+
composed: true,
|
|
302
|
+
detail: { error: error.message },
|
|
303
|
+
})
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
224
308
|
render() {
|
|
225
309
|
return html`
|
|
226
310
|
<canvas
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/utils",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Utility Components of Diverse Uses Based on the Lit Library and Web Components Standard.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"homepage": "https://dile-components.com/",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@dile/iconlib": "^2.0.1",
|
|
24
|
-
"@dile/ui": "^3.
|
|
24
|
+
"@dile/ui": "^3.13.0",
|
|
25
25
|
"@lion/ui": "^0.21.0",
|
|
26
26
|
"linkify-string": "^4.1.3",
|
|
27
27
|
"linkifyjs": "^4.1.3",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e4b428c6b9cee3e0f20520c5baa979e232f90dda"
|
|
35
35
|
}
|