All files / src SSVGPropertyFactory.js

71.42% Statements 5/7
50% Branches 2/4
100% Functions 1/1
71.42% Lines 5/7

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                            1x                         46x 46x     46x     46x    
// @ts-check
 
import SSVGPropertyBoolean from './SSVGPropertyBoolean';
import SSVGPropertyNumber from './SSVGPropertyNumber';
import SSVGPropertyEnum from './SSVGPropertyEnum';
import SSVGPropertyAuto from './SSVGPropertyAuto';
 
/**
 * @typedef {import('./SSVGState').default} SSVGState
 * @typedef {import('./SSVGProperty').default} SSVGProperty
 * @typedef {typeof import('./SSVGProperty').default} SSVGPropertyType
 */
 
/** @type {{ [type: string]: SSVGPropertyType }} */
const _registry = {
  boolean: SSVGPropertyBoolean,
  number: SSVGPropertyNumber,
  enum: SSVGPropertyEnum,
  auto: SSVGPropertyAuto
};
 
/**
 * @param {SSVGState} ssvg
 * @param {Element} element
 * @return {SSVGProperty}
 */
export function createProperty(ssvg, element) {
  const type = element.getAttribute('type');
  Iif (!type) {
    throw new SyntaxError('property type missing');
  }
  else Iif (!(type in _registry)) {
    throw new SyntaxError('invalid property type: ' + type);
  }
  return new _registry[type](ssvg, element);
}