@elastic/ems-client 8.3.2 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,12 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
8
-
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
9
2
  /*
10
3
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
11
4
  * or more contributor license agreements. Licensed under the Elastic License
12
5
  * 2.0; you may not use this file except in compliance with the Elastic License
13
6
  * 2.0.
14
7
  */
15
- import chroma from 'chroma-js';
16
8
 
9
+ import chroma from 'chroma-js';
17
10
  /**
18
11
  * Resolves a target URL path relative to the host.
19
12
  * This is specifically useed by the Kibana proxy re-routing.
@@ -23,10 +16,8 @@ export function toAbsoluteUrl(host, path) {
23
16
  if (!host) {
24
17
  return path;
25
18
  }
26
-
27
19
  var hostEndWithSlash = host[host.length - 1] === '/';
28
20
  var pathStartsWithSlash = path[0] === '/';
29
-
30
21
  if (hostEndWithSlash === true && pathStartsWithSlash === true) {
31
22
  return host + path.slice(1);
32
23
  } else if (hostEndWithSlash !== pathStartsWithSlash) {
@@ -35,6 +26,7 @@ export function toAbsoluteUrl(host, path) {
35
26
  return host + '/' + path;
36
27
  }
37
28
  }
29
+
38
30
  /*
39
31
  Type with the possible ways to define a color in maplibre
40
32
  */
@@ -51,22 +43,22 @@ function transformColor(paintColor, func) {
51
43
  var newColor = transformColor(stop[1], func);
52
44
  return [stop[0], newColor];
53
45
  });
54
-
55
- var newPaintColor = _objectSpread(_objectSpread({}, paintColor), stops);
56
-
46
+ var newPaintColor = Object.assign({}, paintColor, {
47
+ stops: stops
48
+ });
57
49
  return newPaintColor;
58
50
  } else return paintColor;
59
51
  }
52
+
60
53
  /*
61
54
  This is the function used to generate the current EMS desaturated roadmap
62
55
  */
63
-
64
-
65
56
  export function desaturateColor(paintColor) {
66
57
  return transformColor(paintColor, function (color) {
67
58
  return chroma(color).desaturate(1.1).brighten(0.33);
68
59
  });
69
60
  }
61
+
70
62
  /*
71
63
  Blends an original maplibre color definition with a destination
72
64
  color. Accepts different blending modes and an additional `mix`
@@ -77,7 +69,6 @@ More details:
77
69
  https://gka.github.io/chroma.js/#chroma-blend
78
70
  https://gka.github.io/chroma.js/#chroma-mix
79
71
  */
80
-
81
72
  export function colorizeColor(sourceColor, destColor) {
82
73
  var operation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'screen';
83
74
  var percentage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.5;
@@ -5,7 +5,7 @@
5
5
  * 2.0.
6
6
  */
7
7
 
8
- import { LayerSpecification } from 'maplibre-gl';
8
+ import { FillLayerSpecification, LayerSpecification } from 'maplibre-gl';
9
9
  import { TMSService } from '../src';
10
10
  import { mlLayerTypes } from './ems_client_util';
11
11
  import chroma from 'chroma-js';
@@ -76,4 +76,65 @@ describe('Transform colours', () => {
76
76
  },
77
77
  ]);
78
78
  });
79
+
80
+ it('should work with color expressions with stops', () => {
81
+ const inColor = chroma('#D36086');
82
+ const fillColors = [chroma('rgba(0,0,0,1)'), chroma('rgba(255,0,0,1)')];
83
+ const inOp = 'lighten';
84
+
85
+ const outColors = fillColors.map((fillColor) => {
86
+ return chroma.blend(fillColor, inColor, inOp);
87
+ });
88
+
89
+ const transform = TMSService.transformColorProperties;
90
+
91
+ const layerWithTextColor = {
92
+ id: 'layer',
93
+ type: 'fill',
94
+ source: '',
95
+ paint: {
96
+ 'fill-color': {
97
+ base: 1,
98
+ stops: fillColors.map((fillColor) => {
99
+ return [1, chroma2css(fillColor)];
100
+ }),
101
+ } as unknown,
102
+ },
103
+ } as FillLayerSpecification;
104
+
105
+ const { color } = transform(layerWithTextColor, inColor.hex('rgba'), inOp, 0)[0];
106
+
107
+ expect(color).toEqual({
108
+ base: 1,
109
+ stops: outColors.map((fillColor) => {
110
+ return [1, chroma2css(fillColor)];
111
+ }),
112
+ });
113
+ });
114
+
115
+ it('should return the same colors if no input color is specified', () => {
116
+ const fillColors = ['#ff0000', '#00ff00', '#0000ff'];
117
+
118
+ const transform = TMSService.transformColorProperties;
119
+
120
+ const fillColorPaint = {
121
+ base: 1,
122
+ stops: fillColors.map((fillColor) => {
123
+ return [1, fillColor];
124
+ }),
125
+ };
126
+
127
+ const layerWithFillColor = {
128
+ id: 'layer',
129
+ type: 'fill',
130
+ paint: {
131
+ 'fill-color': fillColorPaint,
132
+ } as unknown,
133
+ } as FillLayerSpecification;
134
+
135
+ const { color, property } = transform(layerWithFillColor)[0];
136
+
137
+ expect(property).toEqual('fill-color');
138
+ expect(color).toEqual(fillColorPaint);
139
+ });
79
140
  });