span.js 1001 B

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Span = void 0;
  4. class Span {
  5. constructor(speech, attributes) {
  6. this.speech = speech;
  7. this.attributes = attributes;
  8. }
  9. static empty() {
  10. return new Span('', {});
  11. }
  12. static stringEmpty(str) {
  13. return new Span(str, {});
  14. }
  15. static stringAttr(str, attr) {
  16. return new Span(str, attr);
  17. }
  18. static singleton(str, def = {}) {
  19. return [Span.stringAttr(str, def)];
  20. }
  21. static node(str, node, def = {}) {
  22. const attr = Span.getAttributes(node);
  23. Object.assign(attr, def);
  24. return new Span(str, attr);
  25. }
  26. static getAttributes(node) {
  27. const attrs = {};
  28. for (const attr of Span.attributeList) {
  29. if (node.hasAttribute(attr)) {
  30. attrs[attr] = node.getAttribute(attr);
  31. }
  32. }
  33. return attrs;
  34. }
  35. }
  36. exports.Span = Span;
  37. Span.attributeList = ['id', 'extid'];