UNPKG

@xysfe/memento-core

Version:

record and replay the web

40 lines (37 loc) 1.67 kB
import { __awaiter, __generator } from '../../../node_modules/tslib/tslib.es6.js'; import { deserializeArg } from './deserialize-args.js'; function canvasMutation(_a) { var event = _a.event, mutation = _a.mutation, target = _a.target, imageMap = _a.imageMap, errorHandler = _a.errorHandler; return __awaiter(this, void 0, Promise, function () { var ctx, original, args, error_1; return __generator(this, function (_b) { switch (_b.label) { case 0: _b.trys.push([0, 4, , 5]); ctx = target.getContext('2d'); if (mutation.setter) { ctx[mutation.property] = mutation.args[0]; return [2]; } original = ctx[mutation.property]; if (!(mutation.property === 'drawImage' && typeof mutation.args[0] === 'string')) return [3, 1]; imageMap.get(event); original.apply(ctx, mutation.args); return [3, 3]; case 1: return [4, Promise.all(mutation.args.map(deserializeArg(imageMap, ctx)))]; case 2: args = _b.sent(); original.apply(ctx, args); _b.label = 3; case 3: return [3, 5]; case 4: error_1 = _b.sent(); errorHandler(mutation, error_1); return [3, 5]; case 5: return [2]; } }); }); } export { canvasMutation as default };