@webilix/ngx-helper-m3 0.0.12 → 0.0.13

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, makeEnvironmentProviders, Injector, Component, HostBinding, Input, Pipe, Injectable, Optional, Inject, EventEmitter, Output, inject, Directive, createComponent } from '@angular/core';
2
+ import { InjectionToken, makeEnvironmentProviders, Injector, Component, HostBinding, Input, Pipe, Injectable, Optional, Inject, EventEmitter, Output, inject, Directive, HostListener, createComponent } from '@angular/core';
3
3
  import { NgComponentOutlet, NgClass } from '@angular/common';
4
4
  import * as i1$2 from '@angular/material/button';
5
5
  import { MatButton, MatIconButton, MatButtonModule } from '@angular/material/button';
@@ -18,9 +18,9 @@ import * as i2$1 from '@angular/material/dialog';
18
18
  import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
19
19
  import * as i1$3 from '@angular/material/bottom-sheet';
20
20
  import { MAT_BOTTOM_SHEET_DATA } from '@angular/material/bottom-sheet';
21
+ import { trigger, transition, style, animate } from '@angular/animations';
21
22
  import * as i1$4 from '@angular/common/http';
22
23
  import { HttpHeaders, HttpEventType } from '@angular/common/http';
23
- import { trigger, transition, style, animate } from '@angular/animations';
24
24
 
25
25
  const NGX_HELPER_CONFIG = new InjectionToken('NGX-HELPER-CONFIG');
26
26
  const provideNgxHelperConfig = (config) => {
@@ -398,7 +398,7 @@ class ComponentService {
398
398
  return value === undefined
399
399
  ? { title: item.title, value: '' }
400
400
  : typeof value === 'string'
401
- ? { title: item.title, value: value.trim() }
401
+ ? { title: item.title, value: value.trim(), color: item.color }
402
402
  : {
403
403
  title: item.title,
404
404
  value: pipeTransform(value),
@@ -1276,10 +1276,312 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImpor
1276
1276
  args: [{ providedIn: 'root' }]
1277
1277
  }], ctorParameters: () => [{ type: i1$3.MatBottomSheet }, { type: i2$1.MatDialog }] });
1278
1278
 
