UNPKG

@progress/kendo-angular-barcodes

Version:
362 lines (361 loc) 12 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { ChangeDetectionStrategy, Component, ElementRef, Input, NgZone, Renderer2 } from '@angular/core'; import { QRCode } from '@progress/kendo-charts'; import { BaseComponent } from './base.component'; import { packageMetadata } from './package-metadata'; import { ResizeSensorComponent } from '@progress/kendo-angular-common'; import * as i0 from "@angular/core"; const DEFAULT_COLOR = '#000'; const DEFAULT_BACKGROUND = '#fff'; const DEFAULT_ERROR_CORRECTION = 'L'; /** * Represents the Kendo UI QR Code component for Angular. * * @example * ```ts * import { Component } from '@angular/core'; * * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ export class QRCodeComponent extends BaseComponent { element; renderer; ngZone; /** * The background color of the QR Code. Accepts a valid CSS color string, including hex and rgb. * * @default "white" * * @example * ```ts-preview * import { Component } from '@angular/core'; * * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * background="#fc0"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ background; /** * The border of the QR Code. * * @example * ```ts-preview * import { Component } from '@angular/core'; * import { Border } from '@progress/kendo-angular-barcodes'; * * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * [border]="qrcodeBorder" [padding]="5"> * </kendo-qrcode> * ` * }) * export class AppComponent { * qrcodeBorder: Border = { * color: '#fc0', * width: 2 * }; * } * ``` */ border; /** * The color of the QR Code. Accepts a valid CSS color string, including hex and rgb. * * @default "black" * * @example * ```ts-preview * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * color="#fc0"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ color; /** * The encoding mode used to encode the value. * * > **Important** The UTF-8 encoding is not included in the specifications and is not supported by all readers. * * The possible values are: * * `"ISO_8859_1"`&mdash;Supports all characters from the [ISO/IEC 8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) character set. * * `"UTF_8"`&mdash;Supports all [Unicode](https://en.wikipedia.org/wiki/List_of_Unicode_characters) characters. * * @default "ISO_8859_1" * * @example * ```ts-preview * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="АБВ" encoding="UTF_8"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ encoding; /** * The error correction level to use. * * The possible values are: * * `"L"`&mdash;Approximately 7% of the codewords can be restored. * * `"M"`&mdash;Approximately 15% of the codewords can be restored. * * `"Q"`&mdash;Approximately 25% of the codewords can be restored. * * `"H"`&mdash;Approximately 30% of the codewords can be restored. * * @default "L" * * @example * ```ts-preview * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * errorCorrection="Q"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ errorCorrection; /** * An optional image overlay that will placed over the QR Code. * * > **Note** Always test if the code reads correctly with the applied overlay. * > Depending on the length of the value and the size of the overlay, you might need to raise the `errorCorrection` level to `"M"` or `"H"`. * * @example * ```ts-preview * import { QRCodeOverlay } from '@progress/kendo-angular-barcodes'; * * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * [overlay]="qrcodeOverlay"> * </kendo-qrcode> * ` * }) * export class AppComponent { * qrcodeOverlay: QRCodeOverlay = { * type: 'swiss' * }; * } * ``` */ overlay; /** * The padding of the QR Code. The value sets all paddings in pixels. * * @default 0 * * @example * ```ts-preview * import { Component } from '@angular/core'; * * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * [padding]="10" background="#fc0"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ padding; /** * Sets the preferred rendering mode of the QR Code. * * The supported values are: * * `"canvas"`&mdash;Renders the component as a Canvas element. * * `"svg"`&mdash;Renders the component as an inline SVG document. * * @default "svg" * * @example * ```ts-preview * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * renderAs="canvas"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ renderAs; /** * Specifies the size of a QR Code. Numeric values are treated as pixels. * * If no size is specified, the size will be determined from the element width and height. * If the element has width or height of zero, a default value of 200 pixels will be used. * * @default "200px" * * @example * ```ts-preview * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * [size]="200"> * </kendo-qrcode> * * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * [style.width.px]="200" [style.height.px]="200"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ size; /** * The value of the QR Code. * * @example * ```ts-preview * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ value; /** * Limits the automatic resizing of the QR Code. Sets the maximum number of times per second * that the component redraws its content when the size of its container changes. * Defaults to `10`. To disable the automatic resizing, set it to `0`. * * @example * ```ts * _@Component({ * selector: 'my-app', * template: ` * <kendo-qrcode value="https://www.telerik.com/kendo-angular-ui" * [resizeRateLimit]="2"> * </kendo-qrcode> * ` * }) * export class AppComponent { * } * ``` */ resizeRateLimit = 10; get options() { return { background: this.background || DEFAULT_BACKGROUND, border: this.border, color: this.color || DEFAULT_COLOR, encoding: this.encoding, errorCorrection: this.errorCorrection || DEFAULT_ERROR_CORRECTION, overlay: this.overlay || {}, padding: this.padding, renderAs: this.renderAs, size: this.size, value: this.value }; } constructor(element, renderer, ngZone) { super(element, renderer, ngZone); this.element = element; this.renderer = renderer; this.ngZone = ngZone; } createInstance(element, options) { return new QRCode(element, options, this.onError.bind(this)); } onError(error) { error.name = packageMetadata.productName + ' QRCode'; if (this.isDevMode()) { throw error; } else { console.warn(error); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: QRCodeComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: QRCodeComponent, isStandalone: true, selector: "kendo-qrcode", inputs: { background: "background", border: "border", color: "color", encoding: "encoding", errorCorrection: "errorCorrection", overlay: "overlay", padding: "padding", renderAs: "renderAs", size: "size", value: "value", resizeRateLimit: "resizeRateLimit" }, exportAs: ["kendoQRCode"], usesInheritance: true, ngImport: i0, template: ` <kendo-resize-sensor (resize)="onResize()" [rateLimit]="resizeRateLimit"></kendo-resize-sensor> `, isInline: true, dependencies: [{ kind: "component", type: ResizeSensorComponent, selector: "kendo-resize-sensor", inputs: ["rateLimit"], outputs: ["resize"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: QRCodeComponent, decorators: [{ type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'kendo-qrcode', exportAs: 'kendoQRCode', template: ` <kendo-resize-sensor (resize)="onResize()" [rateLimit]="resizeRateLimit"></kendo-resize-sensor> `, standalone: true, imports: [ResizeSensorComponent] }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }]; }, propDecorators: { background: [{ type: Input }], border: [{ type: Input }], color: [{ type: Input }], encoding: [{ type: Input }], errorCorrection: [{ type: Input }], overlay: [{ type: Input }], padding: [{ type: Input }], renderAs: [{ type: Input }], size: [{ type: Input }], value: [{ type: Input }], resizeRateLimit: [{ type: Input }] } });