# all files / ol/ colorlike.js

100% Statements 10/10
100% Branches 5/5
100% Functions 2/2
100% Lines 10/10

    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
    421×
    1×

    1×

    1×

    1×
    172×
    106×

    66×

    1×
    248×

     goog.provide('ol.ColorLike');
    goog.provide('ol.colorlike');

    goog.require('ol.color');

    /**
     * A type accepted by CanvasRenderingContext2D.fillStyle.
     * Represents a color, pattern, or gradient.
     *
     * @typedef {string|CanvasPattern|CanvasGradient}
     * @api
     */
    ol.ColorLike;

    /**
     * @param {ol.Color|ol.ColorLike} color Color.
     * @return {ol.ColorLike} The color as an ol.ColorLike
     * @api
     */
    ol.colorlike.asColorLike = function(color) {
      if (ol.colorlike.isColorLike(color)) {
        return /** @type {string|CanvasPattern|CanvasGradient} */ (color);
      } else {
        return ol.color.asString(/** @type {ol.Color} */ (color));
      }
    };

    /**
     * @param {?} color The value that is potentially an ol.ColorLike
     * @return {boolean} Whether the color is an ol.ColorLike
     */
    ol.colorlike.isColorLike = function(color) {
      return (
          typeof color === 'string' ||
          color instanceof CanvasPattern ||
          color instanceof CanvasGradient
      );
    };