"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require("../../../../../Class/$");
const Semifunctional_1 = require("../../../../../Class/Semifunctional");
const _ids_1 = require("../../../../_ids");
class ToBlob extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['canvas', 'quality', 'type'],
            fo: ['blob'],
            i: ['done'],
        }, {
            input: {
                canvas: {
                    ref: true,
                },
            },
            output: {
                blob: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_TO_BLOB);
    }
    f({ canvas, quality, type }, done) {
        return __awaiter(this, void 0, void 0, function* () {
            let _blob;
            try {
                _blob = yield canvas.toBlob(type, quality);
            }
            catch (err) {
                done(undefined, err.message);
                return;
            }
            const blob = new (class _Blob extends _1.$ {
                constructor() {
                    super(...arguments);
                    this.__ = ['B', 'IM', 'BO'];
                }
                image() {
                    return __awaiter(this, void 0, void 0, function* () {
                        return _blob;
                    });
                }
                blob() {
                    return __awaiter(this, void 0, void 0, function* () {
                        return _blob;
                    });
                }
                raw() {
                    return __awaiter(this, void 0, void 0, function* () {
                        return _blob;
                    });
                }
            })(this.__system);
            done({
                blob,
            });
        });
    }
    onIterDataInputData(name) {
        // if (name === 'done') {
        this._forward_empty('blob');
        this._backward('done');
        // }
    }
}
exports.default = ToBlob;
//# sourceMappingURL=index.js.map