1279
- class UploadComponent {
1279
+ class ToastComponent {
1280
+ elementRef;
1281
+ onClick = () => this.close();
1282
+ host = true;
1283
+ className = 'ngx-helper-m3-toast';
1284
+ top = '1rem';
1285
+ textColor;
1286
+ borderColor;
1287
+ backgroundColor;
1288
+ id;
1289
+ icon;
1290
+ messages = [];
1291
+ config;
1292
+ init;
1293
+ close;
1294
+ timeout;
1295
+ showClose;
1296
+ animation;
1297
+ progress = 0;
1298
+ start = 0;
1299
+ interval;
1300
+ constructor(elementRef) {
1301
+ this.elementRef = elementRef;
1302
+ }
1303
+ ngOnInit() {
1304
+ this.borderColor = this.backgroundColor;
1305
+ const xPosition = this.config.helper?.toastXPosition || 'CENTER';
1306
+ this.className = `ngx-helper-m3-toast ${xPosition.toLowerCase()}`;
1307
+ const toastTimeout = this.config.helper?.toastTimeout === undefined || this.config.helper?.toastTimeout < 0
1308
+ ? 4000
1309
+ : this.config.helper?.toastTimeout;
1310
+ this.timeout =
1311
+ this.config.toast.timeout === undefined || this.config.toast.timeout < 0
1312
+ ? toastTimeout
1313
+ : this.config.toast.timeout;
1314
+ this.showClose = this.config.toast.showClose || this.timeout === 0;
1315
+ this.animation = this.config.helper?.toastProgressAnimation || 'DECREASE';
1316
+ if (this.timeout) {
1317
+ this.start = new Date().getTime();
1318
+ this.interval = setInterval(() => {
1319
+ const timer = new Date().getTime();
1320
+ this.progress = ((timer - this.start) * 100) / this.timeout;
1321
+ this.progress = this.progress < 100 ? +this.progress.toFixed(2) : 100;
1322
+ if (this.progress === 100)
1323
+ this.close();
1324
+ }, 25);
1325
+ }
1326
+ }
1327
+ ngOnDestroy() {
1328
+ if (this.interval)
1329
+ clearInterval(this.interval);
1330
+ }
1331
+ ngAfterViewInit() {
1332
+ this.init();
1333
+ }
1334
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: ToastComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
1335
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.4", type: ToastComponent, isStandalone: true, selector: "ng-component", host: { attributes: { "selector": "toast" }, listeners: { "click": "onClick()" }, properties: { "@host": "this.host", "className": "this.className", "style.top": "this.top", "style.color": "this.textColor", "style.border-color": "this.borderColor", "style.background-color": "this.backgroundColor" } }, ngImport: i0, template: "<div class=\"content\">\n <div class=\"toast\">\n <mat-icon [style.color]=\"textColor\" class=\"icon\">{{ icon }}</mat-icon>\n <ul>\n @for (message of messages; track $index) {\n <li [innerHTML]=\"message | ngxHelperMultiLine\"></li>\n }\n </ul>\n </div>\n <!-- CLOSE ICON -->\n @if (showClose) {\n <mat-icon [style.color]=\"textColor\" class=\"close\">close</mat-icon>\n }\n</div>\n\n<div class=\"progress-container\" [style.background-color]=\"backgroundColor\">\n @if (timeout !== 0) {\n <div\n class=\"progress-value\"\n [style.background-color]=\"'color-mix(in srgb, ' + backgroundColor + ', black 25%)'\"\n [style.width]=\"(animation === 'DECREASE' ? 100 - progress : progress) + '%'\"\n ></div>\n }\n</div>\n", styles: [""], dependencies: [{ kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "pipe", type: NgxHelperMultiLinePipe, name: "ngxHelperMultiLine" }], animations: [
1336
+ trigger('host', [
1337
+ transition(':enter', [
1338
+ style({ top: 0, opacity: 0 }),
1339
+ animate('350ms ease-in-out', style({ top: '*', opacity: 1 })),
1340
+ ]),
1341
+ ]),
1342
+ ] });
1343
+ }
1344
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: ToastComponent, decorators: [{
1345
+ type: Component,
1346
+ args: [{ host: { selector: 'toast' }, imports: [MatIcon, NgxHelperMultiLinePipe], animations: [
1347
+ trigger('host', [
1348
+ transition(':enter', [
1349
+ style({ top: 0, opacity: 0 }),
1350
+ animate('350ms ease-in-out', style({ top: '*', opacity: 1 })),
1351
+ ]),
1352
+ ]),
1353
+ ], template: "<div class=\"content\">\n <div class=\"toast\">\n <mat-icon [style.color]=\"textColor\" class=\"icon\">{{ icon }}</mat-icon>\n <ul>\n @for (message of messages; track $index) {\n <li [innerHTML]=\"message | ngxHelperMultiLine\"></li>\n }\n </ul>\n </div>\n <!-- CLOSE ICON -->\n @if (showClose) {\n <mat-icon [style.color]=\"textColor\" class=\"close\">close</mat-icon>\n }\n</div>\n\n<div class=\"progress-container\" [style.background-color]=\"backgroundColor\">\n @if (timeout !== 0) {\n <div\n class=\"progress-value\"\n [style.background-color]=\"'color-mix(in srgb, ' + backgroundColor + ', black 25%)'\"\n [style.width]=\"(animation === 'DECREASE' ? 100 - progress : progress) + '%'\"\n ></div>\n }\n</div>\n" }]
1354
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { onClick: [{
1355
+ type: HostListener,
1356
+ args: ['click']
1357
+ }], host: [{
1358
+ type: HostBinding,
1359
+ args: ['@host']
1360
+ }], className: [{
1361
+ type: HostBinding,
1362
+ args: ['className']
1363
+ }], top: [{
1364
+ type: HostBinding,
1365
+ args: ['style.top']
1366
+ }], textColor: [{
1367
+ type: HostBinding,
1368
+ args: ['style.color']
1369
+ }], borderColor: [{
1370
+ type: HostBinding,
1371
+ args: ['style.border-color']
1372
+ }], backgroundColor: [{
1373
+ type: HostBinding,
1374
+ args: ['style.background-color']
1375
+ }] } });
1376
+
1377
+ class NgxHelperToastService {
1378
+ applicationRef;
1379
+ injector;
1380
+ config;
1381
+ components = [];
1382
+ constructor(applicationRef, injector, config) {
1383
+ this.applicationRef = applicationRef;
1384
+ this.injector = injector;
1385
+ this.config = config;
1386
+ }
1387
+ getId() {
1388
+ let id = undefined;
1389
+ while (!id || this.components.some((c) => c.id === id))
1390
+ id = Helper.STRING.getRandom(10);
1391
+ return id;
1392
+ }
1393
+ updatePositions() {
1394
+ let top = 0;
1395
+ this.components.forEach((c, index) => {
1396
+ c.componentRef.instance.top = `calc(${(index / 1.5).toFixed(1)}rem + calc(${top}px + 1rem))`;
1397
+ top += +c.componentRef.instance.elementRef.nativeElement.offsetHeight;
1398
+ });
1399
+ }
1400
+ toast(toast, message, arg1, arg2) {
1401
+ const config = arg2 ? arg1 : typeof arg1 === 'object' ? arg1 : {};
1402
+ const onClose = arg2 || (typeof arg1 === 'function' ? arg1 : () => { });
1403
+ const messages = typeof message === 'string' ? [message] : message;
1404
+ const content = [toast.icon, toast.textColor, toast.backgroundColor, ...messages].join('\n');
1405
+ const duplicate = this.components.find((component) => component.content === content);
1406
+ if (!this.config?.toastAllowDuplicates && duplicate) {
1407
+ if (this.config?.toastResetDuplicates) {
1408
+ duplicate.componentRef.instance.start = new Date().getTime();
1409
+ duplicate.componentRef.instance.progress = 0;
1410
+ }
1411
+ return;
1412
+ }
1413
+ const componentRef = createComponent(ToastComponent, {
1414
+ environmentInjector: this.applicationRef.injector,
1415
+ elementInjector: this.injector,
1416
+ });
1417
+ const id = this.getId();
1418
+ componentRef.instance.id = id;
1419
+ componentRef.instance.icon = toast.icon;
1420
+ componentRef.instance.textColor = toast.textColor;
1421
+ componentRef.instance.backgroundColor = toast.backgroundColor;
1422
+ componentRef.instance.messages = messages;
1423
+ componentRef.instance.config = { helper: this.config, toast: config };
1424
+ componentRef.instance.init = () => this.updatePositions();
1425
+ componentRef.instance.close = () => {
1426
+ this.applicationRef.detachView(componentRef.hostView);
1427
+ document.body.removeChild(htmlElement);
1428
+ componentRef.destroy();
1429
+ this.components = this.components.filter((c) => c.id !== componentRef.instance.id);
1430
+ this.updatePositions();
1431
+ if (onClose)
1432
+ onClose();
1433
+ };
1434
+ const htmlElement = componentRef.hostView.rootNodes[0];
1435
+ this.applicationRef.attachView(componentRef.hostView);
1436
+ document.body.appendChild(htmlElement);
1437
+ this.components.push({ id, componentRef, content });
1438
+ this.updatePositions();
1439
+ }
1440
+ info(message, arg1, arg2) {
1441
+ const toast = { icon: 'warning_amber', textColor: '#fff', backgroundColor: '#2f96b4' };
1442
+ this.toast(toast, message, arg1, arg2);
1443
+ }
1444
+ success(message, arg1, arg2) {
1445
+ const toast = { icon: 'done_all', textColor: '#fff', backgroundColor: '#51a351' };
1446
+ this.toast(toast, message, arg1, arg2);
1447
+ }
1448
+ warning(message, arg1, arg2) {
1449
+ const toast = { icon: 'info', textColor: '#fff', backgroundColor: '#f89406' };
1450
+ this.toast(toast, message, arg1, arg2);
1451
+ }
1452
+ error(message, arg1, arg2) {
1453
+ const toast = { icon: 'cancel', textColor: '#fff', backgroundColor: '#bd362f' };
1454
+ this.toast(toast, message, arg1, arg2);
1455
+ }
1456
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperToastService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: NGX_HELPER_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1457
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperToastService, providedIn: 'root' });
1458
+ }
1459
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperToastService, decorators: [{
1460
+ type: Injectable,
1461
+ args: [{ providedIn: 'root' }]
1462
+ }], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: undefined, decorators: [{
1463
+ type: Optional
1464
+ }, {
1465
+ type: Inject,
1466
+ args: [NGX_HELPER_CONFIG]
1467
+ }] }] });
1468
+
1469
+ class DownloadComponent {
1280
1470
  httpClient;
1471
+ ngxHelperToastService;
1472
+ host = true;
1281
1473
  className = 'ngx-helper-m3-http';
1474
+ bottom = '1rem';
1475
+ id;
1476
+ path;
1477
+ title;
1478
+ config;
1479
+ onSuccess;
1480
+ onError;
1481
+ close;
1482
+ progress = 0;
1483
+ constructor(httpClient, ngxHelperToastService) {
1484
+ this.httpClient = httpClient;
1485
+ this.ngxHelperToastService = ngxHelperToastService;
1486
+ }
1487
+ ngAfterViewInit() {
1488
+ setTimeout(this.download.bind(this), 0);
1489
+ }
1490
+ download() {
1491
+ let headers = new HttpHeaders();
1492
+ const header = this.config.header || {};
1493
+ Object.keys(header).forEach((key) => (headers = headers.set(key, header[key])));
1494
+ let request;
1495
+ switch (this.config.method || 'GET') {
1496
+ case 'GET':
1497
+ request = this.httpClient.get(this.path, {
1498
+ headers,
1499
+ reportProgress: true,
1500
+ observe: 'events',
1501
+ responseType: 'arraybuffer',
1502
+ });
1503
+ break;
1504
+ case 'POST':
1505
+ request = this.httpClient.post(this.path, {
1506
+ headers,
1507
+ reportProgress: true,
1508
+ observe: 'events',
1509
+ responseType: 'arraybuffer',
1510
+ });
1511
+ break;
1512
+ case 'PUT':
1513
+ request = this.httpClient.put(this.path, {
1514
+ headers,
1515
+ reportProgress: true,
1516
+ observe: 'events',
1517
+ responseType: 'arraybuffer',
1518
+ });
1519
+ break;
1520
+ case 'PATCH':
1521
+ request = this.httpClient.patch(this.path, {
1522
+ headers,
1523
+ reportProgress: true,
1524
+ observe: 'events',
1525
+ responseType: 'arraybuffer',
1526
+ });
1527
+ break;
1528
+ }
1529
+ request.subscribe({
1530
+ next: (event) => {
1531
+ switch (event.type) {
1532
+ case HttpEventType.DownloadProgress:
1533
+ const progress = event.loaded && event.total ? Math.ceil((event.loaded / event.total) * 1000) / 10 : 0;
1534
+ this.progress = progress <= 100 ? progress : 100;
1535
+ break;
1536
+ case HttpEventType.Response:
1537
+ console.log(event);
1538
+ this.progress = 100;
1539
+ this.onSuccess(event.body);
1540
+ this.close();
1541
+ break;
1542
+ }
1543
+ },
1544
+ error: () => {
1545
+ this.onError();
1546
+ this.close();
1547
+ },
1548
+ });
1549
+ }
1550
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DownloadComponent, deps: [{ token: i1$4.HttpClient }, { token: NgxHelperToastService }], target: i0.ɵɵFactoryTarget.Component });
1551
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: DownloadComponent, isStandalone: true, selector: "ng-component", host: { attributes: { "selector": "download" }, properties: { "@host": "this.host", "className": "this.className", "style.bottom": "this.bottom" } }, ngImport: i0, template: "<div class=\"content\">\n <mat-icon>file_download</mat-icon>\n <div class=\"title\">{{ title }}</div>\n</div>\n\n<div class=\"progress-container\">\n <div class=\"progress-value\" [style.width]=\"progress + '%'\"></div>\n</div>\n", styles: [""], dependencies: [{ kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], animations: [
1552
+ trigger('host', [
1553
+ transition(':enter', [
1554
+ style({ left: 'calc(-250px - 1rem)' }),
1555
+ animate('100ms ease-in-out', style({ left: '1rem' })),
1556
+ ]),
1557
+ ]),
1558
+ ] });
1559
+ }
1560
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DownloadComponent, decorators: [{
1561
+ type: Component,
1562
+ args: [{ host: { selector: 'download' }, imports: [MatIcon], animations: [
1563
+ trigger('host', [
1564
+ transition(':enter', [
1565
+ style({ left: 'calc(-250px - 1rem)' }),
1566
+ animate('100ms ease-in-out', style({ left: '1rem' })),
1567
+ ]),
1568
+ ]),
1569
+ ], template: "<div class=\"content\">\n <mat-icon>file_download</mat-icon>\n <div class=\"title\">{{ title }}</div>\n</div>\n\n<div class=\"progress-container\">\n <div class=\"progress-value\" [style.width]=\"progress + '%'\"></div>\n</div>\n" }]
1570
+ }], ctorParameters: () => [{ type: i1$4.HttpClient }, { type: NgxHelperToastService }], propDecorators: { host: [{
1571
+ type: HostBinding,
1572
+ args: ['@host']
1573
+ }], className: [{
1574
+ type: HostBinding,
1575
+ args: ['className']
1576
+ }], bottom: [{
1577
+ type: HostBinding,
1578
+ args: ['style.bottom']
1579
+ }] } });
1580
+
1581
+ class UploadComponent {
1582
+ httpClient;
1282
1583
  host = true;
1584
+ className = 'ngx-helper-m3-http';
1283
1585
  bottom = '1rem';
1284
1586
  id;
1285
1587
  file;
@@ -1332,7 +1634,7 @@ class UploadComponent {
1332
1634
  });
