processor.js 1016 B

1234567891011121314151617181920212223242526272829303132
  1. import { KeyCode } from './event_util.js';
  2. export class Processor {
  3. static stringify_(x) {
  4. return x ? x.toString() : x;
  5. }
  6. constructor(name, methods) {
  7. this.name = name;
  8. this.process = methods.processor;
  9. this.postprocess =
  10. methods.postprocessor || ((x, _y) => x);
  11. this.processor = this.postprocess
  12. ? function (x) {
  13. return this.postprocess(this.process(x), x);
  14. }
  15. : this.process;
  16. this.print = methods.print || Processor.stringify_;
  17. this.pprint = methods.pprint || this.print;
  18. }
  19. }
  20. Processor.LocalState = { walker: null, speechGenerator: null, highlighter: null };
  21. export class KeyProcessor extends Processor {
  22. static getKey_(key) {
  23. return typeof key === 'string'
  24. ?
  25. KeyCode[key.toUpperCase()]
  26. : key;
  27. }
  28. constructor(name, methods) {
  29. super(name, methods);
  30. this.key = methods.key || KeyProcessor.getKey_;
  31. }
  32. }