store_util.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.nodeCounter = nodeCounter;
  4. exports.pauseSeparator = pauseSeparator;
  5. exports.contentIterator = contentIterator;
  6. const auditory_description_js_1 = require("../audio/auditory_description.js");
  7. const XpathUtil = require("../common/xpath_util.js");
  8. const engine_js_1 = require("../common/engine.js");
  9. function nodeCounter(nodes, context) {
  10. const localLength = nodes.length;
  11. let localCounter = 0;
  12. let localContext = context;
  13. if (!context) {
  14. localContext = '';
  15. }
  16. return function () {
  17. if (localCounter < localLength) {
  18. localCounter += 1;
  19. }
  20. return localContext + ' ' + localCounter;
  21. };
  22. }
  23. function pauseSeparator(_nodes, context) {
  24. const numeral = parseFloat(context);
  25. const value = isNaN(numeral) ? context : numeral;
  26. return function () {
  27. return [
  28. auditory_description_js_1.AuditoryDescription.create({
  29. text: '',
  30. personality: { pause: value }
  31. })
  32. ];
  33. };
  34. }
  35. function contentIterator(nodes, context) {
  36. let contentNodes;
  37. if (nodes.length > 0) {
  38. contentNodes = XpathUtil.evalXPath('../../content/*', nodes[0]);
  39. }
  40. else {
  41. contentNodes = [];
  42. }
  43. return function () {
  44. const content = contentNodes.shift();
  45. const contextDescr = context
  46. ? [auditory_description_js_1.AuditoryDescription.create({ text: context }, { translate: true })]
  47. : [];
  48. if (!content) {
  49. return contextDescr;
  50. }
  51. const descrs = engine_js_1.Engine.evaluateNode(content);
  52. return contextDescr.concat(descrs);
  53. };
  54. }