"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapOffscreenCanvas = wrapOffscreenCanvas;
const _1 = require("../Class/$");
const draw_1 = require("../client/canvas/draw");
const APINotImplementedError_1 = require("../exception/APINotImplementedError");
const Component_1 = require("../system/platform/component/canvas/Canvas/Component");
const FileReader_1 = require("./FileReader");
function wrapOffscreenCanvas(offscreenCanvas, offscreenCanvasCtx, system) {
    const stream = new (class OffscreenCanvas_ extends _1.$ {
        constructor() {
            super(...arguments);
            this.__ = ['CA'];
        }
        async clear() {
            (0, Component_1.clearCanvas)(offscreenCanvasCtx);
        }
        async drawImage(imageBitmap, x, y, width, height) {
            offscreenCanvasCtx.drawImage(imageBitmap, x, y, width, height);
        }
        strokePath(d) {
            offscreenCanvasCtx.stroke(new Path2D(d));
        }
        fillPath(d, fillRule) {
            offscreenCanvasCtx.fill(new Path2D(d), fillRule);
        }
        scale(sx, sy) {
            offscreenCanvasCtx.scale(sx, sy);
        }
        translate(x, y) {
            offscreenCanvasCtx.translate(x, y);
        }
        async draw(step) {
            (0, draw_1.draw)(offscreenCanvasCtx, step);
        }
        async toBlob(type, quality) {
            if ('convertToBlob' in offscreenCanvas) {
                return offscreenCanvas.convertToBlob({ type, quality });
            }
            else {
                throw new APINotImplementedError_1.APINotSupportedError('OffscreenCanvas convertToBlob');
            }
        }
        async toDataUrl(type, quality) {
            const blob = await this.toBlob(type, quality);
            return (0, FileReader_1.readBlobAsDataUrl)(this.__system, blob);
        }
        async captureStream({ frameRate, }) {
            throw new APINotImplementedError_1.APINotSupportedError('Offscreen Canvas Capture Stream');
        }
        async getImageData(x, y, width, height) {
            return offscreenCanvasCtx.getImageData(x, y, width, height);
        }
        async putImageData(image, dx, dy, x, y, width, height) {
            offscreenCanvasCtx.putImageData(image, dx, dy, x, y, width, height);
        }
    })(system);
    return stream;
}
//# sourceMappingURL=OffscreenCanvas.js.map