1333
1635
  }
1334
1636
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: UploadComponent, deps: [{ token: i1$4.HttpClient }], target: i0.ɵɵFactoryTarget.Component });
1335
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: UploadComponent, isStandalone: true, selector: "ng-component", host: { attributes: { "selector": "upload" }, properties: { "className": "this.className", "@host": "this.host", "style.bottom": "this.bottom" } }, ngImport: i0, template: "<div class=\"content\">\n <mat-icon>file_upload</mat-icon>\n <div class=\"file\">{{ file.name }}</div>\n</div>\n\n<div class=\"progress-container\">\n <div class=\"progress-value\" [style.width]=\"progress + '%'\"></div>\n</div>\n", styles: [""], dependencies: [{ kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], animations: [
1637
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: UploadComponent, isStandalone: true, selector: "ng-component", host: { attributes: { "selector": "upload" }, properties: { "@host": "this.host", "className": "this.className", "style.bottom": "this.bottom" } }, ngImport: i0, template: "<div class=\"content\">\n <mat-icon>file_upload</mat-icon>\n <div class=\"file\">{{ file.name }}</div>\n</div>\n\n<div class=\"progress-container\">\n <div class=\"progress-value\" [style.width]=\"progress + '%'\"></div>\n</div>\n", styles: [""], dependencies: [{ kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }], animations: [
1336
1638
  trigger('host', [
1337
1639
  transition(':enter', [
1338
1640
  style({ left: 'calc(-250px - 1rem)' }),
@@ -1351,12 +1653,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImpor
1351
1653
  ]),
1352
1654
  ]),
1353
1655
  ], template: "<div class=\"content\">\n <mat-icon>file_upload</mat-icon>\n <div class=\"file\">{{ file.name }}</div>\n</div>\n\n<div class=\"progress-container\">\n <div class=\"progress-value\" [style.width]=\"progress + '%'\"></div>\n</div>\n" }]
