2
0

xfa_text.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.XfaText = void 0;
  27. class XfaText {
  28. static textContent(xfa) {
  29. const items = [];
  30. const output = {
  31. items,
  32. styles: Object.create(null)
  33. };
  34. function walk(node) {
  35. if (!node) {
  36. return;
  37. }
  38. let str = null;
  39. const name = node.name;
  40. if (name === "#text") {
  41. str = node.value;
  42. } else if (!XfaText.shouldBuildText(name)) {
  43. return;
  44. } else if (node?.attributes?.textContent) {
  45. str = node.attributes.textContent;
  46. } else if (node.value) {
  47. str = node.value;
  48. }
  49. if (str !== null) {
  50. items.push({
  51. str
  52. });
  53. }
  54. if (!node.children) {
  55. return;
  56. }
  57. for (const child of node.children) {
  58. walk(child);
  59. }
  60. }
  61. walk(xfa);
  62. return output;
  63. }
  64. static shouldBuildText(name) {
  65. return !(name === "textarea" || name === "input" || name === "option" || name === "select");
  66. }
  67. }
  68. exports.XfaText = XfaText;