{"version":3,"file":"ajf-core-image.mjs","sources":["../../../projects/core/image/src/image-icon.ts","../../../projects/core/image/src/image-type.ts","../../../projects/core/image/src/image.ts","../../../projects/core/image/src/public_api.ts","../../../projects/core/image/src/ajf-core-image.ts"],"sourcesContent":["/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nexport interface AjfImageIcon {\n  fontSet: string;\n  fontIcon: string;\n}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\n// tslint:disable-next-line:prefer-const-enum\nexport enum AjfImageType {\n  Image,\n  Flag,\n  Icon,\n  LENGTH,\n}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {\n  Directive,\n  ElementRef,\n  Input,\n  OnDestroy,\n  OnInit,\n  Renderer2,\n  RendererStyleFlags2,\n} from '@angular/core';\nimport {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';\nimport {BehaviorSubject, Observable, Subscription} from 'rxjs';\n\nimport {AjfImageIcon} from './image-icon';\nimport {AjfImageType} from './image-type';\n\n@Directive()\nexport abstract class AjfImage implements OnDestroy, OnInit {\n  iconComponent: ElementRef | undefined;\n\n  /**\n   * if 0 take image by url\n   * if 1 take image by icon\n   * if 2 take image by class\n   *\n   */\n  @Input()\n  set type(type: AjfImageType | null) {\n    this._imageType.next(type);\n  }\n\n  @Input()\n  set imageUrl(imageUrl: string | null) {\n    imageUrl = typeof imageUrl === 'string' ? imageUrl : '';\n    this._url.next(\n      imageUrl.startsWith('data:image/svg+xml;base64,')\n        ? this._domSanitizer.bypassSecurityTrustResourceUrl(imageUrl)\n        : imageUrl,\n    );\n  }\n\n  @Input()\n  set icon(icon: AjfImageIcon | null) {\n    this._iconObj.next(icon);\n  }\n\n  @Input()\n  set flag(flag: string | null) {\n    this._flagName.next(flag);\n  }\n\n  readonly imageTypes = AjfImageType;\n\n  private _imageType = new BehaviorSubject<AjfImageType | null>(null);\n  readonly imageType: Observable<AjfImageType | null> = this\n    ._imageType as Observable<AjfImageType | null>;\n\n  private _url = new BehaviorSubject<string | SafeResourceUrl | null>(null);\n  readonly url: Observable<string | SafeResourceUrl | null> = this._url as Observable<\n    string | SafeResourceUrl | null\n  >;\n\n  private _iconObj = new BehaviorSubject<AjfImageIcon | null>(null);\n  readonly iconObj: Observable<AjfImageIcon | null> = this\n    ._iconObj as Observable<AjfImageIcon | null>;\n\n  private _flagName = new BehaviorSubject<string | null>(null);\n  readonly flagName: Observable<string | null> = this._flagName as Observable<string | null>;\n\n  private _iconSub = Subscription.EMPTY;\n\n  constructor(\n    private _el: ElementRef,\n    private _renderer: Renderer2,\n    private _domSanitizer: DomSanitizer,\n  ) {\n    this._iconSub = this.iconObj.subscribe(() => this._updateIconSize());\n  }\n\n  ngOnDestroy(): void {\n    if (this._iconSub && !this._iconSub.closed) {\n      this._iconSub.unsubscribe();\n    }\n  }\n\n  ngOnInit(): void {\n    this._updateIconSize();\n  }\n\n  private _updateIconSize(): void {\n    const icon = this._iconObj.getValue();\n    if (icon == null) {\n      return;\n    }\n    const styles = this._el.nativeElement.style;\n    if (this.iconComponent == null || styles == null || styles.fontSize == null) {\n      return;\n    }\n    const fontSize: string = styles.fontSize;\n    if (fontSize.match(/^[0-9]+px$/) != null) {\n      const el = this.iconComponent.nativeElement;\n      this._renderer.setStyle(el, 'width', fontSize, RendererStyleFlags2.Important);\n      this._renderer.setStyle(el, 'height', fontSize, RendererStyleFlags2.Important);\n    }\n  }\n}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nexport * from './image-icon';\nexport * from './image-type';\nexport * from './image';\n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