store_util.js 1.4 KB

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