@progress/kendo-angular-barcodes
Version:
Kendo UI Angular Barcodes
113 lines (112 loc) • 4.35 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Directive, ElementRef, Input, isDevMode, NgZone, Renderer2, ViewChild } from '@angular/core';
import { isDocumentAvailable } from '@progress/kendo-angular-common';
import { exportImage, exportSVG } from '@progress/kendo-drawing';
import { validatePackage } from '@progress/kendo-licensing';
import { packageMetadata } from './package-metadata';
import * as i0 from "@angular/core";
/**
* @hidden
*/
export class BaseComponent {
element;
renderer;
ngZone;
resizeRateLimit = 10;
surfaceElement;
instance;
get autoResize() {
return this.resizeRateLimit > 0;
}
get canRender() {
return isDocumentAvailable() && Boolean(this.element);
}
constructor(element, renderer, ngZone) {
this.element = element;
this.renderer = renderer;
this.ngZone = ngZone;
validatePackage(packageMetadata);
}
ngAfterViewInit() {
this.refresh();
}
ngOnChanges(changes) {
// Need to create a new instance if the rendering mode changes.
if (changes['renderAs'] && this.instance) {
this.instance.destroy();
this.instance = null;
}
this.refresh();
}
/**
* Detects the size of the container and redraws the component.
* Resizing is automatic unless you set the `resizeRateLimit` option to `0`.
*/
resize() {
if (this.instance) {
this.instance.redraw();
}
}
/**
* @hidden
*/
onResize() {
if (this.autoResize) {
this.resize();
}
}
/**
* Exports the component as an image. The export operation is asynchronous and returns a promise.
*
* @param {ImageExportOptions} options - The parameters for the exported image.
* @returns {Promise<string>} - A promise that will be resolved with a PNG image encoded as a Data URI.
*/
exportImage(options = {}) {
return exportImage(this.exportVisual(), options);
}
/**
* Exports the component as an SVG document. The export operation is asynchronous and returns a promise.
*
* @param options - The parameters for the exported file.
* @returns - A promise that will be resolved with an SVG document that is encoded as a Data URI.
*/
exportSVG(options = {}) {
return exportSVG(this.exportVisual(), options);
}
/**
* Exports the component as a Drawing Group.
*
* @returns - The exported Group.
*/
exportVisual() {
return this.instance.exportVisual();
}
refresh() {
if (!this.canRender) {
return;
}
if (!this.instance) {
const element = this.element.nativeElement;
this.instance = this.createInstance(element, this.options);
}
else {
this.instance.setOptions(this.options);
}
}
isDevMode() {
return isDevMode();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: BaseComponent, inputs: { resizeRateLimit: "resizeRateLimit" }, viewQueries: [{ propertyName: "surfaceElement", first: true, predicate: ["surface"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseComponent, decorators: [{
type: Directive
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }]; }, propDecorators: { resizeRateLimit: [{
type: Input
}], surfaceElement: [{
type: ViewChild,
args: ['surface', { static: true }]
}] } });