@snowplow/browser-plugin-debugger 3.24.2 → 3.24.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/dist/index.umd.js CHANGED
@@ -1,994 +1,999 @@
1
1
  /*!
2
- * Debugger for Snowplow v3.24.2 (http://bit.ly/sp-js)
2
+ * Debugger for Snowplow v3.24.3 (http://bit.ly/sp-js)
3
3
  * Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
4
4
  * Licensed under BSD-3-Clause
5
5
  */
6
6
 
7
7
  (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.snowplowDebugger = {}));
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.snowplowDebugger = {}));
11
11
  })(this, (function (exports) { 'use strict';
12
12
 
13
- /*! *****************************************************************************
14
- Copyright (c) Microsoft Corporation.
15
-
16
- Permission to use, copy, modify, and/or distribute this software for any
17
- purpose with or without fee is hereby granted.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
- PERFORMANCE OF THIS SOFTWARE.
26
- ***************************************************************************** */
27
-
28
- function __spreadArray(to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
34
- }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- }
37
-
38
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
39
-
40
- /*!
41
- * Core functionality for Snowplow JavaScript trackers v3.24.2 (http://bit.ly/sp-js)
42
- * Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
43
- * Licensed under BSD-3-Clause
44
- */
45
-
46
- var version$1 = "3.24.2";
47
-
48
- /*
49
- * Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)
50
- * and Contributors (http://phpjs.org/authors)
51
- *
52
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
53
- * this software and associated documentation files (the "Software"), to deal in
54
- * the Software without restriction, including without limitation the rights to
55
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
56
- * of the Software, and to permit persons to whom the Software is furnished to do
57
- * so, subject to the following conditions:
58
- *
59
- * The above copyright notice and this permission notice shall be included in all
60
- * copies or substantial portions of the Software.
61
- *
62
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68
- * SOFTWARE.
69
- */
70
- /**
71
- * Decodes a url safe Base 64 encoded string
72
- * @remarks See: {@link http://tools.ietf.org/html/rfc4648#page-7}
73
- * @param data - String to decode
74
- * @returns The decoded string
75
- */
76
- function base64urldecode(data) {
77
- if (!data) {
78
- return data;
79
- }
80
- var padding = 4 - (data.length % 4);
81
- switch (padding) {
82
- case 2:
83
- data += '==';
84
- break;
85
- case 3:
86
- data += '=';
87
- break;
88
- }
89
- var b64Data = data.replace(/-/g, '+').replace(/_/g, '/');
90
- return base64decode(b64Data);
91
- }
92
- /**
93
- * Encodes a string into a url safe Base 64 encoded string
94
- * @remarks See: {@link http://tools.ietf.org/html/rfc4648#page-7}
95
- * @param data - String to encode
96
- * @returns The url safe Base 64 string
97
- */
98
- function base64urlencode(data) {
99
- if (!data) {
100
- return data;
101
- }
102
- var enc = base64encode(data);
103
- return enc.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
104
- }
105
- var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
106
- /**
107
- * Encode string as base64.
108
- * Any type can be passed, but will be stringified
109
- *
110
- * @param data - string to encode
111
- * @returns base64-encoded string
112
- */
113
- function base64encode(data) {
114
- // discuss at: http://phpjs.org/functions/base64_encode/
115
- // original by: Tyler Akins (http://rumkin.com)
116
- // improved by: Bayron Guevara
117
- // improved by: Thunder.m
118
- // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
119
- // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
120
- // improved by: Rafał Kukawski (http://kukawski.pl)
121
- // bugfixed by: Pellentesque Malesuada
122
- // example 1: base64_encode('Kevin van Zonneveld');
123
- // returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
124
- // example 2: base64_encode('a');
125
- // returns 2: 'YQ=='
126
- // example 3: base64_encode('✓ à la mode');
127
- // returns 3: '4pyTIMOgIGxhIG1vZGU='
128
- var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0;
129
- var tmp_arr = [];
130
- if (!data) {
131
- return data;
13
+ /******************************************************************************
14
+ Copyright (c) Microsoft Corporation.
15
+
16
+ Permission to use, copy, modify, and/or distribute this software for any
17
+ purpose with or without fee is hereby granted.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
20
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
22
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25
+ PERFORMANCE OF THIS SOFTWARE.
26
+ ***************************************************************************** */
27
+
28
+ function __spreadArray(to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
132
33
  }
133
- data = unescape(encodeURIComponent(data));
134
- do {
135
- // pack three octets into four hexets
136
- o1 = data.charCodeAt(i++);
137
- o2 = data.charCodeAt(i++);
138
- o3 = data.charCodeAt(i++);
139
- bits = (o1 << 16) | (o2 << 8) | o3;
140
- h1 = (bits >> 18) & 0x3f;
141
- h2 = (bits >> 12) & 0x3f;
142
- h3 = (bits >> 6) & 0x3f;
143
- h4 = bits & 0x3f;
144
- // use hexets to index into b64, and append result to encoded string
145
- tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
146
- } while (i < data.length);
147
- var enc = tmp_arr.join('');
148
- var r = data.length % 3;
149
- return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
150
34
  }
151
- /**
152
- * Decode base64 to string
153
- *
154
- * @param data - base64 to string
155
- * @returns decoded string
156
- */
157
- function base64decode(encodedData) {
158
- // discuss at: http://locutus.io/php/base64_decode/
159
- // original by: Tyler Akins (http://rumkin.com)
160
- // improved by: Thunder.m
161
- // improved by: Kevin van Zonneveld (http://kvz.io)
162
- // improved by: Kevin van Zonneveld (http://kvz.io)
163
- // input by: Aman Gupta
164
- // input by: Brett Zamir (http://brett-zamir.me)
165
- // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
166
- // bugfixed by: Pellentesque Malesuada
167
- // bugfixed by: Kevin van Zonneveld (http://kvz.io)
168
- // improved by: Indigo744
169
- // example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==')
170
- // returns 1: 'Kevin van Zonneveld'
171
- // example 2: base64_decode('YQ==')
172
- // returns 2: 'a'
173
- // example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=')
174
- // returns 3: '✓ à la mode'
175
- // decodeUTF8string()
176
- // Internal function to decode properly UTF8 string
177
- // Adapted from Solution #1 at https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
178
- var decodeUTF8string = function (str) {
179
- // Going backwards: from bytestream, to percent-encoding, to original string.
180
- return decodeURIComponent(str
181
- .split('')
182
- .map(function (c) {
183
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
184
- })
185
- .join(''));
186
- };
187
- var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '';
188
- var tmpArr = [];
189
- if (!encodedData) {
190
- return encodedData;
191
- }
192
- encodedData += '';
193
- do {
194
- // unpack four hexets into three octets using index points in b64
195
- h1 = b64.indexOf(encodedData.charAt(i++));
196
- h2 = b64.indexOf(encodedData.charAt(i++));
197
- h3 = b64.indexOf(encodedData.charAt(i++));
198
- h4 = b64.indexOf(encodedData.charAt(i++));
199
- bits = (h1 << 18) | (h2 << 12) | (h3 << 6) | h4;
200
- o1 = (bits >> 16) & 0xff;
201
- o2 = (bits >> 8) & 0xff;
202
- o3 = bits & 0xff;
203
- if (h3 === 64) {
204
- tmpArr[ac++] = String.fromCharCode(o1);
205
- }
206
- else if (h4 === 64) {
207
- tmpArr[ac++] = String.fromCharCode(o1, o2);
208
- }
209
- else {
210
- tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
211
- }
212
- } while (i < encodedData.length);
213
- dec = tmpArr.join('');
214
- return decodeUTF8string(dec.replace(/\0+$/, ''));
215
- }
216
- /**
217
- * A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods.
218
- * Will base64 encode JSON, if desired, on build
219
- *
220
- * @returns The request builder, with add and build methods
221
- */
222
- function payloadJsonProcessor(encodeBase64) {
223
- return function (payloadBuilder, jsonForProcessing, contextEntitiesForProcessing) {
224
- var add = function (json, keyIfEncoded, keyIfNotEncoded) {
225
- var str = JSON.stringify(json);
226
- if (encodeBase64) {
227
- payloadBuilder.add(keyIfEncoded, base64urlencode(str));
228
- }
229
- else {
230
- payloadBuilder.add(keyIfNotEncoded, str);
231
- }
232
- };
233
- var getContextFromPayload = function () {
234
- var payload = payloadBuilder.getPayload();
235
- if (encodeBase64 ? payload.cx : payload.co) {
236
- return JSON.parse(encodeBase64 ? base64urldecode(payload.cx) : payload.co);
237
- }
238
- return undefined;
239
- };
240
- var combineContexts = function (originalContext, newContext) {
241
- var context = originalContext || getContextFromPayload();
242
- if (context) {
243
- context.data = context.data.concat(newContext.data);
244
- }
245
- else {
246
- context = newContext;
247
- }
248
- return context;
249
- };
250
- var context = undefined;
251
- for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) {
252
- var json = jsonForProcessing_1[_i];
253
- if (json.keyIfEncoded === 'cx') {
254
- context = combineContexts(context, json.json);
255
- }
256
- else {
257
- add(json.json, json.keyIfEncoded, json.keyIfNotEncoded);
258
- }
259
- }
260
- jsonForProcessing.length = 0;
261
- if (contextEntitiesForProcessing.length) {
262
- var newContext = {
263
- schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0',
264
- data: __spreadArray([], contextEntitiesForProcessing, true)
265
- };
266
- context = combineContexts(context, newContext);
267
- contextEntitiesForProcessing.length = 0;
268
- }
269
- if (context) {
270
- add(context, 'cx', 'co');
271
- }
272
- };
273
- }
274
- var LOG_LEVEL;
275
- (function (LOG_LEVEL) {
276
- LOG_LEVEL[LOG_LEVEL["none"] = 0] = "none";
277
- LOG_LEVEL[LOG_LEVEL["error"] = 1] = "error";
278
- LOG_LEVEL[LOG_LEVEL["warn"] = 2] = "warn";
279
- LOG_LEVEL[LOG_LEVEL["debug"] = 3] = "debug";
280
- LOG_LEVEL[LOG_LEVEL["info"] = 4] = "info";
281
- })(LOG_LEVEL || (LOG_LEVEL = {}));
282
- /**
283
- * Slices a schema into its composite parts. Useful for ruleset filtering.
284
- * @param input - A schema string
285
- * @returns The vendor, schema name, major, minor and patch information of a schema string
286
- */
287
- function getSchemaParts(input) {
288
- var re = new RegExp('^iglu:([a-zA-Z0-9-_.]+)/([a-zA-Z0-9-_]+)/jsonschema/([1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$');
289
- var matches = re.exec(input);
290
- if (matches !== null)
291
- return matches.slice(1, 6);
292
- return undefined;
293
- }
294
-
295
- /*
296
- * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
297
- * All rights reserved.
298
- *
299
- * Redistribution and use in source and binary forms, with or without
300
- * modification, are permitted provided that the following conditions are met:
301
- *
302
- * 1. Redistributions of source code must retain the above copyright notice, this
303
- * list of conditions and the following disclaimer.
304
- *
305
- * 2. Redistributions in binary form must reproduce the above copyright notice,
306
- * this list of conditions and the following disclaimer in the documentation
307
- * and/or other materials provided with the distribution.
308
- *
309
- * 3. Neither the name of the copyright holder nor the names of its
310
- * contributors may be used to endorse or promote products derived from
311
- * this software without specific prior written permission.
312
- *
313
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
314
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
315
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
316
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
317
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
318
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
319
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
320
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
321
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
322
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
323
- */
324
- var version = version$1;
325
-
326
- var randomColor = {exports: {}};
327
-
328
- (function (module, exports) {
329
- (function(root, factory) {
330
-
331
- // Support CommonJS
332
- {
333
- var randomColor = factory();
334
-
335
- // Support NodeJS & Component, which allow module.exports to be a function
336
- if (module && module.exports) {
337
- exports = module.exports = randomColor;
338
- }
339
-
340
- // Support CommonJS 1.1.1 spec
341
- exports.randomColor = randomColor;
342
-
343
- // Support AMD
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ }
37
+
38
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
39
+ var e = new Error(message);
40
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
41
+ };
42
+
43
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
44
+
45
+ /*!
46
+ * Core functionality for Snowplow JavaScript trackers v3.24.3 (http://bit.ly/sp-js)
47
+ * Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
48
+ * Licensed under BSD-3-Clause
49
+ */
50
+
51
+ var version$1 = "3.24.3";
52
+
53
+ /*
54
+ * Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io)
55
+ * and Contributors (http://phpjs.org/authors)
56
+ *
57
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
58
+ * this software and associated documentation files (the "Software"), to deal in
59
+ * the Software without restriction, including without limitation the rights to
60
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
61
+ * of the Software, and to permit persons to whom the Software is furnished to do
62
+ * so, subject to the following conditions:
63
+ *
64
+ * The above copyright notice and this permission notice shall be included in all
65
+ * copies or substantial portions of the Software.
66
+ *
67
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
+ * SOFTWARE.
74
+ */
75
+ /**
76
+ * Decodes a url safe Base 64 encoded string
77
+ * @remarks See: {@link http://tools.ietf.org/html/rfc4648#page-7}
78
+ * @param data - String to decode
79
+ * @returns The decoded string
80
+ */
81
+ function base64urldecode(data) {
82
+ if (!data) {
83
+ return data;
84
+ }
85
+ var padding = 4 - (data.length % 4);
86
+ switch (padding) {
87
+ case 2:
88
+ data += '==';
89
+ break;
90
+ case 3:
91
+ data += '=';
92
+ break;
93
+ }
94
+ var b64Data = data.replace(/-/g, '+').replace(/_/g, '/');
95
+ return base64decode(b64Data);
96
+ }
97
+ /**
98
+ * Encodes a string into a url safe Base 64 encoded string
99
+ * @remarks See: {@link http://tools.ietf.org/html/rfc4648#page-7}
100
+ * @param data - String to encode
101
+ * @returns The url safe Base 64 string
102
+ */
103
+ function base64urlencode(data) {
104
+ if (!data) {
105
+ return data;
106
+ }
107
+ var enc = base64encode(data);
108
+ return enc.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
109
+ }
110
+ var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
111
+ /**
112
+ * Encode string as base64.
113
+ * Any type can be passed, but will be stringified
114
+ *
115
+ * @param data - string to encode
116
+ * @returns base64-encoded string
117
+ */
118
+ function base64encode(data) {
119
+ // discuss at: http://phpjs.org/functions/base64_encode/
120
+ // original by: Tyler Akins (http://rumkin.com)
121
+ // improved by: Bayron Guevara
122
+ // improved by: Thunder.m
123
+ // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
124
+ // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
125
+ // improved by: Rafał Kukawski (http://kukawski.pl)
126
+ // bugfixed by: Pellentesque Malesuada
127
+ // example 1: base64_encode('Kevin van Zonneveld');
128
+ // returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
129
+ // example 2: base64_encode('a');
130
+ // returns 2: 'YQ=='
131
+ // example 3: base64_encode('✓ à la mode');
132
+ // returns 3: '4pyTIMOgIGxhIG1vZGU='
133
+ var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0;
134
+ var tmp_arr = [];
135
+ if (!data) {
136
+ return data;
137
+ }
138
+ data = unescape(encodeURIComponent(data));
139
+ do {
140
+ // pack three octets into four hexets
141
+ o1 = data.charCodeAt(i++);
142
+ o2 = data.charCodeAt(i++);
143
+ o3 = data.charCodeAt(i++);
144
+ bits = (o1 << 16) | (o2 << 8) | o3;
145
+ h1 = (bits >> 18) & 0x3f;
146
+ h2 = (bits >> 12) & 0x3f;
147
+ h3 = (bits >> 6) & 0x3f;
148
+ h4 = bits & 0x3f;
149
+ // use hexets to index into b64, and append result to encoded string
150
+ tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
151
+ } while (i < data.length);
152
+ var enc = tmp_arr.join('');
153
+ var r = data.length % 3;
154
+ return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
155
+ }
156
+ /**
157
+ * Decode base64 to string
158
+ *
159
+ * @param data - base64 to string
160
+ * @returns decoded string
161
+ */
162
+ function base64decode(encodedData) {
163
+ // discuss at: http://locutus.io/php/base64_decode/
164
+ // original by: Tyler Akins (http://rumkin.com)
165
+ // improved by: Thunder.m
166
+ // improved by: Kevin van Zonneveld (http://kvz.io)
167
+ // improved by: Kevin van Zonneveld (http://kvz.io)
168
+ // input by: Aman Gupta
169
+ // input by: Brett Zamir (http://brett-zamir.me)
170
+ // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
171
+ // bugfixed by: Pellentesque Malesuada
172
+ // bugfixed by: Kevin van Zonneveld (http://kvz.io)
173
+ // improved by: Indigo744
174
+ // example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==')
175
+ // returns 1: 'Kevin van Zonneveld'
176
+ // example 2: base64_decode('YQ==')
177
+ // returns 2: 'a'
178
+ // example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=')
179
+ // returns 3: '✓ à la mode'
180
+ // decodeUTF8string()
181
+ // Internal function to decode properly UTF8 string
182
+ // Adapted from Solution #1 at https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
183
+ var decodeUTF8string = function (str) {
184
+ // Going backwards: from bytestream, to percent-encoding, to original string.
185
+ return decodeURIComponent(str
186
+ .split('')
187
+ .map(function (c) {
188
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
189
+ })
190
+ .join(''));
191
+ };
192
+ var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = '';
193
+ var tmpArr = [];
194
+ if (!encodedData) {
195
+ return encodedData;
196
+ }
197
+ encodedData += '';
198
+ do {
199
+ // unpack four hexets into three octets using index points in b64
200
+ h1 = b64.indexOf(encodedData.charAt(i++));
201
+ h2 = b64.indexOf(encodedData.charAt(i++));
202
+ h3 = b64.indexOf(encodedData.charAt(i++));
203
+ h4 = b64.indexOf(encodedData.charAt(i++));
204
+ bits = (h1 << 18) | (h2 << 12) | (h3 << 6) | h4;
205
+ o1 = (bits >> 16) & 0xff;
206
+ o2 = (bits >> 8) & 0xff;
207
+ o3 = bits & 0xff;
208
+ if (h3 === 64) {
209
+ tmpArr[ac++] = String.fromCharCode(o1);
210
+ }
211
+ else if (h4 === 64) {
212
+ tmpArr[ac++] = String.fromCharCode(o1, o2);
213
+ }
214
+ else {
215
+ tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
216
+ }
217
+ } while (i < encodedData.length);
218
+ dec = tmpArr.join('');
219
+ return decodeUTF8string(dec.replace(/\0+$/, ''));
220
+ }
221
+ /**
222
+ * A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods.
223
+ * Will base64 encode JSON, if desired, on build
224
+ *
225
+ * @returns The request builder, with add and build methods
226
+ */
227
+ function payloadJsonProcessor(encodeBase64) {
228
+ return function (payloadBuilder, jsonForProcessing, contextEntitiesForProcessing) {
229
+ var add = function (json, keyIfEncoded, keyIfNotEncoded) {
230
+ var str = JSON.stringify(json);
231
+ if (encodeBase64) {
232
+ payloadBuilder.add(keyIfEncoded, base64urlencode(str));
233
+ }
234
+ else {
235
+ payloadBuilder.add(keyIfNotEncoded, str);
236
+ }
237
+ };
238
+ var getContextFromPayload = function () {
239
+ var payload = payloadBuilder.getPayload();
240
+ if (encodeBase64 ? payload.cx : payload.co) {
241
+ return JSON.parse(encodeBase64 ? base64urldecode(payload.cx) : payload.co);
242
+ }
243
+ return undefined;
244
+ };
245
+ var combineContexts = function (originalContext, newContext) {
246
+ var context = originalContext || getContextFromPayload();
247
+ if (context) {
248
+ context.data = context.data.concat(newContext.data);
249
+ }
250
+ else {
251
+ context = newContext;
252
+ }
253
+ return context;
254
+ };
255
+ var context = undefined;
256
+ for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) {
257
+ var json = jsonForProcessing_1[_i];
258
+ if (json.keyIfEncoded === 'cx') {
259
+ context = combineContexts(context, json.json);
260
+ }
261
+ else {
262
+ add(json.json, json.keyIfEncoded, json.keyIfNotEncoded);
263
+ }
264
+ }
265
+ jsonForProcessing.length = 0;
266
+ if (contextEntitiesForProcessing.length) {
267
+ var newContext = {
268
+ schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0',
269
+ data: __spreadArray([], contextEntitiesForProcessing, true)
270
+ };
271
+ context = combineContexts(context, newContext);
272
+ contextEntitiesForProcessing.length = 0;
273
+ }
274
+ if (context) {
275
+ add(context, 'cx', 'co');
276
+ }
277
+ };
278
+ }
279
+ var LOG_LEVEL;
280
+ (function (LOG_LEVEL) {
281
+ LOG_LEVEL[LOG_LEVEL["none"] = 0] = "none";
282
+ LOG_LEVEL[LOG_LEVEL["error"] = 1] = "error";
283
+ LOG_LEVEL[LOG_LEVEL["warn"] = 2] = "warn";
284
+ LOG_LEVEL[LOG_LEVEL["debug"] = 3] = "debug";
285
+ LOG_LEVEL[LOG_LEVEL["info"] = 4] = "info";
286
+ })(LOG_LEVEL || (LOG_LEVEL = {}));
287
+ /**
288
+ * Slices a schema into its composite parts. Useful for ruleset filtering.
289
+ * @param input - A schema string
290
+ * @returns The vendor, schema name, major, minor and patch information of a schema string
291
+ */
292
+ function getSchemaParts(input) {
293
+ var re = new RegExp('^iglu:([a-zA-Z0-9-_.]+)/([a-zA-Z0-9-_]+)/jsonschema/([1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$');
294
+ var matches = re.exec(input);
295
+ if (matches !== null)
296
+ return matches.slice(1, 6);
297
+ return undefined;
298
+ }
299
+
300
+ /*
301
+ * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
302
+ * All rights reserved.
303
+ *
304
+ * Redistribution and use in source and binary forms, with or without
305
+ * modification, are permitted provided that the following conditions are met:
306
+ *
307
+ * 1. Redistributions of source code must retain the above copyright notice, this
308
+ * list of conditions and the following disclaimer.
309
+ *
310
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
311
+ * this list of conditions and the following disclaimer in the documentation
312
+ * and/or other materials provided with the distribution.
313
+ *
314
+ * 3. Neither the name of the copyright holder nor the names of its
315
+ * contributors may be used to endorse or promote products derived from
316
+ * this software without specific prior written permission.
317
+ *
318
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
319
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
320
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
321
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
322
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
323
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
324
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
325
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
326
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
327
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
328
+ */
329
+ var version = version$1;
330
+
331
+ var randomColor = {exports: {}};
332
+
333
+ (function (module, exports) {
334
+ (function(root, factory) {
335
+
336
+ // Support CommonJS
337
+ {
338
+ var randomColor = factory();
339
+
340
+ // Support NodeJS & Component, which allow module.exports to be a function
341
+ if (module && module.exports) {
342
+ exports = module.exports = randomColor;
344
343
  }
345
344
 
346
- }(commonjsGlobal, function() {
347
-
348
- // Seed to get repeatable colors
349
- var seed = null;
350
-
351
- // Shared color dictionary
352
- var colorDictionary = {};
345
+ // Support CommonJS 1.1.1 spec
346
+ exports.randomColor = randomColor;
353
347
 
354
- // Populate the color dictionary
355
- loadColorBounds();
348
+ // Support AMD
349
+ }
356
350
 
357
- // check if a range is taken
358
- var colorRanges = [];
351
+ }(commonjsGlobal, function() {
359
352
 
360
- var randomColor = function (options) {
353
+ // Seed to get repeatable colors
354
+ var seed = null;
361
355
 
362
- options = options || {};
356
+ // Shared color dictionary
357
+ var colorDictionary = {};
363
358
 
364
- // Check if there is a seed and ensure it's an
365
- // integer. Otherwise, reset the seed value.
366
- if (options.seed !== undefined && options.seed !== null && options.seed === parseInt(options.seed, 10)) {
367
- seed = options.seed;
359
+ // Populate the color dictionary
360
+ loadColorBounds();
368
361
 
369
- // A string was passed as a seed
370
- } else if (typeof options.seed === 'string') {
371
- seed = stringToInteger(options.seed);
362
+ // check if a range is taken
363
+ var colorRanges = [];
372
364
 
373
- // Something was passed as a seed but it wasn't an integer or string
374
- } else if (options.seed !== undefined && options.seed !== null) {
375
- throw new TypeError('The seed value must be an integer or string');
365
+ var randomColor = function (options) {
376
366
 
377
- // No seed, reset the value outside.
378
- } else {
379
- seed = null;
380
- }
367
+ options = options || {};
381
368
 
382
- var H,S,B;
369
+ // Check if there is a seed and ensure it's an
370
+ // integer. Otherwise, reset the seed value.
371
+ if (options.seed !== undefined && options.seed !== null && options.seed === parseInt(options.seed, 10)) {
372
+ seed = options.seed;
383
373
 
384
- // Check if we need to generate multiple colors
385
- if (options.count !== null && options.count !== undefined) {
374
+ // A string was passed as a seed
375
+ } else if (typeof options.seed === 'string') {
376
+ seed = stringToInteger(options.seed);
386
377
 
387
- var totalColors = options.count,
388
- colors = [];
389
- // Value false at index i means the range i is not taken yet.
390
- for (var i = 0; i < options.count; i++) {
391
- colorRanges.push(false);
392
- }
393
- options.count = null;
378
+ // Something was passed as a seed but it wasn't an integer or string
379
+ } else if (options.seed !== undefined && options.seed !== null) {
380
+ throw new TypeError('The seed value must be an integer or string');
394
381
 
395
- while (totalColors > colors.length) {
382
+ // No seed, reset the value outside.
383
+ } else {
384
+ seed = null;
385
+ }
396
386
 
397
- var color = randomColor(options);
387
+ var H,S,B;
398
388
 
399
- if (seed !== null) {
400
- options.seed = seed;
401
- }
389
+ // Check if we need to generate multiple colors
390
+ if (options.count !== null && options.count !== undefined) {
402
391
 
403
- colors.push(color);
392
+ var totalColors = options.count,
393
+ colors = [];
394
+ // Value false at index i means the range i is not taken yet.
395
+ for (var i = 0; i < options.count; i++) {
396
+ colorRanges.push(false);
404
397
  }
398
+ options.count = null;
405
399
 
406
- options.count = totalColors;
400
+ while (totalColors > colors.length) {
407
401
 
408
- return colors;
409
- }
402
+ var color = randomColor(options);
410
403
 
411
- // First we pick a hue (H)
412
- H = pickHue(options);
404
+ if (seed !== null) {
405
+ options.seed = seed;
406
+ }
413
407
 
414
- // Then use H to determine saturation (S)
415
- S = pickSaturation(H, options);
408
+ colors.push(color);
409
+ }
416
410
 
417
- // Then use S and H to determine brightness (B).
418
- B = pickBrightness(H, S, options);
411
+ options.count = totalColors;
419
412
 
420
- // Then we return the HSB color in the desired format
421
- return setFormat([H,S,B], options);
422
- };
413
+ return colors;
414
+ }
423
415
 
424
- function pickHue(options) {
425
- if (colorRanges.length > 0) {
426
- var hueRange = getRealHueRange(options.hue);
416
+ // First we pick a hue (H)
417
+ H = pickHue(options);
427
418
 
428
- var hue = randomWithin(hueRange);
419
+ // Then use H to determine saturation (S)
420
+ S = pickSaturation(H, options);
429
421
 
430
- //Each of colorRanges.length ranges has a length equal approximatelly one step
431
- var step = (hueRange[1] - hueRange[0]) / colorRanges.length;
422
+ // Then use S and H to determine brightness (B).
423
+ B = pickBrightness(H, S, options);
432
424
 
433
- var j = parseInt((hue - hueRange[0]) / step);
425
+ // Then we return the HSB color in the desired format
426
+ return setFormat([H,S,B], options);
427
+ };
434
428
 
435
- //Check if the range j is taken
436
- if (colorRanges[j] === true) {
437
- j = (j + 2) % colorRanges.length;
438
- }
439
- else {
440
- colorRanges[j] = true;
441
- }
429
+ function pickHue(options) {
430
+ if (colorRanges.length > 0) {
431
+ var hueRange = getRealHueRange(options.hue);
442
432
 
443
- var min = (hueRange[0] + j * step) % 359,
444
- max = (hueRange[0] + (j + 1) * step) % 359;
433
+ var hue = randomWithin(hueRange);
445
434
 
446
- hueRange = [min, max];
435
+ //Each of colorRanges.length ranges has a length equal approximatelly one step
436
+ var step = (hueRange[1] - hueRange[0]) / colorRanges.length;
447
437
 
448
- hue = randomWithin(hueRange);
438
+ var j = parseInt((hue - hueRange[0]) / step);
449
439
 
450
- if (hue < 0) {hue = 360 + hue;}
451
- return hue
440
+ //Check if the range j is taken
441
+ if (colorRanges[j] === true) {
442
+ j = (j + 2) % colorRanges.length;
452
443
  }
453
444
  else {
454
- var hueRange = getHueRange(options.hue);
445
+ colorRanges[j] = true;
446
+ }
455
447
 
456
- hue = randomWithin(hueRange);
457
- // Instead of storing red as two seperate ranges,
458
- // we group them, using negative numbers
459
- if (hue < 0) {
460
- hue = 360 + hue;
461
- }
448
+ var min = (hueRange[0] + j * step) % 359,
449
+ max = (hueRange[0] + (j + 1) * step) % 359;
462
450
 
463
- return hue;
464
- }
465
- }
451
+ hueRange = [min, max];
466
452
 
467
- function pickSaturation (hue, options) {
453
+ hue = randomWithin(hueRange);
468
454
 
469
- if (options.hue === 'monochrome') {
470
- return 0;
455
+ if (hue < 0) {hue = 360 + hue;}
456
+ return hue
457
+ }
458
+ else {
459
+ var hueRange = getHueRange(options.hue);
460
+
461
+ hue = randomWithin(hueRange);
462
+ // Instead of storing red as two seperate ranges,
463
+ // we group them, using negative numbers
464
+ if (hue < 0) {
465
+ hue = 360 + hue;
471
466
  }
472
467
 
473
- if (options.luminosity === 'random') {
474
- return randomWithin([0,100]);
475
- }
468
+ return hue;
469
+ }
470
+ }
471
+
472
+ function pickSaturation (hue, options) {
473
+
474
+ if (options.hue === 'monochrome') {
475
+ return 0;
476
+ }
476
477
 
477
- var saturationRange = getSaturationRange(hue);
478
+ if (options.luminosity === 'random') {
479
+ return randomWithin([0,100]);
480
+ }
478
481
 
479
- var sMin = saturationRange[0],
480
- sMax = saturationRange[1];
482
+ var saturationRange = getSaturationRange(hue);
481
483
 
482
- switch (options.luminosity) {
484
+ var sMin = saturationRange[0],
485
+ sMax = saturationRange[1];
483
486
 
484
- case 'bright':
485
- sMin = 55;
486
- break;
487
+ switch (options.luminosity) {
487
488
 
488
- case 'dark':
489
- sMin = sMax - 10;
490
- break;
489
+ case 'bright':
490
+ sMin = 55;
491
+ break;
491
492
 
492
- case 'light':
493
- sMax = 55;
494
- break;
495
- }
493
+ case 'dark':
494
+ sMin = sMax - 10;
495
+ break;
496
496
 
497
- return randomWithin([sMin, sMax]);
497
+ case 'light':
498
+ sMax = 55;
499
+ break;
500
+ }
498
501
 
499
- }
502
+ return randomWithin([sMin, sMax]);
500
503
 
501
- function pickBrightness (H, S, options) {
504
+ }
502
505
 
503
- var bMin = getMinimumBrightness(H, S),
504
- bMax = 100;
506
+ function pickBrightness (H, S, options) {
505
507
 
506
- switch (options.luminosity) {
508
+ var bMin = getMinimumBrightness(H, S),
509
+ bMax = 100;
507
510
 
508
- case 'dark':
509
- bMax = bMin + 20;
510
- break;
511
+ switch (options.luminosity) {
511
512
 
512
- case 'light':
513
- bMin = (bMax + bMin)/2;
514
- break;
513
+ case 'dark':
514
+ bMax = bMin + 20;
515
+ break;
515
516
 
516
- case 'random':
517
- bMin = 0;
518
- bMax = 100;
519
- break;
520
- }
517
+ case 'light':
518
+ bMin = (bMax + bMin)/2;
519
+ break;
521
520
 
522
- return randomWithin([bMin, bMax]);
521
+ case 'random':
522
+ bMin = 0;
523
+ bMax = 100;
524
+ break;
523
525
  }
524
526
 
525
- function setFormat (hsv, options) {
527
+ return randomWithin([bMin, bMax]);
528
+ }
526
529
 
527
- switch (options.format) {
530
+ function setFormat (hsv, options) {
528
531
 
529
- case 'hsvArray':
530
- return hsv;
532
+ switch (options.format) {
531
533
 
532
- case 'hslArray':
533
- return HSVtoHSL(hsv);
534
+ case 'hsvArray':
535
+ return hsv;
534
536
 
535
- case 'hsl':
536
- var hsl = HSVtoHSL(hsv);
537
- return 'hsl('+hsl[0]+', '+hsl[1]+'%, '+hsl[2]+'%)';
537
+ case 'hslArray':
538
+ return HSVtoHSL(hsv);
538
539
 
539
- case 'hsla':
540
- var hslColor = HSVtoHSL(hsv);
541
- var alpha = options.alpha || Math.random();
542
- return 'hsla('+hslColor[0]+', '+hslColor[1]+'%, '+hslColor[2]+'%, ' + alpha + ')';
540
+ case 'hsl':
541
+ var hsl = HSVtoHSL(hsv);
542
+ return 'hsl('+hsl[0]+', '+hsl[1]+'%, '+hsl[2]+'%)';
543
543
 
544
- case 'rgbArray':
545
- return HSVtoRGB(hsv);
544
+ case 'hsla':
545
+ var hslColor = HSVtoHSL(hsv);
546
+ var alpha = options.alpha || Math.random();
547
+ return 'hsla('+hslColor[0]+', '+hslColor[1]+'%, '+hslColor[2]+'%, ' + alpha + ')';
546
548
 
547
- case 'rgb':
548
- var rgb = HSVtoRGB(hsv);
549
- return 'rgb(' + rgb.join(', ') + ')';
549
+ case 'rgbArray':
550
+ return HSVtoRGB(hsv);
550
551
 
551
- case 'rgba':
552
- var rgbColor = HSVtoRGB(hsv);
553
- var alpha = options.alpha || Math.random();
554
- return 'rgba(' + rgbColor.join(', ') + ', ' + alpha + ')';
552
+ case 'rgb':
553
+ var rgb = HSVtoRGB(hsv);
554
+ return 'rgb(' + rgb.join(', ') + ')';
555
555
 
556
- default:
557
- return HSVtoHex(hsv);
558
- }
556
+ case 'rgba':
557
+ var rgbColor = HSVtoRGB(hsv);
558
+ var alpha = options.alpha || Math.random();
559
+ return 'rgba(' + rgbColor.join(', ') + ', ' + alpha + ')';
559
560
 
561
+ default:
562
+ return HSVtoHex(hsv);
560
563
  }
561
564
 
562
- function getMinimumBrightness(H, S) {
565
+ }
563
566
 
564
- var lowerBounds = getColorInfo(H).lowerBounds;
567
+ function getMinimumBrightness(H, S) {
565
568
 
566
- for (var i = 0; i < lowerBounds.length - 1; i++) {
569
+ var lowerBounds = getColorInfo(H).lowerBounds;
567
570
 
568
- var s1 = lowerBounds[i][0],
569
- v1 = lowerBounds[i][1];
571
+ for (var i = 0; i < lowerBounds.length - 1; i++) {
570
572
 
571
- var s2 = lowerBounds[i+1][0],
572
- v2 = lowerBounds[i+1][1];
573
+ var s1 = lowerBounds[i][0],
574
+ v1 = lowerBounds[i][1];
573
575
 
574
- if (S >= s1 && S <= s2) {
576
+ var s2 = lowerBounds[i+1][0],
577
+ v2 = lowerBounds[i+1][1];
575
578
 
576
- var m = (v2 - v1)/(s2 - s1),
577
- b = v1 - m*s1;
579
+ if (S >= s1 && S <= s2) {
578
580
 
579
- return m*S + b;
580
- }
581
+ var m = (v2 - v1)/(s2 - s1),
582
+ b = v1 - m*s1;
581
583
 
584
+ return m*S + b;
582
585
  }
583
586
 
584
- return 0;
585
587
  }
586
588
 
587
- function getHueRange (colorInput) {
589
+ return 0;
590
+ }
588
591
 
589
- if (typeof parseInt(colorInput) === 'number') {
592
+ function getHueRange (colorInput) {
590
593
 
591
- var number = parseInt(colorInput);
594
+ if (typeof parseInt(colorInput) === 'number') {
592
595
 
593
- if (number < 360 && number > 0) {
594
- return [number, number];
595
- }
596
+ var number = parseInt(colorInput);
596
597
 
598
+ if (number < 360 && number > 0) {
599
+ return [number, number];
597
600
  }
598
601
 
599
- if (typeof colorInput === 'string') {
600
-
601
- if (colorDictionary[colorInput]) {
602
- var color = colorDictionary[colorInput];
603
- if (color.hueRange) {return color.hueRange;}
604
- } else if (colorInput.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) {
605
- var hue = HexToHSB(colorInput)[0];
606
- return [ hue, hue ];
607
- }
608
- }
602
+ }
609
603
 
610
- return [0,360];
604
+ if (typeof colorInput === 'string') {
611
605
 
606
+ if (colorDictionary[colorInput]) {
607
+ var color = colorDictionary[colorInput];
608
+ if (color.hueRange) {return color.hueRange;}
609
+ } else if (colorInput.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) {
610
+ var hue = HexToHSB(colorInput)[0];
611
+ return [ hue, hue ];
612
+ }
612
613
  }
613
614
 
614
- function getSaturationRange (hue) {
615
- return getColorInfo(hue).saturationRange;
616
- }
615
+ return [0,360];
617
616
 
618
- function getColorInfo (hue) {
617
+ }
619
618
 
620
- // Maps red colors to make picking hue easier
621
- if (hue >= 334 && hue <= 360) {
622
- hue-= 360;
623
- }
619
+ function getSaturationRange (hue) {
620
+ return getColorInfo(hue).saturationRange;
621
+ }
622
+
623
+ function getColorInfo (hue) {
624
624
 
625
- for (var colorName in colorDictionary) {
626
- var color = colorDictionary[colorName];
627
- if (color.hueRange &&
628
- hue >= color.hueRange[0] &&
629
- hue <= color.hueRange[1]) {
630
- return colorDictionary[colorName];
631
- }
632
- } return 'Color not found';
625
+ // Maps red colors to make picking hue easier
626
+ if (hue >= 334 && hue <= 360) {
627
+ hue-= 360;
633
628
  }
634
629
 
635
- function randomWithin (range) {
636
- if (seed === null) {
637
- //generate random evenly destinct number from : https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
638
- var golden_ratio = 0.618033988749895;
639
- var r=Math.random();
640
- r += golden_ratio;
641
- r %= 1;
642
- return Math.floor(range[0] + r*(range[1] + 1 - range[0]));
643
- } else {
644
- //Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
645
- var max = range[1] || 1;
646
- var min = range[0] || 0;
647
- seed = (seed * 9301 + 49297) % 233280;
648
- var rnd = seed / 233280.0;
649
- return Math.floor(min + rnd * (max - min));
630
+ for (var colorName in colorDictionary) {
631
+ var color = colorDictionary[colorName];
632
+ if (color.hueRange &&
633
+ hue >= color.hueRange[0] &&
634
+ hue <= color.hueRange[1]) {
635
+ return colorDictionary[colorName];
636
+ }
637
+ } return 'Color not found';
650
638
  }
651
- }
652
639
 
653
- function HSVtoHex (hsv){
640
+ function randomWithin (range) {
641
+ if (seed === null) {
642
+ //generate random evenly destinct number from : https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
643
+ var golden_ratio = 0.618033988749895;
644
+ var r=Math.random();
645
+ r += golden_ratio;
646
+ r %= 1;
647
+ return Math.floor(range[0] + r*(range[1] + 1 - range[0]));
648
+ } else {
649
+ //Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
650
+ var max = range[1] || 1;
651
+ var min = range[0] || 0;
652
+ seed = (seed * 9301 + 49297) % 233280;
653
+ var rnd = seed / 233280.0;
654
+ return Math.floor(min + rnd * (max - min));
655
+ }
656
+ }
654
657
 
655
- var rgb = HSVtoRGB(hsv);
658
+ function HSVtoHex (hsv){
656
659
 
657
- function componentToHex(c) {
658
- var hex = c.toString(16);
659
- return hex.length == 1 ? '0' + hex : hex;
660
- }
660
+ var rgb = HSVtoRGB(hsv);
661
661
 
662
- var hex = '#' + componentToHex(rgb[0]) + componentToHex(rgb[1]) + componentToHex(rgb[2]);
662
+ function componentToHex(c) {
663
+ var hex = c.toString(16);
664
+ return hex.length == 1 ? '0' + hex : hex;
665
+ }
663
666
 
664
- return hex;
667
+ var hex = '#' + componentToHex(rgb[0]) + componentToHex(rgb[1]) + componentToHex(rgb[2]);
665
668
 
666
- }
669
+ return hex;
667
670
 
668
- function defineColor (name, hueRange, lowerBounds) {
671
+ }
669
672
 
670
- var sMin = lowerBounds[0][0],
671
- sMax = lowerBounds[lowerBounds.length - 1][0],
673
+ function defineColor (name, hueRange, lowerBounds) {
672
674
 
673
- bMin = lowerBounds[lowerBounds.length - 1][1],
674
- bMax = lowerBounds[0][1];
675
+ var sMin = lowerBounds[0][0],
676
+ sMax = lowerBounds[lowerBounds.length - 1][0],
675
677
 
676
- colorDictionary[name] = {
677
- hueRange: hueRange,
678
- lowerBounds: lowerBounds,
679
- saturationRange: [sMin, sMax],
680
- brightnessRange: [bMin, bMax]
681
- };
678
+ bMin = lowerBounds[lowerBounds.length - 1][1],
679
+ bMax = lowerBounds[0][1];
682
680
 
683
- }
681
+ colorDictionary[name] = {
682
+ hueRange: hueRange,
683
+ lowerBounds: lowerBounds,
684
+ saturationRange: [sMin, sMax],
685
+ brightnessRange: [bMin, bMax]
686
+ };
684
687
 
685
- function loadColorBounds () {
686
-
687
- defineColor(
688
- 'monochrome',
689
- null,
690
- [[0,0],[100,0]]
691
- );
692
-
693
- defineColor(
694
- 'red',
695
- [-26,18],
696
- [[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]
697
- );
698
-
699
- defineColor(
700
- 'orange',
701
- [18,46],
702
- [[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]
703
- );
704
-
705
- defineColor(
706
- 'yellow',
707
- [46,62],
708
- [[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]
709
- );
710
-
711
- defineColor(
712
- 'green',
713
- [62,178],
714
- [[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]
715
- );
716
-
717
- defineColor(
718
- 'blue',
719
- [178, 257],
720
- [[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]
721
- );
722
-
723
- defineColor(
724
- 'purple',
725
- [257, 282],
726
- [[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]
727
- );
728
-
729
- defineColor(
730
- 'pink',
731
- [282, 334],
732
- [[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]]
733
- );
688
+ }
734
689
 
735
- }
690
+ function loadColorBounds () {
691
+
692
+ defineColor(
693
+ 'monochrome',
694
+ null,
695
+ [[0,0],[100,0]]
696
+ );
697
+
698
+ defineColor(
699
+ 'red',
700
+ [-26,18],
701
+ [[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]
702
+ );
703
+
704
+ defineColor(
705
+ 'orange',
706
+ [18,46],
707
+ [[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]
708
+ );
709
+
710
+ defineColor(
711
+ 'yellow',
712
+ [46,62],
713
+ [[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]
714
+ );
715
+
716
+ defineColor(
717
+ 'green',
718
+ [62,178],
719
+ [[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]
720
+ );
721
+
722
+ defineColor(
723
+ 'blue',
724
+ [178, 257],
725
+ [[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]
726
+ );
727
+
728
+ defineColor(
729
+ 'purple',
730
+ [257, 282],
731
+ [[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]
732
+ );
733
+
734
+ defineColor(
735
+ 'pink',
736
+ [282, 334],
737
+ [[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]]
738
+ );
736
739
 
737
- function HSVtoRGB (hsv) {
738
-
739
- // this doesn't work for the values of 0 and 360
740
- // here's the hacky fix
741
- var h = hsv[0];
742
- if (h === 0) {h = 1;}
743
- if (h === 360) {h = 359;}
744
-
745
- // Rebase the h,s,v values
746
- h = h/360;
747
- var s = hsv[1]/100,
748
- v = hsv[2]/100;
749
-
750
- var h_i = Math.floor(h*6),
751
- f = h * 6 - h_i,
752
- p = v * (1 - s),
753
- q = v * (1 - f*s),
754
- t = v * (1 - (1 - f)*s),
755
- r = 256,
756
- g = 256,
757
- b = 256;
758
-
759
- switch(h_i) {
760
- case 0: r = v; g = t; b = p; break;
761
- case 1: r = q; g = v; b = p; break;
762
- case 2: r = p; g = v; b = t; break;
763
- case 3: r = p; g = q; b = v; break;
764
- case 4: r = t; g = p; b = v; break;
765
- case 5: r = v; g = p; b = q; break;
766
- }
740
+ }
767
741
 
768
- var result = [Math.floor(r*255), Math.floor(g*255), Math.floor(b*255)];
769
- return result;
742
+ function HSVtoRGB (hsv) {
743
+
744
+ // this doesn't work for the values of 0 and 360
745
+ // here's the hacky fix
746
+ var h = hsv[0];
747
+ if (h === 0) {h = 1;}
748
+ if (h === 360) {h = 359;}
749
+
750
+ // Rebase the h,s,v values
751
+ h = h/360;
752
+ var s = hsv[1]/100,
753
+ v = hsv[2]/100;
754
+
755
+ var h_i = Math.floor(h*6),
756
+ f = h * 6 - h_i,
757
+ p = v * (1 - s),
758
+ q = v * (1 - f*s),
759
+ t = v * (1 - (1 - f)*s),
760
+ r = 256,
761
+ g = 256,
762
+ b = 256;
763
+
764
+ switch(h_i) {
765
+ case 0: r = v; g = t; b = p; break;
766
+ case 1: r = q; g = v; b = p; break;
767
+ case 2: r = p; g = v; b = t; break;
768
+ case 3: r = p; g = q; b = v; break;
769
+ case 4: r = t; g = p; b = v; break;
770
+ case 5: r = v; g = p; b = q; break;
770
771
  }
771
772
 
772
- function HexToHSB (hex) {
773
- hex = hex.replace(/^#/, '');
774
- hex = hex.length === 3 ? hex.replace(/(.)/g, '$1$1') : hex;
773
+ var result = [Math.floor(r*255), Math.floor(g*255), Math.floor(b*255)];
774
+ return result;
775
+ }
775
776
 
776
- var red = parseInt(hex.substr(0, 2), 16) / 255,
777
- green = parseInt(hex.substr(2, 2), 16) / 255,
778
- blue = parseInt(hex.substr(4, 2), 16) / 255;
777
+ function HexToHSB (hex) {
778
+ hex = hex.replace(/^#/, '');
779
+ hex = hex.length === 3 ? hex.replace(/(.)/g, '$1$1') : hex;
779
780
 
780
- var cMax = Math.max(red, green, blue),
781
- delta = cMax - Math.min(red, green, blue),
782
- saturation = cMax ? (delta / cMax) : 0;
781
+ var red = parseInt(hex.substr(0, 2), 16) / 255,
782
+ green = parseInt(hex.substr(2, 2), 16) / 255,
783
+ blue = parseInt(hex.substr(4, 2), 16) / 255;
783
784
 
784
- switch (cMax) {
785
- case red: return [ 60 * (((green - blue) / delta) % 6) || 0, saturation, cMax ];
786
- case green: return [ 60 * (((blue - red) / delta) + 2) || 0, saturation, cMax ];
787
- case blue: return [ 60 * (((red - green) / delta) + 4) || 0, saturation, cMax ];
788
- }
789
- }
785
+ var cMax = Math.max(red, green, blue),
786
+ delta = cMax - Math.min(red, green, blue),
787
+ saturation = cMax ? (delta / cMax) : 0;
790
788
 
791
- function HSVtoHSL (hsv) {
792
- var h = hsv[0],
793
- s = hsv[1]/100,
794
- v = hsv[2]/100,
795
- k = (2-s)*v;
796
-
797
- return [
798
- h,
799
- Math.round(s*v / (k<1 ? k : 2-k) * 10000) / 100,
800
- k/2 * 100
801
- ];
789
+ switch (cMax) {
790
+ case red: return [ 60 * (((green - blue) / delta) % 6) || 0, saturation, cMax ];
791
+ case green: return [ 60 * (((blue - red) / delta) + 2) || 0, saturation, cMax ];
792
+ case blue: return [ 60 * (((red - green) / delta) + 4) || 0, saturation, cMax ];
802
793
  }
794
+ }
803
795
 
804
- function stringToInteger (string) {
805
- var total = 0;
806
- for (var i = 0; i !== string.length; i++) {
807
- if (total >= Number.MAX_SAFE_INTEGER) break;
808
- total += string.charCodeAt(i);
809
- }
810
- return total
796
+ function HSVtoHSL (hsv) {
797
+ var h = hsv[0],
798
+ s = hsv[1]/100,
799
+ v = hsv[2]/100,
800
+ k = (2-s)*v;
801
+
802
+ return [
803
+ h,
804
+ Math.round(s*v / (k<1 ? k : 2-k) * 10000) / 100,
805
+ k/2 * 100
806
+ ];
807
+ }
808
+
809
+ function stringToInteger (string) {
810
+ var total = 0;
811
+ for (var i = 0; i !== string.length; i++) {
812
+ if (total >= Number.MAX_SAFE_INTEGER) break;
813
+ total += string.charCodeAt(i);
811
814
  }
815
+ return total
816
+ }
812
817
 
813
- // get The range of given hue when options.count!=0
814
- function getRealHueRange(colorHue)
815
- { if (!isNaN(colorHue)) {
816
- var number = parseInt(colorHue);
818
+ // get The range of given hue when options.count!=0
819
+ function getRealHueRange(colorHue)
820
+ { if (!isNaN(colorHue)) {
821
+ var number = parseInt(colorHue);
817
822
 
818
- if (number < 360 && number > 0) {
819
- return getColorInfo(colorHue).hueRange
820
- }
823
+ if (number < 360 && number > 0) {
824
+ return getColorInfo(colorHue).hueRange
821
825
  }
822
- else if (typeof colorHue === 'string') {
826
+ }
827
+ else if (typeof colorHue === 'string') {
823
828
 
824
- if (colorDictionary[colorHue]) {
825
- var color = colorDictionary[colorHue];
829
+ if (colorDictionary[colorHue]) {
830
+ var color = colorDictionary[colorHue];
826
831
 
827
- if (color.hueRange) {
828
- return color.hueRange
829
- }
830
- } else if (colorHue.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) {
831
- var hue = HexToHSB(colorHue)[0];
832
- return getColorInfo(hue).hueRange
833
- }
832
+ if (color.hueRange) {
833
+ return color.hueRange
834
+ }
835
+ } else if (colorHue.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) {
836
+ var hue = HexToHSB(colorHue)[0];
837
+ return getColorInfo(hue).hueRange
834
838
  }
835
-
836
- return [0,360]
837
- }
838
- return randomColor;
839
- }));
840
- }(randomColor, randomColor.exports));
841
-
842
- var randomcolor = randomColor.exports;
843
-
844
- /*
845
- * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
846
- * All rights reserved.
847
- *
848
- * Redistribution and use in source and binary forms, with or without
849
- * modification, are permitted provided that the following conditions are met:
850
- *
851
- * 1. Redistributions of source code must retain the above copyright notice, this
852
- * list of conditions and the following disclaimer.
853
- *
854
- * 2. Redistributions in binary form must reproduce the above copyright notice,
855
- * this list of conditions and the following disclaimer in the documentation
856
- * and/or other materials provided with the distribution.
857
- *
858
- * 3. Neither the name of the copyright holder nor the names of its
859
- * contributors may be used to endorse or promote products derived from
860
- * this software without specific prior written permission.
861
- *
862
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
863
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
864
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
865
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
866
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
867
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
868
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
869
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
870
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
871
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
872
- */
873
- /**
874
- * Adds advertisement tracking functions
875
- */
876
- function DebuggerPlugin(logLevel) {
877
- if (logLevel === void 0) { logLevel = LOG_LEVEL.debug; }
878
- var LOG;
879
- var tracker;
880
- var eventColour;
881
- var colours = {
882
- event: function () { return "color: White; background: ".concat(eventColour, "; font-weight: bold; padding: 1px 4px; border-radius: 2px;"); },
883
- snowplowPurple: 'color: White; background: #6638B8; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
884
- activated: 'color: White; background: #9E62DD; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
885
- payload: 'color: White; background: #3748B8; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
886
- json: 'color: White; background: #388AB8; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
887
- schema: 'color: White; background: #268047; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
888
- schemaVersion: 'color: White; background: #80265F; font-weight: bold; padding: 1px 4px; border-radius: 2px;'
889
- };
890
- var debug = function (style, message, extra) {
891
- var _a = extra !== null && extra !== void 0 ? extra : [''], extraMessage = _a[0], rest = _a.slice(1);
892
- LOG.debug.apply(LOG, __spreadArray(["v".concat(version, " %c").concat(tracker.namespace, "%c %c%s") + extraMessage,
893
- colours.snowplowPurple,
894
- '',
895
- style,
896
- message], rest, false));
897
- };
898
- function jsonInterceptor(encodeBase64) {
899
- var log = function (jsonType, data) {
900
- var schemaParts = getSchemaParts(data['schema']);
901
- debug(colours.event(), 'Event', [
902
- '%c%s%c%s%c%s\n%o',
903
- colours.json,
904
- "".concat(jsonType, ": ").concat(schemaParts ? schemaParts[1] : 'Unknown Schema'),
905
- colours.schemaVersion,
906
- schemaParts ? "Version: ".concat(schemaParts[2], "-").concat(schemaParts[3], "-").concat(schemaParts[4]) : 'Unknown Schema Version',
907
- colours.schema,
908
- schemaParts ? "Vendor: ".concat(schemaParts[0]) : 'Unknown Vendor',
909
- data['data'],
910
- ]);
911
- };
912
- return function (payloadBuilder, jsonForProcessing, contextEntitiesForProcessing) {
913
- if (jsonForProcessing.length) {
914
- var _loop_1 = function (json) {
915
- var data = json.json['data'];
916
- if (Array.isArray(data)) {
917
- data.forEach(function (d) {
918
- log(getJsonType(json), d);
919
- });
920
- }
921
- else {
922
- log(getJsonType(json), data);
923
- }
924
- };
925
- for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) {
926
- var json = jsonForProcessing_1[_i];
927
- _loop_1(json);
928
- }
929
- }
930
- if (contextEntitiesForProcessing.length) {
931
- for (var _a = 0, contextEntitiesForProcessing_1 = contextEntitiesForProcessing; _a < contextEntitiesForProcessing_1.length; _a++) {
932
- var entity = contextEntitiesForProcessing_1[_a];
933
- log('Context', entity);
934
- }
935
- }
936
- return payloadJsonProcessor(encodeBase64)(payloadBuilder, jsonForProcessing, contextEntitiesForProcessing);
937
- };
938
- }
939
- return {
940
- logger: function (logger) {
941
- LOG = logger;
942
- logger.setLogLevel(logLevel);
943
- },
944
- activateBrowserPlugin: function (t) {
945
- tracker = t;
946
- debug(colours.activated, 'Tracker Activated');
947
- },
948
- beforeTrack: function (payloadBuilder) {
949
- eventColour = randomcolor({ luminosity: 'dark' });
950
- payloadBuilder.withJsonProcessor(jsonInterceptor(tracker.core.getBase64Encoding()));
951
- debug(colours.event(), 'Event', ['%c%s', colours.snowplowPurple, getEventType(payloadBuilder)]);
952
- payloadBuilder.build();
953
- },
954
- afterTrack: function (payload) {
955
- debug(colours.event(), 'Event', ['%c%s\n%o', colours.payload, 'Payload', payload]);
956
- }
957
- };
958
- }
959
- function getJsonType(json) {
960
- switch (json.keyIfEncoded) {
961
- case 'cx':
962
- return 'Context';
963
- case 'ue_px':
964
- return 'Self Describing';
965
- default:
966
- return "".concat(json.keyIfEncoded, ", ").concat(json.keyIfNotEncoded);
967
- }
968
- }
969
- function getEventType(payloadBuilder) {
970
- var payload = payloadBuilder.getPayload();
971
- switch (payload['e']) {
972
- case 'pv':
973
- return 'Page View';
974
- case 'pp':
975
- return 'Page Ping';
976
- case 'tr':
977
- return 'Ecommerce Transaction';
978
- case 'ti':
979
- return 'Ecommerce Transaction Item';
980
- case 'se':
981
- return 'Structured Event';
982
- case 'ue':
983
- return 'Self Describing';
984
- default:
985
- return typeof payload['e'] === 'string' ? payload['e'] : 'Invalid';
986
- }
987
839
  }
988
840
 
989
- exports.DebuggerPlugin = DebuggerPlugin;
841
+ return [0,360]
842
+ }
843
+ return randomColor;
844
+ }));
845
+ }(randomColor, randomColor.exports));
846
+
847
+ var randomcolor = randomColor.exports;
848
+
849
+ /*
850
+ * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
851
+ * All rights reserved.
852
+ *
853
+ * Redistribution and use in source and binary forms, with or without
854
+ * modification, are permitted provided that the following conditions are met:
855
+ *
856
+ * 1. Redistributions of source code must retain the above copyright notice, this
857
+ * list of conditions and the following disclaimer.
858
+ *
859
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
860
+ * this list of conditions and the following disclaimer in the documentation
861
+ * and/or other materials provided with the distribution.
862
+ *
863
+ * 3. Neither the name of the copyright holder nor the names of its
864
+ * contributors may be used to endorse or promote products derived from
865
+ * this software without specific prior written permission.
866
+ *
867
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
868
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
869
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
870
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
871
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
872
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
873
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
874
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
875
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
876
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
877
+ */
878
+ /**
879
+ * Adds advertisement tracking functions
880
+ */
881
+ function DebuggerPlugin(logLevel) {
882
+ if (logLevel === void 0) { logLevel = LOG_LEVEL.debug; }
883
+ var LOG;
884
+ var tracker;
885
+ var eventColour;
886
+ var colours = {
887
+ event: function () { return "color: White; background: ".concat(eventColour, "; font-weight: bold; padding: 1px 4px; border-radius: 2px;"); },
888
+ snowplowPurple: 'color: White; background: #6638B8; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
889
+ activated: 'color: White; background: #9E62DD; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
890
+ payload: 'color: White; background: #3748B8; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
891
+ json: 'color: White; background: #388AB8; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
892
+ schema: 'color: White; background: #268047; font-weight: bold; padding: 1px 4px; border-radius: 2px;',
893
+ schemaVersion: 'color: White; background: #80265F; font-weight: bold; padding: 1px 4px; border-radius: 2px;'
894
+ };
895
+ var debug = function (style, message, extra) {
896
+ var _a = extra !== null && extra !== void 0 ? extra : [''], extraMessage = _a[0], rest = _a.slice(1);
897
+ LOG.debug.apply(LOG, __spreadArray(["v".concat(version, " %c").concat(tracker.namespace, "%c %c%s") + extraMessage,
898
+ colours.snowplowPurple,
899
+ '',
900
+ style,
901
+ message], rest, false));
902
+ };
903
+ function jsonInterceptor(encodeBase64) {
904
+ var log = function (jsonType, data) {
905
+ var schemaParts = getSchemaParts(data['schema']);
906
+ debug(colours.event(), 'Event', [
907
+ '%c%s%c%s%c%s\n%o',
908
+ colours.json,
909
+ "".concat(jsonType, ": ").concat(schemaParts ? schemaParts[1] : 'Unknown Schema'),
910
+ colours.schemaVersion,
911
+ schemaParts ? "Version: ".concat(schemaParts[2], "-").concat(schemaParts[3], "-").concat(schemaParts[4]) : 'Unknown Schema Version',
912
+ colours.schema,
913
+ schemaParts ? "Vendor: ".concat(schemaParts[0]) : 'Unknown Vendor',
914
+ data['data'],
915
+ ]);
916
+ };
917
+ return function (payloadBuilder, jsonForProcessing, contextEntitiesForProcessing) {
918
+ if (jsonForProcessing.length) {
919
+ var _loop_1 = function (json) {
920
+ var data = json.json['data'];
921
+ if (Array.isArray(data)) {
922
+ data.forEach(function (d) {
923
+ log(getJsonType(json), d);
924
+ });
925
+ }
926
+ else {
927
+ log(getJsonType(json), data);
928
+ }
929
+ };
930
+ for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) {
931
+ var json = jsonForProcessing_1[_i];
932
+ _loop_1(json);
933
+ }
934
+ }
935
+ if (contextEntitiesForProcessing.length) {
936
+ for (var _a = 0, contextEntitiesForProcessing_1 = contextEntitiesForProcessing; _a < contextEntitiesForProcessing_1.length; _a++) {
937
+ var entity = contextEntitiesForProcessing_1[_a];
938
+ log('Context', entity);
939
+ }
940
+ }
941
+ return payloadJsonProcessor(encodeBase64)(payloadBuilder, jsonForProcessing, contextEntitiesForProcessing);
942
+ };
943
+ }
944
+ return {
945
+ logger: function (logger) {
946
+ LOG = logger;
947
+ logger.setLogLevel(logLevel);
948
+ },
949
+ activateBrowserPlugin: function (t) {
950
+ tracker = t;
951
+ debug(colours.activated, 'Tracker Activated');
952
+ },
953
+ beforeTrack: function (payloadBuilder) {
954
+ eventColour = randomcolor({ luminosity: 'dark' });
955
+ payloadBuilder.withJsonProcessor(jsonInterceptor(tracker.core.getBase64Encoding()));
956
+ debug(colours.event(), 'Event', ['%c%s', colours.snowplowPurple, getEventType(payloadBuilder)]);
957
+ payloadBuilder.build();
958
+ },
959
+ afterTrack: function (payload) {
960
+ debug(colours.event(), 'Event', ['%c%s\n%o', colours.payload, 'Payload', payload]);
961
+ }
962
+ };
963
+ }
964
+ function getJsonType(json) {
965
+ switch (json.keyIfEncoded) {
966
+ case 'cx':
967
+ return 'Context';
968
+ case 'ue_px':
969
+ return 'Self Describing';
970
+ default:
971
+ return "".concat(json.keyIfEncoded, ", ").concat(json.keyIfNotEncoded);
972
+ }
973
+ }
974
+ function getEventType(payloadBuilder) {
975
+ var payload = payloadBuilder.getPayload();
976
+ switch (payload['e']) {
977
+ case 'pv':
978
+ return 'Page View';
979
+ case 'pp':
980
+ return 'Page Ping';
981
+ case 'tr':
982
+ return 'Ecommerce Transaction';
983
+ case 'ti':
984
+ return 'Ecommerce Transaction Item';
985
+ case 'se':
986
+ return 'Structured Event';
987
+ case 'ue':
988
+ return 'Self Describing';
989
+ default:
990
+ return typeof payload['e'] === 'string' ? payload['e'] : 'Invalid';
991
+ }
992
+ }
993
+
994
+ exports.DebuggerPlugin = DebuggerPlugin;
990
995
 
991
- Object.defineProperty(exports, '__esModule', { value: true });
996
+ Object.defineProperty(exports, '__esModule', { value: true });
992
997
 
993
998
  }));
994
999
  //# sourceMappingURL=index.umd.js.map