版博士V2.0程序
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.
 
 
 
 

99 lines
3.1 KiB

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
  7. /**
  8. * HTML Slot Element.
  9. *
  10. * Reference:
  11. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement.
  12. */
  13. class HTMLSlotElement extends HTMLElement_1.default {
  14. constructor() {
  15. super(...arguments);
  16. // Events
  17. this.onslotchange = null;
  18. }
  19. /**
  20. * Returns name.
  21. *
  22. * @returns Name.
  23. */
  24. get name() {
  25. return this.getAttributeNS(null, 'name') || '';
  26. }
  27. /**
  28. * Sets name.
  29. *
  30. * @param name Name.
  31. */
  32. set name(name) {
  33. this.setAttributeNS(null, 'name', name);
  34. }
  35. /**
  36. * Sets the slot's manually assigned nodes to an ordered set of slottables.
  37. *
  38. * @param _nodes Nodes.
  39. */
  40. assign(..._nodes) {
  41. // TODO: Do nothing for now. We need to find an example of how it is expected to work before it can be implemented.
  42. }
  43. /**
  44. * Returns assigned nodes.
  45. *
  46. * @param [options] Options.
  47. * @param [options.flatten] A boolean value indicating whether to return the assigned nodes of any available child <slot> elements (true) or not (false). Defaults to false.
  48. * @returns Nodes.
  49. */
  50. assignedNodes(options) {
  51. const host = this.getRootNode()?.host;
  52. // TODO: Add support for options.flatten. We need to find an example of how it is expected to work before it can be implemented.
  53. if (host) {
  54. const name = this.name;
  55. if (name) {
  56. return this.assignedElements(options);
  57. }
  58. return host.childNodes.slice();
  59. }
  60. return [];
  61. }
  62. /**
  63. * Returns assigned elements.
  64. *
  65. * @param [_options] Options.
  66. * @param [_options.flatten] A boolean value indicating whether to return the assigned elements of any available child <slot> elements (true) or not (false). Defaults to false.
  67. * @returns Nodes.
  68. */
  69. assignedElements(_options) {
  70. const host = this.getRootNode()?.host;
  71. // TODO: Add support for options.flatten. We need to find an example of how it expected to work before it can be implemented.
  72. if (host) {
  73. const name = this.name;
  74. if (name) {
  75. const assignedElements = [];
  76. for (const child of host.children) {
  77. if (child.slot === name) {
  78. assignedElements.push(child);
  79. }
  80. }
  81. return assignedElements;
  82. }
  83. return host.children.slice();
  84. }
  85. return [];
  86. }
  87. /**
  88. * Clones a node.
  89. *
  90. * @override
  91. * @param [deep=false] "true" to clone deep.
  92. * @returns Cloned node.
  93. */
  94. cloneNode(deep = false) {
  95. return super.cloneNode(deep);
  96. }
  97. }
  98. exports.default = HTMLSlotElement;
  99. //# sourceMappingURL=HTMLSlotElement.js.map