@xysfe/memento-core
Version:
record and replay the web
69 lines (66 loc) • 2.84 kB
JavaScript
import { __awaiter, __generator } from '../../../node_modules/tslib/tslib.es6.js';
import { CanvasContext } from '../../types.js';
import webglMutation from './webgl.js';
import canvasMutation$1 from './2d.js';
function canvasMutation(_a) {
var event = _a.event, mutation = _a.mutation, target = _a.target, imageMap = _a.imageMap, canvasEventMap = _a.canvasEventMap, errorHandler = _a.errorHandler;
return __awaiter(this, void 0, Promise, function () {
var precomputedMutation, commands, i, command, i, command, error_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 10, , 11]);
precomputedMutation = canvasEventMap.get(event) || mutation;
commands = 'commands' in precomputedMutation
? precomputedMutation.commands
: [precomputedMutation];
if (![CanvasContext.WebGL, CanvasContext.WebGL2].includes(mutation.type)) return [3, 5];
i = 0;
_b.label = 1;
case 1:
if (!(i < commands.length)) return [3, 4];
command = commands[i];
return [4, webglMutation({
mutation: command,
type: mutation.type,
target: target,
imageMap: imageMap,
errorHandler: errorHandler,
})];
case 2:
_b.sent();
_b.label = 3;
case 3:
i++;
return [3, 1];
case 4: return [2];
case 5:
i = 0;
_b.label = 6;
case 6:
if (!(i < commands.length)) return [3, 9];
command = commands[i];
return [4, canvasMutation$1({
event: event,
mutation: command,
target: target,
imageMap: imageMap,
errorHandler: errorHandler,
})];
case 7:
_b.sent();
_b.label = 8;
case 8:
i++;
return [3, 6];
case 9: return [3, 11];
case 10:
error_1 = _b.sent();
errorHandler(mutation, error_1);
return [3, 11];
case 11: return [2];
}
});
});
}
export { canvasMutation as default };