Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DOMElement.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = exports.serialize = exports.test = void 0;
  6. var _markup = require('./lib/markup');
  7. /**
  8. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  9. *
  10. * This source code is licensed under the MIT license found in the
  11. * LICENSE file in the root directory of this source tree.
  12. */
  13. const ELEMENT_NODE = 1;
  14. const TEXT_NODE = 3;
  15. const COMMENT_NODE = 8;
  16. const FRAGMENT_NODE = 11;
  17. const ELEMENT_REGEXP = /^((HTML|SVG)\w*)?Element$/;
  18. const testHasAttribute = val => {
  19. try {
  20. return typeof val.hasAttribute === 'function' && val.hasAttribute('is');
  21. } catch {
  22. return false;
  23. }
  24. };
  25. const testNode = val => {
  26. const constructorName = val.constructor.name;
  27. const {nodeType, tagName} = val;
  28. const isCustomElement =
  29. (typeof tagName === 'string' && tagName.includes('-')) ||
  30. testHasAttribute(val);
  31. return (
  32. (nodeType === ELEMENT_NODE &&
  33. (ELEMENT_REGEXP.test(constructorName) || isCustomElement)) ||
  34. (nodeType === TEXT_NODE && constructorName === 'Text') ||
  35. (nodeType === COMMENT_NODE && constructorName === 'Comment') ||
  36. (nodeType === FRAGMENT_NODE && constructorName === 'DocumentFragment')
  37. );
  38. };
  39. const test = val => {
  40. var _val$constructor;
  41. return (
  42. (val === null || val === void 0
  43. ? void 0
  44. : (_val$constructor = val.constructor) === null ||
  45. _val$constructor === void 0
  46. ? void 0
  47. : _val$constructor.name) && testNode(val)
  48. );
  49. };
  50. exports.test = test;
  51. function nodeIsText(node) {
  52. return node.nodeType === TEXT_NODE;
  53. }
  54. function nodeIsComment(node) {
  55. return node.nodeType === COMMENT_NODE;
  56. }
  57. function nodeIsFragment(node) {
  58. return node.nodeType === FRAGMENT_NODE;
  59. }
  60. const serialize = (node, config, indentation, depth, refs, printer) => {
  61. if (nodeIsText(node)) {
  62. return (0, _markup.printText)(node.data, config);
  63. }
  64. if (nodeIsComment(node)) {
  65. return (0, _markup.printComment)(node.data, config);
  66. }
  67. const type = nodeIsFragment(node)
  68. ? `DocumentFragment`
  69. : node.tagName.toLowerCase();
  70. if (++depth > config.maxDepth) {
  71. return (0, _markup.printElementAsLeaf)(type, config);
  72. }
  73. return (0, _markup.printElement)(
  74. type,
  75. (0, _markup.printProps)(
  76. nodeIsFragment(node)
  77. ? []
  78. : Array.from(node.attributes)
  79. .map(attr => attr.name)
  80. .sort(),
  81. nodeIsFragment(node)
  82. ? {}
  83. : Array.from(node.attributes).reduce((props, attribute) => {
  84. props[attribute.name] = attribute.value;
  85. return props;
  86. }, {}),
  87. config,
  88. indentation + config.indent,
  89. depth,
  90. refs,
  91. printer
  92. ),
  93. (0, _markup.printChildren)(
  94. Array.prototype.slice.call(node.childNodes || node.children),
  95. config,
  96. indentation + config.indent,
  97. depth,
  98. refs,
  99. printer
  100. ),
  101. config,
  102. indentation
  103. );
  104. };
  105. exports.serialize = serialize;
  106. const plugin = {
  107. serialize,
  108. test
  109. };
  110. var _default = plugin;
  111. exports.default = _default;