processor.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.KeyProcessor = exports.Processor = void 0;
  4. const event_util_js_1 = require("./event_util.js");
  5. class Processor {
  6. static stringify_(x) {
  7. return x ? x.toString() : x;
  8. }
  9. constructor(name, methods) {
  10. this.name = name;
  11. this.process = methods.processor;
  12. this.postprocess =
  13. methods.postprocessor || ((x, _y) => x);
  14. this.processor = this.postprocess
  15. ? function (x) {
  16. return this.postprocess(this.process(x), x);
  17. }
  18. : this.process;
  19. this.print = methods.print || Processor.stringify_;
  20. this.pprint = methods.pprint || this.print;
  21. }
  22. }
  23. exports.Processor = Processor;
  24. Processor.LocalState = { walker: null, speechGenerator: null, highlighter: null };
  25. class KeyProcessor extends Processor {
  26. static getKey_(key) {
  27. return typeof key === 'string'
  28. ?
  29. event_util_js_1.KeyCode[key.toUpperCase()]
  30. : key;
  31. }
  32. constructor(name, methods) {
  33. super(name, methods);
  34. this.key = methods.key || KeyProcessor.getKey_;
  35. }
  36. }
  37. exports.KeyProcessor = KeyProcessor;