All files / lib/svg SvgStyles.ts

98.5% Statements 66/67
80% Branches 4/5
100% Functions 1/1
98.5% Lines 66/67

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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90                              1x 1x 1x 1x   1x 1x   1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   28x 28x     28x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 576x 576x 576x 576x 576x 576x 576x 576x 576x 72x 72x 72x 180x 180x 72x 72x 576x 576x 576x 576x 576x 1x 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 */
 
import { Base } from '~/straps';
import { Shape } from '~/item/Shape';
import { PathItem } from '~/path/PathItem';
import { TextItem } from '~/text/TextItem';
 
export const SvgStyles = Base.each(
  {
    // Fill
    fillColor: ['fill', 'color'],
    fillRule: ['fill-rule', 'string'],
    // Stroke
    strokeColor: ['stroke', 'color'],
    strokeWidth: ['stroke-width', 'number'],
    strokeCap: ['stroke-linecap', 'string'],
    strokeJoin: ['stroke-linejoin', 'string'],
    strokeScaling: [
      'vector-effect',
      'lookup',
      {
        true: 'none',
        false: 'non-scaling-stroke',
      },
      function (item, value) {
        // no inheritance, only applies to graphical elements
        return (
          !value && // false, meaning non-scaling-stroke
          (item instanceof PathItem || item instanceof Shape || item instanceof TextItem)
        );
      },
    ],
    miterLimit: ['stroke-miterlimit', 'number'],
    dashArray: ['stroke-dasharray', 'array'],
    dashOffset: ['stroke-dashoffset', 'number'],
    // Text
    fontFamily: ['font-family', 'string'],
    fontWeight: ['font-weight', 'string'],
    fontSize: ['font-size', 'number'],
    justification: [
      'text-anchor',
      'lookup',
      {
        left: 'start',
        center: 'middle',
        right: 'end',
      },
    ],
    // Item
    opacity: ['opacity', 'number'],
    blendMode: ['mix-blend-mode', 'style'],
  },
  function (entry, key) {
    var part = Base.capitalize(key),
      lookup = entry[2];
    this[key] = {
      type: entry[1],
      property: key,
      attribute: entry[0],
      toSVG: lookup,
      fromSVG:
        lookup &&
        Base.each(
          lookup,
          function (value, name) {
            this[value] = name;
          },
          {}
        ),
      exportFilter: entry[3],
      get: 'get' + part,
      set: 'set' + part,
    };
  },
  {}
);