Add barcode-detector-api-polyfill dependency and update environment variable declarations in SvelteKit project
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
/**
|
||||
* Aztec Code reader to use from browser.
|
||||
*
|
||||
* @class BrowserAztecCodeReader
|
||||
* @extends {BrowserCodeReader}
|
||||
*/
|
||||
export declare class BrowserAztecCodeReader extends BrowserCodeReader {
|
||||
/**
|
||||
* Creates an instance of BrowserAztecCodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*
|
||||
* @memberOf BrowserAztecCodeReader
|
||||
*/
|
||||
constructor(timeBetweenScansMillis?: number);
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import AztecReader from '../core/aztec/AztecReader';
|
||||
/**
|
||||
* Aztec Code reader to use from browser.
|
||||
*
|
||||
* @class BrowserAztecCodeReader
|
||||
* @extends {BrowserCodeReader}
|
||||
*/
|
||||
var BrowserAztecCodeReader = /** @class */ (function (_super) {
|
||||
__extends(BrowserAztecCodeReader, _super);
|
||||
/**
|
||||
* Creates an instance of BrowserAztecCodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*
|
||||
* @memberOf BrowserAztecCodeReader
|
||||
*/
|
||||
function BrowserAztecCodeReader(timeBetweenScansMillis) {
|
||||
if (timeBetweenScansMillis === void 0) { timeBetweenScansMillis = 500; }
|
||||
return _super.call(this, new AztecReader(), timeBetweenScansMillis) || this;
|
||||
}
|
||||
return BrowserAztecCodeReader;
|
||||
}(BrowserCodeReader));
|
||||
export { BrowserAztecCodeReader };
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import DecodeHintType from '../core/DecodeHintType';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* Barcode reader reader to use from browser.
|
||||
*/
|
||||
export declare class BrowserBarcodeReader extends BrowserCodeReader {
|
||||
/**
|
||||
* Creates an instance of BrowserBarcodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
* @param {Map<DecodeHintType, any>} hints
|
||||
*/
|
||||
constructor(timeBetweenScansMillis?: number, hints?: Map<DecodeHintType, any>);
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import MultiFormatOneDReader from '../core/oned/MultiFormatOneDReader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* Barcode reader reader to use from browser.
|
||||
*/
|
||||
var BrowserBarcodeReader = /** @class */ (function (_super) {
|
||||
__extends(BrowserBarcodeReader, _super);
|
||||
/**
|
||||
* Creates an instance of BrowserBarcodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
* @param {Map<DecodeHintType, any>} hints
|
||||
*/
|
||||
function BrowserBarcodeReader(timeBetweenScansMillis, hints) {
|
||||
if (timeBetweenScansMillis === void 0) { timeBetweenScansMillis = 500; }
|
||||
return _super.call(this, new MultiFormatOneDReader(hints), timeBetweenScansMillis, hints) || this;
|
||||
}
|
||||
return BrowserBarcodeReader;
|
||||
}(BrowserCodeReader));
|
||||
export { BrowserBarcodeReader };
|
||||
+411
@@ -0,0 +1,411 @@
|
||||
import BinaryBitmap from '../core/BinaryBitmap';
|
||||
import DecodeHintType from '../core/DecodeHintType';
|
||||
import Reader from '../core/Reader';
|
||||
import Result from '../core/Result';
|
||||
import { DecodeContinuouslyCallback } from './DecodeContinuouslyCallback';
|
||||
import { HTMLVisualMediaElement } from './HTMLVisualMediaElement';
|
||||
import { VideoInputDevice } from './VideoInputDevice';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* Base class for browser code reader.
|
||||
*/
|
||||
export declare class BrowserCodeReader {
|
||||
protected readonly reader: Reader;
|
||||
protected timeBetweenScansMillis: number;
|
||||
protected _hints?: Map<DecodeHintType, any>;
|
||||
/**
|
||||
* If navigator is present.
|
||||
*/
|
||||
get hasNavigator(): boolean;
|
||||
/**
|
||||
* If mediaDevices under navigator is supported.
|
||||
*/
|
||||
get isMediaDevicesSuported(): boolean;
|
||||
/**
|
||||
* If enumerateDevices under navigator is supported.
|
||||
*/
|
||||
get canEnumerateDevices(): boolean;
|
||||
/**
|
||||
* This will break the loop.
|
||||
*/
|
||||
private _stopContinuousDecode;
|
||||
/**
|
||||
* This will break the loop.
|
||||
*/
|
||||
private _stopAsyncDecode;
|
||||
/**
|
||||
* Delay time between decode attempts made by the scanner.
|
||||
*/
|
||||
protected _timeBetweenDecodingAttempts: number;
|
||||
/** Time between two decoding tries in milli seconds. */
|
||||
get timeBetweenDecodingAttempts(): number;
|
||||
/**
|
||||
* Change the time span the decoder waits between two decoding tries.
|
||||
*
|
||||
* @param {number} millis Time between two decoding tries in milli seconds.
|
||||
*/
|
||||
set timeBetweenDecodingAttempts(millis: number);
|
||||
/**
|
||||
* The HTML canvas element, used to draw the video or image's frame for decoding.
|
||||
*/
|
||||
protected captureCanvas: HTMLCanvasElement;
|
||||
/**
|
||||
* The HTML canvas element context.
|
||||
*/
|
||||
protected captureCanvasContext: CanvasRenderingContext2D;
|
||||
/**
|
||||
* The HTML image element, used as a fallback for the video element when decoding.
|
||||
*/
|
||||
protected imageElement: HTMLImageElement;
|
||||
/**
|
||||
* Should contain the current registered listener for image loading,
|
||||
* used to unregister that listener when needed.
|
||||
*/
|
||||
protected imageLoadedListener: EventListener;
|
||||
/**
|
||||
* The stream output from camera.
|
||||
*/
|
||||
protected stream: MediaStream;
|
||||
/**
|
||||
* The HTML video element, used to display the camera stream.
|
||||
*/
|
||||
protected videoElement: HTMLVideoElement;
|
||||
/**
|
||||
* Should contain the current registered listener for video loaded-metadata,
|
||||
* used to unregister that listener when needed.
|
||||
*/
|
||||
protected videoCanPlayListener: EventListener;
|
||||
/**
|
||||
* Should contain the current registered listener for video play-ended,
|
||||
* used to unregister that listener when needed.
|
||||
*/
|
||||
protected videoEndedListener: EventListener;
|
||||
/**
|
||||
* Should contain the current registered listener for video playing,
|
||||
* used to unregister that listener when needed.
|
||||
*/
|
||||
protected videoPlayingEventListener: EventListener;
|
||||
/**
|
||||
* Sets the hints.
|
||||
*/
|
||||
set hints(hints: Map<DecodeHintType, any>);
|
||||
/**
|
||||
* Sets the hints.
|
||||
*/
|
||||
get hints(): Map<DecodeHintType, any>;
|
||||
/**
|
||||
* Creates an instance of BrowserCodeReader.
|
||||
* @param {Reader} reader The reader instance to decode the barcode
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent successful decode tries
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
constructor(reader: Reader, timeBetweenScansMillis?: number, _hints?: Map<DecodeHintType, any>);
|
||||
/**
|
||||
* Lists all the available video input devices.
|
||||
*/
|
||||
listVideoInputDevices(): Promise<MediaDeviceInfo[]>;
|
||||
/**
|
||||
* Obtain the list of available devices with type 'videoinput'.
|
||||
*
|
||||
* @returns {Promise<VideoInputDevice[]>} an array of available video input devices
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*
|
||||
* @deprecated Use `listVideoInputDevices` instead.
|
||||
*/
|
||||
getVideoInputDevices(): Promise<VideoInputDevice[]>;
|
||||
/**
|
||||
* Let's you find a device using it's Id.
|
||||
*/
|
||||
findDeviceById(deviceId: string): Promise<MediaDeviceInfo>;
|
||||
/**
|
||||
* Decodes the barcode from the device specified by deviceId while showing the video in the specified video element.
|
||||
*
|
||||
* @param deviceId the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available.
|
||||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*
|
||||
* @deprecated Use `decodeOnceFromVideoDevice` instead.
|
||||
*/
|
||||
decodeFromInputVideoDevice(deviceId?: string, videoSource?: string | HTMLVideoElement): Promise<Result>;
|
||||
/**
|
||||
* In one attempt, tries to decode the barcode from the device specified by deviceId while showing the video in the specified video element.
|
||||
*
|
||||
* @param deviceId the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available.
|
||||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeOnceFromVideoDevice(deviceId?: string, videoSource?: string | HTMLVideoElement): Promise<Result>;
|
||||
/**
|
||||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element.
|
||||
*
|
||||
* @param constraints the media stream constraints to get s valid media stream to decode from
|
||||
* @param video the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeOnceFromConstraints(constraints: MediaStreamConstraints, videoSource?: string | HTMLVideoElement): Promise<Result>;
|
||||
/**
|
||||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element.
|
||||
*
|
||||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from
|
||||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns {Promise<Result>} The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeOnceFromStream(stream: MediaStream, videoSource?: string | HTMLVideoElement): Promise<Result>;
|
||||
/**
|
||||
* Continuously decodes the barcode from the device specified by device while showing the video in the specified video element.
|
||||
*
|
||||
* @param {string|null} [deviceId] the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available.
|
||||
* @param {string|HTMLVideoElement|null} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns {Promise<void>}
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*
|
||||
* @deprecated Use `decodeFromVideoDevice` instead.
|
||||
*/
|
||||
decodeFromInputVideoDeviceContinuously(deviceId: string | null, videoSource: string | HTMLVideoElement | null, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
/**
|
||||
* Continuously tries to decode the barcode from the device specified by device while showing the video in the specified video element.
|
||||
*
|
||||
* @param {string|null} [deviceId] the id of one of the devices obtained after calling getVideoInputDevices. Can be undefined, in this case it will decode from one of the available devices, preffering the main camera (environment facing) if available.
|
||||
* @param {string|HTMLVideoElement|null} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns {Promise<void>}
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeFromVideoDevice(deviceId: string | null, videoSource: string | HTMLVideoElement | null, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
/**
|
||||
* Continuously tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element.
|
||||
*
|
||||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from
|
||||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns {Promise<Result>} The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeFromConstraints(constraints: MediaStreamConstraints, videoSource: string | HTMLVideoElement, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
/**
|
||||
* In one attempt, tries to decode the barcode from a stream obtained from the given constraints while showing the video in the specified video element.
|
||||
*
|
||||
* @param {MediaStream} [constraints] the media stream constraints to get s valid media stream to decode from
|
||||
* @param {string|HTMLVideoElement} [video] the video element in page where to show the video while decoding. Can be either an element id or directly an HTMLVideoElement. Can be undefined, in which case no video will be shown.
|
||||
* @returns {Promise<Result>} The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeFromStream(stream: MediaStream, videoSource: string | HTMLVideoElement, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
/**
|
||||
* Breaks the decoding loop.
|
||||
*/
|
||||
stopAsyncDecode(): void;
|
||||
/**
|
||||
* Breaks the decoding loop.
|
||||
*/
|
||||
stopContinuousDecode(): void;
|
||||
/**
|
||||
* Sets the new stream and request a new decoding-with-delay.
|
||||
*
|
||||
* @param stream The stream to be shown in the video element.
|
||||
* @param decodeFn A callback for the decode method.
|
||||
*/
|
||||
protected attachStreamToVideo(stream: MediaStream, videoSource: string | HTMLVideoElement): Promise<HTMLVideoElement>;
|
||||
/**
|
||||
*
|
||||
* @param videoElement
|
||||
*/
|
||||
protected playVideoOnLoadAsync(videoElement: HTMLVideoElement): Promise<void>;
|
||||
/**
|
||||
* Binds listeners and callbacks to the videoElement.
|
||||
*
|
||||
* @param element
|
||||
* @param callbackFn
|
||||
*/
|
||||
protected playVideoOnLoad(element: HTMLVideoElement, callbackFn: EventListener): void;
|
||||
/**
|
||||
* Checks if the given video element is currently playing.
|
||||
*/
|
||||
isVideoPlaying(video: HTMLVideoElement): boolean;
|
||||
/**
|
||||
* Just tries to play the video and logs any errors.
|
||||
* The play call is only made is the video is not already playing.
|
||||
*/
|
||||
tryPlayVideo(videoElement: HTMLVideoElement): Promise<void>;
|
||||
/**
|
||||
* Searches and validates a media element.
|
||||
*/
|
||||
getMediaElement(mediaElementId: string, type: string): HTMLVisualMediaElement;
|
||||
/**
|
||||
* Decodes the barcode from an image.
|
||||
*
|
||||
* @param {(string|HTMLImageElement)} [source] The image element that can be either an element id or the element itself. Can be undefined in which case the decoding will be done from the imageUrl parameter.
|
||||
* @param {string} [url]
|
||||
* @returns {Promise<Result>} The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeFromImage(source?: string | HTMLImageElement, url?: string): Promise<Result>;
|
||||
/**
|
||||
* Decodes the barcode from a video.
|
||||
*
|
||||
* @param {(string|HTMLImageElement)} [source] The image element that can be either an element id or the element itself. Can be undefined in which case the decoding will be done from the imageUrl parameter.
|
||||
* @param {string} [url]
|
||||
* @returns {Promise<Result>} The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
decodeFromVideo(source?: string | HTMLVideoElement, url?: string): Promise<Result>;
|
||||
/**
|
||||
* Decodes continuously the barcode from a video.
|
||||
*
|
||||
* @param {(string|HTMLImageElement)} [source] The image element that can be either an element id or the element itself. Can be undefined in which case the decoding will be done from the imageUrl parameter.
|
||||
* @param {string} [url]
|
||||
* @returns {Promise<Result>} The decoding result.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
decodeFromVideoContinuously(source: string | HTMLVideoElement | null, url: string | null, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
/**
|
||||
* Decodes something from an image HTML element.
|
||||
*/
|
||||
decodeFromImageElement(source: string | HTMLImageElement): Promise<Result>;
|
||||
/**
|
||||
* Decodes something from an image HTML element.
|
||||
*/
|
||||
decodeFromVideoElement(source: string | HTMLVideoElement): Promise<Result>;
|
||||
/**
|
||||
* Decodes something from an image HTML element.
|
||||
*/
|
||||
decodeFromVideoElementContinuously(source: string | HTMLVideoElement, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
/**
|
||||
* Sets up the video source so it can be decoded when loaded.
|
||||
*
|
||||
* @param source The video source element.
|
||||
*/
|
||||
private _decodeFromVideoElementSetup;
|
||||
/**
|
||||
* Decodes an image from a URL.
|
||||
*/
|
||||
decodeFromImageUrl(url?: string): Promise<Result>;
|
||||
/**
|
||||
* Decodes an image from a URL.
|
||||
*/
|
||||
decodeFromVideoUrl(url: string): Promise<Result>;
|
||||
/**
|
||||
* Decodes an image from a URL.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
decodeFromVideoUrlContinuously(url: string, callbackFn: DecodeContinuouslyCallback): Promise<void>;
|
||||
private _decodeOnLoadImage;
|
||||
private _decodeOnLoadVideo;
|
||||
private _decodeOnLoadVideoContinuously;
|
||||
isImageLoaded(img: HTMLImageElement): boolean;
|
||||
prepareImageElement(imageSource?: HTMLImageElement | string): HTMLImageElement;
|
||||
/**
|
||||
* Sets a HTMLVideoElement for scanning or creates a new one.
|
||||
*
|
||||
* @param videoSource The HTMLVideoElement to be set.
|
||||
*/
|
||||
prepareVideoElement(videoSource?: HTMLVideoElement | string): HTMLVideoElement;
|
||||
/**
|
||||
* Tries to decode from the video input until it finds some value.
|
||||
*/
|
||||
decodeOnce(element: HTMLVisualMediaElement, retryIfNotFound?: boolean, retryIfChecksumOrFormatError?: boolean): Promise<Result>;
|
||||
/**
|
||||
* Continuously decodes from video input.
|
||||
*/
|
||||
decodeContinuously(element: HTMLVideoElement, callbackFn: DecodeContinuouslyCallback): void;
|
||||
/**
|
||||
* Gets the BinaryBitmap for ya! (and decodes it)
|
||||
*/
|
||||
decode(element: HTMLVisualMediaElement): Result;
|
||||
/**
|
||||
* Creates a binaryBitmap based in some image source.
|
||||
*
|
||||
* @param mediaElement HTML element containing drawable image source.
|
||||
*/
|
||||
createBinaryBitmap(mediaElement: HTMLVisualMediaElement): BinaryBitmap;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected getCaptureCanvasContext(mediaElement?: HTMLVisualMediaElement): CanvasRenderingContext2D;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected getCaptureCanvas(mediaElement?: HTMLVisualMediaElement): HTMLCanvasElement;
|
||||
/**
|
||||
* Overwriting this allows you to manipulate the next frame in anyway you want before decode.
|
||||
*/
|
||||
drawFrameOnCanvas(srcElement: HTMLVideoElement, dimensions?: {
|
||||
sx: number;
|
||||
sy: number;
|
||||
sWidth: number;
|
||||
sHeight: number;
|
||||
dx: number;
|
||||
dy: number;
|
||||
dWidth: number;
|
||||
dHeight: number;
|
||||
}, canvasElementContext?: CanvasRenderingContext2D): void;
|
||||
/**
|
||||
* Ovewriting this allows you to manipulate the snapshot image in anyway you want before decode.
|
||||
*/
|
||||
drawImageOnCanvas(srcElement: HTMLImageElement, dimensions?: {
|
||||
sx: number;
|
||||
sy: number;
|
||||
sWidth: number;
|
||||
sHeight: number;
|
||||
dx: number;
|
||||
dy: number;
|
||||
dWidth: number;
|
||||
dHeight: number;
|
||||
}, canvasElementContext?: CanvasRenderingContext2D): void;
|
||||
/**
|
||||
* Call the encapsulated readers decode
|
||||
*/
|
||||
decodeBitmap(binaryBitmap: BinaryBitmap): Result;
|
||||
/**
|
||||
* 🖌 Prepares the canvas for capture and scan frames.
|
||||
*/
|
||||
createCaptureCanvas(mediaElement?: HTMLVisualMediaElement): HTMLCanvasElement;
|
||||
/**
|
||||
* Stops the continuous scan and cleans the stream.
|
||||
*/
|
||||
protected stopStreams(): void;
|
||||
/**
|
||||
* Resets the code reader to the initial state. Cancels any ongoing barcode scanning from video or camera.
|
||||
*
|
||||
* @memberOf BrowserCodeReader
|
||||
*/
|
||||
reset(): void;
|
||||
private _destroyVideoElement;
|
||||
private _destroyImageElement;
|
||||
/**
|
||||
* Cleans canvas references 🖌
|
||||
*/
|
||||
private _destroyCaptureCanvas;
|
||||
/**
|
||||
* Defines what the videoElement src will be.
|
||||
*
|
||||
* @param videoElement
|
||||
* @param stream
|
||||
*/
|
||||
addVideoSource(videoElement: HTMLVideoElement, stream: MediaStream): void;
|
||||
/**
|
||||
* Unbinds a HTML video src property.
|
||||
*
|
||||
* @param videoElement
|
||||
*/
|
||||
private cleanVideoSource;
|
||||
}
|
||||
+1077
File diff suppressed because it is too large
Load Diff
+13
@@ -0,0 +1,13 @@
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* QR Code reader to use from browser.
|
||||
*/
|
||||
export declare class BrowserDatamatrixCodeReader extends BrowserCodeReader {
|
||||
/**
|
||||
* Creates an instance of BrowserQRCodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*/
|
||||
constructor(timeBetweenScansMillis?: number);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import DataMatrixReader from '../core/datamatrix/DataMatrixReader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* QR Code reader to use from browser.
|
||||
*/
|
||||
var BrowserDatamatrixCodeReader = /** @class */ (function (_super) {
|
||||
__extends(BrowserDatamatrixCodeReader, _super);
|
||||
/**
|
||||
* Creates an instance of BrowserQRCodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*/
|
||||
function BrowserDatamatrixCodeReader(timeBetweenScansMillis) {
|
||||
if (timeBetweenScansMillis === void 0) { timeBetweenScansMillis = 500; }
|
||||
return _super.call(this, new DataMatrixReader(), timeBetweenScansMillis) || this;
|
||||
}
|
||||
return BrowserDatamatrixCodeReader;
|
||||
}(BrowserCodeReader));
|
||||
export { BrowserDatamatrixCodeReader };
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import MultiFormatReader from '../core/MultiFormatReader';
|
||||
import BinaryBitmap from '../core/BinaryBitmap';
|
||||
import Result from '../core/Result';
|
||||
import DecodeHintType from '../core/DecodeHintType';
|
||||
export declare class BrowserMultiFormatReader extends BrowserCodeReader {
|
||||
protected readonly reader: MultiFormatReader;
|
||||
constructor(hints?: Map<DecodeHintType, any>, timeBetweenScansMillis?: number);
|
||||
/**
|
||||
* Overwrite decodeBitmap to call decodeWithState, which will pay
|
||||
* attention to the hints set in the constructor function
|
||||
*/
|
||||
decodeBitmap(binaryBitmap: BinaryBitmap): Result;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import MultiFormatReader from '../core/MultiFormatReader';
|
||||
var BrowserMultiFormatReader = /** @class */ (function (_super) {
|
||||
__extends(BrowserMultiFormatReader, _super);
|
||||
function BrowserMultiFormatReader(hints, timeBetweenScansMillis) {
|
||||
if (hints === void 0) { hints = null; }
|
||||
if (timeBetweenScansMillis === void 0) { timeBetweenScansMillis = 500; }
|
||||
var _this = this;
|
||||
var reader = new MultiFormatReader();
|
||||
reader.setHints(hints);
|
||||
_this = _super.call(this, reader, timeBetweenScansMillis) || this;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* Overwrite decodeBitmap to call decodeWithState, which will pay
|
||||
* attention to the hints set in the constructor function
|
||||
*/
|
||||
BrowserMultiFormatReader.prototype.decodeBitmap = function (binaryBitmap) {
|
||||
return this.reader.decodeWithState(binaryBitmap);
|
||||
};
|
||||
return BrowserMultiFormatReader;
|
||||
}(BrowserCodeReader));
|
||||
export { BrowserMultiFormatReader };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* QR Code reader to use from browser.
|
||||
*/
|
||||
export declare class BrowserPDF417Reader extends BrowserCodeReader {
|
||||
/**
|
||||
* Creates an instance of BrowserPDF417Reader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*/
|
||||
constructor(timeBetweenScansMillis?: number);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import PDF417Reader from '../core/pdf417/PDF417Reader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* QR Code reader to use from browser.
|
||||
*/
|
||||
var BrowserPDF417Reader = /** @class */ (function (_super) {
|
||||
__extends(BrowserPDF417Reader, _super);
|
||||
/**
|
||||
* Creates an instance of BrowserPDF417Reader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*/
|
||||
function BrowserPDF417Reader(timeBetweenScansMillis) {
|
||||
if (timeBetweenScansMillis === void 0) { timeBetweenScansMillis = 500; }
|
||||
return _super.call(this, new PDF417Reader(), timeBetweenScansMillis) || this;
|
||||
}
|
||||
return BrowserPDF417Reader;
|
||||
}(BrowserCodeReader));
|
||||
export { BrowserPDF417Reader };
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* QR Code reader to use from browser.
|
||||
*/
|
||||
export declare class BrowserQRCodeReader extends BrowserCodeReader {
|
||||
/**
|
||||
* Creates an instance of BrowserQRCodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*/
|
||||
constructor(timeBetweenScansMillis?: number);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import { BrowserCodeReader } from './BrowserCodeReader';
|
||||
import QRCodeReader from '../core/qrcode/QRCodeReader';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* QR Code reader to use from browser.
|
||||
*/
|
||||
var BrowserQRCodeReader = /** @class */ (function (_super) {
|
||||
__extends(BrowserQRCodeReader, _super);
|
||||
/**
|
||||
* Creates an instance of BrowserQRCodeReader.
|
||||
* @param {number} [timeBetweenScansMillis=500] the time delay between subsequent decode tries
|
||||
*/
|
||||
function BrowserQRCodeReader(timeBetweenScansMillis) {
|
||||
if (timeBetweenScansMillis === void 0) { timeBetweenScansMillis = 500; }
|
||||
return _super.call(this, new QRCodeReader(), timeBetweenScansMillis) || this;
|
||||
}
|
||||
return BrowserQRCodeReader;
|
||||
}(BrowserCodeReader));
|
||||
export { BrowserQRCodeReader };
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
import EncodeHintType from '../core/EncodeHintType';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*/
|
||||
declare class BrowserQRCodeSvgWriter {
|
||||
private static readonly QUIET_ZONE_SIZE;
|
||||
/**
|
||||
* SVG markup NameSpace
|
||||
*/
|
||||
private static readonly SVG_NS;
|
||||
/**
|
||||
* Writes and renders a QRCode SVG element.
|
||||
*
|
||||
* @param contents
|
||||
* @param width
|
||||
* @param height
|
||||
* @param hints
|
||||
*/
|
||||
write(contents: string, width: number, height: number, hints?: Map<EncodeHintType, any>): SVGSVGElement;
|
||||
/**
|
||||
* Renders the result and then appends it to the DOM.
|
||||
*/
|
||||
writeToDom(containerElement: string | HTMLElement, contents: string, width: number, height: number, hints?: Map<EncodeHintType, any>): void;
|
||||
/**
|
||||
* Note that the input matrix uses 0 == white, 1 == black.
|
||||
* The output matrix uses 0 == black, 255 == white (i.e. an 8 bit greyscale bitmap).
|
||||
*/
|
||||
private renderResult;
|
||||
/**
|
||||
* Creates a SVG element.
|
||||
*
|
||||
* @param w SVG's width attribute
|
||||
* @param h SVG's height attribute
|
||||
*/
|
||||
private createSVGElement;
|
||||
/**
|
||||
* Creates a SVG rect element.
|
||||
*
|
||||
* @param x Element's x coordinate
|
||||
* @param y Element's y coordinate
|
||||
* @param w Element's width attribute
|
||||
* @param h Element's height attribute
|
||||
*/
|
||||
private createSvgRectElement;
|
||||
}
|
||||
export { BrowserQRCodeSvgWriter };
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
import EncodeHintType from '../core/EncodeHintType';
|
||||
import Encoder from '../core/qrcode/encoder/Encoder';
|
||||
import ErrorCorrectionLevel from '../core/qrcode/decoder/ErrorCorrectionLevel';
|
||||
import IllegalArgumentException from '../core/IllegalArgumentException';
|
||||
import IllegalStateException from '../core/IllegalStateException';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*/
|
||||
var BrowserQRCodeSvgWriter = /** @class */ (function () {
|
||||
function BrowserQRCodeSvgWriter() {
|
||||
}
|
||||
/**
|
||||
* Writes and renders a QRCode SVG element.
|
||||
*
|
||||
* @param contents
|
||||
* @param width
|
||||
* @param height
|
||||
* @param hints
|
||||
*/
|
||||
BrowserQRCodeSvgWriter.prototype.write = function (contents, width, height, hints) {
|
||||
if (hints === void 0) { hints = null; }
|
||||
if (contents.length === 0) {
|
||||
throw new IllegalArgumentException('Found empty contents');
|
||||
}
|
||||
// if (format != BarcodeFormat.QR_CODE) {
|
||||
// throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format)
|
||||
// }
|
||||
if (width < 0 || height < 0) {
|
||||
throw new IllegalArgumentException('Requested dimensions are too small: ' + width + 'x' + height);
|
||||
}
|
||||
var errorCorrectionLevel = ErrorCorrectionLevel.L;
|
||||
var quietZone = BrowserQRCodeSvgWriter.QUIET_ZONE_SIZE;
|
||||
if (hints !== null) {
|
||||
if (undefined !== hints.get(EncodeHintType.ERROR_CORRECTION)) {
|
||||
errorCorrectionLevel = ErrorCorrectionLevel.fromString(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
|
||||
}
|
||||
if (undefined !== hints.get(EncodeHintType.MARGIN)) {
|
||||
quietZone = Number.parseInt(hints.get(EncodeHintType.MARGIN).toString(), 10);
|
||||
}
|
||||
}
|
||||
var code = Encoder.encode(contents, errorCorrectionLevel, hints);
|
||||
return this.renderResult(code, width, height, quietZone);
|
||||
};
|
||||
/**
|
||||
* Renders the result and then appends it to the DOM.
|
||||
*/
|
||||
BrowserQRCodeSvgWriter.prototype.writeToDom = function (containerElement, contents, width, height, hints) {
|
||||
if (hints === void 0) { hints = null; }
|
||||
if (typeof containerElement === 'string') {
|
||||
containerElement = document.querySelector(containerElement);
|
||||
}
|
||||
var svgElement = this.write(contents, width, height, hints);
|
||||
if (containerElement)
|
||||
containerElement.appendChild(svgElement);
|
||||
};
|
||||
/**
|
||||
* Note that the input matrix uses 0 == white, 1 == black.
|
||||
* The output matrix uses 0 == black, 255 == white (i.e. an 8 bit greyscale bitmap).
|
||||
*/
|
||||
BrowserQRCodeSvgWriter.prototype.renderResult = function (code, width /*int*/, height /*int*/, quietZone /*int*/) {
|
||||
var input = code.getMatrix();
|
||||
if (input === null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
var inputWidth = input.getWidth();
|
||||
var inputHeight = input.getHeight();
|
||||
var qrWidth = inputWidth + (quietZone * 2);
|
||||
var qrHeight = inputHeight + (quietZone * 2);
|
||||
var outputWidth = Math.max(width, qrWidth);
|
||||
var outputHeight = Math.max(height, qrHeight);
|
||||
var multiple = Math.min(Math.floor(outputWidth / qrWidth), Math.floor(outputHeight / qrHeight));
|
||||
// Padding includes both the quiet zone and the extra white pixels to accommodate the requested
|
||||
// dimensions. For example, if input is 25x25 the QR will be 33x33 including the quiet zone.
|
||||
// If the requested size is 200x160, the multiple will be 4, for a QR of 132x132. These will
|
||||
// handle all the padding from 100x100 (the actual QR) up to 200x160.
|
||||
var leftPadding = Math.floor((outputWidth - (inputWidth * multiple)) / 2);
|
||||
var topPadding = Math.floor((outputHeight - (inputHeight * multiple)) / 2);
|
||||
var svgElement = this.createSVGElement(outputWidth, outputHeight);
|
||||
for (var inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
|
||||
// Write the contents of this row of the barcode
|
||||
for (var inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
|
||||
if (input.get(inputX, inputY) === 1) {
|
||||
var svgRectElement = this.createSvgRectElement(outputX, outputY, multiple, multiple);
|
||||
svgElement.appendChild(svgRectElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return svgElement;
|
||||
};
|
||||
/**
|
||||
* Creates a SVG element.
|
||||
*
|
||||
* @param w SVG's width attribute
|
||||
* @param h SVG's height attribute
|
||||
*/
|
||||
BrowserQRCodeSvgWriter.prototype.createSVGElement = function (w, h) {
|
||||
var svgElement = document.createElementNS(BrowserQRCodeSvgWriter.SVG_NS, 'svg');
|
||||
svgElement.setAttributeNS(null, 'height', w.toString());
|
||||
svgElement.setAttributeNS(null, 'width', h.toString());
|
||||
return svgElement;
|
||||
};
|
||||
/**
|
||||
* Creates a SVG rect element.
|
||||
*
|
||||
* @param x Element's x coordinate
|
||||
* @param y Element's y coordinate
|
||||
* @param w Element's width attribute
|
||||
* @param h Element's height attribute
|
||||
*/
|
||||
BrowserQRCodeSvgWriter.prototype.createSvgRectElement = function (x, y, w, h) {
|
||||
var rect = document.createElementNS(BrowserQRCodeSvgWriter.SVG_NS, 'rect');
|
||||
rect.setAttributeNS(null, 'x', x.toString());
|
||||
rect.setAttributeNS(null, 'y', y.toString());
|
||||
rect.setAttributeNS(null, 'height', w.toString());
|
||||
rect.setAttributeNS(null, 'width', h.toString());
|
||||
rect.setAttributeNS(null, 'fill', '#000000');
|
||||
return rect;
|
||||
};
|
||||
BrowserQRCodeSvgWriter.QUIET_ZONE_SIZE = 4;
|
||||
/**
|
||||
* SVG markup NameSpace
|
||||
*/
|
||||
BrowserQRCodeSvgWriter.SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
return BrowserQRCodeSvgWriter;
|
||||
}());
|
||||
export { BrowserQRCodeSvgWriter };
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import EncodeHintType from '../core/EncodeHintType';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*/
|
||||
declare abstract class BrowserSvgCodeWriter {
|
||||
/**
|
||||
* Default quiet zone in pixels.
|
||||
*/
|
||||
private static readonly QUIET_ZONE_SIZE;
|
||||
/**
|
||||
* SVG markup NameSpace
|
||||
*/
|
||||
private static readonly SVG_NS;
|
||||
/**
|
||||
* A HTML container element for the image.
|
||||
*/
|
||||
private containerElement;
|
||||
/**
|
||||
* Constructs. 😉
|
||||
*/
|
||||
constructor(containerElement: string | HTMLElement);
|
||||
/**
|
||||
* Writes the QR code to a SVG and renders it in the container.
|
||||
*/
|
||||
write(contents: string, width: number, height: number, hints?: Map<EncodeHintType, any>): SVGSVGElement;
|
||||
/**
|
||||
* Encodes the content to a Barcode type.
|
||||
*/
|
||||
private encode;
|
||||
/**
|
||||
* Renders the SVG in the container.
|
||||
*
|
||||
* @note the input matrix uses 0 == white, 1 == black. The output matrix uses 0 == black, 255 == white (i.e. an 8 bit greyscale bitmap).
|
||||
*/
|
||||
private renderResult;
|
||||
/**
|
||||
* Creates a SVG element.
|
||||
*/
|
||||
protected createSVGElement(w: number, h: number): SVGSVGElement;
|
||||
/**
|
||||
* Creates a SVG rect.
|
||||
*/
|
||||
protected createSvgPathPlaceholderElement(w: number, h: number): SVGPathElement;
|
||||
/**
|
||||
* Creates a SVG rect.
|
||||
*/
|
||||
protected createSvgRectElement(x: number, y: number, w: number, h: number): SVGRectElement;
|
||||
}
|
||||
export { BrowserSvgCodeWriter };
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
import EncodeHintType from '../core/EncodeHintType';
|
||||
import Encoder from '../core/qrcode/encoder/Encoder';
|
||||
import ErrorCorrectionLevel from '../core/qrcode/decoder/ErrorCorrectionLevel';
|
||||
import IllegalArgumentException from '../core/IllegalArgumentException';
|
||||
import IllegalStateException from '../core/IllegalStateException';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*/
|
||||
var BrowserSvgCodeWriter = /** @class */ (function () {
|
||||
/**
|
||||
* Constructs. 😉
|
||||
*/
|
||||
function BrowserSvgCodeWriter(containerElement) {
|
||||
if (typeof containerElement === 'string') {
|
||||
this.containerElement = document.getElementById(containerElement);
|
||||
}
|
||||
else {
|
||||
this.containerElement = containerElement;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Writes the QR code to a SVG and renders it in the container.
|
||||
*/
|
||||
BrowserSvgCodeWriter.prototype.write = function (contents, width, height, hints) {
|
||||
if (hints === void 0) { hints = null; }
|
||||
if (contents.length === 0) {
|
||||
throw new IllegalArgumentException('Found empty contents');
|
||||
}
|
||||
if (width < 0 || height < 0) {
|
||||
throw new IllegalArgumentException('Requested dimensions are too small: ' + width + 'x' + height);
|
||||
}
|
||||
var quietZone = hints && hints.get(EncodeHintType.MARGIN) !== undefined
|
||||
? Number.parseInt(hints.get(EncodeHintType.MARGIN).toString(), 10)
|
||||
: BrowserSvgCodeWriter.QUIET_ZONE_SIZE;
|
||||
var code = this.encode(hints, contents);
|
||||
return this.renderResult(code, width, height, quietZone);
|
||||
};
|
||||
/**
|
||||
* Encodes the content to a Barcode type.
|
||||
*/
|
||||
BrowserSvgCodeWriter.prototype.encode = function (hints, contents) {
|
||||
var errorCorrectionLevel = ErrorCorrectionLevel.L;
|
||||
if (hints && hints.get(EncodeHintType.ERROR_CORRECTION) !== undefined) {
|
||||
errorCorrectionLevel = ErrorCorrectionLevel.fromString(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
|
||||
}
|
||||
var code = Encoder.encode(contents, errorCorrectionLevel, hints);
|
||||
return code;
|
||||
};
|
||||
/**
|
||||
* Renders the SVG in the container.
|
||||
*
|
||||
* @note the input matrix uses 0 == white, 1 == black. The output matrix uses 0 == black, 255 == white (i.e. an 8 bit greyscale bitmap).
|
||||
*/
|
||||
BrowserSvgCodeWriter.prototype.renderResult = function (code, width /*int*/, height /*int*/, quietZone /*int*/) {
|
||||
// if (this.format && format != this.format) {
|
||||
// throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format)
|
||||
// }
|
||||
var input = code.getMatrix();
|
||||
if (input === null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
var inputWidth = input.getWidth();
|
||||
var inputHeight = input.getHeight();
|
||||
var qrWidth = inputWidth + (quietZone * 2);
|
||||
var qrHeight = inputHeight + (quietZone * 2);
|
||||
var outputWidth = Math.max(width, qrWidth);
|
||||
var outputHeight = Math.max(height, qrHeight);
|
||||
var multiple = Math.min(Math.floor(outputWidth / qrWidth), Math.floor(outputHeight / qrHeight));
|
||||
// Padding includes both the quiet zone and the extra white pixels to accommodate the requested
|
||||
// dimensions. For example, if input is 25x25 the QR will be 33x33 including the quiet zone.
|
||||
// If the requested size is 200x160, the multiple will be 4, for a QR of 132x132. These will
|
||||
// handle all the padding from 100x100 (the actual QR) up to 200x160.
|
||||
var leftPadding = Math.floor((outputWidth - (inputWidth * multiple)) / 2);
|
||||
var topPadding = Math.floor((outputHeight - (inputHeight * multiple)) / 2);
|
||||
var svgElement = this.createSVGElement(outputWidth, outputHeight);
|
||||
var placeholder = this.createSvgPathPlaceholderElement(width, height);
|
||||
svgElement.append(placeholder);
|
||||
this.containerElement.appendChild(svgElement);
|
||||
// 2D loop
|
||||
for (var inputY = 0, outputY = topPadding; inputY < inputHeight; inputY++, outputY += multiple) {
|
||||
// Write the contents of this row of the barcode
|
||||
for (var inputX = 0, outputX = leftPadding; inputX < inputWidth; inputX++, outputX += multiple) {
|
||||
if (input.get(inputX, inputY) === 1) {
|
||||
var svgRectElement = this.createSvgRectElement(outputX, outputY, multiple, multiple);
|
||||
svgElement.appendChild(svgRectElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
return svgElement;
|
||||
};
|
||||
/**
|
||||
* Creates a SVG element.
|
||||
*/
|
||||
BrowserSvgCodeWriter.prototype.createSVGElement = function (w, h) {
|
||||
var el = document.createElementNS(BrowserSvgCodeWriter.SVG_NS, 'svg');
|
||||
el.setAttributeNS(null, 'width', h.toString());
|
||||
el.setAttributeNS(null, 'height', w.toString());
|
||||
return el;
|
||||
};
|
||||
/**
|
||||
* Creates a SVG rect.
|
||||
*/
|
||||
BrowserSvgCodeWriter.prototype.createSvgPathPlaceholderElement = function (w, h) {
|
||||
var el = document.createElementNS(BrowserSvgCodeWriter.SVG_NS, 'path');
|
||||
el.setAttributeNS(null, 'd', "M0 0h" + w + "v" + h + "H0z");
|
||||
el.setAttributeNS(null, 'fill', 'none');
|
||||
return el;
|
||||
};
|
||||
/**
|
||||
* Creates a SVG rect.
|
||||
*/
|
||||
BrowserSvgCodeWriter.prototype.createSvgRectElement = function (x, y, w, h) {
|
||||
var el = document.createElementNS(BrowserSvgCodeWriter.SVG_NS, 'rect');
|
||||
el.setAttributeNS(null, 'x', x.toString());
|
||||
el.setAttributeNS(null, 'y', y.toString());
|
||||
el.setAttributeNS(null, 'height', w.toString());
|
||||
el.setAttributeNS(null, 'width', h.toString());
|
||||
el.setAttributeNS(null, 'fill', '#000000');
|
||||
return el;
|
||||
};
|
||||
/**
|
||||
* Default quiet zone in pixels.
|
||||
*/
|
||||
BrowserSvgCodeWriter.QUIET_ZONE_SIZE = 4;
|
||||
/**
|
||||
* SVG markup NameSpace
|
||||
*/
|
||||
BrowserSvgCodeWriter.SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
return BrowserSvgCodeWriter;
|
||||
}());
|
||||
export { BrowserSvgCodeWriter };
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import Exception from '../core/Exception';
|
||||
import Result from '../core/Result';
|
||||
/**
|
||||
* Callback format for continuous decode scan.
|
||||
*/
|
||||
export declare type DecodeContinuouslyCallback = (result: Result, error?: Exception) => any;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import LuminanceSource from '../core/LuminanceSource';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*/
|
||||
export declare class HTMLCanvasElementLuminanceSource extends LuminanceSource {
|
||||
private canvas;
|
||||
private buffer;
|
||||
private static DEGREE_TO_RADIANS;
|
||||
private static FRAME_INDEX;
|
||||
private tempCanvasElement;
|
||||
constructor(canvas: HTMLCanvasElement, doAutoInvert?: boolean);
|
||||
private static makeBufferFromCanvasImageData;
|
||||
private static toGrayscaleBuffer;
|
||||
getRow(y: number, row: Uint8ClampedArray): Uint8ClampedArray;
|
||||
getMatrix(): Uint8ClampedArray;
|
||||
isCropSupported(): boolean;
|
||||
crop(left: number, top: number, width: number, height: number): LuminanceSource;
|
||||
/**
|
||||
* This is always true, since the image is a gray-scale image.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
isRotateSupported(): boolean;
|
||||
rotateCounterClockwise(): LuminanceSource;
|
||||
rotateCounterClockwise45(): LuminanceSource;
|
||||
private getTempCanvasElement;
|
||||
private rotate;
|
||||
invert(): LuminanceSource;
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
import InvertedLuminanceSource from '../core/InvertedLuminanceSource';
|
||||
import LuminanceSource from '../core/LuminanceSource';
|
||||
import IllegalArgumentException from '../core/IllegalArgumentException';
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*/
|
||||
var HTMLCanvasElementLuminanceSource = /** @class */ (function (_super) {
|
||||
__extends(HTMLCanvasElementLuminanceSource, _super);
|
||||
function HTMLCanvasElementLuminanceSource(canvas, doAutoInvert) {
|
||||
if (doAutoInvert === void 0) { doAutoInvert = false; }
|
||||
var _this = _super.call(this, canvas.width, canvas.height) || this;
|
||||
_this.canvas = canvas;
|
||||
_this.tempCanvasElement = null;
|
||||
_this.buffer = HTMLCanvasElementLuminanceSource.makeBufferFromCanvasImageData(canvas, doAutoInvert);
|
||||
return _this;
|
||||
}
|
||||
HTMLCanvasElementLuminanceSource.makeBufferFromCanvasImageData = function (canvas, doAutoInvert) {
|
||||
if (doAutoInvert === void 0) { doAutoInvert = false; }
|
||||
var imageData = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
|
||||
return HTMLCanvasElementLuminanceSource.toGrayscaleBuffer(imageData.data, canvas.width, canvas.height, doAutoInvert);
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.toGrayscaleBuffer = function (imageBuffer, width, height, doAutoInvert) {
|
||||
if (doAutoInvert === void 0) { doAutoInvert = false; }
|
||||
var grayscaleBuffer = new Uint8ClampedArray(width * height);
|
||||
HTMLCanvasElementLuminanceSource.FRAME_INDEX = !HTMLCanvasElementLuminanceSource.FRAME_INDEX;
|
||||
if (HTMLCanvasElementLuminanceSource.FRAME_INDEX || !doAutoInvert) {
|
||||
for (var i = 0, j = 0, length_1 = imageBuffer.length; i < length_1; i += 4, j++) {
|
||||
var gray = void 0;
|
||||
var alpha = imageBuffer[i + 3];
|
||||
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||
// barcode image. Force any such pixel to be white:
|
||||
if (alpha === 0) {
|
||||
gray = 0xFF;
|
||||
}
|
||||
else {
|
||||
var pixelR = imageBuffer[i];
|
||||
var pixelG = imageBuffer[i + 1];
|
||||
var pixelB = imageBuffer[i + 2];
|
||||
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
||||
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
||||
// 0x200 >> 10 is 0.5, it implements rounding.
|
||||
gray = (306 * pixelR +
|
||||
601 * pixelG +
|
||||
117 * pixelB +
|
||||
0x200) >> 10;
|
||||
}
|
||||
grayscaleBuffer[j] = gray;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var i = 0, j = 0, length_2 = imageBuffer.length; i < length_2; i += 4, j++) {
|
||||
var gray = void 0;
|
||||
var alpha = imageBuffer[i + 3];
|
||||
// The color of fully-transparent pixels is irrelevant. They are often, technically, fully-transparent
|
||||
// black (0 alpha, and then 0 RGB). They are often used, of course as the "white" area in a
|
||||
// barcode image. Force any such pixel to be white:
|
||||
if (alpha === 0) {
|
||||
gray = 0xFF;
|
||||
}
|
||||
else {
|
||||
var pixelR = imageBuffer[i];
|
||||
var pixelG = imageBuffer[i + 1];
|
||||
var pixelB = imageBuffer[i + 2];
|
||||
// .299R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC),
|
||||
// (306*R) >> 10 is approximately equal to R*0.299, and so on.
|
||||
// 0x200 >> 10 is 0.5, it implements rounding.
|
||||
gray = (306 * pixelR +
|
||||
601 * pixelG +
|
||||
117 * pixelB +
|
||||
0x200) >> 10;
|
||||
}
|
||||
grayscaleBuffer[j] = 0xFF - gray;
|
||||
}
|
||||
}
|
||||
return grayscaleBuffer;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.getRow = function (y /*int*/, row) {
|
||||
if (y < 0 || y >= this.getHeight()) {
|
||||
throw new IllegalArgumentException('Requested row is outside the image: ' + y);
|
||||
}
|
||||
var width = this.getWidth();
|
||||
var start = y * width;
|
||||
if (row === null) {
|
||||
row = this.buffer.slice(start, start + width);
|
||||
}
|
||||
else {
|
||||
if (row.length < width) {
|
||||
row = new Uint8ClampedArray(width);
|
||||
}
|
||||
// The underlying raster of image consists of bytes with the luminance values
|
||||
// TODO: can avoid set/slice?
|
||||
row.set(this.buffer.slice(start, start + width));
|
||||
}
|
||||
return row;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.getMatrix = function () {
|
||||
return this.buffer;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.isCropSupported = function () {
|
||||
return true;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.crop = function (left /*int*/, top /*int*/, width /*int*/, height /*int*/) {
|
||||
_super.prototype.crop.call(this, left, top, width, height);
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* This is always true, since the image is a gray-scale image.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
HTMLCanvasElementLuminanceSource.prototype.isRotateSupported = function () {
|
||||
return true;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.rotateCounterClockwise = function () {
|
||||
this.rotate(-90);
|
||||
return this;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.rotateCounterClockwise45 = function () {
|
||||
this.rotate(-45);
|
||||
return this;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.getTempCanvasElement = function () {
|
||||
if (null === this.tempCanvasElement) {
|
||||
var tempCanvasElement = this.canvas.ownerDocument.createElement('canvas');
|
||||
tempCanvasElement.width = this.canvas.width;
|
||||
tempCanvasElement.height = this.canvas.height;
|
||||
this.tempCanvasElement = tempCanvasElement;
|
||||
}
|
||||
return this.tempCanvasElement;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.rotate = function (angle) {
|
||||
var tempCanvasElement = this.getTempCanvasElement();
|
||||
var tempContext = tempCanvasElement.getContext('2d');
|
||||
var angleRadians = angle * HTMLCanvasElementLuminanceSource.DEGREE_TO_RADIANS;
|
||||
// Calculate and set new dimensions for temp canvas
|
||||
var width = this.canvas.width;
|
||||
var height = this.canvas.height;
|
||||
var newWidth = Math.ceil(Math.abs(Math.cos(angleRadians)) * width + Math.abs(Math.sin(angleRadians)) * height);
|
||||
var newHeight = Math.ceil(Math.abs(Math.sin(angleRadians)) * width + Math.abs(Math.cos(angleRadians)) * height);
|
||||
tempCanvasElement.width = newWidth;
|
||||
tempCanvasElement.height = newHeight;
|
||||
// Draw at center of temp canvas to prevent clipping of image data
|
||||
tempContext.translate(newWidth / 2, newHeight / 2);
|
||||
tempContext.rotate(angleRadians);
|
||||
tempContext.drawImage(this.canvas, width / -2, height / -2);
|
||||
this.buffer = HTMLCanvasElementLuminanceSource.makeBufferFromCanvasImageData(tempCanvasElement);
|
||||
return this;
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.prototype.invert = function () {
|
||||
return new InvertedLuminanceSource(this);
|
||||
};
|
||||
HTMLCanvasElementLuminanceSource.DEGREE_TO_RADIANS = Math.PI / 180;
|
||||
HTMLCanvasElementLuminanceSource.FRAME_INDEX = true;
|
||||
return HTMLCanvasElementLuminanceSource;
|
||||
}(LuminanceSource));
|
||||
export { HTMLCanvasElementLuminanceSource };
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* HTML elements that can be decoded.
|
||||
*/
|
||||
export declare type HTMLVisualMediaElement = HTMLVideoElement | HTMLImageElement;
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* Video input device metadata containing the id and label of the device if available.
|
||||
*/
|
||||
export declare class VideoInputDevice implements MediaDeviceInfo {
|
||||
deviceId: string;
|
||||
label: string;
|
||||
/** @inheritdoc */
|
||||
readonly kind = "videoinput";
|
||||
/** @inheritdoc */
|
||||
readonly groupId: string;
|
||||
/**
|
||||
* Creates an instance of VideoInputDevice.
|
||||
*
|
||||
* @param {string} deviceId the video input device id
|
||||
* @param {string} label the label of the device if available
|
||||
*/
|
||||
constructor(deviceId: string, label: string, groupId?: string);
|
||||
/** @inheritdoc */
|
||||
toJSON(): {
|
||||
kind: string;
|
||||
groupId: string;
|
||||
deviceId: string;
|
||||
label: string;
|
||||
};
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @deprecated Moving to @zxing/browser
|
||||
*
|
||||
* Video input device metadata containing the id and label of the device if available.
|
||||
*/
|
||||
var VideoInputDevice = /** @class */ (function () {
|
||||
/**
|
||||
* Creates an instance of VideoInputDevice.
|
||||
*
|
||||
* @param {string} deviceId the video input device id
|
||||
* @param {string} label the label of the device if available
|
||||
*/
|
||||
function VideoInputDevice(deviceId, label, groupId) {
|
||||
this.deviceId = deviceId;
|
||||
this.label = label;
|
||||
/** @inheritdoc */
|
||||
this.kind = 'videoinput';
|
||||
this.groupId = groupId || undefined;
|
||||
}
|
||||
/** @inheritdoc */
|
||||
VideoInputDevice.prototype.toJSON = function () {
|
||||
return {
|
||||
kind: this.kind,
|
||||
groupId: this.groupId,
|
||||
deviceId: this.deviceId,
|
||||
label: this.label,
|
||||
};
|
||||
};
|
||||
return VideoInputDevice;
|
||||
}());
|
||||
export { VideoInputDevice };
|
||||
Reference in New Issue
Block a user