aboutsummaryrefslogtreecommitdiff
path: root/node_modules/jsdom/lib/jsdom/living/helpers/svg/render.js
blob: 651568daa8b089afff9b08f84028f2c21705520b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";
const { SVG_NS } = require("../namespaces");

// https://svgwg.org/svg2-draft/render.html#TermNeverRenderedElement
const neverRenderedElements = new Set([
  "clipPath",
  "defs",
  "desc",
  "linearGradient",
  "marker",
  "mask",
  "metadata",
  "pattern",
  "radialGradient",
  "script",
  "style",
  "title",
  "symbol"
]);

// https://svgwg.org/svg2-draft/render.html#Rendered-vs-NonRendered
exports.isRenderedElement = elImpl => {
  if (neverRenderedElements.has(elImpl._localName)) {
    return false;
  }

  // This does not check for elements excluded because of conditional processing attributes or ‘switch’ structures,
  // because conditional processing is not implemented.
  // https://svgwg.org/svg2-draft/struct.html#ConditionalProcessing

  // This does not check for computed style of display being none, since that is not yet implemented for HTML
  // focusability either (and there are no tests yet).

  if (!elImpl.isConnected) {
    return false;
  }

  // The spec is unclear about how to deal with non-SVG parents, so we only perform this check for SVG-namespace
  // parents.
  if (elImpl.parentElement && elImpl.parentElement._namespaceURI === SVG_NS &&
                              !exports.isRenderedElement(elImpl.parentNode)) {
    return false;
  }

  return true;
};