@record-evolution/widget-mapbox 1.4.11

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.
@@ -0,0 +1,2617 @@
1
+ /* @license Copyright (c) 2023 Record Evolution GmbH. All rights reserved.*/
2
+ import mapboxgl from 'https://esm.run/mapbox-gl@3.0.1';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise, SuppressedError, Symbol */
19
+
20
+ function __decorate(decorators, target, key, desc) {
21
+ var c = arguments.length,
22
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
23
+ d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
26
+ }
27
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
28
+ var e = new Error(message);
29
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
30
+ };
31
+
32
+ /**
33
+ * @license
34
+ * Copyright 2019 Google LLC
35
+ * SPDX-License-Identifier: BSD-3-Clause
36
+ */
37
+ const t$3 = globalThis,
38
+ e$3 = t$3.ShadowRoot && (void 0 === t$3.ShadyCSS || t$3.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype,
39
+ s$3 = Symbol(),
40
+ o$3 = new WeakMap();
41
+ let n$3 = class n {
42
+ constructor(t, e, o) {
43
+ if (this._$cssResult$ = !0, o !== s$3) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
44
+ this.cssText = t, this.t = e;
45
+ }
46
+ get styleSheet() {
47
+ let t = this.o;
48
+ const s = this.t;
49
+ if (e$3 && void 0 === t) {
50
+ const e = void 0 !== s && 1 === s.length;
51
+ e && (t = o$3.get(s)), void 0 === t && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), e && o$3.set(s, t));
52
+ }
53
+ return t;
54
+ }
55
+ toString() {
56
+ return this.cssText;
57
+ }
58
+ };
59
+ const r$6 = t => new n$3("string" == typeof t ? t : t + "", void 0, s$3),
60
+ i$3 = (t, ...e) => {
61
+ const o = 1 === t.length ? t[0] : e.reduce((e, s, o) => e + (t => {
62
+ if (!0 === t._$cssResult$) return t.cssText;
63
+ if ("number" == typeof t) return t;
64
+ throw Error("Value passed to 'css' function must be a 'css' function result: " + t + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
65
+ })(s) + t[o + 1], t[0]);
66
+ return new n$3(o, t, s$3);
67
+ },
68
+ S$1 = (s, o) => {
69
+ if (e$3) s.adoptedStyleSheets = o.map(t => t instanceof CSSStyleSheet ? t : t.styleSheet);else for (const e of o) {
70
+ const o = document.createElement("style"),
71
+ n = t$3.litNonce;
72
+ void 0 !== n && o.setAttribute("nonce", n), o.textContent = e.cssText, s.appendChild(o);
73
+ }
74
+ },
75
+ c$3 = e$3 ? t => t : t => t instanceof CSSStyleSheet ? (t => {
76
+ let e = "";
77
+ for (const s of t.cssRules) e += s.cssText;
78
+ return r$6(e);
79
+ })(t) : t;
80
+
81
+ /**
82
+ * @license
83
+ * Copyright 2017 Google LLC
84
+ * SPDX-License-Identifier: BSD-3-Clause
85
+ */
86
+ const {
87
+ is: i$2,
88
+ defineProperty: e$2,
89
+ getOwnPropertyDescriptor: r$5,
90
+ getOwnPropertyNames: h$2,
91
+ getOwnPropertySymbols: o$2,
92
+ getPrototypeOf: n$2
93
+ } = Object,
94
+ a$1 = globalThis,
95
+ c$2 = a$1.trustedTypes,
96
+ l$1 = c$2 ? c$2.emptyScript : "",
97
+ p$2 = a$1.reactiveElementPolyfillSupport,
98
+ d$1 = (t, s) => t,
99
+ u$3 = {
100
+ toAttribute(t, s) {
101
+ switch (s) {
102
+ case Boolean:
103
+ t = t ? l$1 : null;
104
+ break;
105
+ case Object:
106
+ case Array:
107
+ t = null == t ? t : JSON.stringify(t);
108
+ }
109
+ return t;
110
+ },
111
+ fromAttribute(t, s) {
112
+ let i = t;
113
+ switch (s) {
114
+ case Boolean:
115
+ i = null !== t;
116
+ break;
117
+ case Number:
118
+ i = null === t ? null : Number(t);
119
+ break;
120
+ case Object:
121
+ case Array:
122
+ try {
123
+ i = JSON.parse(t);
124
+ } catch (t) {
125
+ i = null;
126
+ }
127
+ }
128
+ return i;
129
+ }
130
+ },
131
+ f$1 = (t, s) => !i$2(t, s),
132
+ y$1 = {
133
+ attribute: !0,
134
+ type: String,
135
+ converter: u$3,
136
+ reflect: !1,
137
+ hasChanged: f$1
138
+ };
139
+ Symbol.metadata ??= Symbol("metadata"), a$1.litPropertyMetadata ??= new WeakMap();
140
+ class b extends HTMLElement {
141
+ static addInitializer(t) {
142
+ this._$Ei(), (this.l ??= []).push(t);
143
+ }
144
+ static get observedAttributes() {
145
+ return this.finalize(), this._$Eh && [...this._$Eh.keys()];
146
+ }
147
+ static createProperty(t, s = y$1) {
148
+ if (s.state && (s.attribute = !1), this._$Ei(), this.elementProperties.set(t, s), !s.noAccessor) {
149
+ const i = Symbol(),
150
+ r = this.getPropertyDescriptor(t, i, s);
151
+ void 0 !== r && e$2(this.prototype, t, r);
152
+ }
153
+ }
154
+ static getPropertyDescriptor(t, s, i) {
155
+ const {
156
+ get: e,
157
+ set: h
158
+ } = r$5(this.prototype, t) ?? {
159
+ get() {
160
+ return this[s];
161
+ },
162
+ set(t) {
163
+ this[s] = t;
164
+ }
165
+ };
166
+ return {
167
+ get() {
168
+ return e?.call(this);
169
+ },
170
+ set(s) {
171
+ const r = e?.call(this);
172
+ h.call(this, s), this.requestUpdate(t, r, i);
173
+ },
174
+ configurable: !0,
175
+ enumerable: !0
176
+ };
177
+ }
178
+ static getPropertyOptions(t) {
179
+ return this.elementProperties.get(t) ?? y$1;
180
+ }
181
+ static _$Ei() {
182
+ if (this.hasOwnProperty(d$1("elementProperties"))) return;
183
+ const t = n$2(this);
184
+ t.finalize(), void 0 !== t.l && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
185
+ }
186
+ static finalize() {
187
+ if (this.hasOwnProperty(d$1("finalized"))) return;
188
+ if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(d$1("properties"))) {
189
+ const t = this.properties,
190
+ s = [...h$2(t), ...o$2(t)];
191
+ for (const i of s) this.createProperty(i, t[i]);
192
+ }
193
+ const t = this[Symbol.metadata];
194
+ if (null !== t) {
195
+ const s = litPropertyMetadata.get(t);
196
+ if (void 0 !== s) for (const [t, i] of s) this.elementProperties.set(t, i);
197
+ }
198
+ this._$Eh = new Map();
199
+ for (const [t, s] of this.elementProperties) {
200
+ const i = this._$Eu(t, s);
201
+ void 0 !== i && this._$Eh.set(i, t);
202
+ }
203
+ this.elementStyles = this.finalizeStyles(this.styles);
204
+ }
205
+ static finalizeStyles(s) {
206
+ const i = [];
207
+ if (Array.isArray(s)) {
208
+ const e = new Set(s.flat(1 / 0).reverse());
209
+ for (const s of e) i.unshift(c$3(s));
210
+ } else void 0 !== s && i.push(c$3(s));
211
+ return i;
212
+ }
213
+ static _$Eu(t, s) {
214
+ const i = s.attribute;
215
+ return !1 === i ? void 0 : "string" == typeof i ? i : "string" == typeof t ? t.toLowerCase() : void 0;
216
+ }
217
+ constructor() {
218
+ super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
219
+ }
220
+ _$Ev() {
221
+ this._$Eg = new Promise(t => this.enableUpdating = t), this._$AL = new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach(t => t(this));
222
+ }
223
+ addController(t) {
224
+ (this._$ES ??= []).push(t), void 0 !== this.renderRoot && this.isConnected && t.hostConnected?.();
225
+ }
226
+ removeController(t) {
227
+ this._$ES?.splice(this._$ES.indexOf(t) >>> 0, 1);
228
+ }
229
+ _$E_() {
230
+ const t = new Map(),
231
+ s = this.constructor.elementProperties;
232
+ for (const i of s.keys()) this.hasOwnProperty(i) && (t.set(i, this[i]), delete this[i]);
233
+ t.size > 0 && (this._$Ep = t);
234
+ }
235
+ createRenderRoot() {
236
+ const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
237
+ return S$1(t, this.constructor.elementStyles), t;
238
+ }
239
+ connectedCallback() {
240
+ this.renderRoot ??= this.createRenderRoot(), this.enableUpdating(!0), this._$ES?.forEach(t => t.hostConnected?.());
241
+ }
242
+ enableUpdating(t) {}
243
+ disconnectedCallback() {
244
+ this._$ES?.forEach(t => t.hostDisconnected?.());
245
+ }
246
+ attributeChangedCallback(t, s, i) {
247
+ this._$AK(t, i);
248
+ }
249
+ _$EO(t, s) {
250
+ const i = this.constructor.elementProperties.get(t),
251
+ e = this.constructor._$Eu(t, i);
252
+ if (void 0 !== e && !0 === i.reflect) {
253
+ const r = (void 0 !== i.converter?.toAttribute ? i.converter : u$3).toAttribute(s, i.type);
254
+ this._$Em = t, null == r ? this.removeAttribute(e) : this.setAttribute(e, r), this._$Em = null;
255
+ }
256
+ }
257
+ _$AK(t, s) {
258
+ const i = this.constructor,
259
+ e = i._$Eh.get(t);
260
+ if (void 0 !== e && this._$Em !== e) {
261
+ const t = i.getPropertyOptions(e),
262
+ r = "function" == typeof t.converter ? {
263
+ fromAttribute: t.converter
264
+ } : void 0 !== t.converter?.fromAttribute ? t.converter : u$3;
265
+ this._$Em = e, this[e] = r.fromAttribute(s, t.type), this._$Em = null;
266
+ }
267
+ }
268
+ requestUpdate(t, s, i, e = !1, r) {
269
+ if (void 0 !== t) {
270
+ if (i ??= this.constructor.getPropertyOptions(t), !(i.hasChanged ?? f$1)(e ? r : this[t], s)) return;
271
+ this.C(t, s, i);
272
+ }
273
+ !1 === this.isUpdatePending && (this._$Eg = this._$EP());
274
+ }
275
+ C(t, s, i) {
276
+ this._$AL.has(t) || this._$AL.set(t, s), !0 === i.reflect && this._$Em !== t && (this._$Ej ??= new Set()).add(t);
277
+ }
278
+ async _$EP() {
279
+ this.isUpdatePending = !0;
280
+ try {
281
+ await this._$Eg;
282
+ } catch (t) {
283
+ Promise.reject(t);
284
+ }
285
+ const t = this.scheduleUpdate();
286
+ return null != t && (await t), !this.isUpdatePending;
287
+ }
288
+ scheduleUpdate() {
289
+ return this.performUpdate();
290
+ }
291
+ performUpdate() {
292
+ if (!this.isUpdatePending) return;
293
+ if (!this.hasUpdated) {
294
+ if (this._$Ep) {
295
+ for (const [t, s] of this._$Ep) this[t] = s;
296
+ this._$Ep = void 0;
297
+ }
298
+ const t = this.constructor.elementProperties;
299
+ if (t.size > 0) for (const [s, i] of t) !0 !== i.wrapped || this._$AL.has(s) || void 0 === this[s] || this.C(s, this[s], i);
300
+ }
301
+ let t = !1;
302
+ const s = this._$AL;
303
+ try {
304
+ t = this.shouldUpdate(s), t ? (this.willUpdate(s), this._$ES?.forEach(t => t.hostUpdate?.()), this.update(s)) : this._$ET();
305
+ } catch (s) {
306
+ throw t = !1, this._$ET(), s;
307
+ }
308
+ t && this._$AE(s);
309
+ }
310
+ willUpdate(t) {}
311
+ _$AE(t) {
312
+ this._$ES?.forEach(t => t.hostUpdated?.()), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
313
+ }
314
+ _$ET() {
315
+ this._$AL = new Map(), this.isUpdatePending = !1;
316
+ }
317
+ get updateComplete() {
318
+ return this.getUpdateComplete();
319
+ }
320
+ getUpdateComplete() {
321
+ return this._$Eg;
322
+ }
323
+ shouldUpdate(t) {
324
+ return !0;
325
+ }
326
+ update(t) {
327
+ this._$Ej &&= this._$Ej.forEach(t => this._$EO(t, this[t])), this._$ET();
328
+ }
329
+ updated(t) {}
330
+ firstUpdated(t) {}
331
+ }
332
+ b.elementStyles = [], b.shadowRootOptions = {
333
+ mode: "open"
334
+ }, b[d$1("elementProperties")] = new Map(), b[d$1("finalized")] = new Map(), p$2?.({
335
+ ReactiveElement: b
336
+ }), (a$1.reactiveElementVersions ??= []).push("2.0.1");
337
+
338
+ /**
339
+ * @license
340
+ * Copyright 2017 Google LLC
341
+ * SPDX-License-Identifier: BSD-3-Clause
342
+ */
343
+ const t$2 = globalThis,
344
+ i$1 = t$2.trustedTypes,
345
+ s$2 = i$1 ? i$1.createPolicy("lit-html", {
346
+ createHTML: t => t
347
+ }) : void 0,
348
+ e$1 = "$lit$",
349
+ h$1 = `lit$${(Math.random() + "").slice(9)}$`,
350
+ o$1 = "?" + h$1,
351
+ n$1 = `<${o$1}>`,
352
+ r$4 = document,
353
+ l = () => r$4.createComment(""),
354
+ c$1 = t => null === t || "object" != typeof t && "function" != typeof t,
355
+ a = Array.isArray,
356
+ u$2 = t => a(t) || "function" == typeof t?.[Symbol.iterator],
357
+ d = "[ \t\n\f\r]",
358
+ f = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,
359
+ v$1 = /-->/g,
360
+ _ = />/g,
361
+ m$1 = RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`, "g"),
362
+ p$1 = /'/g,
363
+ g = /"/g,
364
+ $ = /^(?:script|style|textarea|title)$/i,
365
+ y = t => (i, ...s) => ({
366
+ _$litType$: t,
367
+ strings: i,
368
+ values: s
369
+ }),
370
+ x = y(1),
371
+ w = Symbol.for("lit-noChange"),
372
+ T = Symbol.for("lit-nothing"),
373
+ A = new WeakMap(),
374
+ E = r$4.createTreeWalker(r$4, 129);
375
+ function C(t, i) {
376
+ if (!Array.isArray(t) || !t.hasOwnProperty("raw")) throw Error("invalid template strings array");
377
+ return void 0 !== s$2 ? s$2.createHTML(i) : i;
378
+ }
379
+ const P = (t, i) => {
380
+ const s = t.length - 1,
381
+ o = [];
382
+ let r,
383
+ l = 2 === i ? "<svg>" : "",
384
+ c = f;
385
+ for (let i = 0; i < s; i++) {
386
+ const s = t[i];
387
+ let a,
388
+ u,
389
+ d = -1,
390
+ y = 0;
391
+ for (; y < s.length && (c.lastIndex = y, u = c.exec(s), null !== u);) y = c.lastIndex, c === f ? "!--" === u[1] ? c = v$1 : void 0 !== u[1] ? c = _ : void 0 !== u[2] ? ($.test(u[2]) && (r = RegExp("</" + u[2], "g")), c = m$1) : void 0 !== u[3] && (c = m$1) : c === m$1 ? ">" === u[0] ? (c = r ?? f, d = -1) : void 0 === u[1] ? d = -2 : (d = c.lastIndex - u[2].length, a = u[1], c = void 0 === u[3] ? m$1 : '"' === u[3] ? g : p$1) : c === g || c === p$1 ? c = m$1 : c === v$1 || c === _ ? c = f : (c = m$1, r = void 0);
392
+ const x = c === m$1 && t[i + 1].startsWith("/>") ? " " : "";
393
+ l += c === f ? s + n$1 : d >= 0 ? (o.push(a), s.slice(0, d) + e$1 + s.slice(d) + h$1 + x) : s + h$1 + (-2 === d ? i : x);
394
+ }
395
+ return [C(t, l + (t[s] || "<?>") + (2 === i ? "</svg>" : "")), o];
396
+ };
397
+ class V {
398
+ constructor({
399
+ strings: t,
400
+ _$litType$: s
401
+ }, n) {
402
+ let r;
403
+ this.parts = [];
404
+ let c = 0,
405
+ a = 0;
406
+ const u = t.length - 1,
407
+ d = this.parts,
408
+ [f, v] = P(t, s);
409
+ if (this.el = V.createElement(f, n), E.currentNode = this.el.content, 2 === s) {
410
+ const t = this.el.content.firstChild;
411
+ t.replaceWith(...t.childNodes);
412
+ }
413
+ for (; null !== (r = E.nextNode()) && d.length < u;) {
414
+ if (1 === r.nodeType) {
415
+ if (r.hasAttributes()) for (const t of r.getAttributeNames()) if (t.endsWith(e$1)) {
416
+ const i = v[a++],
417
+ s = r.getAttribute(t).split(h$1),
418
+ e = /([.?@])?(.*)/.exec(i);
419
+ d.push({
420
+ type: 1,
421
+ index: c,
422
+ name: e[2],
423
+ strings: s,
424
+ ctor: "." === e[1] ? k : "?" === e[1] ? H : "@" === e[1] ? I : R
425
+ }), r.removeAttribute(t);
426
+ } else t.startsWith(h$1) && (d.push({
427
+ type: 6,
428
+ index: c
429
+ }), r.removeAttribute(t));
430
+ if ($.test(r.tagName)) {
431
+ const t = r.textContent.split(h$1),
432
+ s = t.length - 1;
433
+ if (s > 0) {
434
+ r.textContent = i$1 ? i$1.emptyScript : "";
435
+ for (let i = 0; i < s; i++) r.append(t[i], l()), E.nextNode(), d.push({
436
+ type: 2,
437
+ index: ++c
438
+ });
439
+ r.append(t[s], l());
440
+ }
441
+ }
442
+ } else if (8 === r.nodeType) if (r.data === o$1) d.push({
443
+ type: 2,
444
+ index: c
445
+ });else {
446
+ let t = -1;
447
+ for (; -1 !== (t = r.data.indexOf(h$1, t + 1));) d.push({
448
+ type: 7,
449
+ index: c
450
+ }), t += h$1.length - 1;
451
+ }
452
+ c++;
453
+ }
454
+ }
455
+ static createElement(t, i) {
456
+ const s = r$4.createElement("template");
457
+ return s.innerHTML = t, s;
458
+ }
459
+ }
460
+ function N(t, i, s = t, e) {
461
+ if (i === w) return i;
462
+ let h = void 0 !== e ? s._$Co?.[e] : s._$Cl;
463
+ const o = c$1(i) ? void 0 : i._$litDirective$;
464
+ return h?.constructor !== o && (h?._$AO?.(!1), void 0 === o ? h = void 0 : (h = new o(t), h._$AT(t, s, e)), void 0 !== e ? (s._$Co ??= [])[e] = h : s._$Cl = h), void 0 !== h && (i = N(t, h._$AS(t, i.values), h, e)), i;
465
+ }
466
+ class S {
467
+ constructor(t, i) {
468
+ this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = i;
469
+ }
470
+ get parentNode() {
471
+ return this._$AM.parentNode;
472
+ }
473
+ get _$AU() {
474
+ return this._$AM._$AU;
475
+ }
476
+ u(t) {
477
+ const {
478
+ el: {
479
+ content: i
480
+ },
481
+ parts: s
482
+ } = this._$AD,
483
+ e = (t?.creationScope ?? r$4).importNode(i, !0);
484
+ E.currentNode = e;
485
+ let h = E.nextNode(),
486
+ o = 0,
487
+ n = 0,
488
+ l = s[0];
489
+ for (; void 0 !== l;) {
490
+ if (o === l.index) {
491
+ let i;
492
+ 2 === l.type ? i = new M(h, h.nextSibling, this, t) : 1 === l.type ? i = new l.ctor(h, l.name, l.strings, this, t) : 6 === l.type && (i = new L(h, this, t)), this._$AV.push(i), l = s[++n];
493
+ }
494
+ o !== l?.index && (h = E.nextNode(), o++);
495
+ }
496
+ return E.currentNode = r$4, e;
497
+ }
498
+ p(t) {
499
+ let i = 0;
500
+ for (const s of this._$AV) void 0 !== s && (void 0 !== s.strings ? (s._$AI(t, s, i), i += s.strings.length - 2) : s._$AI(t[i])), i++;
501
+ }
502
+ }
503
+ class M {
504
+ get _$AU() {
505
+ return this._$AM?._$AU ?? this._$Cv;
506
+ }
507
+ constructor(t, i, s, e) {
508
+ this.type = 2, this._$AH = T, this._$AN = void 0, this._$AA = t, this._$AB = i, this._$AM = s, this.options = e, this._$Cv = e?.isConnected ?? !0;
509
+ }
510
+ get parentNode() {
511
+ let t = this._$AA.parentNode;
512
+ const i = this._$AM;
513
+ return void 0 !== i && 11 === t?.nodeType && (t = i.parentNode), t;
514
+ }
515
+ get startNode() {
516
+ return this._$AA;
517
+ }
518
+ get endNode() {
519
+ return this._$AB;
520
+ }
521
+ _$AI(t, i = this) {
522
+ t = N(this, t, i), c$1(t) ? t === T || null == t || "" === t ? (this._$AH !== T && this._$AR(), this._$AH = T) : t !== this._$AH && t !== w && this._(t) : void 0 !== t._$litType$ ? this.g(t) : void 0 !== t.nodeType ? this.$(t) : u$2(t) ? this.T(t) : this._(t);
523
+ }
524
+ k(t) {
525
+ return this._$AA.parentNode.insertBefore(t, this._$AB);
526
+ }
527
+ $(t) {
528
+ this._$AH !== t && (this._$AR(), this._$AH = this.k(t));
529
+ }
530
+ _(t) {
531
+ this._$AH !== T && c$1(this._$AH) ? this._$AA.nextSibling.data = t : this.$(r$4.createTextNode(t)), this._$AH = t;
532
+ }
533
+ g(t) {
534
+ const {
535
+ values: i,
536
+ _$litType$: s
537
+ } = t,
538
+ e = "number" == typeof s ? this._$AC(t) : (void 0 === s.el && (s.el = V.createElement(C(s.h, s.h[0]), this.options)), s);
539
+ if (this._$AH?._$AD === e) this._$AH.p(i);else {
540
+ const t = new S(e, this),
541
+ s = t.u(this.options);
542
+ t.p(i), this.$(s), this._$AH = t;
543
+ }
544
+ }
545
+ _$AC(t) {
546
+ let i = A.get(t.strings);
547
+ return void 0 === i && A.set(t.strings, i = new V(t)), i;
548
+ }
549
+ T(t) {
550
+ a(this._$AH) || (this._$AH = [], this._$AR());
551
+ const i = this._$AH;
552
+ let s,
553
+ e = 0;
554
+ for (const h of t) e === i.length ? i.push(s = new M(this.k(l()), this.k(l()), this, this.options)) : s = i[e], s._$AI(h), e++;
555
+ e < i.length && (this._$AR(s && s._$AB.nextSibling, e), i.length = e);
556
+ }
557
+ _$AR(t = this._$AA.nextSibling, i) {
558
+ for (this._$AP?.(!1, !0, i); t && t !== this._$AB;) {
559
+ const i = t.nextSibling;
560
+ t.remove(), t = i;
561
+ }
562
+ }
563
+ setConnected(t) {
564
+ void 0 === this._$AM && (this._$Cv = t, this._$AP?.(t));
565
+ }
566
+ }
567
+ class R {
568
+ get tagName() {
569
+ return this.element.tagName;
570
+ }
571
+ get _$AU() {
572
+ return this._$AM._$AU;
573
+ }
574
+ constructor(t, i, s, e, h) {
575
+ this.type = 1, this._$AH = T, this._$AN = void 0, this.element = t, this.name = i, this._$AM = e, this.options = h, s.length > 2 || "" !== s[0] || "" !== s[1] ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = T;
576
+ }
577
+ _$AI(t, i = this, s, e) {
578
+ const h = this.strings;
579
+ let o = !1;
580
+ if (void 0 === h) t = N(this, t, i, 0), o = !c$1(t) || t !== this._$AH && t !== w, o && (this._$AH = t);else {
581
+ const e = t;
582
+ let n, r;
583
+ for (t = h[0], n = 0; n < h.length - 1; n++) r = N(this, e[s + n], i, n), r === w && (r = this._$AH[n]), o ||= !c$1(r) || r !== this._$AH[n], r === T ? t = T : t !== T && (t += (r ?? "") + h[n + 1]), this._$AH[n] = r;
584
+ }
585
+ o && !e && this.O(t);
586
+ }
587
+ O(t) {
588
+ t === T ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
589
+ }
590
+ }
591
+ class k extends R {
592
+ constructor() {
593
+ super(...arguments), this.type = 3;
594
+ }
595
+ O(t) {
596
+ this.element[this.name] = t === T ? void 0 : t;
597
+ }
598
+ }
599
+ class H extends R {
600
+ constructor() {
601
+ super(...arguments), this.type = 4;
602
+ }
603
+ O(t) {
604
+ this.element.toggleAttribute(this.name, !!t && t !== T);
605
+ }
606
+ }
607
+ class I extends R {
608
+ constructor(t, i, s, e, h) {
609
+ super(t, i, s, e, h), this.type = 5;
610
+ }
611
+ _$AI(t, i = this) {
612
+ if ((t = N(this, t, i, 0) ?? T) === w) return;
613
+ const s = this._$AH,
614
+ e = t === T && s !== T || t.capture !== s.capture || t.once !== s.once || t.passive !== s.passive,
615
+ h = t !== T && (s === T || e);
616
+ e && this.element.removeEventListener(this.name, this, s), h && this.element.addEventListener(this.name, this, t), this._$AH = t;
617
+ }
618
+ handleEvent(t) {
619
+ "function" == typeof this._$AH ? this._$AH.call(this.options?.host ?? this.element, t) : this._$AH.handleEvent(t);
620
+ }
621
+ }
622
+ class L {
623
+ constructor(t, i, s) {
624
+ this.element = t, this.type = 6, this._$AN = void 0, this._$AM = i, this.options = s;
625
+ }
626
+ get _$AU() {
627
+ return this._$AM._$AU;
628
+ }
629
+ _$AI(t) {
630
+ N(this, t);
631
+ }
632
+ }
633
+ const z = {
634
+ j: e$1,
635
+ P: h$1,
636
+ A: o$1,
637
+ C: 1,
638
+ M: P,
639
+ L: S,
640
+ R: u$2,
641
+ V: N,
642
+ D: M,
643
+ I: R,
644
+ H,
645
+ N: I,
646
+ U: k,
647
+ B: L
648
+ },
649
+ Z = t$2.litHtmlPolyfillSupport;
650
+ Z?.(V, M), (t$2.litHtmlVersions ??= []).push("3.0.2");
651
+ const j = (t, i, s) => {
652
+ const e = s?.renderBefore ?? i;
653
+ let h = e._$litPart$;
654
+ if (void 0 === h) {
655
+ const t = s?.renderBefore ?? null;
656
+ e._$litPart$ = h = new M(i.insertBefore(l(), t), t, void 0, s ?? {});
657
+ }
658
+ return h._$AI(t), h;
659
+ };
660
+
661
+ /**
662
+ * @license
663
+ * Copyright 2017 Google LLC
664
+ * SPDX-License-Identifier: BSD-3-Clause
665
+ */
666
+ let s$1 = class s extends b {
667
+ constructor() {
668
+ super(...arguments), this.renderOptions = {
669
+ host: this
670
+ }, this._$Do = void 0;
671
+ }
672
+ createRenderRoot() {
673
+ const t = super.createRenderRoot();
674
+ return this.renderOptions.renderBefore ??= t.firstChild, t;
675
+ }
676
+ update(t) {
677
+ const i = this.render();
678
+ this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = j(i, this.renderRoot, this.renderOptions);
679
+ }
680
+ connectedCallback() {
681
+ super.connectedCallback(), this._$Do?.setConnected(!0);
682
+ }
683
+ disconnectedCallback() {
684
+ super.disconnectedCallback(), this._$Do?.setConnected(!1);
685
+ }
686
+ render() {
687
+ return w;
688
+ }
689
+ };
690
+ s$1._$litElement$ = !0, s$1[("finalized")] = !0, globalThis.litElementHydrateSupport?.({
691
+ LitElement: s$1
692
+ });
693
+ const r$3 = globalThis.litElementPolyfillSupport;
694
+ r$3?.({
695
+ LitElement: s$1
696
+ });
697
+ (globalThis.litElementVersions ??= []).push("4.0.1");
698
+
699
+ /**
700
+ * @license
701
+ * Copyright 2017 Google LLC
702
+ * SPDX-License-Identifier: BSD-3-Clause
703
+ */
704
+ const o = {
705
+ attribute: !0,
706
+ type: String,
707
+ converter: u$3,
708
+ reflect: !1,
709
+ hasChanged: f$1
710
+ },
711
+ r$2 = (t = o, e, r) => {
712
+ const {
713
+ kind: n,
714
+ metadata: i
715
+ } = r;
716
+ let s = globalThis.litPropertyMetadata.get(i);
717
+ if (void 0 === s && globalThis.litPropertyMetadata.set(i, s = new Map()), s.set(r.name, t), "accessor" === n) {
718
+ const {
719
+ name: o
720
+ } = r;
721
+ return {
722
+ set(r) {
723
+ const n = e.get.call(this);
724
+ e.set.call(this, r), this.requestUpdate(o, n, t);
725
+ },
726
+ init(e) {
727
+ return void 0 !== e && this.C(o, void 0, t), e;
728
+ }
729
+ };
730
+ }
731
+ if ("setter" === n) {
732
+ const {
733
+ name: o
734
+ } = r;
735
+ return function (r) {
736
+ const n = this[o];
737
+ e.call(this, r), this.requestUpdate(o, n, t);
738
+ };
739
+ }
740
+ throw Error("Unsupported decorator location: " + n);
741
+ };
742
+ function n(t) {
743
+ return (e, o) => "object" == typeof o ? r$2(t, e, o) : ((t, e, o) => {
744
+ const r = e.hasOwnProperty(o);
745
+ return e.constructor.createProperty(o, r ? {
746
+ ...t,
747
+ wrapped: !0
748
+ } : t), r ? Object.getOwnPropertyDescriptor(e, o) : void 0;
749
+ })(t, e, o);
750
+ }
751
+
752
+ /**
753
+ * @license
754
+ * Copyright 2017 Google LLC
755
+ * SPDX-License-Identifier: BSD-3-Clause
756
+ */
757
+ function r$1(r) {
758
+ return n({
759
+ ...r,
760
+ state: !0,
761
+ attribute: !1
762
+ });
763
+ }
764
+
765
+ /**
766
+ * @license
767
+ * Copyright 2017 Google LLC
768
+ * SPDX-License-Identifier: BSD-3-Clause
769
+ */
770
+ const t$1 = {
771
+ ATTRIBUTE: 1,
772
+ CHILD: 2,
773
+ PROPERTY: 3,
774
+ BOOLEAN_ATTRIBUTE: 4,
775
+ EVENT: 5,
776
+ ELEMENT: 6
777
+ },
778
+ e = t => (...e) => ({
779
+ _$litDirective$: t,
780
+ values: e
781
+ });
782
+ class i {
783
+ constructor(t) {}
784
+ get _$AU() {
785
+ return this._$AM._$AU;
786
+ }
787
+ _$AT(t, e, i) {
788
+ this._$Ct = t, this._$AM = e, this._$Ci = i;
789
+ }
790
+ _$AS(t, e) {
791
+ return this.update(t, e);
792
+ }
793
+ update(t, e) {
794
+ return this.render(...e);
795
+ }
796
+ }
797
+
798
+ /**
799
+ * @license
800
+ * Copyright 2020 Google LLC
801
+ * SPDX-License-Identifier: BSD-3-Clause
802
+ */
803
+ const {
804
+ D: t
805
+ } = z,
806
+ s = () => document.createComment(""),
807
+ r = (o, i, n) => {
808
+ const e = o._$AA.parentNode,
809
+ l = void 0 === i ? o._$AB : i._$AA;
810
+ if (void 0 === n) {
811
+ const i = e.insertBefore(s(), l),
812
+ c = e.insertBefore(s(), l);
813
+ n = new t(i, c, o, o.options);
814
+ } else {
815
+ const t = n._$AB.nextSibling,
816
+ i = n._$AM,
817
+ c = i !== o;
818
+ if (c) {
819
+ let t;
820
+ n._$AQ?.(o), n._$AM = o, void 0 !== n._$AP && (t = o._$AU) !== i._$AU && n._$AP(t);
821
+ }
822
+ if (t !== l || c) {
823
+ let o = n._$AA;
824
+ for (; o !== t;) {
825
+ const t = o.nextSibling;
826
+ e.insertBefore(o, l), o = t;
827
+ }
828
+ }
829
+ }
830
+ return n;
831
+ },
832
+ v = (o, t, i = o) => (o._$AI(t, i), o),
833
+ u$1 = {},
834
+ m = (o, t = u$1) => o._$AH = t,
835
+ p = o => o._$AH,
836
+ h = o => {
837
+ o._$AP?.(!1, !0);
838
+ let t = o._$AA;
839
+ const i = o._$AB.nextSibling;
840
+ for (; t !== i;) {
841
+ const o = t.nextSibling;
842
+ t.remove(), t = o;
843
+ }
844
+ };
845
+
846
+ /**
847
+ * @license
848
+ * Copyright 2017 Google LLC
849
+ * SPDX-License-Identifier: BSD-3-Clause
850
+ */
851
+ const u = (e, s, t) => {
852
+ const r = new Map();
853
+ for (let l = s; l <= t; l++) r.set(e[l], l);
854
+ return r;
855
+ },
856
+ c = e(class extends i {
857
+ constructor(e) {
858
+ if (super(e), e.type !== t$1.CHILD) throw Error("repeat() can only be used in text expressions");
859
+ }
860
+ ht(e, s, t) {
861
+ let r;
862
+ void 0 === t ? t = s : void 0 !== s && (r = s);
863
+ const l = [],
864
+ o = [];
865
+ let i = 0;
866
+ for (const s of e) l[i] = r ? r(s, i) : i, o[i] = t(s, i), i++;
867
+ return {
868
+ values: o,
869
+ keys: l
870
+ };
871
+ }
872
+ render(e, s, t) {
873
+ return this.ht(e, s, t).values;
874
+ }
875
+ update(s, [t, r$1, c]) {
876
+ const d = p(s),
877
+ {
878
+ values: p$1,
879
+ keys: a
880
+ } = this.ht(t, r$1, c);
881
+ if (!Array.isArray(d)) return this.dt = a, p$1;
882
+ const h$1 = this.dt ??= [],
883
+ v$1 = [];
884
+ let m$1,
885
+ y,
886
+ x = 0,
887
+ j = d.length - 1,
888
+ k = 0,
889
+ w$1 = p$1.length - 1;
890
+ for (; x <= j && k <= w$1;) if (null === d[x]) x++;else if (null === d[j]) j--;else if (h$1[x] === a[k]) v$1[k] = v(d[x], p$1[k]), x++, k++;else if (h$1[j] === a[w$1]) v$1[w$1] = v(d[j], p$1[w$1]), j--, w$1--;else if (h$1[x] === a[w$1]) v$1[w$1] = v(d[x], p$1[w$1]), r(s, v$1[w$1 + 1], d[x]), x++, w$1--;else if (h$1[j] === a[k]) v$1[k] = v(d[j], p$1[k]), r(s, d[x], d[j]), j--, k++;else if (void 0 === m$1 && (m$1 = u(a, k, w$1), y = u(h$1, x, j)), m$1.has(h$1[x])) {
891
+ if (m$1.has(h$1[j])) {
892
+ const e = y.get(a[k]),
893
+ t = void 0 !== e ? d[e] : null;
894
+ if (null === t) {
895
+ const e = r(s, d[x]);
896
+ v(e, p$1[k]), v$1[k] = e;
897
+ } else v$1[k] = v(t, p$1[k]), r(s, d[x], t), d[e] = null;
898
+ k++;
899
+ } else h(d[j]), j--;
900
+ } else h(d[x]), x++;
901
+ for (; k <= w$1;) {
902
+ const e = r(s, v$1[w$1 + 1]);
903
+ v(e, p$1[k]), v$1[k++] = e;
904
+ }
905
+ for (; x <= j;) {
906
+ const e = d[x++];
907
+ null !== e && h(e);
908
+ }
909
+ return this.dt = a, m(s, v$1), w;
910
+ }
911
+ });
912
+
913
+ // This file is autogenerated. It's used to publish ESM to npm.
914
+ function _typeof(obj) {
915
+ "@babel/helpers - typeof";
916
+
917
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
918
+ return typeof obj;
919
+ } : function (obj) {
920
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
921
+ }, _typeof(obj);
922
+ }
923
+
924
+ // https://github.com/bgrins/TinyColor
925
+ // Brian Grinstead, MIT License
926
+
927
+ var trimLeft = /^\s+/;
928
+ var trimRight = /\s+$/;
929
+ function tinycolor(color, opts) {
930
+ color = color ? color : "";
931
+ opts = opts || {};
932
+
933
+ // If input is already a tinycolor, return itself
934
+ if (color instanceof tinycolor) {
935
+ return color;
936
+ }
937
+ // If we are called as a function, call using new instead
938
+ if (!(this instanceof tinycolor)) {
939
+ return new tinycolor(color, opts);
940
+ }
941
+ var rgb = inputToRGB(color);
942
+ this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
943
+ this._gradientType = opts.gradientType;
944
+
945
+ // Don't let the range of [0,255] come back in [0,1].
946
+ // Potentially lose a little bit of precision here, but will fix issues where
947
+ // .5 gets interpreted as half of the total, instead of half of 1
948
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
949
+ if (this._r < 1) this._r = Math.round(this._r);
950
+ if (this._g < 1) this._g = Math.round(this._g);
951
+ if (this._b < 1) this._b = Math.round(this._b);
952
+ this._ok = rgb.ok;
953
+ }
954
+ tinycolor.prototype = {
955
+ isDark: function isDark() {
956
+ return this.getBrightness() < 128;
957
+ },
958
+ isLight: function isLight() {
959
+ return !this.isDark();
960
+ },
961
+ isValid: function isValid() {
962
+ return this._ok;
963
+ },
964
+ getOriginalInput: function getOriginalInput() {
965
+ return this._originalInput;
966
+ },
967
+ getFormat: function getFormat() {
968
+ return this._format;
969
+ },
970
+ getAlpha: function getAlpha() {
971
+ return this._a;
972
+ },
973
+ getBrightness: function getBrightness() {
974
+ //http://www.w3.org/TR/AERT#color-contrast
975
+ var rgb = this.toRgb();
976
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
977
+ },
978
+ getLuminance: function getLuminance() {
979
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
980
+ var rgb = this.toRgb();
981
+ var RsRGB, GsRGB, BsRGB, R, G, B;
982
+ RsRGB = rgb.r / 255;
983
+ GsRGB = rgb.g / 255;
984
+ BsRGB = rgb.b / 255;
985
+ if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
986
+ if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
987
+ if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
988
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
989
+ },
990
+ setAlpha: function setAlpha(value) {
991
+ this._a = boundAlpha(value);
992
+ this._roundA = Math.round(100 * this._a) / 100;
993
+ return this;
994
+ },
995
+ toHsv: function toHsv() {
996
+ var hsv = rgbToHsv(this._r, this._g, this._b);
997
+ return {
998
+ h: hsv.h * 360,
999
+ s: hsv.s,
1000
+ v: hsv.v,
1001
+ a: this._a
1002
+ };
1003
+ },
1004
+ toHsvString: function toHsvString() {
1005
+ var hsv = rgbToHsv(this._r, this._g, this._b);
1006
+ var h = Math.round(hsv.h * 360),
1007
+ s = Math.round(hsv.s * 100),
1008
+ v = Math.round(hsv.v * 100);
1009
+ return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
1010
+ },
1011
+ toHsl: function toHsl() {
1012
+ var hsl = rgbToHsl(this._r, this._g, this._b);
1013
+ return {
1014
+ h: hsl.h * 360,
1015
+ s: hsl.s,
1016
+ l: hsl.l,
1017
+ a: this._a
1018
+ };
1019
+ },
1020
+ toHslString: function toHslString() {
1021
+ var hsl = rgbToHsl(this._r, this._g, this._b);
1022
+ var h = Math.round(hsl.h * 360),
1023
+ s = Math.round(hsl.s * 100),
1024
+ l = Math.round(hsl.l * 100);
1025
+ return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
1026
+ },
1027
+ toHex: function toHex(allow3Char) {
1028
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
1029
+ },
1030
+ toHexString: function toHexString(allow3Char) {
1031
+ return "#" + this.toHex(allow3Char);
1032
+ },
1033
+ toHex8: function toHex8(allow4Char) {
1034
+ return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
1035
+ },
1036
+ toHex8String: function toHex8String(allow4Char) {
1037
+ return "#" + this.toHex8(allow4Char);
1038
+ },
1039
+ toRgb: function toRgb() {
1040
+ return {
1041
+ r: Math.round(this._r),
1042
+ g: Math.round(this._g),
1043
+ b: Math.round(this._b),
1044
+ a: this._a
1045
+ };
1046
+ },
1047
+ toRgbString: function toRgbString() {
1048
+ return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
1049
+ },
1050
+ toPercentageRgb: function toPercentageRgb() {
1051
+ return {
1052
+ r: Math.round(bound01(this._r, 255) * 100) + "%",
1053
+ g: Math.round(bound01(this._g, 255) * 100) + "%",
1054
+ b: Math.round(bound01(this._b, 255) * 100) + "%",
1055
+ a: this._a
1056
+ };
1057
+ },
1058
+ toPercentageRgbString: function toPercentageRgbString() {
1059
+ return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
1060
+ },
1061
+ toName: function toName() {
1062
+ if (this._a === 0) {
1063
+ return "transparent";
1064
+ }
1065
+ if (this._a < 1) {
1066
+ return false;
1067
+ }
1068
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
1069
+ },
1070
+ toFilter: function toFilter(secondColor) {
1071
+ var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
1072
+ var secondHex8String = hex8String;
1073
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
1074
+ if (secondColor) {
1075
+ var s = tinycolor(secondColor);
1076
+ secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
1077
+ }
1078
+ return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
1079
+ },
1080
+ toString: function toString(format) {
1081
+ var formatSet = !!format;
1082
+ format = format || this._format;
1083
+ var formattedString = false;
1084
+ var hasAlpha = this._a < 1 && this._a >= 0;
1085
+ var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
1086
+ if (needsAlphaFormat) {
1087
+ // Special case for "transparent", all other non-alpha formats
1088
+ // will return rgba when there is transparency.
1089
+ if (format === "name" && this._a === 0) {
1090
+ return this.toName();
1091
+ }
1092
+ return this.toRgbString();
1093
+ }
1094
+ if (format === "rgb") {
1095
+ formattedString = this.toRgbString();
1096
+ }
1097
+ if (format === "prgb") {
1098
+ formattedString = this.toPercentageRgbString();
1099
+ }
1100
+ if (format === "hex" || format === "hex6") {
1101
+ formattedString = this.toHexString();
1102
+ }
1103
+ if (format === "hex3") {
1104
+ formattedString = this.toHexString(true);
1105
+ }
1106
+ if (format === "hex4") {
1107
+ formattedString = this.toHex8String(true);
1108
+ }
1109
+ if (format === "hex8") {
1110
+ formattedString = this.toHex8String();
1111
+ }
1112
+ if (format === "name") {
1113
+ formattedString = this.toName();
1114
+ }
1115
+ if (format === "hsl") {
1116
+ formattedString = this.toHslString();
1117
+ }
1118
+ if (format === "hsv") {
1119
+ formattedString = this.toHsvString();
1120
+ }
1121
+ return formattedString || this.toHexString();
1122
+ },
1123
+ clone: function clone() {
1124
+ return tinycolor(this.toString());
1125
+ },
1126
+ _applyModification: function _applyModification(fn, args) {
1127
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
1128
+ this._r = color._r;
1129
+ this._g = color._g;
1130
+ this._b = color._b;
1131
+ this.setAlpha(color._a);
1132
+ return this;
1133
+ },
1134
+ lighten: function lighten() {
1135
+ return this._applyModification(_lighten, arguments);
1136
+ },
1137
+ brighten: function brighten() {
1138
+ return this._applyModification(_brighten, arguments);
1139
+ },
1140
+ darken: function darken() {
1141
+ return this._applyModification(_darken, arguments);
1142
+ },
1143
+ desaturate: function desaturate() {
1144
+ return this._applyModification(_desaturate, arguments);
1145
+ },
1146
+ saturate: function saturate() {
1147
+ return this._applyModification(_saturate, arguments);
1148
+ },
1149
+ greyscale: function greyscale() {
1150
+ return this._applyModification(_greyscale, arguments);
1151
+ },
1152
+ spin: function spin() {
1153
+ return this._applyModification(_spin, arguments);
1154
+ },
1155
+ _applyCombination: function _applyCombination(fn, args) {
1156
+ return fn.apply(null, [this].concat([].slice.call(args)));
1157
+ },
1158
+ analogous: function analogous() {
1159
+ return this._applyCombination(_analogous, arguments);
1160
+ },
1161
+ complement: function complement() {
1162
+ return this._applyCombination(_complement, arguments);
1163
+ },
1164
+ monochromatic: function monochromatic() {
1165
+ return this._applyCombination(_monochromatic, arguments);
1166
+ },
1167
+ splitcomplement: function splitcomplement() {
1168
+ return this._applyCombination(_splitcomplement, arguments);
1169
+ },
1170
+ // Disabled until https://github.com/bgrins/TinyColor/issues/254
1171
+ // polyad: function (number) {
1172
+ // return this._applyCombination(polyad, [number]);
1173
+ // },
1174
+ triad: function triad() {
1175
+ return this._applyCombination(polyad, [3]);
1176
+ },
1177
+ tetrad: function tetrad() {
1178
+ return this._applyCombination(polyad, [4]);
1179
+ }
1180
+ };
1181
+
1182
+ // If input is an object, force 1 into "1.0" to handle ratios properly
1183
+ // String input requires "1.0" as input, so 1 will be treated as 1
1184
+ tinycolor.fromRatio = function (color, opts) {
1185
+ if (_typeof(color) == "object") {
1186
+ var newColor = {};
1187
+ for (var i in color) {
1188
+ if (color.hasOwnProperty(i)) {
1189
+ if (i === "a") {
1190
+ newColor[i] = color[i];
1191
+ } else {
1192
+ newColor[i] = convertToPercentage(color[i]);
1193
+ }
1194
+ }
1195
+ }
1196
+ color = newColor;
1197
+ }
1198
+ return tinycolor(color, opts);
1199
+ };
1200
+
1201
+ // Given a string or object, convert that input to RGB
1202
+ // Possible string inputs:
1203
+ //
1204
+ // "red"
1205
+ // "#f00" or "f00"
1206
+ // "#ff0000" or "ff0000"
1207
+ // "#ff000000" or "ff000000"
1208
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
1209
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
1210
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
1211
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
1212
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
1213
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
1214
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
1215
+ //
1216
+ function inputToRGB(color) {
1217
+ var rgb = {
1218
+ r: 0,
1219
+ g: 0,
1220
+ b: 0
1221
+ };
1222
+ var a = 1;
1223
+ var s = null;
1224
+ var v = null;
1225
+ var l = null;
1226
+ var ok = false;
1227
+ var format = false;
1228
+ if (typeof color == "string") {
1229
+ color = stringInputToObject(color);
1230
+ }
1231
+ if (_typeof(color) == "object") {
1232
+ if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
1233
+ rgb = rgbToRgb(color.r, color.g, color.b);
1234
+ ok = true;
1235
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
1236
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
1237
+ s = convertToPercentage(color.s);
1238
+ v = convertToPercentage(color.v);
1239
+ rgb = hsvToRgb(color.h, s, v);
1240
+ ok = true;
1241
+ format = "hsv";
1242
+ } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
1243
+ s = convertToPercentage(color.s);
1244
+ l = convertToPercentage(color.l);
1245
+ rgb = hslToRgb(color.h, s, l);
1246
+ ok = true;
1247
+ format = "hsl";
1248
+ }
1249
+ if (color.hasOwnProperty("a")) {
1250
+ a = color.a;
1251
+ }
1252
+ }
1253
+ a = boundAlpha(a);
1254
+ return {
1255
+ ok: ok,
1256
+ format: color.format || format,
1257
+ r: Math.min(255, Math.max(rgb.r, 0)),
1258
+ g: Math.min(255, Math.max(rgb.g, 0)),
1259
+ b: Math.min(255, Math.max(rgb.b, 0)),
1260
+ a: a
1261
+ };
1262
+ }
1263
+
1264
+ // Conversion Functions
1265
+ // --------------------
1266
+
1267
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
1268
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
1269
+
1270
+ // `rgbToRgb`
1271
+ // Handle bounds / percentage checking to conform to CSS color spec
1272
+ // <http://www.w3.org/TR/css3-color/>
1273
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
1274
+ // *Returns:* { r, g, b } in [0, 255]
1275
+ function rgbToRgb(r, g, b) {
1276
+ return {
1277
+ r: bound01(r, 255) * 255,
1278
+ g: bound01(g, 255) * 255,
1279
+ b: bound01(b, 255) * 255
1280
+ };
1281
+ }
1282
+
1283
+ // `rgbToHsl`
1284
+ // Converts an RGB color value to HSL.
1285
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
1286
+ // *Returns:* { h, s, l } in [0,1]
1287
+ function rgbToHsl(r, g, b) {
1288
+ r = bound01(r, 255);
1289
+ g = bound01(g, 255);
1290
+ b = bound01(b, 255);
1291
+ var max = Math.max(r, g, b),
1292
+ min = Math.min(r, g, b);
1293
+ var h,
1294
+ s,
1295
+ l = (max + min) / 2;
1296
+ if (max == min) {
1297
+ h = s = 0; // achromatic
1298
+ } else {
1299
+ var d = max - min;
1300
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1301
+ switch (max) {
1302
+ case r:
1303
+ h = (g - b) / d + (g < b ? 6 : 0);
1304
+ break;
1305
+ case g:
1306
+ h = (b - r) / d + 2;
1307
+ break;
1308
+ case b:
1309
+ h = (r - g) / d + 4;
1310
+ break;
1311
+ }
1312
+ h /= 6;
1313
+ }
1314
+ return {
1315
+ h: h,
1316
+ s: s,
1317
+ l: l
1318
+ };
1319
+ }
1320
+
1321
+ // `hslToRgb`
1322
+ // Converts an HSL color value to RGB.
1323
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
1324
+ // *Returns:* { r, g, b } in the set [0, 255]
1325
+ function hslToRgb(h, s, l) {
1326
+ var r, g, b;
1327
+ h = bound01(h, 360);
1328
+ s = bound01(s, 100);
1329
+ l = bound01(l, 100);
1330
+ function hue2rgb(p, q, t) {
1331
+ if (t < 0) t += 1;
1332
+ if (t > 1) t -= 1;
1333
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
1334
+ if (t < 1 / 2) return q;
1335
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
1336
+ return p;
1337
+ }
1338
+ if (s === 0) {
1339
+ r = g = b = l; // achromatic
1340
+ } else {
1341
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1342
+ var p = 2 * l - q;
1343
+ r = hue2rgb(p, q, h + 1 / 3);
1344
+ g = hue2rgb(p, q, h);
1345
+ b = hue2rgb(p, q, h - 1 / 3);
1346
+ }
1347
+ return {
1348
+ r: r * 255,
1349
+ g: g * 255,
1350
+ b: b * 255
1351
+ };
1352
+ }
1353
+
1354
+ // `rgbToHsv`
1355
+ // Converts an RGB color value to HSV
1356
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
1357
+ // *Returns:* { h, s, v } in [0,1]
1358
+ function rgbToHsv(r, g, b) {
1359
+ r = bound01(r, 255);
1360
+ g = bound01(g, 255);
1361
+ b = bound01(b, 255);
1362
+ var max = Math.max(r, g, b),
1363
+ min = Math.min(r, g, b);
1364
+ var h,
1365
+ s,
1366
+ v = max;
1367
+ var d = max - min;
1368
+ s = max === 0 ? 0 : d / max;
1369
+ if (max == min) {
1370
+ h = 0; // achromatic
1371
+ } else {
1372
+ switch (max) {
1373
+ case r:
1374
+ h = (g - b) / d + (g < b ? 6 : 0);
1375
+ break;
1376
+ case g:
1377
+ h = (b - r) / d + 2;
1378
+ break;
1379
+ case b:
1380
+ h = (r - g) / d + 4;
1381
+ break;
1382
+ }
1383
+ h /= 6;
1384
+ }
1385
+ return {
1386
+ h: h,
1387
+ s: s,
1388
+ v: v
1389
+ };
1390
+ }
1391
+
1392
+ // `hsvToRgb`
1393
+ // Converts an HSV color value to RGB.
1394
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
1395
+ // *Returns:* { r, g, b } in the set [0, 255]
1396
+ function hsvToRgb(h, s, v) {
1397
+ h = bound01(h, 360) * 6;
1398
+ s = bound01(s, 100);
1399
+ v = bound01(v, 100);
1400
+ var i = Math.floor(h),
1401
+ f = h - i,
1402
+ p = v * (1 - s),
1403
+ q = v * (1 - f * s),
1404
+ t = v * (1 - (1 - f) * s),
1405
+ mod = i % 6,
1406
+ r = [v, q, p, p, t, v][mod],
1407
+ g = [t, v, v, q, p, p][mod],
1408
+ b = [p, p, t, v, v, q][mod];
1409
+ return {
1410
+ r: r * 255,
1411
+ g: g * 255,
1412
+ b: b * 255
1413
+ };
1414
+ }
1415
+
1416
+ // `rgbToHex`
1417
+ // Converts an RGB color to hex
1418
+ // Assumes r, g, and b are contained in the set [0, 255]
1419
+ // Returns a 3 or 6 character hex
1420
+ function rgbToHex(r, g, b, allow3Char) {
1421
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
1422
+
1423
+ // Return a 3 character hex if possible
1424
+ if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
1425
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
1426
+ }
1427
+ return hex.join("");
1428
+ }
1429
+
1430
+ // `rgbaToHex`
1431
+ // Converts an RGBA color plus alpha transparency to hex
1432
+ // Assumes r, g, b are contained in the set [0, 255] and
1433
+ // a in [0, 1]. Returns a 4 or 8 character rgba hex
1434
+ function rgbaToHex(r, g, b, a, allow4Char) {
1435
+ var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
1436
+
1437
+ // Return a 4 character hex if possible
1438
+ if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
1439
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
1440
+ }
1441
+ return hex.join("");
1442
+ }
1443
+
1444
+ // `rgbaToArgbHex`
1445
+ // Converts an RGBA color to an ARGB Hex8 string
1446
+ // Rarely used, but required for "toFilter()"
1447
+ function rgbaToArgbHex(r, g, b, a) {
1448
+ var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
1449
+ return hex.join("");
1450
+ }
1451
+
1452
+ // `equals`
1453
+ // Can be called with any tinycolor input
1454
+ tinycolor.equals = function (color1, color2) {
1455
+ if (!color1 || !color2) return false;
1456
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
1457
+ };
1458
+ tinycolor.random = function () {
1459
+ return tinycolor.fromRatio({
1460
+ r: Math.random(),
1461
+ g: Math.random(),
1462
+ b: Math.random()
1463
+ });
1464
+ };
1465
+
1466
+ // Modification Functions
1467
+ // ----------------------
1468
+ // Thanks to less.js for some of the basics here
1469
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
1470
+
1471
+ function _desaturate(color, amount) {
1472
+ amount = amount === 0 ? 0 : amount || 10;
1473
+ var hsl = tinycolor(color).toHsl();
1474
+ hsl.s -= amount / 100;
1475
+ hsl.s = clamp01(hsl.s);
1476
+ return tinycolor(hsl);
1477
+ }
1478
+ function _saturate(color, amount) {
1479
+ amount = amount === 0 ? 0 : amount || 10;
1480
+ var hsl = tinycolor(color).toHsl();
1481
+ hsl.s += amount / 100;
1482
+ hsl.s = clamp01(hsl.s);
1483
+ return tinycolor(hsl);
1484
+ }
1485
+ function _greyscale(color) {
1486
+ return tinycolor(color).desaturate(100);
1487
+ }
1488
+ function _lighten(color, amount) {
1489
+ amount = amount === 0 ? 0 : amount || 10;
1490
+ var hsl = tinycolor(color).toHsl();
1491
+ hsl.l += amount / 100;
1492
+ hsl.l = clamp01(hsl.l);
1493
+ return tinycolor(hsl);
1494
+ }
1495
+ function _brighten(color, amount) {
1496
+ amount = amount === 0 ? 0 : amount || 10;
1497
+ var rgb = tinycolor(color).toRgb();
1498
+ rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
1499
+ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
1500
+ rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
1501
+ return tinycolor(rgb);
1502
+ }
1503
+ function _darken(color, amount) {
1504
+ amount = amount === 0 ? 0 : amount || 10;
1505
+ var hsl = tinycolor(color).toHsl();
1506
+ hsl.l -= amount / 100;
1507
+ hsl.l = clamp01(hsl.l);
1508
+ return tinycolor(hsl);
1509
+ }
1510
+
1511
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
1512
+ // Values outside of this range will be wrapped into this range.
1513
+ function _spin(color, amount) {
1514
+ var hsl = tinycolor(color).toHsl();
1515
+ var hue = (hsl.h + amount) % 360;
1516
+ hsl.h = hue < 0 ? 360 + hue : hue;
1517
+ return tinycolor(hsl);
1518
+ }
1519
+
1520
+ // Combination Functions
1521
+ // ---------------------
1522
+ // Thanks to jQuery xColor for some of the ideas behind these
1523
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
1524
+
1525
+ function _complement(color) {
1526
+ var hsl = tinycolor(color).toHsl();
1527
+ hsl.h = (hsl.h + 180) % 360;
1528
+ return tinycolor(hsl);
1529
+ }
1530
+ function polyad(color, number) {
1531
+ if (isNaN(number) || number <= 0) {
1532
+ throw new Error("Argument to polyad must be a positive number");
1533
+ }
1534
+ var hsl = tinycolor(color).toHsl();
1535
+ var result = [tinycolor(color)];
1536
+ var step = 360 / number;
1537
+ for (var i = 1; i < number; i++) {
1538
+ result.push(tinycolor({
1539
+ h: (hsl.h + i * step) % 360,
1540
+ s: hsl.s,
1541
+ l: hsl.l
1542
+ }));
1543
+ }
1544
+ return result;
1545
+ }
1546
+ function _splitcomplement(color) {
1547
+ var hsl = tinycolor(color).toHsl();
1548
+ var h = hsl.h;
1549
+ return [tinycolor(color), tinycolor({
1550
+ h: (h + 72) % 360,
1551
+ s: hsl.s,
1552
+ l: hsl.l
1553
+ }), tinycolor({
1554
+ h: (h + 216) % 360,
1555
+ s: hsl.s,
1556
+ l: hsl.l
1557
+ })];
1558
+ }
1559
+ function _analogous(color, results, slices) {
1560
+ results = results || 6;
1561
+ slices = slices || 30;
1562
+ var hsl = tinycolor(color).toHsl();
1563
+ var part = 360 / slices;
1564
+ var ret = [tinycolor(color)];
1565
+ for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
1566
+ hsl.h = (hsl.h + part) % 360;
1567
+ ret.push(tinycolor(hsl));
1568
+ }
1569
+ return ret;
1570
+ }
1571
+ function _monochromatic(color, results) {
1572
+ results = results || 6;
1573
+ var hsv = tinycolor(color).toHsv();
1574
+ var h = hsv.h,
1575
+ s = hsv.s,
1576
+ v = hsv.v;
1577
+ var ret = [];
1578
+ var modification = 1 / results;
1579
+ while (results--) {
1580
+ ret.push(tinycolor({
1581
+ h: h,
1582
+ s: s,
1583
+ v: v
1584
+ }));
1585
+ v = (v + modification) % 1;
1586
+ }
1587
+ return ret;
1588
+ }
1589
+
1590
+ // Utility Functions
1591
+ // ---------------------
1592
+
1593
+ tinycolor.mix = function (color1, color2, amount) {
1594
+ amount = amount === 0 ? 0 : amount || 50;
1595
+ var rgb1 = tinycolor(color1).toRgb();
1596
+ var rgb2 = tinycolor(color2).toRgb();
1597
+ var p = amount / 100;
1598
+ var rgba = {
1599
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
1600
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
1601
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
1602
+ a: (rgb2.a - rgb1.a) * p + rgb1.a
1603
+ };
1604
+ return tinycolor(rgba);
1605
+ };
1606
+
1607
+ // Readability Functions
1608
+ // ---------------------
1609
+ // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
1610
+
1611
+ // `contrast`
1612
+ // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
1613
+ tinycolor.readability = function (color1, color2) {
1614
+ var c1 = tinycolor(color1);
1615
+ var c2 = tinycolor(color2);
1616
+ return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
1617
+ };
1618
+
1619
+ // `isReadable`
1620
+ // Ensure that foreground and background color combinations meet WCAG2 guidelines.
1621
+ // The third argument is an optional Object.
1622
+ // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
1623
+ // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
1624
+ // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
1625
+
1626
+ // *Example*
1627
+ // tinycolor.isReadable("#000", "#111") => false
1628
+ // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
1629
+ tinycolor.isReadable = function (color1, color2, wcag2) {
1630
+ var readability = tinycolor.readability(color1, color2);
1631
+ var wcag2Parms, out;
1632
+ out = false;
1633
+ wcag2Parms = validateWCAG2Parms(wcag2);
1634
+ switch (wcag2Parms.level + wcag2Parms.size) {
1635
+ case "AAsmall":
1636
+ case "AAAlarge":
1637
+ out = readability >= 4.5;
1638
+ break;
1639
+ case "AAlarge":
1640
+ out = readability >= 3;
1641
+ break;
1642
+ case "AAAsmall":
1643
+ out = readability >= 7;
1644
+ break;
1645
+ }
1646
+ return out;
1647
+ };
1648
+
1649
+ // `mostReadable`
1650
+ // Given a base color and a list of possible foreground or background
1651
+ // colors for that base, returns the most readable color.
1652
+ // Optionally returns Black or White if the most readable color is unreadable.
1653
+ // *Example*
1654
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
1655
+ // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
1656
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
1657
+ // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
1658
+ tinycolor.mostReadable = function (baseColor, colorList, args) {
1659
+ var bestColor = null;
1660
+ var bestScore = 0;
1661
+ var readability;
1662
+ var includeFallbackColors, level, size;
1663
+ args = args || {};
1664
+ includeFallbackColors = args.includeFallbackColors;
1665
+ level = args.level;
1666
+ size = args.size;
1667
+ for (var i = 0; i < colorList.length; i++) {
1668
+ readability = tinycolor.readability(baseColor, colorList[i]);
1669
+ if (readability > bestScore) {
1670
+ bestScore = readability;
1671
+ bestColor = tinycolor(colorList[i]);
1672
+ }
1673
+ }
1674
+ if (tinycolor.isReadable(baseColor, bestColor, {
1675
+ level: level,
1676
+ size: size
1677
+ }) || !includeFallbackColors) {
1678
+ return bestColor;
1679
+ } else {
1680
+ args.includeFallbackColors = false;
1681
+ return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
1682
+ }
1683
+ };
1684
+
1685
+ // Big List of Colors
1686
+ // ------------------
1687
+ // <https://www.w3.org/TR/css-color-4/#named-colors>
1688
+ var names = tinycolor.names = {
1689
+ aliceblue: "f0f8ff",
1690
+ antiquewhite: "faebd7",
1691
+ aqua: "0ff",
1692
+ aquamarine: "7fffd4",
1693
+ azure: "f0ffff",
1694
+ beige: "f5f5dc",
1695
+ bisque: "ffe4c4",
1696
+ black: "000",
1697
+ blanchedalmond: "ffebcd",
1698
+ blue: "00f",
1699
+ blueviolet: "8a2be2",
1700
+ brown: "a52a2a",
1701
+ burlywood: "deb887",
1702
+ burntsienna: "ea7e5d",
1703
+ cadetblue: "5f9ea0",
1704
+ chartreuse: "7fff00",
1705
+ chocolate: "d2691e",
1706
+ coral: "ff7f50",
1707
+ cornflowerblue: "6495ed",
1708
+ cornsilk: "fff8dc",
1709
+ crimson: "dc143c",
1710
+ cyan: "0ff",
1711
+ darkblue: "00008b",
1712
+ darkcyan: "008b8b",
1713
+ darkgoldenrod: "b8860b",
1714
+ darkgray: "a9a9a9",
1715
+ darkgreen: "006400",
1716
+ darkgrey: "a9a9a9",
1717
+ darkkhaki: "bdb76b",
1718
+ darkmagenta: "8b008b",
1719
+ darkolivegreen: "556b2f",
1720
+ darkorange: "ff8c00",
1721
+ darkorchid: "9932cc",
1722
+ darkred: "8b0000",
1723
+ darksalmon: "e9967a",
1724
+ darkseagreen: "8fbc8f",
1725
+ darkslateblue: "483d8b",
1726
+ darkslategray: "2f4f4f",
1727
+ darkslategrey: "2f4f4f",
1728
+ darkturquoise: "00ced1",
1729
+ darkviolet: "9400d3",
1730
+ deeppink: "ff1493",
1731
+ deepskyblue: "00bfff",
1732
+ dimgray: "696969",
1733
+ dimgrey: "696969",
1734
+ dodgerblue: "1e90ff",
1735
+ firebrick: "b22222",
1736
+ floralwhite: "fffaf0",
1737
+ forestgreen: "228b22",
1738
+ fuchsia: "f0f",
1739
+ gainsboro: "dcdcdc",
1740
+ ghostwhite: "f8f8ff",
1741
+ gold: "ffd700",
1742
+ goldenrod: "daa520",
1743
+ gray: "808080",
1744
+ green: "008000",
1745
+ greenyellow: "adff2f",
1746
+ grey: "808080",
1747
+ honeydew: "f0fff0",
1748
+ hotpink: "ff69b4",
1749
+ indianred: "cd5c5c",
1750
+ indigo: "4b0082",
1751
+ ivory: "fffff0",
1752
+ khaki: "f0e68c",
1753
+ lavender: "e6e6fa",
1754
+ lavenderblush: "fff0f5",
1755
+ lawngreen: "7cfc00",
1756
+ lemonchiffon: "fffacd",
1757
+ lightblue: "add8e6",
1758
+ lightcoral: "f08080",
1759
+ lightcyan: "e0ffff",
1760
+ lightgoldenrodyellow: "fafad2",
1761
+ lightgray: "d3d3d3",
1762
+ lightgreen: "90ee90",
1763
+ lightgrey: "d3d3d3",
1764
+ lightpink: "ffb6c1",
1765
+ lightsalmon: "ffa07a",
1766
+ lightseagreen: "20b2aa",
1767
+ lightskyblue: "87cefa",
1768
+ lightslategray: "789",
1769
+ lightslategrey: "789",
1770
+ lightsteelblue: "b0c4de",
1771
+ lightyellow: "ffffe0",
1772
+ lime: "0f0",
1773
+ limegreen: "32cd32",
1774
+ linen: "faf0e6",
1775
+ magenta: "f0f",
1776
+ maroon: "800000",
1777
+ mediumaquamarine: "66cdaa",
1778
+ mediumblue: "0000cd",
1779
+ mediumorchid: "ba55d3",
1780
+ mediumpurple: "9370db",
1781
+ mediumseagreen: "3cb371",
1782
+ mediumslateblue: "7b68ee",
1783
+ mediumspringgreen: "00fa9a",
1784
+ mediumturquoise: "48d1cc",
1785
+ mediumvioletred: "c71585",
1786
+ midnightblue: "191970",
1787
+ mintcream: "f5fffa",
1788
+ mistyrose: "ffe4e1",
1789
+ moccasin: "ffe4b5",
1790
+ navajowhite: "ffdead",
1791
+ navy: "000080",
1792
+ oldlace: "fdf5e6",
1793
+ olive: "808000",
1794
+ olivedrab: "6b8e23",
1795
+ orange: "ffa500",
1796
+ orangered: "ff4500",
1797
+ orchid: "da70d6",
1798
+ palegoldenrod: "eee8aa",
1799
+ palegreen: "98fb98",
1800
+ paleturquoise: "afeeee",
1801
+ palevioletred: "db7093",
1802
+ papayawhip: "ffefd5",
1803
+ peachpuff: "ffdab9",
1804
+ peru: "cd853f",
1805
+ pink: "ffc0cb",
1806
+ plum: "dda0dd",
1807
+ powderblue: "b0e0e6",
1808
+ purple: "800080",
1809
+ rebeccapurple: "663399",
1810
+ red: "f00",
1811
+ rosybrown: "bc8f8f",
1812
+ royalblue: "4169e1",
1813
+ saddlebrown: "8b4513",
1814
+ salmon: "fa8072",
1815
+ sandybrown: "f4a460",
1816
+ seagreen: "2e8b57",
1817
+ seashell: "fff5ee",
1818
+ sienna: "a0522d",
1819
+ silver: "c0c0c0",
1820
+ skyblue: "87ceeb",
1821
+ slateblue: "6a5acd",
1822
+ slategray: "708090",
1823
+ slategrey: "708090",
1824
+ snow: "fffafa",
1825
+ springgreen: "00ff7f",
1826
+ steelblue: "4682b4",
1827
+ tan: "d2b48c",
1828
+ teal: "008080",
1829
+ thistle: "d8bfd8",
1830
+ tomato: "ff6347",
1831
+ turquoise: "40e0d0",
1832
+ violet: "ee82ee",
1833
+ wheat: "f5deb3",
1834
+ white: "fff",
1835
+ whitesmoke: "f5f5f5",
1836
+ yellow: "ff0",
1837
+ yellowgreen: "9acd32"
1838
+ };
1839
+
1840
+ // Make it easy to access colors via `hexNames[hex]`
1841
+ var hexNames = tinycolor.hexNames = flip(names);
1842
+
1843
+ // Utilities
1844
+ // ---------
1845
+
1846
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
1847
+ function flip(o) {
1848
+ var flipped = {};
1849
+ for (var i in o) {
1850
+ if (o.hasOwnProperty(i)) {
1851
+ flipped[o[i]] = i;
1852
+ }
1853
+ }
1854
+ return flipped;
1855
+ }
1856
+
1857
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
1858
+ function boundAlpha(a) {
1859
+ a = parseFloat(a);
1860
+ if (isNaN(a) || a < 0 || a > 1) {
1861
+ a = 1;
1862
+ }
1863
+ return a;
1864
+ }
1865
+
1866
+ // Take input from [0, n] and return it as [0, 1]
1867
+ function bound01(n, max) {
1868
+ if (isOnePointZero(n)) n = "100%";
1869
+ var processPercent = isPercentage(n);
1870
+ n = Math.min(max, Math.max(0, parseFloat(n)));
1871
+
1872
+ // Automatically convert percentage into number
1873
+ if (processPercent) {
1874
+ n = parseInt(n * max, 10) / 100;
1875
+ }
1876
+
1877
+ // Handle floating point rounding errors
1878
+ if (Math.abs(n - max) < 0.000001) {
1879
+ return 1;
1880
+ }
1881
+
1882
+ // Convert into [0, 1] range if it isn't already
1883
+ return n % max / parseFloat(max);
1884
+ }
1885
+
1886
+ // Force a number between 0 and 1
1887
+ function clamp01(val) {
1888
+ return Math.min(1, Math.max(0, val));
1889
+ }
1890
+
1891
+ // Parse a base-16 hex value into a base-10 integer
1892
+ function parseIntFromHex(val) {
1893
+ return parseInt(val, 16);
1894
+ }
1895
+
1896
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
1897
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
1898
+ function isOnePointZero(n) {
1899
+ return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
1900
+ }
1901
+
1902
+ // Check to see if string passed in is a percentage
1903
+ function isPercentage(n) {
1904
+ return typeof n === "string" && n.indexOf("%") != -1;
1905
+ }
1906
+
1907
+ // Force a hex value to have 2 characters
1908
+ function pad2(c) {
1909
+ return c.length == 1 ? "0" + c : "" + c;
1910
+ }
1911
+
1912
+ // Replace a decimal with it's percentage value
1913
+ function convertToPercentage(n) {
1914
+ if (n <= 1) {
1915
+ n = n * 100 + "%";
1916
+ }
1917
+ return n;
1918
+ }
1919
+
1920
+ // Converts a decimal to a hex value
1921
+ function convertDecimalToHex(d) {
1922
+ return Math.round(parseFloat(d) * 255).toString(16);
1923
+ }
1924
+ // Converts a hex value to a decimal
1925
+ function convertHexToDecimal(h) {
1926
+ return parseIntFromHex(h) / 255;
1927
+ }
1928
+ var matchers = function () {
1929
+ // <http://www.w3.org/TR/css3-values/#integers>
1930
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
1931
+
1932
+ // <http://www.w3.org/TR/css3-values/#number-value>
1933
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
1934
+
1935
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
1936
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
1937
+
1938
+ // Actual matching.
1939
+ // Parentheses and commas are optional, but not required.
1940
+ // Whitespace can take the place of commas or opening paren
1941
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1942
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
1943
+ return {
1944
+ CSS_UNIT: new RegExp(CSS_UNIT),
1945
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
1946
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
1947
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
1948
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
1949
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
1950
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
1951
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1952
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
1953
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
1954
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
1955
+ };
1956
+ }();
1957
+
1958
+ // `isValidCSSUnit`
1959
+ // Take in a single string / number and check to see if it looks like a CSS unit
1960
+ // (see `matchers` above for definition).
1961
+ function isValidCSSUnit(color) {
1962
+ return !!matchers.CSS_UNIT.exec(color);
1963
+ }
1964
+
1965
+ // `stringInputToObject`
1966
+ // Permissive string parsing. Take in a number of formats, and output an object
1967
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
1968
+ function stringInputToObject(color) {
1969
+ color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
1970
+ var named = false;
1971
+ if (names[color]) {
1972
+ color = names[color];
1973
+ named = true;
1974
+ } else if (color == "transparent") {
1975
+ return {
1976
+ r: 0,
1977
+ g: 0,
1978
+ b: 0,
1979
+ a: 0,
1980
+ format: "name"
1981
+ };
1982
+ }
1983
+
1984
+ // Try to match string input using regular expressions.
1985
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1986
+ // Just return an object and let the conversion functions handle that.
1987
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
1988
+ var match;
1989
+ if (match = matchers.rgb.exec(color)) {
1990
+ return {
1991
+ r: match[1],
1992
+ g: match[2],
1993
+ b: match[3]
1994
+ };
1995
+ }
1996
+ if (match = matchers.rgba.exec(color)) {
1997
+ return {
1998
+ r: match[1],
1999
+ g: match[2],
2000
+ b: match[3],
2001
+ a: match[4]
2002
+ };
2003
+ }
2004
+ if (match = matchers.hsl.exec(color)) {
2005
+ return {
2006
+ h: match[1],
2007
+ s: match[2],
2008
+ l: match[3]
2009
+ };
2010
+ }
2011
+ if (match = matchers.hsla.exec(color)) {
2012
+ return {
2013
+ h: match[1],
2014
+ s: match[2],
2015
+ l: match[3],
2016
+ a: match[4]
2017
+ };
2018
+ }
2019
+ if (match = matchers.hsv.exec(color)) {
2020
+ return {
2021
+ h: match[1],
2022
+ s: match[2],
2023
+ v: match[3]
2024
+ };
2025
+ }
2026
+ if (match = matchers.hsva.exec(color)) {
2027
+ return {
2028
+ h: match[1],
2029
+ s: match[2],
2030
+ v: match[3],
2031
+ a: match[4]
2032
+ };
2033
+ }
2034
+ if (match = matchers.hex8.exec(color)) {
2035
+ return {
2036
+ r: parseIntFromHex(match[1]),
2037
+ g: parseIntFromHex(match[2]),
2038
+ b: parseIntFromHex(match[3]),
2039
+ a: convertHexToDecimal(match[4]),
2040
+ format: named ? "name" : "hex8"
2041
+ };
2042
+ }
2043
+ if (match = matchers.hex6.exec(color)) {
2044
+ return {
2045
+ r: parseIntFromHex(match[1]),
2046
+ g: parseIntFromHex(match[2]),
2047
+ b: parseIntFromHex(match[3]),
2048
+ format: named ? "name" : "hex"
2049
+ };
2050
+ }
2051
+ if (match = matchers.hex4.exec(color)) {
2052
+ return {
2053
+ r: parseIntFromHex(match[1] + "" + match[1]),
2054
+ g: parseIntFromHex(match[2] + "" + match[2]),
2055
+ b: parseIntFromHex(match[3] + "" + match[3]),
2056
+ a: convertHexToDecimal(match[4] + "" + match[4]),
2057
+ format: named ? "name" : "hex8"
2058
+ };
2059
+ }
2060
+ if (match = matchers.hex3.exec(color)) {
2061
+ return {
2062
+ r: parseIntFromHex(match[1] + "" + match[1]),
2063
+ g: parseIntFromHex(match[2] + "" + match[2]),
2064
+ b: parseIntFromHex(match[3] + "" + match[3]),
2065
+ format: named ? "name" : "hex"
2066
+ };
2067
+ }
2068
+ return false;
2069
+ }
2070
+ function validateWCAG2Parms(parms) {
2071
+ // return valid WCAG2 parms for isReadable.
2072
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
2073
+ var level, size;
2074
+ parms = parms || {
2075
+ level: "AA",
2076
+ size: "small"
2077
+ };
2078
+ level = (parms.level || "AA").toUpperCase();
2079
+ size = (parms.size || "small").toLowerCase();
2080
+ if (level !== "AA" && level !== "AAA") {
2081
+ level = "AA";
2082
+ }
2083
+ if (size !== "small" && size !== "large") {
2084
+ size = "small";
2085
+ }
2086
+ return {
2087
+ level: level,
2088
+ size: size
2089
+ };
2090
+ }
2091
+
2092
+ class WidgetMapbox extends s$1 {
2093
+ constructor() {
2094
+ super();
2095
+ this.inputData = undefined;
2096
+ this.map = undefined;
2097
+ this.dataSets = [];
2098
+ this.dataSources = new Map();
2099
+ this.colors = new Map();
2100
+ this.version = '1.4.11';
2101
+ this.resizeObserver = new ResizeObserver(() => {
2102
+ var _a;
2103
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.resize();
2104
+ this.fitBounds();
2105
+ });
2106
+ mapboxgl.accessToken = 'pk.eyJ1IjoibWFya29wZSIsImEiOiJjazc1OWlsNjkwN2pyM2VxajV1eGRnYzgwIn0.3lVksk1nej_0KnWjCkBDAA';
2107
+ }
2108
+ update(changedProperties) {
2109
+ changedProperties.forEach((propName) => {
2110
+ if (propName === 'inputData') {
2111
+ this.transformInputData();
2112
+ }
2113
+ });
2114
+ super.update(changedProperties);
2115
+ }
2116
+ firstUpdated() {
2117
+ this.transformInputData();
2118
+ this.createMap();
2119
+ this.resizeObserver.observe(this.map._container);
2120
+ this.fitBounds();
2121
+ }
2122
+ fitBounds() {
2123
+ const bounds = new mapboxgl.LngLatBounds();
2124
+ this.dataSources.forEach((col) => {
2125
+ col.features.forEach(f => {
2126
+ var _a;
2127
+ // @ts-ignore
2128
+ if ((_a = f.geometry.coordinates) === null || _a === void 0 ? void 0 : _a.length)
2129
+ bounds.extend(f.geometry.coordinates);
2130
+ });
2131
+ });
2132
+ if (!bounds.isEmpty()) {
2133
+ this.map.fitBounds(bounds, { maxZoom: 14, padding: 16, duration: 100, });
2134
+ }
2135
+ }
2136
+ transformInputData() {
2137
+ var _a, _b, _c;
2138
+ if (!((_a = this === null || this === void 0 ? void 0 : this.inputData) === null || _a === void 0 ? void 0 : _a.settings) || !((_c = (_b = this === null || this === void 0 ? void 0 : this.inputData) === null || _b === void 0 ? void 0 : _b.dataseries) === null || _c === void 0 ? void 0 : _c.length))
2139
+ return;
2140
+ if (this.map && this.inputData.settings.style !== this.mapStyle) {
2141
+ this.createMap();
2142
+ }
2143
+ // choose random color if dataseries has none and store it for furure updates
2144
+ this.inputData.dataseries.forEach(ds => {
2145
+ var _a;
2146
+ if (!this.colors.has(ds.label)) {
2147
+ ds.color = (_a = ds.color) !== null && _a !== void 0 ? _a : tinycolor.random().toString();
2148
+ this.colors.set(ds.label, ds.color);
2149
+ }
2150
+ });
2151
+ // console.log('The input data', this.inputData.dataseries[0], this.inputData.dataseries[1])
2152
+ // Pivot inputData if required
2153
+ this.dataSets = [];
2154
+ this.inputData.dataseries.forEach(ds => {
2155
+ var _a;
2156
+ const color = this.colors.get(ds.label);
2157
+ const distincts = [...new Set(ds.data.map((d) => d.pivot))];
2158
+ const derivedColors = tinycolor(color).monochromatic(distincts.length).map((c) => c.toHexString());
2159
+ if (distincts.length > 1) {
2160
+ distincts.forEach((piv, i) => {
2161
+ const pds = {
2162
+ label: `${ds.label} ${piv}`,
2163
+ order: ds.order,
2164
+ type: ds.type,
2165
+ latestValues: ds.latestValues,
2166
+ color: derivedColors[i],
2167
+ config: ds.config,
2168
+ data: ds.data.filter(d => d.pivot === piv)
2169
+ };
2170
+ this.dataSets.push(pds);
2171
+ });
2172
+ }
2173
+ else {
2174
+ ds.color = (_a = ds.color) !== null && _a !== void 0 ? _a : this.colors[ds.label];
2175
+ this.dataSets.push(ds);
2176
+ }
2177
+ });
2178
+ this.inputData.dataseries = [];
2179
+ // Filter for latest Values
2180
+ this.dataSets.forEach(ds => {
2181
+ if (ds.latestValues > 0)
2182
+ ds.data = ds.data.splice(-ds.latestValues);
2183
+ });
2184
+ // console.log('mapbox datasets', this.dataSets)
2185
+ // create geojson sources
2186
+ this.dataSets.sort((a, b) => b.order - a.order).forEach(ds => {
2187
+ this.dataSources.set('input:' + ds.label, {
2188
+ type: 'FeatureCollection',
2189
+ features: this.createGEOJson(ds)
2190
+ });
2191
+ if (this.map)
2192
+ this.syncDataLayers();
2193
+ // console.log('mapbox DataLayers', this.dataSources)
2194
+ });
2195
+ }
2196
+ createGEOJson(ds) {
2197
+ if (ds.type !== 'line') {
2198
+ const features = ds.data
2199
+ .filter(p => p.lon !== undefined
2200
+ && p.lat !== undefined
2201
+ && p.value !== undefined
2202
+ && typeof p.lon === 'number'
2203
+ && typeof p.lat === 'number'
2204
+ && typeof p.value === 'number')
2205
+ .map(p => {
2206
+ const point = {
2207
+ type: 'Feature',
2208
+ geometry: {
2209
+ type: 'Point',
2210
+ coordinates: [p.lon, p.lat]
2211
+ },
2212
+ properties: {
2213
+ value: Math.round(p.value)
2214
+ }
2215
+ };
2216
+ return point;
2217
+ });
2218
+ return features;
2219
+ }
2220
+ const line = ds.data.reverse()
2221
+ .filter(p => p.lon !== undefined && p.lat !== undefined)
2222
+ .map(p => [p.lon, p.lat, p.alt]);
2223
+ const feature = {
2224
+ type: 'Feature',
2225
+ geometry: {
2226
+ type: 'LineString',
2227
+ coordinates: line
2228
+ },
2229
+ properties: {}
2230
+ };
2231
+ return [feature];
2232
+ }
2233
+ addCircleLayer(dataSet) {
2234
+ var _a, _b;
2235
+ if (!dataSet)
2236
+ return;
2237
+ const layerConfig = {
2238
+ 'id': dataSet.label + ':circle',
2239
+ 'type': 'circle',
2240
+ 'source': 'input:' + dataSet.label,
2241
+ 'paint': {
2242
+ ...dataSet.config['circle'],
2243
+ "circle-radius": ['get', 'value'],
2244
+ "circle-radius-transition": {
2245
+ duration: 1000,
2246
+ delay: 0
2247
+ },
2248
+ "circle-color": dataSet.color
2249
+ },
2250
+ // Place polygons under labels, roads and buildings.
2251
+ // 'aeroway-polygon'
2252
+ };
2253
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addLayer(layerConfig);
2254
+ if (!dataSet.config['symbol'])
2255
+ return;
2256
+ const layerConfig2 = {
2257
+ 'id': dataSet.label + ':symbol',
2258
+ 'type': 'symbol',
2259
+ 'source': 'input:' + dataSet.label,
2260
+ layout: {
2261
+ 'text-field': ['get', 'value'],
2262
+ 'text-size': dataSet.config['symbol']['text-size'],
2263
+ 'text-anchor': 'center',
2264
+ },
2265
+ paint: {
2266
+ 'text-color': dataSet.config['symbol']['text-color'],
2267
+ }
2268
+ // Place polygons under labels, roads and buildings.
2269
+ // 'aeroway-polygon'
2270
+ };
2271
+ (_b = this.map) === null || _b === void 0 ? void 0 : _b.addLayer(layerConfig2);
2272
+ }
2273
+ addSymbolLayer(dataSet) {
2274
+ var _a;
2275
+ if (!dataSet)
2276
+ return;
2277
+ const layerConfig = {
2278
+ 'id': dataSet.label + ':symbol',
2279
+ 'type': 'symbol',
2280
+ 'source': 'input:' + dataSet.label,
2281
+ layout: {
2282
+ 'text-field': ['get', 'value'],
2283
+ 'text-size': dataSet.config['symbol']['text-size'],
2284
+ 'text-anchor': 'center',
2285
+ 'icon-image': dataSet.config.symbol['icon-image'],
2286
+ 'icon-size': dataSet.config.symbol['icon-size']
2287
+ },
2288
+ paint: {
2289
+ 'text-color': dataSet.config['symbol']['text-color'],
2290
+ }
2291
+ // Place polygons under labels, roads and buildings.
2292
+ // 'aeroway-polygon'
2293
+ };
2294
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addLayer(layerConfig);
2295
+ }
2296
+ addHeatmapLayer(dataSet) {
2297
+ var _a;
2298
+ if (!dataSet)
2299
+ return;
2300
+ const min = Math.min(...dataSet.data.map(p => p.value));
2301
+ const max = Math.max(...dataSet.data.map(p => p.value));
2302
+ const layerConfig = {
2303
+ 'id': dataSet.label + ':heatmap',
2304
+ 'type': 'heatmap',
2305
+ 'source': 'input:' + dataSet.label,
2306
+ paint: {
2307
+ ...dataSet.config.heatmap,
2308
+ 'heatmap-color': [
2309
+ "interpolate",
2310
+ ["linear"],
2311
+ ["heatmap-density"],
2312
+ 0, "rgba(0, 0, 255, 0)",
2313
+ 0.1, "royalblue",
2314
+ 0.3, "cyan",
2315
+ 0.5, "lime",
2316
+ 0.7, "yellow",
2317
+ 1, "tomato"
2318
+ ],
2319
+ // Increase the heatmap weight based on frequency and property magnitude
2320
+ 'heatmap-weight': [
2321
+ 'interpolate',
2322
+ ['linear'],
2323
+ ['get', 'value'],
2324
+ min, 0,
2325
+ max, 3
2326
+ ],
2327
+ // // Increase the heatmap color weight weight by zoom level
2328
+ // // heatmap-intensity is a multiplier on top of heatmap-weight
2329
+ // 'heatmap-intensity': [
2330
+ // 'interpolate',
2331
+ // ['linear'],
2332
+ // ['zoom'],
2333
+ // 0, 1,
2334
+ // 9, 3
2335
+ // ],
2336
+ // Adjust the heatmap radius by zoom level
2337
+ 'heatmap-radius': [
2338
+ 'interpolate',
2339
+ ['linear'],
2340
+ ['get', 'value'],
2341
+ min, 30,
2342
+ max, 30 + dataSet.config.heatmap['heatmap-radius']
2343
+ ],
2344
+ 'heatmap-radius-transition': {
2345
+ duration: 1000,
2346
+ delay: 0
2347
+ }
2348
+ // // Transition from heatmap to circle layer by zoom level
2349
+ // 'heatmap-opacity': [
2350
+ // 'interpolate',
2351
+ // ['linear'],
2352
+ // ['zoom'],
2353
+ // 7, 1,
2354
+ // 9, 0
2355
+ // ]
2356
+ }
2357
+ // Place polygons under labels, roads and buildings.
2358
+ // 'aeroway-polygon'
2359
+ };
2360
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addLayer(layerConfig);
2361
+ }
2362
+ addLineLayer(dataSet) {
2363
+ var _a, _b;
2364
+ if (!dataSet)
2365
+ return;
2366
+ const layerConfig = {
2367
+ 'id': dataSet.label + ':line',
2368
+ 'type': 'line',
2369
+ 'source': 'input:' + dataSet.label,
2370
+ layout: {
2371
+ 'line-cap': 'round',
2372
+ },
2373
+ paint: {
2374
+ ...dataSet.config.line,
2375
+ "line-color": dataSet.color,
2376
+ }
2377
+ // Place polygons under labels, roads and buildings.
2378
+ // 'aeroway-polygon'
2379
+ };
2380
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addLayer(layerConfig);
2381
+ if (!dataSet.config.symbol['icon-image'])
2382
+ return;
2383
+ const layerConfig2 = {
2384
+ 'id': dataSet.label + ':symbol',
2385
+ 'type': 'symbol',
2386
+ 'source': 'input:' + dataSet.label,
2387
+ layout: {
2388
+ 'icon-image': dataSet.config.symbol['icon-image'],
2389
+ 'icon-size': dataSet.config.symbol['icon-size'],
2390
+ },
2391
+ paint: {
2392
+ 'icon-color': dataSet.color
2393
+ }
2394
+ // Place polygons under labels, roads and buildings.
2395
+ // 'aeroway-polygon'
2396
+ };
2397
+ (_b = this.map) === null || _b === void 0 ? void 0 : _b.addLayer(layerConfig2);
2398
+ }
2399
+ syncDataLayers() {
2400
+ var _a, _b, _c;
2401
+ // remove sources and all Layers that are not part of the inputData anymore
2402
+ const sources = (_a = this.map.getStyle().sources) !== null && _a !== void 0 ? _a : [];
2403
+ const mySources = Object.entries(sources).filter(([l]) => l.startsWith('input:'));
2404
+ mySources.forEach(([label]) => {
2405
+ if (!this.dataSources.has(label)) {
2406
+ // remove all layers using this source
2407
+ this.map.getStyle().layers.filter((la) => la.id === label + ':' + la.type).forEach((la) => {
2408
+ this.map.removeLayer(la.id);
2409
+ });
2410
+ this.map.removeSource(label);
2411
+ }
2412
+ });
2413
+ // add new layers or update the data of existing layers
2414
+ this.dataSets.forEach(ds => {
2415
+ var _a;
2416
+ const fc = this.dataSources.get('input:' + ds.label);
2417
+ const src = this.map.getSource('input:' + ds.label);
2418
+ if (src) {
2419
+ src.setData(fc || []);
2420
+ return;
2421
+ }
2422
+ // console.log('adding source', ds.label, ds.type)
2423
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addSource('input:' + ds.label, {
2424
+ type: 'geojson',
2425
+ data: fc || []
2426
+ });
2427
+ switch (ds.type) {
2428
+ case 'circle':
2429
+ this.addCircleLayer(ds);
2430
+ return;
2431
+ case 'symbol':
2432
+ this.addSymbolLayer(ds);
2433
+ return;
2434
+ case 'heatmap':
2435
+ this.addHeatmapLayer(ds);
2436
+ return;
2437
+ case 'line':
2438
+ this.addLineLayer(ds);
2439
+ }
2440
+ });
2441
+ if ((_c = (_b = this.inputData) === null || _b === void 0 ? void 0 : _b.settings) === null || _c === void 0 ? void 0 : _c.follow)
2442
+ this.fitBounds();
2443
+ }
2444
+ addBuildingLayer() {
2445
+ // Insert the layer beneath any symbol layer.
2446
+ const { layers } = this.map.getStyle();
2447
+ let labelLayerId = 0;
2448
+ for (let i = 0; i < layers.length; i++) {
2449
+ if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
2450
+ labelLayerId = layers[i].id;
2451
+ break;
2452
+ }
2453
+ }
2454
+ this.map.addLayer({
2455
+ 'id': '3d-buildings',
2456
+ 'source': 'composite',
2457
+ 'source-layer': 'building',
2458
+ 'filter': ['==', 'extrude', 'true'],
2459
+ 'type': 'fill-extrusion',
2460
+ 'minzoom': 14,
2461
+ 'paint': {
2462
+ 'fill-extrusion-color': '#aaa',
2463
+ // use an 'interpolate' expression to add a smooth transition effect to the
2464
+ // buildings as the user zooms in
2465
+ 'fill-extrusion-height': [
2466
+ "interpolate", ["linear"],
2467
+ ["zoom"],
2468
+ 14, 0,
2469
+ 14.05, ["get", "height"]
2470
+ ],
2471
+ 'fill-extrusion-base': [
2472
+ "interpolate", ["linear"],
2473
+ ["zoom"],
2474
+ 14, 0,
2475
+ 14.05, ["get", "min_height"]
2476
+ ],
2477
+ 'fill-extrusion-opacity': .6
2478
+ }
2479
+ }, labelLayerId);
2480
+ }
2481
+ createMap() {
2482
+ var _a, _b, _c, _d;
2483
+ if (this.map)
2484
+ return;
2485
+ this.mapStyle = (_b = (_a = this.inputData) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.style;
2486
+ this.map = new mapboxgl.Map({
2487
+ container: (_c = this.shadowRoot) === null || _c === void 0 ? void 0 : _c.getElementById('map'),
2488
+ style: `mapbox://styles/mapbox/${(_d = this.mapStyle) !== null && _d !== void 0 ? _d : 'light-v11'}`,
2489
+ center: [8.6841700, 50.1155200],
2490
+ zoom: 1.8,
2491
+ attributionControl: false
2492
+ });
2493
+ this.map.scrollZoom.disable();
2494
+ this.map.addControl(new mapboxgl.NavigationControl(), 'top-right');
2495
+ const scale = new mapboxgl.ScaleControl({
2496
+ maxWidth: 80,
2497
+ unit: 'metric'
2498
+ });
2499
+ this.map.addControl(scale, 'bottom-left');
2500
+ console.log('MAPBOX VERSION', mapboxgl.version);
2501
+ this.map.on('load', () => {
2502
+ this.addBuildingLayer();
2503
+ this.syncDataLayers();
2504
+ });
2505
+ }
2506
+ render() {
2507
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2508
+ return x `
2509
+ <link href="https://api.mapbox.com/mapbox-gl-js/v${mapboxgl.version}/mapbox-gl.css" rel="stylesheet">
2510
+ <div class="wrapper">
2511
+ <header>
2512
+ <div class="title">
2513
+ <h3 class="paging" ?active=${(_b = (_a = this.inputData) === null || _a === void 0 ? void 0 : _a.settings) === null || _b === void 0 ? void 0 : _b.title}>${(_d = (_c = this.inputData) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.title}</h3>
2514
+ <p class="paging" ?active=${(_f = (_e = this.inputData) === null || _e === void 0 ? void 0 : _e.settings) === null || _f === void 0 ? void 0 : _f.subTitle}>${(_h = (_g = this.inputData) === null || _g === void 0 ? void 0 : _g.settings) === null || _h === void 0 ? void 0 : _h.subTitle}</p>
2515
+ </div>
2516
+ <div class="legend paging" ?active=${(_k = (_j = this === null || this === void 0 ? void 0 : this.inputData) === null || _j === void 0 ? void 0 : _j.settings) === null || _k === void 0 ? void 0 : _k.showLegend}>
2517
+ ${c(this.dataSets, ds => ds.label, ds => {
2518
+ return x `
2519
+ <div class="label">
2520
+ <div style="background: ${ds.color}; width: 24px; height: 12px;"></div>
2521
+ <div>${ds.label}</div>
2522
+ </div>
2523
+ `;
2524
+ })}
2525
+ </div>
2526
+ </header>
2527
+ <div id="map"></div>
2528
+ </div>
2529
+ `;
2530
+ }
2531
+ }
2532
+ WidgetMapbox.styles = i$3 `
2533
+ :host {
2534
+ display: block;
2535
+ color: var(--re-bar-text-color, #000);
2536
+ font-family: sans-serif;
2537
+ padding: 16px;
2538
+ box-sizing: border-box;
2539
+ margin: auto;
2540
+ }
2541
+
2542
+ .paging:not([active]) { display: none !important; }
2543
+
2544
+ header {
2545
+ display: flex;
2546
+ margin: 0 0 16px 0;
2547
+ gap: 24px;
2548
+ justify-content: space-between;
2549
+ }
2550
+ h3 {
2551
+ margin: 0;
2552
+ max-width: 300px;
2553
+ overflow: hidden;
2554
+ text-overflow: ellipsis;
2555
+ white-space: nowrap;
2556
+ }
2557
+ p {
2558
+ margin: 10px 0 0 0;
2559
+ max-width: 300px;
2560
+ font-size: 14px;
2561
+ overflow: hidden;
2562
+ text-overflow: ellipsis;
2563
+ white-space: nowrap;
2564
+ line-height: 17px;
2565
+ }
2566
+
2567
+ .wrapper {
2568
+ display: flex;
2569
+ flex-direction: column;
2570
+ height: 100%;
2571
+ width: 100%;
2572
+ }
2573
+ #map {
2574
+ flex: 1;
2575
+ }
2576
+
2577
+ .title {
2578
+ white-space: nowrap;
2579
+ }
2580
+
2581
+ .legend {
2582
+ display: flex;
2583
+ flex-wrap: wrap;
2584
+ gap: 12px;
2585
+ }
2586
+
2587
+ .label {
2588
+ display: flex;
2589
+ align-items: center;
2590
+ font-size: 14px;
2591
+ gap: 8px
2592
+ }
2593
+
2594
+ a.mapboxgl-ctrl-logo {
2595
+ display: none;
2596
+ }
2597
+
2598
+ `;
2599
+ __decorate([
2600
+ n({ type: Object })
2601
+ ], WidgetMapbox.prototype, "inputData", void 0);
2602
+ __decorate([
2603
+ r$1()
2604
+ ], WidgetMapbox.prototype, "map", void 0);
2605
+ __decorate([
2606
+ r$1()
2607
+ ], WidgetMapbox.prototype, "dataSets", void 0);
2608
+ __decorate([
2609
+ r$1()
2610
+ ], WidgetMapbox.prototype, "dataSources", void 0);
2611
+ __decorate([
2612
+ r$1()
2613
+ ], WidgetMapbox.prototype, "colors", void 0);
2614
+ window.customElements.define('widget-mapbox-1.4.11', WidgetMapbox);
2615
+
2616
+ export { WidgetMapbox };
2617
+ //# sourceMappingURL=widget-mapbox.js.map