1354
- }], ctorParameters: () => [{ type: i1$4.HttpClient }], propDecorators: { className: [{
1355
- type: HostBinding,
1356
- args: ['className']
1357
- }], host: [{
1656
+ }], ctorParameters: () => [{ type: i1$4.HttpClient }], propDecorators: { host: [{
1358
1657
  type: HostBinding,
1359
1658
  args: ['@host']
1659
+ }], className: [{
1660
+ type: HostBinding,
1661
+ args: ['className']
1360
1662
  }], bottom: [{
1361
1663
  type: HostBinding,
1362
1664
  args: ['style.bottom']
@@ -1365,10 +1667,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImpor
1365
1667
  class NgxHelperHttpService {
1366
1668
  applicationRef;
1367
1669
  injector;
1670
+ ngxHelperToastService;
1368
1671
  components = [];
1369
- constructor(applicationRef, injector) {
1672
+ constructor(applicationRef, injector, ngxHelperToastService) {
1370
1673
  this.applicationRef = applicationRef;
1371
1674
  this.injector = injector;
1675
+ this.ngxHelperToastService = ngxHelperToastService;
1372
1676
  }
1373
1677
  getId() {
1374
1678
  let id = undefined;
@@ -1381,6 +1685,54 @@ class NgxHelperHttpService {
1381
1685
  c.componentRef.instance.bottom = `calc(${(index / 1.5).toFixed(1)}rem + calc(${index * 40}px + 1rem))`;
1382
1686
  });
1383
1687
  }
1688
+ getBuffer(path, title, config) {
1689
+ return new Promise((resolve, reject) => {
1690
+ const componentRef = createComponent(DownloadComponent, {
1691
+ environmentInjector: this.applicationRef.injector,
1692
+ elementInjector: this.injector,
1693
+ });
1694
+ const id = this.getId();
1695
+ componentRef.instance.id = id;
1696
+ componentRef.instance.path = path;
1697
+ componentRef.instance.title = title;
1698
+ componentRef.instance.config = config || {};
1699
+ componentRef.instance.onSuccess = (arrayBuffer) => resolve(arrayBuffer);
1700
+ componentRef.instance.onError = () => reject();
1701
+ componentRef.instance.close = () => {
1702
+ this.applicationRef.detachView(componentRef.hostView);
1703
+ document.body.removeChild(htmlElement);
1704
+ componentRef.destroy();
1705
+ this.components = this.components.filter((c) => c.id !== componentRef.instance.id);
1706
+ this.updatePositions();
1707
+ };
1708
+ const htmlElement = componentRef.hostView.rootNodes[0];
1709
+ this.applicationRef.attachView(componentRef.hostView);
1710
+ document.body.appendChild(htmlElement);
1711
+ this.components.push({ id, componentRef });
1712
+ this.updatePositions();
1713
+ });
1714
+ }
1715
+ download(path, title, config) {
1716
+ const onError = () => this.ngxHelperToastService.error('امکان دانلود فایل وجود ندارد.');
1717
+ const onSuccess = (arrayBuffer) => {
1718
+ try {
1719
+ const split = path
1720
+ .split('.')
1721
+ .map((text) => text.trim().replace(/\//gi, ''))
1722
+ .filter((text) => !!text);
1723
+ const name = Helper.STRING.getFileName(title, split[split.length - 1] || '');
1724
+ const href = URL.createObjectURL(new Blob([arrayBuffer]));
1725
+ const a = document.createElement('a');
1726
+ a.href = href;
1727
+ a.download = name;
1728
+ a.click();
1729
+ }
1730
+ catch (e) {
1731
+ onError();
1732
+ }
1733
+ };
1734
+ this.getBuffer(path, title, config || {}).then(onSuccess, onError);
1735
+ }
1384
1736
  upload(file, url, arg1, arg2, arg3) {
1385
1737
  const config = typeof arg3 === 'function' ? arg1 : {};
1386
1738
  const onSuccess = typeof arg3 === 'function' ? arg2 : arg1;
@@ -1397,6 +1749,7 @@ class NgxHelperHttpService {
1397
1749
  componentRef.instance.close = (type, result, status) => {
1398
1750
  this.applicationRef.detachView(componentRef.hostView);
1399
1751
  document.body.removeChild(htmlElement);
1752
+ componentRef.destroy();
1400
1753
  this.components = this.components.filter((c) => c.id !== componentRef.instance.id);
1401
1754
  this.updatePositions();
1402
1755
  switch (type) {
@@ -1414,13 +1767,41 @@ class NgxHelperHttpService {
1414
1767
  this.components.push({ id, componentRef });
1415
1768
  this.updatePositions();
1416
1769
  }
1417
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperHttpService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
1770
+ printPDF(data, config) {
1771
+ const getPDF = () => {
1772
+ return new Promise((resolve, reject) => {
1773
+ if (typeof data !== 'string') {
1774
+ resolve(new Blob([data], { type: 'application/pdf' }));
1775
+ return;
1776
+ }
1777
+ this.getBuffer(data, 'دریافت فایل', config || {}).then((arrayBuffer) => resolve(new Blob([arrayBuffer], { type: 'application/pdf' })), () => reject());
1778
+ });
1779
+ };
1780
+ getPDF().then((blob) => {
1781
+ try {
1782
+ const prevIframe = document.getElementById('ngx-helper-http-pdf-download-iframe');
1783
+ if (prevIframe)
1784
+ document.body.removeChild(prevIframe);
1785
+ const src = URL.createObjectURL(blob);
1786
+ const iframe = document.createElement('iframe');
1787
+ iframe.id = 'ngx-helper-http-pdf-download-iframe';
1788
+ iframe.style.display = 'none';
1789
+ document.body.appendChild(iframe);
1790
+ iframe.src = src;
1791
+ iframe.onload = () => iframe.contentWindow?.print();
1792
+ }
1793
+ catch (e) {
1794
+ this.ngxHelperToastService.error('امکان پرینت فایل وجود ندارد.');
1795
+ }
1796
+ }, () => this.ngxHelperToastService.error('امکان دانلود فایل وجود ندارد.'));
1797
+ }
1798
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperHttpService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: NgxHelperToastService }], target: i0.ɵɵFactoryTarget.Injectable });
1418
1799
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperHttpService, providedIn: 'root' });
1419
1800
  }
1420
1801
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: NgxHelperHttpService, decorators: [{
1421
1802
  type: Injectable,
1422
1803
  args: [{ providedIn: 'root' }]
1423
- }], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }] });
1804
+ }], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: NgxHelperToastService }] });
1424
1805
 
