@elastic/ems-client 8.3.2 → 8.3.3

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5
5
 
6
+ ## [8.3.3] - 2022-05-24
7
+
8
+ - Make percentage an optional parameter #117
9
+ - Make color and operation optional parameters #118
6
10
 
7
11
  ## [8.3.2] - 2022-05-16
8
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/ems-client",
3
- "version": "8.3.2",
3
+ "version": "8.3.3",
4
4
  "description": "JavaScript client library for the Elastic Maps Service",
5
5
  "main": "target/node/index.js",
6
6
  "browser": "target/web/index.js",
package/src/index.ts CHANGED
@@ -8,3 +8,4 @@
8
8
  export { EMSClient, FileLayerField } from './ems_client';
9
9
  export { FileLayer } from './file_layer';
10
10
  export { TMSService, EmsSprite, EmsSpriteSheet } from './tms_service';
11
+ export { blendMode } from './utils';
@@ -220,9 +220,9 @@ export class TMSService extends AbstractEmsService {
220
220
  */
221
221
  public static transformColorProperties(
222
222
  layer: LayerSpecification,
223
- color: string,
224
- operation: blendMode,
225
- percentage: number
223
+ color?: string,
224
+ operation?: blendMode,
225
+ percentage?: number
226
226
  ): { property: keyof layerPaintProperty; color: mbColorDefinition | undefined }[] {
227
227
  if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
228
228
  const paint = layer.paint as layerPaintProperty;
@@ -250,7 +250,10 @@ export class TMSService extends AbstractEmsService {
250
250
  const paintColor = paint[type];
251
251
  return {
252
252
  property: type,
253
- color: paintColor ? colorizeColor(paintColor, color, operation, percentage) : paintColor,
253
+ color:
254
+ paintColor && color
255
+ ? colorizeColor(paintColor, color, operation, percentage)
256
+ : paintColor,
254
257
  };
255
258
  });
256
259
  } else {
package/src/utils.ts CHANGED
@@ -76,7 +76,7 @@ function transformColor(paintColor: mbColorDefinition, func: Function): mbColorD
76
76
  const newColor = transformColor(stop[1], func);
77
77
  return [stop[0], newColor];
78
78
  });
79
- const newPaintColor = { ...paintColor, ...stops };
79
+ const newPaintColor = Object.assign({}, paintColor, { stops });
80
80
  return newPaintColor;
81
81
  } else return paintColor;
82
82
  }
package/target/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { EMSClient, FileLayerField } from './ems_client';
2
2
  export { FileLayer } from './file_layer';
3
3
  export { TMSService, EmsSprite, EmsSpriteSheet } from './tms_service';
4
+ export { blendMode } from './utils';
@@ -39,9 +39,17 @@ Object.defineProperty(exports, "TMSService", {
39
39
  return _tms_service.TMSService;
40
40
  }
41
41
  });
42
+ Object.defineProperty(exports, "blendMode", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _utils.blendMode;
46
+ }
47
+ });
42
48
 
43
49
  var _ems_client = require("./ems_client");
44
50
 
45
51
  var _file_layer = require("./file_layer");
46
52
 
47
- var _tms_service = require("./tms_service");
53
+ var _tms_service = require("./tms_service");
54
+
55
+ var _utils = require("./utils");
@@ -144,7 +144,7 @@ class TMSService extends _ems_service.AbstractEmsService {
144
144
  const paintColor = paint[type];
145
145
  return {
146
146
  property: type,
147
- color: paintColor ? (0, _utils.colorizeColor)(paintColor, color, operation, percentage) : paintColor
147
+ color: paintColor && color ? (0, _utils.colorizeColor)(paintColor, color, operation, percentage) : paintColor
148
148
  };
149
149
  });
150
150
  } else {
@@ -56,9 +56,9 @@ function transformColor(paintColor, func) {
56
56
  const newColor = transformColor(stop[1], func);
57
57
  return [stop[0], newColor];
58
58
  });
59
- const newPaintColor = { ...paintColor,
60
- ...stops
61
- };
59
+ const newPaintColor = Object.assign({}, paintColor, {
60
+ stops
61
+ });
62
62
  return newPaintColor;
63
63
  } else return paintColor;
64
64
  }
@@ -47,7 +47,7 @@ export declare class TMSService extends AbstractEmsService {
47
47
  private _getVectorStyleJsonInlined;
48
48
  constructor(config: TMSServiceConfig, emsClient: EMSClient, proxyPath: string);
49
49
  static transformLanguageProperty(layer: LayerSpecification, lang: string): DataDrivenPropertyValueSpecification<FormattedSpecification> | undefined;
50
- static transformColorProperties(layer: LayerSpecification, color: string, operation: blendMode, percentage: number): {
50
+ static transformColorProperties(layer: LayerSpecification, color?: string, operation?: blendMode, percentage?: number): {
51
51
  property: keyof layerPaintProperty;
52
52
  color: mbColorDefinition | undefined;
53
53
  }[];
@@ -6,4 +6,5 @@
6
6
  */
7
7
  export { EMSClient, FileLayerField } from './ems_client';
8
8
  export { FileLayer } from './file_layer';
9
- export { TMSService, EmsSprite, EmsSpriteSheet } from './tms_service';
9
+ export { TMSService, EmsSprite, EmsSpriteSheet } from './tms_service';
10
+ export { blendMode } from './utils';
@@ -917,7 +917,7 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
917
917
  var paintColor = paint[type];
918
918
  return {
919
919
  property: type,
920
- color: paintColor ? colorizeColor(paintColor, color, operation, percentage) : paintColor
920
+ color: paintColor && color ? colorizeColor(paintColor, color, operation, percentage) : paintColor
921
921
  };
922
922
  });
923
923
  } else {
@@ -1,9 +1,3 @@
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
1
  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
2
 
9
3
  /*
@@ -51,9 +45,9 @@ function transformColor(paintColor, func) {
51
45
  var newColor = transformColor(stop[1], func);
52
46
  return [stop[0], newColor];
53
47
  });
54
-
55
- var newPaintColor = _objectSpread(_objectSpread({}, paintColor), stops);
56
-
48
+ var newPaintColor = Object.assign({}, paintColor, {
49
+ stops: stops
50
+ });
57
51
  return newPaintColor;
58
52
  } else return paintColor;
59
53
  }
@@ -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
  });