define(['exports', 'aurelia-framework', './quagga.min'], function (exports, _aureliaFramework, _quagga) {
    'use strict';

    exports.__esModule = true;
    exports.PragmaBarcodeScanner = undefined;

    var Quagga = _interopRequireWildcard(_quagga);

    function _interopRequireWildcard(obj) {
        if (obj && obj.__esModule) {
            return obj;
        } else {
            var newObj = {};

            if (obj != null) {
                for (var key in obj) {
                    if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];
                }
            }

            newObj.default = obj;
            return newObj;
        }
    }

    function _initDefineProp(target, property, descriptor, context) {
        if (!descriptor) return;
        Object.defineProperty(target, property, {
            enumerable: descriptor.enumerable,
            configurable: descriptor.configurable,
            writable: descriptor.writable,
            value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
        });
    }

    function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
        var desc = {};
        Object['ke' + 'ys'](descriptor).forEach(function (key) {
            desc[key] = descriptor[key];
        });
        desc.enumerable = !!desc.enumerable;
        desc.configurable = !!desc.configurable;

        if ('value' in desc || desc.initializer) {
            desc.writable = true;
        }

        desc = decorators.slice().reverse().reduce(function (desc, decorator) {
            return decorator(target, property, desc) || desc;
        }, desc);

        if (context && desc.initializer !== void 0) {
            desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
            desc.initializer = undefined;
        }

        if (desc.initializer === void 0) {
            Object['define' + 'Property'](target, property, desc);
            desc = null;
        }

        return desc;
    }

    function _initializerWarningHelper(descriptor, context) {
        throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
    }

    var _dec, _dec2, _class, _desc, _value, _class2, _descriptor;

    let PragmaBarcodeScanner = exports.PragmaBarcodeScanner = (_dec = (0, _aureliaFramework.customElement)('pragma-barcode-scanner'), _dec2 = (0, _aureliaFramework.inject)(Element), _dec(_class = _dec2(_class = (_class2 = class PragmaBarcodeScanner {

        constructor(element) {
            _initDefineProp(this, 'code', _descriptor, this);

            this.element = element;
        }

        attached() {
            this.detectedHandler = this.detected.bind(this);
        }

        detached() {
            this.stop();
        }

        start() {
            Quagga.init({
                inputStream: {
                    name: "Live",
                    type: "LiveStream",
                    target: this.viewport },
                decoder: {
                    readers: ["ean_reader"]
                }
            }, function (err) {
                if (err) {
                    console.log(err);
                    return;
                }
                console.log("Initialization finished. Ready to start");
                Quagga.start();
            });

            Quagga.onDetected(this.detectedHandler);
        }

        stop() {
            Quagga.stop();
        }

        detected(result) {
            this.code = result.codeResult.code;

            console.log(this.code);
            this.stop();
        }
    }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, 'code', [_aureliaFramework.bindable], {
        enumerable: true,
        initializer: null
    })), _class2)) || _class) || _class);
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInByYWdtYS1iYXJjb2RlLXNjYW5uZXIuanMiXSwibmFtZXMiOlsiUXVhZ2dhIiwiUHJhZ21hQmFyY29kZVNjYW5uZXIiLCJFbGVtZW50IiwiY29uc3RydWN0b3IiLCJlbGVtZW50IiwiYXR0YWNoZWQiLCJkZXRlY3RlZEhhbmRsZXIiLCJkZXRlY3RlZCIsImJpbmQiLCJkZXRhY2hlZCIsInN0b3AiLCJzdGFydCIsImluaXQiLCJpbnB1dFN0cmVhbSIsIm5hbWUiLCJ0eXBlIiwidGFyZ2V0Iiwidmlld3BvcnQiLCJkZWNvZGVyIiwicmVhZGVycyIsImVyciIsImNvbnNvbGUiLCJsb2ciLCJvbkRldGVjdGVkIiwicmVzdWx0IiwiY29kZSIsImNvZGVSZXN1bHQiXSwibWFwcGluZ3MiOiI7Ozs7OztRQUNZQSxNOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O1FBSUNDLG9CLFdBQUFBLG9CLFdBRloscUNBQWMsd0JBQWQsQyxVQUNBLDhCQUFPQyxPQUFQLEMsMENBQ00sTUFBTUQsb0JBQU4sQ0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GRlY29kZXIgOiB7XHJcbiAgICAgICAgICAgICAgICByZWFkZXJzIDogW1wiZWFuX3JlYWRlclwiXVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSwgZnVuY3Rpb24oZXJyKSB7XHJcbiAgICAgICAgICAgIGlmIChlcnIpIHtcclxuICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycik7XHJcbiAgICAgICAgICAgICAgICByZXR1cm5cclxuICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICBjb25zb2xlLmxvZyhcIkluaXRpYWxpemF0aW9uIGZpbmlzaGVkLiBSZWFkeSB0byBzdGFydFwiKTtcclxuICAgICAgICAgICAgUXVhZ2dhLnN0YXJ0KCk7XHJcbiAgICAgICAgfSk7XHJcblxyXG4gICAgICAgIFF1YWdnYS5vbkRldGVjdGVkKHRoaXMuZGV0ZWN0ZWRIYW5kbGVyKTtcclxuICAgIH1cclxuXHJcbiAgICBzdG9wKCkge1xyXG4gICAgICAgIFF1YWdnYS5zdG9wKCk7XHJcbiAgICB9XHJcblxyXG4gICAgZGV0ZWN0ZWQocmVzdWx0KSB7XHJcbiAgICAgICAgdGhpcy5jb2RlID0gcmVzdWx0LmNvZGVSZXN1bHQuY29kZTtcclxuXHJcbiAgICAgICAgY29uc29sZS5sb2codGhpcy5jb2RlKTtcclxuICAgICAgICB0aGlzLnN0b3AoKTtcclxuICAgIH1cclxufSJdfQ==