All files / lib/svg SvgElement.ts

100% Statements 40/40
92.3% Branches 12/13
100% Functions 3/3
100% Lines 40/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                                          1x   36x 36x 36x   36x 36x 36x   36x   36x 36x   36x 60x 60x   36x 60x 60x 60x 60x   36x 89x 369x 369x 369x 369x 13x 369x 356x 356x 369x 85x 89x   36x   36x 36x 36x     36x 36x 36x 36x 1x  
/*
 * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
 * http://paperjs.org/
 *
 * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
 * http://juerglehni.com/ & https://puckey.studio/
 *
 * Distributed under the MIT license. See LICENSE file for details.
 *
 * All rights reserved.
 */
 
// TODO: remove eslint-disable comment and deal with errors over time
/* eslint-disable */
 
/**
 * @name SvgElement
 * @namespace
 * @private
 */
// @ts-expect-error = only void funct
export const SvgElement = new (function () {
  // SVG related namespaces
  var svg = 'http://www.w3.org/2000/svg',
    xmlns = 'http://www.w3.org/2000/xmlns',
    xlink = 'http://www.w3.org/1999/xlink',
    // Mapping of attribute names to required namespaces:
    attributeNamespace = {
      href: xlink,
      xlink: xmlns,
      // Only the xmlns attribute needs the trailing slash. See #984
      xmlns: xmlns + '/',
      // IE needs the xmlns namespace when setting 'xmlns:xlink'. See #984
      'xmlns:xlink': xmlns + '/',
    };
 
  function create(tag, attributes, formatter) {
    return set(globalThis.document.createElementNS(svg, tag), attributes, formatter);
  }
 
  function get(node, name) {
    var namespace = attributeNamespace[name],
      value = namespace ? node.getAttributeNS(namespace, name) : node.getAttribute(name);
    return value === 'null' ? null : value;
  }
 
  function set(node, attributes, formatter) {
    for (var name in attributes) {
      var value = attributes[name],
        namespace = attributeNamespace[name];
      if (typeof value === 'number' && formatter) value = formatter.number(value);
      if (namespace) {
        node.setAttributeNS(namespace, name, value);
      } else {
        node.setAttribute(name, value);
      }
    }
    return node;
  }
 
  return /** @lends SvgElement */ {
    // Export namespaces
    svg: svg,
    xmlns: xmlns,
    xlink: xlink,
 
    // Methods
    create: create,
    get: get,
    set: set,
  };
})();