UNPKG

imagerot

Version:

A lightweight, cross-environment image library for applying unique effects via raw image buffers.

35 lines (34 loc) 1.8 kB
"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 }); exports.useEffect = void 0; const applyEffect_1 = require("../applyEffect"); const useEffect = (_a, effectPool_1, effect_1, options_1) => __awaiter(void 0, [_a, effectPool_1, effect_1, options_1], void 0, function* ({ data, width, height }, effectPool, effect, options) { const effectsToUse = (!Array.isArray(effect) ? [effect] : effect); if (Array.isArray(options) && options.length !== effectsToUse.length) { throw new Error('Invalid options length'); } let i = 0; for (let currentEffect of effectsToUse) { if (!effectPool[currentEffect]) { throw new Error(`Invalid effect: ${currentEffect}`); } const applied = yield (0, applyEffect_1.applyEffect)({ data, width, height, effectPool, effect: currentEffect, options: Array.isArray(options) ? options[i] : options }); [data, width, height] = [applied.data, applied.width, applied.height]; i++; } return { data, width, height }; }); exports.useEffect = useEffect;