1425
1806
  /*
1426
1807
  * Public API Surface of ngx-helper-m3
@@ -1430,5 +1811,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImpor
1430
1811
  * Generated bundle index. Do not edit.
1431
1812
  */
1432
1813
 
1433
- export { NGX_HELPER_BOX_DATA, NGX_HELPER_CONFIG, NGX_HELPER_CONTAINER_CLOSE, NGX_HELPER_CONTAINER_DATA, NGX_HELPER_CONTAINER_TYPE, NGX_HELPER_PAGE_GROUP_DATA, NGX_HELPER_PAGE_GROUP_DATA_CHANGE, NGX_HELPER_PAGE_GROUP_ITEM, NgxHelperBankCardPipe, NgxHelperBoxComponent, NgxHelperCardComponent, NgxHelperConfirmService, NgxHelperContainerService, NgxHelperDatePipe, NgxHelperDurationPipe, NgxHelperFileSizePipe, NgxHelperHttpService, NgxHelperLoaderComponent, NgxHelperMobilePipe, NgxHelperMultiLinePipe, NgxHelperNumberPipe, NgxHelperPageGroupComponent, NgxHelperPeriodPipe, NgxHelperPricePipe, NgxHelperSafePipe, NgxHelperSectionColumnComponent, NgxHelperSectionComponent, NgxHelperSectionStickyDirective, NgxHelperValueBoxComponent, NgxHelperValueListComponent, NgxHelperValuePipe, NgxHelperVolumePipe, NgxHelperWeightPipe, provideNgxHelperConfig };
1814
+ export { NGX_HELPER_BOX_DATA, NGX_HELPER_CONFIG, NGX_HELPER_CONTAINER_CLOSE, NGX_HELPER_CONTAINER_DATA, NGX_HELPER_CONTAINER_TYPE, NGX_HELPER_PAGE_GROUP_DATA, NGX_HELPER_PAGE_GROUP_DATA_CHANGE, NGX_HELPER_PAGE_GROUP_ITEM, NgxHelperBankCardPipe, NgxHelperBoxComponent, NgxHelperCardComponent, NgxHelperConfirmService, NgxHelperContainerService, NgxHelperDatePipe, NgxHelperDurationPipe, NgxHelperFileSizePipe, NgxHelperHttpService, NgxHelperLoaderComponent, NgxHelperMobilePipe, NgxHelperMultiLinePipe, NgxHelperNumberPipe, NgxHelperPageGroupComponent, NgxHelperPeriodPipe, NgxHelperPricePipe, NgxHelperSafePipe, NgxHelperSectionColumnComponent, NgxHelperSectionComponent, NgxHelperSectionStickyDirective, NgxHelperToastService, NgxHelperValueBoxComponent, NgxHelperValueListComponent, NgxHelperValuePipe, NgxHelperVolumePipe, NgxHelperWeightPipe, provideNgxHelperConfig };
1434
1815
  //# sourceMappingURL=webilix-ngx-helper-m3.mjs.map