basemapkit 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1048 +1,53 @@
1
- import { language_script_pairs as U, get_country_name as W, get_multiline_name as J } from "@protomaps/basemaps";
2
- const x = {
3
- aliceblue: [240, 248, 255],
4
- antiquewhite: [250, 235, 215],
5
- aqua: [0, 255, 255],
6
- aquamarine: [127, 255, 212],
7
- azure: [240, 255, 255],
8
- beige: [245, 245, 220],
9
- bisque: [255, 228, 196],
10
- black: [0, 0, 0],
11
- blanchedalmond: [255, 235, 205],
12
- blue: [0, 0, 255],
13
- blueviolet: [138, 43, 226],
14
- brown: [165, 42, 42],
15
- burlywood: [222, 184, 135],
16
- cadetblue: [95, 158, 160],
17
- chartreuse: [127, 255, 0],
18
- chocolate: [210, 105, 30],
19
- coral: [255, 127, 80],
20
- cornflowerblue: [100, 149, 237],
21
- cornsilk: [255, 248, 220],
22
- crimson: [220, 20, 60],
23
- cyan: [0, 255, 255],
24
- darkblue: [0, 0, 139],
25
- darkcyan: [0, 139, 139],
26
- darkgoldenrod: [184, 134, 11],
27
- darkgray: [169, 169, 169],
28
- darkgreen: [0, 100, 0],
29
- darkgrey: [169, 169, 169],
30
- darkkhaki: [189, 183, 107],
31
- darkmagenta: [139, 0, 139],
32
- darkolivegreen: [85, 107, 47],
33
- darkorange: [255, 140, 0],
34
- darkorchid: [153, 50, 204],
35
- darkred: [139, 0, 0],
36
- darksalmon: [233, 150, 122],
37
- darkseagreen: [143, 188, 143],
38
- darkslateblue: [72, 61, 139],
39
- darkslategray: [47, 79, 79],
40
- darkslategrey: [47, 79, 79],
41
- darkturquoise: [0, 206, 209],
42
- darkviolet: [148, 0, 211],
43
- deeppink: [255, 20, 147],
44
- deepskyblue: [0, 191, 255],
45
- dimgray: [105, 105, 105],
46
- dimgrey: [105, 105, 105],
47
- dodgerblue: [30, 144, 255],
48
- firebrick: [178, 34, 34],
49
- floralwhite: [255, 250, 240],
50
- forestgreen: [34, 139, 34],
51
- fuchsia: [255, 0, 255],
52
- gainsboro: [220, 220, 220],
53
- ghostwhite: [248, 248, 255],
54
- gold: [255, 215, 0],
55
- goldenrod: [218, 165, 32],
56
- gray: [128, 128, 128],
57
- green: [0, 128, 0],
58
- greenyellow: [173, 255, 47],
59
- grey: [128, 128, 128],
60
- honeydew: [240, 255, 240],
61
- hotpink: [255, 105, 180],
62
- indianred: [205, 92, 92],
63
- indigo: [75, 0, 130],
64
- ivory: [255, 255, 240],
65
- khaki: [240, 230, 140],
66
- lavender: [230, 230, 250],
67
- lavenderblush: [255, 240, 245],
68
- lawngreen: [124, 252, 0],
69
- lemonchiffon: [255, 250, 205],
70
- lightblue: [173, 216, 230],
71
- lightcoral: [240, 128, 128],
72
- lightcyan: [224, 255, 255],
73
- lightgoldenrodyellow: [250, 250, 210],
74
- lightgray: [211, 211, 211],
75
- lightgreen: [144, 238, 144],
76
- lightgrey: [211, 211, 211],
77
- lightpink: [255, 182, 193],
78
- lightsalmon: [255, 160, 122],
79
- lightseagreen: [32, 178, 170],
80
- lightskyblue: [135, 206, 250],
81
- lightslategray: [119, 136, 153],
82
- lightslategrey: [119, 136, 153],
83
- lightsteelblue: [176, 196, 222],
84
- lightyellow: [255, 255, 224],
85
- lime: [0, 255, 0],
86
- limegreen: [50, 205, 50],
87
- linen: [250, 240, 230],
88
- magenta: [255, 0, 255],
89
- maroon: [128, 0, 0],
90
- mediumaquamarine: [102, 205, 170],
91
- mediumblue: [0, 0, 205],
92
- mediumorchid: [186, 85, 211],
93
- mediumpurple: [147, 112, 219],
94
- mediumseagreen: [60, 179, 113],
95
- mediumslateblue: [123, 104, 238],
96
- mediumspringgreen: [0, 250, 154],
97
- mediumturquoise: [72, 209, 204],
98
- mediumvioletred: [199, 21, 133],
99
- midnightblue: [25, 25, 112],
100
- mintcream: [245, 255, 250],
101
- mistyrose: [255, 228, 225],
102
- moccasin: [255, 228, 181],
103
- navajowhite: [255, 222, 173],
104
- navy: [0, 0, 128],
105
- oldlace: [253, 245, 230],
106
- olive: [128, 128, 0],
107
- olivedrab: [107, 142, 35],
108
- orange: [255, 165, 0],
109
- orangered: [255, 69, 0],
110
- orchid: [218, 112, 214],
111
- palegoldenrod: [238, 232, 170],
112
- palegreen: [152, 251, 152],
113
- paleturquoise: [175, 238, 238],
114
- palevioletred: [219, 112, 147],
115
- papayawhip: [255, 239, 213],
116
- peachpuff: [255, 218, 185],
117
- peru: [205, 133, 63],
118
- pink: [255, 192, 203],
119
- plum: [221, 160, 221],
120
- powderblue: [176, 224, 230],
121
- purple: [128, 0, 128],
122
- rebeccapurple: [102, 51, 153],
123
- red: [255, 0, 0],
124
- rosybrown: [188, 143, 143],
125
- royalblue: [65, 105, 225],
126
- saddlebrown: [139, 69, 19],
127
- salmon: [250, 128, 114],
128
- sandybrown: [244, 164, 96],
129
- seagreen: [46, 139, 87],
130
- seashell: [255, 245, 238],
131
- sienna: [160, 82, 45],
132
- silver: [192, 192, 192],
133
- skyblue: [135, 206, 235],
134
- slateblue: [106, 90, 205],
135
- slategray: [112, 128, 144],
136
- slategrey: [112, 128, 144],
137
- snow: [255, 250, 250],
138
- springgreen: [0, 255, 127],
139
- steelblue: [70, 130, 180],
140
- tan: [210, 180, 140],
141
- teal: [0, 128, 128],
142
- thistle: [216, 191, 216],
143
- tomato: [255, 99, 71],
144
- turquoise: [64, 224, 208],
145
- violet: [238, 130, 238],
146
- wheat: [245, 222, 179],
147
- white: [255, 255, 255],
148
- whitesmoke: [245, 245, 245],
149
- yellow: [255, 255, 0],
150
- yellowgreen: [154, 205, 50]
151
- }, Q = /* @__PURE__ */ Object.create(null);
152
- for (const n in x)
153
- Object.hasOwn(x, n) && (Q[x[n]] = n);
154
- const g = {
155
- to: {},
156
- get: {}
157
- };
158
- g.get = function(n) {
159
- const e = n.slice(0, 3).toLowerCase();
160
- let t, i;
161
- switch (e) {
162
- case "hsl": {
163
- t = g.get.hsl(n), i = "hsl";
164
- break;
165
- }
166
- case "hwb": {
167
- t = g.get.hwb(n), i = "hwb";
168
- break;
169
- }
170
- default: {
171
- t = g.get.rgb(n), i = "rgb";
172
- break;
173
- }
174
- }
175
- return t ? { model: i, value: t } : null;
176
- };
177
- g.get.rgb = function(n) {
178
- if (!n)
179
- return null;
180
- const e = /^#([a-f\d]{3,4})$/i, t = /^#([a-f\d]{6})([a-f\d]{2})?$/i, i = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|/]\s*([+-]?[\d.]+)(%?)\s*)?\)$/, o = /^rgba?\(\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[,|/]\s*([+-]?[\d.]+)(%?)\s*)?\)$/, l = /^(\w+)$/;
181
- let r = [0, 0, 0, 1], a, s, u;
182
- if (a = n.match(t)) {
183
- for (u = a[2], a = a[1], s = 0; s < 3; s++) {
184
- const y = s * 2;
185
- r[s] = Number.parseInt(a.slice(y, y + 2), 16);
186
- }
187
- u && (r[3] = Number.parseInt(u, 16) / 255);
188
- } else if (a = n.match(e)) {
189
- for (a = a[1], u = a[3], s = 0; s < 3; s++)
190
- r[s] = Number.parseInt(a[s] + a[s], 16);
191
- u && (r[3] = Number.parseInt(u + u, 16) / 255);
192
- } else if (a = n.match(i)) {
193
- for (s = 0; s < 3; s++)
194
- r[s] = Number.parseInt(a[s + 1], 10);
195
- a[4] && (r[3] = a[5] ? Number.parseFloat(a[4]) * 0.01 : Number.parseFloat(a[4]));
196
- } else if (a = n.match(o)) {
197
- for (s = 0; s < 3; s++)
198
- r[s] = Math.round(Number.parseFloat(a[s + 1]) * 2.55);
199
- a[4] && (r[3] = a[5] ? Number.parseFloat(a[4]) * 0.01 : Number.parseFloat(a[4]));
200
- } else return (a = n.match(l)) ? a[1] === "transparent" ? [0, 0, 0, 0] : Object.hasOwn(x, a[1]) ? (r = x[a[1]], r[3] = 1, r) : null : null;
201
- for (s = 0; s < 3; s++)
202
- r[s] = B(r[s], 0, 255);
203
- return r[3] = B(r[3], 0, 1), r;
204
- };
205
- g.get.hsl = function(n) {
206
- if (!n)
207
- return null;
208
- const e = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d.]+)%\s*,?\s*([+-]?[\d.]+)%\s*(?:[,|/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/, t = n.match(e);
209
- if (t) {
210
- const i = Number.parseFloat(t[4]), o = (Number.parseFloat(t[1]) % 360 + 360) % 360, l = B(Number.parseFloat(t[2]), 0, 100), r = B(Number.parseFloat(t[3]), 0, 100), a = B(Number.isNaN(i) ? 1 : i, 0, 1);
211
- return [o, l, r, a];
212
- }
213
- return null;
214
- };
215
- g.get.hwb = function(n) {
216
- if (!n)
217
- return null;
218
- const e = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d.]+)%\s*,\s*([+-]?[\d.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/, t = n.match(e);
219
- if (t) {
220
- const i = Number.parseFloat(t[4]), o = (Number.parseFloat(t[1]) % 360 + 360) % 360, l = B(Number.parseFloat(t[2]), 0, 100), r = B(Number.parseFloat(t[3]), 0, 100), a = B(Number.isNaN(i) ? 1 : i, 0, 1);
221
- return [o, l, r, a];
222
- }
223
- return null;
224
- };
225
- g.to.hex = function(...n) {
226
- return "#" + A(n[0]) + A(n[1]) + A(n[2]) + (n[3] < 1 ? A(Math.round(n[3] * 255)) : "");
227
- };
228
- g.to.rgb = function(...n) {
229
- return n.length < 4 || n[3] === 1 ? "rgb(" + Math.round(n[0]) + ", " + Math.round(n[1]) + ", " + Math.round(n[2]) + ")" : "rgba(" + Math.round(n[0]) + ", " + Math.round(n[1]) + ", " + Math.round(n[2]) + ", " + n[3] + ")";
230
- };
231
- g.to.rgb.percent = function(...n) {
232
- const e = Math.round(n[0] / 255 * 100), t = Math.round(n[1] / 255 * 100), i = Math.round(n[2] / 255 * 100);
233
- return n.length < 4 || n[3] === 1 ? "rgb(" + e + "%, " + t + "%, " + i + "%)" : "rgba(" + e + "%, " + t + "%, " + i + "%, " + n[3] + ")";
234
- };
235
- g.to.hsl = function(...n) {
236
- return n.length < 4 || n[3] === 1 ? "hsl(" + n[0] + ", " + n[1] + "%, " + n[2] + "%)" : "hsla(" + n[0] + ", " + n[1] + "%, " + n[2] + "%, " + n[3] + ")";
237
- };
238
- g.to.hwb = function(...n) {
239
- let e = "";
240
- return n.length >= 4 && n[3] !== 1 && (e = ", " + n[3]), "hwb(" + n[0] + ", " + n[1] + "%, " + n[2] + "%" + e + ")";
241
- };
242
- g.to.keyword = function(...n) {
243
- return Q[n.slice(0, 3)];
244
- };
245
- function B(n, e, t) {
246
- return Math.min(Math.max(e, n), t);
247
- }
248
- function A(n) {
249
- const e = Math.round(n).toString(16).toUpperCase();
250
- return e.length < 2 ? "0" + e : e;
251
- }
252
- const X = {};
253
- for (const n of Object.keys(x))
254
- X[x[n]] = n;
255
- const c = {
256
- rgb: { channels: 3, labels: "rgb" },
257
- hsl: { channels: 3, labels: "hsl" },
258
- hsv: { channels: 3, labels: "hsv" },
259
- hwb: { channels: 3, labels: "hwb" },
260
- cmyk: { channels: 4, labels: "cmyk" },
261
- xyz: { channels: 3, labels: "xyz" },
262
- lab: { channels: 3, labels: "lab" },
263
- oklab: { channels: 3, labels: ["okl", "oka", "okb"] },
264
- lch: { channels: 3, labels: "lch" },
265
- oklch: { channels: 3, labels: ["okl", "okc", "okh"] },
266
- hex: { channels: 1, labels: ["hex"] },
267
- keyword: { channels: 1, labels: ["keyword"] },
268
- ansi16: { channels: 1, labels: ["ansi16"] },
269
- ansi256: { channels: 1, labels: ["ansi256"] },
270
- hcg: { channels: 3, labels: ["h", "c", "g"] },
271
- apple: { channels: 3, labels: ["r16", "g16", "b16"] },
272
- gray: { channels: 1, labels: ["gray"] }
273
- }, v = (6 / 29) ** 3;
274
- function S(n) {
275
- const e = n > 31308e-7 ? 1.055 * n ** 0.4166666666666667 - 0.055 : n * 12.92;
276
- return Math.min(Math.max(0, e), 1);
277
- }
278
- function C(n) {
279
- return n > 0.04045 ? ((n + 0.055) / 1.055) ** 2.4 : n / 12.92;
280
- }
281
- for (const n of Object.keys(c)) {
282
- if (!("channels" in c[n]))
283
- throw new Error("missing channels property: " + n);
284
- if (!("labels" in c[n]))
285
- throw new Error("missing channel labels property: " + n);
286
- if (c[n].labels.length !== c[n].channels)
287
- throw new Error("channel and label counts mismatch: " + n);
288
- const { channels: e, labels: t } = c[n];
289
- delete c[n].channels, delete c[n].labels, Object.defineProperty(c[n], "channels", { value: e }), Object.defineProperty(c[n], "labels", { value: t });
290
- }
291
- c.rgb.hsl = function(n) {
292
- const e = n[0] / 255, t = n[1] / 255, i = n[2] / 255, o = Math.min(e, t, i), l = Math.max(e, t, i), r = l - o;
293
- let a, s;
294
- switch (l) {
295
- case o: {
296
- a = 0;
297
- break;
298
- }
299
- case e: {
300
- a = (t - i) / r;
301
- break;
302
- }
303
- case t: {
304
- a = 2 + (i - e) / r;
305
- break;
306
- }
307
- case i: {
308
- a = 4 + (e - t) / r;
309
- break;
310
- }
311
- }
312
- a = Math.min(a * 60, 360), a < 0 && (a += 360);
313
- const u = (o + l) / 2;
314
- return l === o ? s = 0 : u <= 0.5 ? s = r / (l + o) : s = r / (2 - l - o), [a, s * 100, u * 100];
315
- };
316
- c.rgb.hsv = function(n) {
317
- let e, t, i, o, l;
318
- const r = n[0] / 255, a = n[1] / 255, s = n[2] / 255, u = Math.max(r, a, s), y = u - Math.min(r, a, s), _ = function(N) {
319
- return (u - N) / 6 / y + 1 / 2;
320
- };
321
- if (y === 0)
322
- o = 0, l = 0;
323
- else {
324
- switch (l = y / u, e = _(r), t = _(a), i = _(s), u) {
325
- case r: {
326
- o = i - t;
327
- break;
328
- }
329
- case a: {
330
- o = 1 / 3 + e - i;
331
- break;
332
- }
333
- case s: {
334
- o = 2 / 3 + t - e;
335
- break;
336
- }
337
- }
338
- o < 0 ? o += 1 : o > 1 && (o -= 1);
339
- }
340
- return [
341
- o * 360,
342
- l * 100,
343
- u * 100
344
- ];
345
- };
346
- c.rgb.hwb = function(n) {
347
- const e = n[0], t = n[1];
348
- let i = n[2];
349
- const o = c.rgb.hsl(n)[0], l = 1 / 255 * Math.min(e, Math.min(t, i));
350
- return i = 1 - 1 / 255 * Math.max(e, Math.max(t, i)), [o, l * 100, i * 100];
351
- };
352
- c.rgb.oklab = function(n) {
353
- const e = C(n[0] / 255), t = C(n[1] / 255), i = C(n[2] / 255), o = Math.cbrt(0.4122214708 * e + 0.5363325363 * t + 0.0514459929 * i), l = Math.cbrt(0.2119034982 * e + 0.6806995451 * t + 0.1073969566 * i), r = Math.cbrt(0.0883024619 * e + 0.2817188376 * t + 0.6299787005 * i), a = 0.2104542553 * o + 0.793617785 * l - 0.0040720468 * r, s = 1.9779984951 * o - 2.428592205 * l + 0.4505937099 * r, u = 0.0259040371 * o + 0.7827717662 * l - 0.808675766 * r;
354
- return [a * 100, s * 100, u * 100];
355
- };
356
- c.rgb.cmyk = function(n) {
357
- const e = n[0] / 255, t = n[1] / 255, i = n[2] / 255, o = Math.min(1 - e, 1 - t, 1 - i), l = (1 - e - o) / (1 - o) || 0, r = (1 - t - o) / (1 - o) || 0, a = (1 - i - o) / (1 - o) || 0;
358
- return [l * 100, r * 100, a * 100, o * 100];
359
- };
360
- function tn(n, e) {
361
- return (n[0] - e[0]) ** 2 + (n[1] - e[1]) ** 2 + (n[2] - e[2]) ** 2;
362
- }
363
- c.rgb.keyword = function(n) {
364
- const e = X[n];
365
- if (e)
366
- return e;
367
- let t = Number.POSITIVE_INFINITY, i;
368
- for (const o of Object.keys(x)) {
369
- const l = x[o], r = tn(n, l);
370
- r < t && (t = r, i = o);
371
- }
372
- return i;
373
- };
374
- c.keyword.rgb = function(n) {
375
- return x[n];
376
- };
377
- c.rgb.xyz = function(n) {
378
- const e = C(n[0] / 255), t = C(n[1] / 255), i = C(n[2] / 255), o = e * 0.4124564 + t * 0.3575761 + i * 0.1804375, l = e * 0.2126729 + t * 0.7151522 + i * 0.072175, r = e * 0.0193339 + t * 0.119192 + i * 0.9503041;
379
- return [o * 100, l * 100, r * 100];
380
- };
381
- c.rgb.lab = function(n) {
382
- const e = c.rgb.xyz(n);
383
- let t = e[0], i = e[1], o = e[2];
384
- t /= 95.047, i /= 100, o /= 108.883, t = t > v ? t ** (1 / 3) : 7.787 * t + 16 / 116, i = i > v ? i ** (1 / 3) : 7.787 * i + 16 / 116, o = o > v ? o ** (1 / 3) : 7.787 * o + 16 / 116;
385
- const l = 116 * i - 16, r = 500 * (t - i), a = 200 * (i - o);
386
- return [l, r, a];
387
- };
388
- c.hsl.rgb = function(n) {
389
- const e = n[0] / 360, t = n[1] / 100, i = n[2] / 100;
390
- let o, l;
391
- if (t === 0)
392
- return l = i * 255, [l, l, l];
393
- const r = i < 0.5 ? i * (1 + t) : i + t - i * t, a = 2 * i - r, s = [0, 0, 0];
394
- for (let u = 0; u < 3; u++)
395
- o = e + 1 / 3 * -(u - 1), o < 0 && o++, o > 1 && o--, 6 * o < 1 ? l = a + (r - a) * 6 * o : 2 * o < 1 ? l = r : 3 * o < 2 ? l = a + (r - a) * (2 / 3 - o) * 6 : l = a, s[u] = l * 255;
396
- return s;
397
- };
398
- c.hsl.hsv = function(n) {
399
- const e = n[0];
400
- let t = n[1] / 100, i = n[2] / 100, o = t;
401
- const l = Math.max(i, 0.01);
402
- i *= 2, t *= i <= 1 ? i : 2 - i, o *= l <= 1 ? l : 2 - l;
403
- const r = (i + t) / 2, a = i === 0 ? 2 * o / (l + o) : 2 * t / (i + t);
404
- return [e, a * 100, r * 100];
405
- };
406
- c.hsv.rgb = function(n) {
407
- const e = n[0] / 60, t = n[1] / 100;
408
- let i = n[2] / 100;
409
- const o = Math.floor(e) % 6, l = e - Math.floor(e), r = 255 * i * (1 - t), a = 255 * i * (1 - t * l), s = 255 * i * (1 - t * (1 - l));
410
- switch (i *= 255, o) {
411
- case 0:
412
- return [i, s, r];
413
- case 1:
414
- return [a, i, r];
415
- case 2:
416
- return [r, i, s];
417
- case 3:
418
- return [r, a, i];
419
- case 4:
420
- return [s, r, i];
421
- case 5:
422
- return [i, r, a];
423
- }
424
- };
425
- c.hsv.hsl = function(n) {
426
- const e = n[0], t = n[1] / 100, i = n[2] / 100, o = Math.max(i, 0.01);
427
- let l, r;
428
- r = (2 - t) * i;
429
- const a = (2 - t) * o;
430
- return l = t * o, l /= a <= 1 ? a : 2 - a, l = l || 0, r /= 2, [e, l * 100, r * 100];
431
- };
432
- c.hwb.rgb = function(n) {
433
- const e = n[0] / 360;
434
- let t = n[1] / 100, i = n[2] / 100;
435
- const o = t + i;
436
- let l;
437
- o > 1 && (t /= o, i /= o);
438
- const r = Math.floor(6 * e), a = 1 - i;
439
- l = 6 * e - r, (r & 1) !== 0 && (l = 1 - l);
440
- const s = t + l * (a - t);
441
- let u, y, _;
442
- switch (r) {
443
- default:
444
- case 6:
445
- case 0: {
446
- u = a, y = s, _ = t;
447
- break;
448
- }
449
- case 1: {
450
- u = s, y = a, _ = t;
451
- break;
452
- }
453
- case 2: {
454
- u = t, y = a, _ = s;
455
- break;
456
- }
457
- case 3: {
458
- u = t, y = s, _ = a;
459
- break;
460
- }
461
- case 4: {
462
- u = s, y = t, _ = a;
463
- break;
464
- }
465
- case 5: {
466
- u = a, y = t, _ = s;
467
- break;
468
- }
469
- }
470
- return [u * 255, y * 255, _ * 255];
471
- };
472
- c.cmyk.rgb = function(n) {
473
- const e = n[0] / 100, t = n[1] / 100, i = n[2] / 100, o = n[3] / 100, l = 1 - Math.min(1, e * (1 - o) + o), r = 1 - Math.min(1, t * (1 - o) + o), a = 1 - Math.min(1, i * (1 - o) + o);
474
- return [l * 255, r * 255, a * 255];
475
- };
476
- c.xyz.rgb = function(n) {
477
- const e = n[0] / 100, t = n[1] / 100, i = n[2] / 100;
478
- let o, l, r;
479
- return o = e * 3.2404542 + t * -1.5371385 + i * -0.4985314, l = e * -0.969266 + t * 1.8760108 + i * 0.041556, r = e * 0.0556434 + t * -0.2040259 + i * 1.0572252, o = S(o), l = S(l), r = S(r), [o * 255, l * 255, r * 255];
480
- };
481
- c.xyz.lab = function(n) {
482
- let e = n[0], t = n[1], i = n[2];
483
- e /= 95.047, t /= 100, i /= 108.883, e = e > v ? e ** (1 / 3) : 7.787 * e + 16 / 116, t = t > v ? t ** (1 / 3) : 7.787 * t + 16 / 116, i = i > v ? i ** (1 / 3) : 7.787 * i + 16 / 116;
484
- const o = 116 * t - 16, l = 500 * (e - t), r = 200 * (t - i);
485
- return [o, l, r];
486
- };
487
- c.xyz.oklab = function(n) {
488
- const e = n[0] / 100, t = n[1] / 100, i = n[2] / 100, o = Math.cbrt(0.8189330101 * e + 0.3618667424 * t - 0.1288597137 * i), l = Math.cbrt(0.0329845436 * e + 0.9293118715 * t + 0.0361456387 * i), r = Math.cbrt(0.0482003018 * e + 0.2643662691 * t + 0.633851707 * i), a = 0.2104542553 * o + 0.793617785 * l - 0.0040720468 * r, s = 1.9779984951 * o - 2.428592205 * l + 0.4505937099 * r, u = 0.0259040371 * o + 0.7827717662 * l - 0.808675766 * r;
489
- return [a * 100, s * 100, u * 100];
490
- };
491
- c.oklab.oklch = function(n) {
492
- return c.lab.lch(n);
493
- };
494
- c.oklab.xyz = function(n) {
495
- const e = n[0] / 100, t = n[1] / 100, i = n[2] / 100, o = (0.999999998 * e + 0.396337792 * t + 0.215803758 * i) ** 3, l = (1.000000008 * e - 0.105561342 * t - 0.063854175 * i) ** 3, r = (1.000000055 * e - 0.089484182 * t - 1.291485538 * i) ** 3, a = 1.227013851 * o - 0.55779998 * l + 0.281256149 * r, s = -0.040580178 * o + 1.11225687 * l - 0.071676679 * r, u = -0.076381285 * o - 0.421481978 * l + 1.58616322 * r;
496
- return [a * 100, s * 100, u * 100];
497
- };
498
- c.oklab.rgb = function(n) {
499
- const e = n[0] / 100, t = n[1] / 100, i = n[2] / 100, o = (e + 0.3963377774 * t + 0.2158037573 * i) ** 3, l = (e - 0.1055613458 * t - 0.0638541728 * i) ** 3, r = (e - 0.0894841775 * t - 1.291485548 * i) ** 3, a = S(4.0767416621 * o - 3.3077115913 * l + 0.2309699292 * r), s = S(-1.2684380046 * o + 2.6097574011 * l - 0.3413193965 * r), u = S(-0.0041960863 * o - 0.7034186147 * l + 1.707614701 * r);
500
- return [a * 255, s * 255, u * 255];
501
- };
502
- c.oklch.oklab = function(n) {
503
- return c.lch.lab(n);
504
- };
505
- c.lab.xyz = function(n) {
506
- const e = n[0], t = n[1], i = n[2];
507
- let o, l, r;
508
- l = (e + 16) / 116, o = t / 500 + l, r = l - i / 200;
509
- const a = l ** 3, s = o ** 3, u = r ** 3;
510
- return l = a > v ? a : (l - 16 / 116) / 7.787, o = s > v ? s : (o - 16 / 116) / 7.787, r = u > v ? u : (r - 16 / 116) / 7.787, o *= 95.047, l *= 100, r *= 108.883, [o, l, r];
511
- };
512
- c.lab.lch = function(n) {
513
- const e = n[0], t = n[1], i = n[2];
514
- let o;
515
- o = Math.atan2(i, t) * 360 / 2 / Math.PI, o < 0 && (o += 360);
516
- const r = Math.sqrt(t * t + i * i);
517
- return [e, r, o];
518
- };
519
- c.lch.lab = function(n) {
520
- const e = n[0], t = n[1], o = n[2] / 360 * 2 * Math.PI, l = t * Math.cos(o), r = t * Math.sin(o);
521
- return [e, l, r];
522
- };
523
- c.rgb.ansi16 = function(n, e = null) {
524
- const [t, i, o] = n;
525
- let l = e === null ? c.rgb.hsv(n)[2] : e;
526
- if (l = Math.round(l / 50), l === 0)
527
- return 30;
528
- let r = 30 + (Math.round(o / 255) << 2 | Math.round(i / 255) << 1 | Math.round(t / 255));
529
- return l === 2 && (r += 60), r;
530
- };
531
- c.hsv.ansi16 = function(n) {
532
- return c.rgb.ansi16(c.hsv.rgb(n), n[2]);
533
- };
534
- c.rgb.ansi256 = function(n) {
535
- const e = n[0], t = n[1], i = n[2];
536
- return e >> 4 === t >> 4 && t >> 4 === i >> 4 ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 * Math.round(t / 255 * 5) + Math.round(i / 255 * 5);
537
- };
538
- c.ansi16.rgb = function(n) {
539
- n = n[0];
540
- let e = n % 10;
541
- if (e === 0 || e === 7)
542
- return n > 50 && (e += 3.5), e = e / 10.5 * 255, [e, e, e];
543
- const t = (Math.trunc(n > 50) + 1) * 0.5, i = (e & 1) * t * 255, o = (e >> 1 & 1) * t * 255, l = (e >> 2 & 1) * t * 255;
544
- return [i, o, l];
545
- };
546
- c.ansi256.rgb = function(n) {
547
- if (n = n[0], n >= 232) {
548
- const l = (n - 232) * 10 + 8;
549
- return [l, l, l];
550
- }
551
- n -= 16;
552
- let e;
553
- const t = Math.floor(n / 36) / 5 * 255, i = Math.floor((e = n % 36) / 6) / 5 * 255, o = e % 6 / 5 * 255;
554
- return [t, i, o];
555
- };
556
- c.rgb.hex = function(n) {
557
- const t = (((Math.round(n[0]) & 255) << 16) + ((Math.round(n[1]) & 255) << 8) + (Math.round(n[2]) & 255)).toString(16).toUpperCase();
558
- return "000000".slice(t.length) + t;
559
- };
560
- c.hex.rgb = function(n) {
561
- const e = n.toString(16).match(/[a-f\d]{6}|[a-f\d]{3}/i);
562
- if (!e)
563
- return [0, 0, 0];
564
- let t = e[0];
565
- e[0].length === 3 && (t = [...t].map((a) => a + a).join(""));
566
- const i = Number.parseInt(t, 16), o = i >> 16 & 255, l = i >> 8 & 255, r = i & 255;
567
- return [o, l, r];
568
- };
569
- c.rgb.hcg = function(n) {
570
- const e = n[0] / 255, t = n[1] / 255, i = n[2] / 255, o = Math.max(Math.max(e, t), i), l = Math.min(Math.min(e, t), i), r = o - l;
571
- let a;
572
- const s = r < 1 ? l / (1 - r) : 0;
573
- return r <= 0 ? a = 0 : o === e ? a = (t - i) / r % 6 : o === t ? a = 2 + (i - e) / r : a = 4 + (e - t) / r, a /= 6, a %= 1, [a * 360, r * 100, s * 100];
574
- };
575
- c.hsl.hcg = function(n) {
576
- const e = n[1] / 100, t = n[2] / 100, i = t < 0.5 ? 2 * e * t : 2 * e * (1 - t);
577
- let o = 0;
578
- return i < 1 && (o = (t - 0.5 * i) / (1 - i)), [n[0], i * 100, o * 100];
579
- };
580
- c.hsv.hcg = function(n) {
581
- const e = n[1] / 100, t = n[2] / 100, i = e * t;
582
- let o = 0;
583
- return i < 1 && (o = (t - i) / (1 - i)), [n[0], i * 100, o * 100];
584
- };
585
- c.hcg.rgb = function(n) {
586
- const e = n[0] / 360, t = n[1] / 100, i = n[2] / 100;
587
- if (t === 0)
588
- return [i * 255, i * 255, i * 255];
589
- const o = [0, 0, 0], l = e % 1 * 6, r = l % 1, a = 1 - r;
590
- let s = 0;
591
- switch (Math.floor(l)) {
592
- case 0: {
593
- o[0] = 1, o[1] = r, o[2] = 0;
594
- break;
595
- }
596
- case 1: {
597
- o[0] = a, o[1] = 1, o[2] = 0;
598
- break;
599
- }
600
- case 2: {
601
- o[0] = 0, o[1] = 1, o[2] = r;
602
- break;
603
- }
604
- case 3: {
605
- o[0] = 0, o[1] = a, o[2] = 1;
606
- break;
607
- }
608
- case 4: {
609
- o[0] = r, o[1] = 0, o[2] = 1;
610
- break;
611
- }
612
- default:
613
- o[0] = 1, o[1] = 0, o[2] = a;
614
- }
615
- return s = (1 - t) * i, [
616
- (t * o[0] + s) * 255,
617
- (t * o[1] + s) * 255,
618
- (t * o[2] + s) * 255
619
- ];
620
- };
621
- c.hcg.hsv = function(n) {
622
- const e = n[1] / 100, t = n[2] / 100, i = e + t * (1 - e);
623
- let o = 0;
624
- return i > 0 && (o = e / i), [n[0], o * 100, i * 100];
625
- };
626
- c.hcg.hsl = function(n) {
627
- const e = n[1] / 100, i = n[2] / 100 * (1 - e) + 0.5 * e;
628
- let o = 0;
629
- return i > 0 && i < 0.5 ? o = e / (2 * i) : i >= 0.5 && i < 1 && (o = e / (2 * (1 - i))), [n[0], o * 100, i * 100];
630
- };
631
- c.hcg.hwb = function(n) {
632
- const e = n[1] / 100, t = n[2] / 100, i = e + t * (1 - e);
633
- return [n[0], (i - e) * 100, (1 - i) * 100];
634
- };
635
- c.hwb.hcg = function(n) {
636
- const e = n[1] / 100, i = 1 - n[2] / 100, o = i - e;
637
- let l = 0;
638
- return o < 1 && (l = (i - o) / (1 - o)), [n[0], o * 100, l * 100];
639
- };
640
- c.apple.rgb = function(n) {
641
- return [n[0] / 65535 * 255, n[1] / 65535 * 255, n[2] / 65535 * 255];
642
- };
643
- c.rgb.apple = function(n) {
644
- return [n[0] / 255 * 65535, n[1] / 255 * 65535, n[2] / 255 * 65535];
645
- };
646
- c.gray.rgb = function(n) {
647
- return [n[0] / 100 * 255, n[0] / 100 * 255, n[0] / 100 * 255];
648
- };
649
- c.gray.hsl = function(n) {
650
- return [0, 0, n[0]];
651
- };
652
- c.gray.hsv = c.gray.hsl;
653
- c.gray.hwb = function(n) {
654
- return [0, 100, n[0]];
655
- };
656
- c.gray.cmyk = function(n) {
657
- return [0, 0, 0, n[0]];
658
- };
659
- c.gray.lab = function(n) {
660
- return [n[0], 0, 0];
661
- };
662
- c.gray.hex = function(n) {
663
- const e = Math.round(n[0] / 100 * 255) & 255, i = ((e << 16) + (e << 8) + e).toString(16).toUpperCase();
664
- return "000000".slice(i.length) + i;
665
- };
666
- c.rgb.gray = function(n) {
667
- return [(n[0] + n[1] + n[2]) / 3 / 255 * 100];
668
- };
669
- function on() {
670
- const n = {}, e = Object.keys(c);
671
- for (let { length: t } = e, i = 0; i < t; i++)
672
- n[e[i]] = {
673
- // http://jsperf.com/1-vs-infinity
674
- // micro-opt, but this is simple.
675
- distance: -1,
676
- parent: null
677
- };
678
- return n;
679
- }
680
- function rn(n) {
681
- const e = on(), t = [n];
682
- for (e[n].distance = 0; t.length > 0; ) {
683
- const i = t.pop(), o = Object.keys(c[i]);
684
- for (let { length: l } = o, r = 0; r < l; r++) {
685
- const a = o[r], s = e[a];
686
- s.distance === -1 && (s.distance = e[i].distance + 1, s.parent = i, t.unshift(a));
687
- }
688
- }
689
- return e;
690
- }
691
- function ln(n, e) {
692
- return function(t) {
693
- return e(n(t));
694
- };
695
- }
696
- function an(n, e) {
697
- const t = [e[n].parent, n];
698
- let i = c[e[n].parent][n], o = e[n].parent;
699
- for (; e[o].parent; )
700
- t.unshift(e[o].parent), i = ln(c[e[o].parent][o], i), o = e[o].parent;
701
- return i.conversion = t, i;
702
- }
703
- function sn(n) {
704
- const e = rn(n), t = {}, i = Object.keys(e);
705
- for (let { length: o } = i, l = 0; l < o; l++) {
706
- const r = i[l];
707
- e[r].parent !== null && (t[r] = an(r, e));
708
- }
709
- return t;
710
- }
711
- const m = {}, cn = Object.keys(c);
712
- function un(n) {
713
- const e = function(...t) {
714
- const i = t[0];
715
- return i == null ? i : (i.length > 1 && (t = i), n(t));
716
- };
717
- return "conversion" in n && (e.conversion = n.conversion), e;
718
- }
719
- function dn(n) {
720
- const e = function(...t) {
721
- const i = t[0];
722
- if (i == null)
723
- return i;
724
- i.length > 1 && (t = i);
725
- const o = n(t);
726
- if (typeof o == "object")
727
- for (let { length: l } = o, r = 0; r < l; r++)
728
- o[r] = Math.round(o[r]);
729
- return o;
730
- };
731
- return "conversion" in n && (e.conversion = n.conversion), e;
732
- }
733
- for (const n of cn) {
734
- m[n] = {}, Object.defineProperty(m[n], "channels", { value: c[n].channels }), Object.defineProperty(m[n], "labels", { value: c[n].labels });
735
- const e = sn(n), t = Object.keys(e);
736
- for (const i of t) {
737
- const o = e[i];
738
- m[n][i] = dn(o), m[n][i].raw = un(o);
739
- }
740
- }
741
- const Z = [
742
- // To be honest, I don't really feel like keyword belongs in color convert, but eh.
743
- "keyword",
744
- // Gray conflicts with some method names, and has its own method defined.
745
- "gray",
746
- // Shouldn't really be in color-convert either...
747
- "hex"
748
- ], $ = {};
749
- for (const n of Object.keys(m))
750
- $[[...m[n].labels].sort().join("")] = n;
751
- const K = {};
752
- function f(n, e) {
753
- if (!(this instanceof f))
754
- return new f(n, e);
755
- if (e && e in Z && (e = null), e && !(e in m))
756
- throw new Error("Unknown model: " + e);
757
- let t, i;
758
- if (n == null)
759
- this.model = "rgb", this.color = [0, 0, 0], this.valpha = 1;
760
- else if (n instanceof f)
761
- this.model = n.model, this.color = [...n.color], this.valpha = n.valpha;
762
- else if (typeof n == "string") {
763
- const o = g.get(n);
764
- if (o === null)
765
- throw new Error("Unable to parse color from string: " + n);
766
- this.model = o.model, i = m[this.model].channels, this.color = o.value.slice(0, i), this.valpha = typeof o.value[i] == "number" ? o.value[i] : 1;
767
- } else if (n.length > 0) {
768
- this.model = e || "rgb", i = m[this.model].channels;
769
- const o = Array.prototype.slice.call(n, 0, i);
770
- this.color = D(o, i), this.valpha = typeof n[i] == "number" ? n[i] : 1;
771
- } else if (typeof n == "number")
772
- this.model = "rgb", this.color = [
773
- n >> 16 & 255,
774
- n >> 8 & 255,
775
- n & 255
776
- ], this.valpha = 1;
777
- else {
778
- this.valpha = 1;
779
- const o = Object.keys(n);
780
- "alpha" in n && (o.splice(o.indexOf("alpha"), 1), this.valpha = typeof n.alpha == "number" ? n.alpha : 0);
781
- const l = o.sort().join("");
782
- if (!(l in $))
783
- throw new Error("Unable to parse color from object: " + JSON.stringify(n));
784
- this.model = $[l];
785
- const { labels: r } = m[this.model], a = [];
786
- for (t = 0; t < r.length; t++)
787
- a.push(n[r[t]]);
788
- this.color = D(a);
789
- }
790
- if (K[this.model])
791
- for (i = m[this.model].channels, t = 0; t < i; t++) {
792
- const o = K[this.model][t];
793
- o && (this.color[t] = o(this.color[t]));
794
- }
795
- this.valpha = Math.max(0, Math.min(1, this.valpha)), Object.freeze && Object.freeze(this);
796
- }
797
- f.prototype = {
798
- toString() {
799
- return this.string();
800
- },
801
- toJSON() {
802
- return this[this.model]();
803
- },
804
- string(n) {
805
- let e = this.model in g.to ? this : this.rgb();
806
- e = e.round(typeof n == "number" ? n : 1);
807
- const t = e.valpha === 1 ? e.color : [...e.color, this.valpha];
808
- return g.to[e.model](...t);
809
- },
810
- percentString(n) {
811
- const e = this.rgb().round(typeof n == "number" ? n : 1), t = e.valpha === 1 ? e.color : [...e.color, this.valpha];
812
- return g.to.rgb.percent(...t);
813
- },
814
- array() {
815
- return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
816
- },
817
- object() {
818
- const n = {}, { channels: e } = m[this.model], { labels: t } = m[this.model];
819
- for (let i = 0; i < e; i++)
820
- n[t[i]] = this.color[i];
821
- return this.valpha !== 1 && (n.alpha = this.valpha), n;
822
- },
823
- unitArray() {
824
- const n = this.rgb().color;
825
- return n[0] /= 255, n[1] /= 255, n[2] /= 255, this.valpha !== 1 && n.push(this.valpha), n;
826
- },
827
- unitObject() {
828
- const n = this.rgb().object();
829
- return n.r /= 255, n.g /= 255, n.b /= 255, this.valpha !== 1 && (n.alpha = this.valpha), n;
830
- },
831
- round(n) {
832
- return n = Math.max(n || 0, 0), new f([...this.color.map(pn(n)), this.valpha], this.model);
833
- },
834
- alpha(n) {
835
- return n !== void 0 ? new f([...this.color, Math.max(0, Math.min(1, n))], this.model) : this.valpha;
836
- },
837
- // Rgb
838
- red: p("rgb", 0, b(255)),
839
- green: p("rgb", 1, b(255)),
840
- blue: p("rgb", 2, b(255)),
841
- hue: p(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, (n) => (n % 360 + 360) % 360),
842
- saturationl: p("hsl", 1, b(100)),
843
- lightness: p("hsl", 2, b(100)),
844
- saturationv: p("hsv", 1, b(100)),
845
- value: p("hsv", 2, b(100)),
846
- chroma: p("hcg", 1, b(100)),
847
- gray: p("hcg", 2, b(100)),
848
- white: p("hwb", 1, b(100)),
849
- wblack: p("hwb", 2, b(100)),
850
- cyan: p("cmyk", 0, b(100)),
851
- magenta: p("cmyk", 1, b(100)),
852
- yellow: p("cmyk", 2, b(100)),
853
- black: p("cmyk", 3, b(100)),
854
- x: p("xyz", 0, b(95.047)),
855
- y: p("xyz", 1, b(100)),
856
- z: p("xyz", 2, b(108.833)),
857
- l: p("lab", 0, b(100)),
858
- a: p("lab", 1),
859
- b: p("lab", 2),
860
- keyword(n) {
861
- return n !== void 0 ? new f(n) : m[this.model].keyword(this.color);
862
- },
863
- hex(n) {
864
- return n !== void 0 ? new f(n) : g.to.hex(...this.rgb().round().color);
865
- },
866
- hexa(n) {
867
- if (n !== void 0)
868
- return new f(n);
869
- const e = this.rgb().round().color;
870
- let t = Math.round(this.valpha * 255).toString(16).toUpperCase();
871
- return t.length === 1 && (t = "0" + t), g.to.hex(...e) + t;
872
- },
873
- rgbNumber() {
874
- const n = this.rgb().color;
875
- return (n[0] & 255) << 16 | (n[1] & 255) << 8 | n[2] & 255;
876
- },
877
- luminosity() {
878
- const n = this.rgb().color, e = [];
879
- for (const [t, i] of n.entries()) {
880
- const o = i / 255;
881
- e[t] = o <= 0.04045 ? o / 12.92 : ((o + 0.055) / 1.055) ** 2.4;
882
- }
883
- return 0.2126 * e[0] + 0.7152 * e[1] + 0.0722 * e[2];
884
- },
885
- contrast(n) {
886
- const e = this.luminosity(), t = n.luminosity();
887
- return e > t ? (e + 0.05) / (t + 0.05) : (t + 0.05) / (e + 0.05);
888
- },
889
- level(n) {
890
- const e = this.contrast(n);
891
- return e >= 7 ? "AAA" : e >= 4.5 ? "AA" : "";
892
- },
893
- isDark() {
894
- const n = this.rgb().color;
895
- return (n[0] * 2126 + n[1] * 7152 + n[2] * 722) / 1e4 < 128;
896
- },
897
- isLight() {
898
- return !this.isDark();
899
- },
900
- negate() {
901
- const n = this.rgb();
902
- for (let e = 0; e < 3; e++)
903
- n.color[e] = 255 - n.color[e];
904
- return n;
905
- },
906
- lighten(n) {
907
- const e = this.hsl();
908
- return e.color[2] += e.color[2] * n, e;
909
- },
910
- darken(n) {
911
- const e = this.hsl();
912
- return e.color[2] -= e.color[2] * n, e;
913
- },
914
- saturate(n) {
915
- const e = this.hsl();
916
- return e.color[1] += e.color[1] * n, e;
917
- },
918
- desaturate(n) {
919
- const e = this.hsl();
920
- return e.color[1] -= e.color[1] * n, e;
921
- },
922
- whiten(n) {
923
- const e = this.hwb();
924
- return e.color[1] += e.color[1] * n, e;
925
- },
926
- blacken(n) {
927
- const e = this.hwb();
928
- return e.color[2] += e.color[2] * n, e;
929
- },
930
- grayscale() {
931
- const n = this.rgb().color, e = n[0] * 0.3 + n[1] * 0.59 + n[2] * 0.11;
932
- return f.rgb(e, e, e);
933
- },
934
- fade(n) {
935
- return this.alpha(this.valpha - this.valpha * n);
936
- },
937
- opaquer(n) {
938
- return this.alpha(this.valpha + this.valpha * n);
939
- },
940
- rotate(n) {
941
- const e = this.hsl();
942
- let t = e.color[0];
943
- return t = (t + n) % 360, t = t < 0 ? 360 + t : t, e.color[0] = t, e;
944
- },
945
- mix(n, e) {
946
- if (!n || !n.rgb)
947
- throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof n);
948
- const t = n.rgb(), i = this.rgb(), o = e === void 0 ? 0.5 : e, l = 2 * o - 1, r = t.alpha() - i.alpha(), a = ((l * r === -1 ? l : (l + r) / (1 + l * r)) + 1) / 2, s = 1 - a;
949
- return f.rgb(
950
- a * t.red() + s * i.red(),
951
- a * t.green() + s * i.green(),
952
- a * t.blue() + s * i.blue(),
953
- t.alpha() * o + i.alpha() * (1 - o)
954
- );
955
- }
956
- };
957
- for (const n of Object.keys(m)) {
958
- if (Z.includes(n))
959
- continue;
960
- const { channels: e } = m[n];
961
- f.prototype[n] = function(...t) {
962
- return this.model === n ? new f(this) : t.length > 0 ? new f(t, n) : new f([...fn(m[this.model][n].raw(this.color)), this.valpha], n);
963
- }, f[n] = function(...t) {
964
- let i = t[0];
965
- return typeof i == "number" && (i = D(t, e)), new f(i, n);
966
- };
967
- }
968
- function hn(n, e) {
969
- return Number(n.toFixed(e));
970
- }
971
- function pn(n) {
972
- return function(e) {
973
- return hn(e, n);
974
- };
975
- }
976
- function p(n, e, t) {
977
- n = Array.isArray(n) ? n : [n];
978
- for (const i of n)
979
- (K[i] || (K[i] = []))[e] = t;
980
- return n = n[0], function(i) {
981
- let o;
982
- return i !== void 0 ? (t && (i = t(i)), o = this[n](), o.color[e] = i, o) : (o = this[n]().color[e], t && (o = t(o)), o);
983
- };
984
- }
985
- function b(n) {
986
- return function(e) {
987
- return Math.max(0, Math.min(n, e));
988
- };
989
- }
990
- function fn(n) {
991
- return Array.isArray(n) ? n : [n];
992
- }
993
- function D(n, e) {
994
- for (let t = 0; t < e; t++)
995
- typeof n[t] != "number" && (n[t] = 0);
996
- return n;
997
- }
998
- function Y(n) {
1
+ import { language_script_pairs as E, get_country_name as A, get_multiline_name as N } from "@protomaps/basemaps";
2
+ import f from "color";
3
+ function j(n) {
999
4
  return !!(typeof n == "string" && (n.startsWith("#") || n.startsWith("rgb(") || n.startsWith("rgba(") || n.startsWith("hsl(") || n.startsWith("hwb(")));
1000
5
  }
1001
- function G(n, e) {
6
+ function S(n, i) {
1002
7
  if (!(typeof n == "string" || typeof n == "number" || typeof n == "boolean" || n === null || n === void 0)) {
1003
8
  if (Array.isArray(n))
1004
- for (let t = 0; t < n.length; t += 1) {
1005
- const i = n[t];
1006
- if (Y(i)) {
1007
- n[t] = e(i);
9
+ for (let e = 0; e < n.length; e += 1) {
10
+ const o = n[e];
11
+ if (j(o)) {
12
+ n[e] = i(o);
1008
13
  continue;
1009
14
  }
1010
- G(i, e);
15
+ S(o, i);
1011
16
  }
1012
17
  else if (typeof n == "object") {
1013
- const t = n, i = Object.keys(n);
1014
- for (const o of i) {
1015
- const l = t[o];
1016
- if (Y(l)) {
1017
- t[o] = e(l);
18
+ const e = n, o = Object.keys(n);
19
+ for (const r of o) {
20
+ const c = e[r];
21
+ if (j(c)) {
22
+ e[r] = i(c);
1018
23
  continue;
1019
24
  }
1020
- G(l, e);
25
+ S(c, i);
1021
26
  }
1022
27
  }
1023
28
  }
1024
29
  }
1025
- function _n(n, e) {
1026
- const t = n / 255, i = t + (1 - t) * t * e;
1027
- return Math.max(0, Math.min(255, i * 255));
30
+ function I(n, i) {
31
+ const e = n / 255, o = e + (1 - e) * e * i;
32
+ return Math.max(0, Math.min(255, o * 255));
1028
33
  }
1029
- function yn(n, e) {
1030
- return n.map((t) => _n(t, e));
34
+ function D(n, i) {
35
+ return n.map((e) => I(e, i));
1031
36
  }
1032
- function bn(n, e, t = 127) {
1033
- const i = Math.max(-0.99, Math.min(0.99, e)), o = i < 0 ? i + 1 : 1 / (1 - i), l = t + o * (n - t);
1034
- return Math.round(Math.max(0, Math.min(255, l)));
37
+ function W(n, i, e = 127) {
38
+ const o = Math.max(-0.99, Math.min(0.99, i)), r = o < 0 ? o + 1 : 1 / (1 - o), c = e + r * (n - e);
39
+ return Math.round(Math.max(0, Math.min(255, c)));
1035
40
  }
1036
- function gn(n, e, t = 127) {
1037
- return n.map((i) => bn(i, e, t));
41
+ function $(n, i, e = 127) {
42
+ return n.map((o) => W(o, i, e));
1038
43
  }
1039
- function mn(n, e, t = 1) {
1040
- return 255 * (n / 255) * (e / 255) * t + n / 255 * (1 - t) * 255;
44
+ function F(n, i, e = 1) {
45
+ return 255 * (n / 255) * (i / 255) * e + n / 255 * (1 - e) * 255;
1041
46
  }
1042
- function kn(n, e, t = 1) {
1043
- return n.map((i, o) => mn(n[o], e[o], t));
47
+ function P(n, i, e = 1) {
48
+ return n.map((o, r) => F(n[r], i[r], e));
1044
49
  }
1045
- const xn = `[
50
+ const U = `[
1046
51
  {
1047
52
  "id": "background",
1048
53
  "type": "background",
@@ -2150,7 +1155,7 @@ const xn = `[
2150
1155
  }
2151
1156
  },
2152
1157
  {
2153
- "id": "roads_major_casing_early",
1158
+ "id": "roads_major_casing_early2",
2154
1159
  "type": "line",
2155
1160
  "source": "<BMK_BM_SRC>",
2156
1161
  "source-layer": "roads",
@@ -2159,29 +1164,31 @@ const xn = `[
2159
1164
  "all",
2160
1165
  ["!has", "is_tunnel"],
2161
1166
  ["!has", "is_bridge"],
2162
- ["==", "kind", "major_road"]
1167
+ ["in", "kind", "major_road"]
2163
1168
  ],
2164
1169
  "layout": {"visibility": "visible"},
2165
1170
  "paint": {
2166
- "line-color": "rgba(194, 194, 194, 1)",
1171
+ "line-color": "#D1CFC7",
2167
1172
  "line-gap-width": [
2168
1173
  "interpolate",
2169
1174
  ["exponential", 1.6],
2170
1175
  ["zoom"],
2171
- 7,
1176
+ 3,
2172
1177
  0,
2173
- 7.5,
1178
+ 3.5,
2174
1179
  0.5,
2175
1180
  18,
2176
- 13
1181
+ 15
2177
1182
  ],
2178
1183
  "line-width": [
2179
1184
  "interpolate",
2180
1185
  ["exponential", 1.6],
2181
1186
  ["zoom"],
2182
- 9,
1187
+ 3,
2183
1188
  0,
2184
- 9.5,
1189
+ 6,
1190
+ 1.3,
1191
+ 12,
2185
1192
  1
2186
1193
  ]
2187
1194
  }
@@ -2195,7 +1202,7 @@ const xn = `[
2195
1202
  "all",
2196
1203
  ["!has", "is_tunnel"],
2197
1204
  ["!has", "is_bridge"],
2198
- ["==", "kind", "major_road"]
1205
+ ["in", "kind", "major_road"]
2199
1206
  ],
2200
1207
  "layout": {"visibility": "visible"},
2201
1208
  "paint": {
@@ -2203,14 +1210,16 @@ const xn = `[
2203
1210
  "interpolate",
2204
1211
  ["exponential", 1.6],
2205
1212
  ["zoom"],
2206
- 6,
1213
+ 3,
2207
1214
  0,
1215
+ 6,
1216
+ 1.1,
2208
1217
  12,
2209
1218
  1.6,
2210
1219
  15,
2211
- 3,
1220
+ 5,
2212
1221
  18,
2213
- 13
1222
+ 15
2214
1223
  ],
2215
1224
  "line-color": "#E7E5DE"
2216
1225
  }
@@ -3241,28 +2250,28 @@ const xn = `[
3241
2250
  }
3242
2251
 
3243
2252
  ]`;
3244
- function nn(n, e) {
3245
- const t = U.filter((i) => i.lang === n);
3246
- if (t.length === 0)
2253
+ function O(n, i) {
2254
+ const e = E.filter((o) => o.lang === n);
2255
+ if (e.length === 0)
3247
2256
  throw new Error(
3248
- `The language "${n}". The languages available are: ${U.map((i) => i.lang).join(", ")}.`
2257
+ `The language "${n}". The languages available are: ${E.map((o) => o.lang).join(", ")}.`
3249
2258
  );
3250
- if (e) {
3251
- if (t.filter((o) => o.script === e).length)
2259
+ if (i) {
2260
+ if (e.filter((r) => r.script === i).length)
3252
2261
  return !0;
3253
2262
  throw new Error(
3254
- `The script "${e}" for the language "${n}" is unsupported. Script available for this language: ${t.map((o) => o.script).join(", ")}.`
2263
+ `The script "${i}" for the language "${n}" is unsupported. Script available for this language: ${e.map((r) => r.script).join(", ")}.`
3255
2264
  );
3256
2265
  }
3257
2266
  return !0;
3258
2267
  }
3259
- function Mn() {
2268
+ function J() {
3260
2269
  const n = Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];
3261
- return nn(n, void 0) ? n : "en";
2270
+ return O(n, void 0) ? n : "en";
3262
2271
  }
3263
- const F = {
3264
- avenue: xn
3265
- }, P = {
2272
+ const b = {
2273
+ avenue: U
2274
+ }, z = {
3266
2275
  "avenue-pop": {
3267
2276
  baseStyle: "avenue",
3268
2277
  colorEdit: {
@@ -3336,118 +2345,118 @@ const F = {
3336
2345
  contrast: [0.2, 200]
3337
2346
  }
3338
2347
  }
3339
- }, H = "__bmk_bm_src", T = "__bmk_tr_src";
3340
- function zn() {
3341
- return Object.keys(F).concat(Object.keys(P));
2348
+ }, L = "__bmk_bm_src", w = "__bmk_tr_src";
2349
+ function V() {
2350
+ return Object.keys(b).concat(Object.keys(z));
3342
2351
  }
3343
- function Sn(n, e) {
3344
- if (n in F)
3345
- return V({
3346
- ...e,
2352
+ function X(n, i) {
2353
+ if (n in b)
2354
+ return T({
2355
+ ...i,
3347
2356
  baseStyleName: n
3348
2357
  });
3349
- if (n in P) {
3350
- const t = P[n];
3351
- return V({
3352
- ...e,
3353
- baseStyleName: t.baseStyle,
3354
- colorEdit: t.colorEdit
2358
+ if (n in z) {
2359
+ const e = z[n];
2360
+ return T({
2361
+ ...i,
2362
+ baseStyleName: e.baseStyle,
2363
+ colorEdit: e.colorEdit
3355
2364
  });
3356
2365
  }
3357
2366
  throw new Error(`The style "${n}" does not exist as a base style, nor as a preset.`);
3358
2367
  }
3359
- function V(n) {
3360
- let e, t;
3361
- const i = n.hideLabels ?? !1;
3362
- if (i)
3363
- e = '""', t = '""';
3364
- else if (typeof n.lang == "string" && nn(n.lang, n.script))
3365
- e = JSON.stringify(W(n.lang, n.script)), t = JSON.stringify(J(n.lang, n.script));
2368
+ function T(n) {
2369
+ let i, e;
2370
+ const o = n.hideLabels ?? !1;
2371
+ if (o)
2372
+ i = '""', e = '""';
2373
+ else if (typeof n.lang == "string" && O(n.lang, n.script))
2374
+ i = JSON.stringify(A(n.lang, n.script)), e = JSON.stringify(N(n.lang, n.script));
3366
2375
  else {
3367
- const k = Mn();
3368
- e = JSON.stringify(W(k)), t = JSON.stringify(J(k));
2376
+ const a = J();
2377
+ i = JSON.stringify(A(a)), e = JSON.stringify(N(a));
3369
2378
  }
3370
- if (!(n.baseStyleName in F))
2379
+ if (!(n.baseStyleName in b))
3371
2380
  throw new Error(`The base style ${n.baseStyleName} does not exist.`);
3372
- const l = F[n.baseStyleName].replaceAll("<BMK_BM_SRC>", H).replaceAll("<BMK_TR_SRC>", T).replaceAll('"<LANG>"', t).replaceAll('"<LANG_COUNTRY>"', e);
3373
- let r;
2381
+ const c = b[n.baseStyleName].replaceAll("<BMK_BM_SRC>", L).replaceAll("<BMK_TR_SRC>", w).replaceAll('"<LANG>"', e).replaceAll('"<LANG_COUNTRY>"', i);
2382
+ let g;
3374
2383
  if (typeof n.tilejson == "string")
3375
- r = n.tilejson;
2384
+ g = n.tilejson;
3376
2385
  else if (typeof n.pmtiles == "string")
3377
- r = `pmtiles://${n.pmtiles}`;
2386
+ g = `pmtiles://${n.pmtiles}`;
3378
2387
  else
3379
2388
  throw new Error('At least one option of "tilejson" or "pmtiles" must be provided as data source.');
3380
- let a = "", s = !1, u = "", y = 0;
3381
- n.terrain && (typeof n.terrain.tilejson == "string" ? a = n.terrain.tilejson : typeof n.terrain.pmtiles == "string" && (a = `pmtiles://${n.terrain.pmtiles}`), a && (s = n.terrain.hillshading ?? !0, y = n.terrain.exaggeration ?? 0), u = n.terrain.encoding ?? "mapbox");
3382
- let _ = JSON.parse(l);
3383
- const N = n.hidePOIs ?? !1;
3384
- if (s || (_ = _.filter((k) => k.id !== "hillshader")), N && (_ = _.filter((k) => k.id !== "pois")), i) {
3385
- const k = _.filter((h) => h.id === "pois");
3386
- if (k.length) {
3387
- const h = k[0];
3388
- if (h.layout !== void 0) {
3389
- const w = h.layout;
3390
- w["text-field"] !== void 0 && (w["text-field"] = "");
2389
+ let u = "", m = !1, C = "", h = 0;
2390
+ n.terrain && (typeof n.terrain.tilejson == "string" ? u = n.terrain.tilejson : typeof n.terrain.pmtiles == "string" && (u = `pmtiles://${n.terrain.pmtiles}`), u && (m = n.terrain.hillshading ?? !0, h = n.terrain.exaggeration ?? 0), C = n.terrain.encoding ?? "mapbox");
2391
+ let s = JSON.parse(c);
2392
+ const R = n.hidePOIs ?? !1;
2393
+ if (m || (s = s.filter((a) => a.id !== "hillshader")), R && (s = s.filter((a) => a.id !== "pois")), o) {
2394
+ const a = s.filter((l) => l.id === "pois");
2395
+ if (a.length) {
2396
+ const l = a[0];
2397
+ if (l.layout !== void 0) {
2398
+ const p = l.layout;
2399
+ p["text-field"] !== void 0 && (p["text-field"] = "");
3391
2400
  }
3392
2401
  }
3393
- _ = _.filter((h) => h.id === "pois" || h.type !== "symbol" ? !0 : !(h.layout !== void 0 && h.layout["text-field"] !== void 0));
2402
+ s = s.filter((l) => l.id === "pois" || l.type !== "symbol" ? !0 : !(l.layout !== void 0 && l.layout["text-field"] !== void 0));
3394
2403
  }
3395
- const d = n.colorEdit ?? {}, R = d.brightness ?? 0, E = d.hueRotation ?? 0, O = d.saturation ?? 0, q = d.negate ?? !1, j = d.brightnessShift ?? 0, I = d.exposure ?? 0;
3396
- return (R !== 0 || E !== 0 || O !== 0 || q === !0 || d.multiplyColor !== void 0 || d.mixColor !== void 0 || j !== 0 || d.contrast !== void 0 || I !== 0) && G(_, (k) => {
3397
- let h = f(k);
3398
- if (q && (h = h.negate()), E !== 0 && (h = h.rotate(E)), O !== 0 && (h = h.saturate(O)), R > 0 ? h = h.lighten(R) : R < 0 && (h = h.darken(R * -1)), j !== 0) {
3399
- const z = h.hsl().array();
3400
- z[2] += j * 100, h = f.hsl(...z);
3401
- }
3402
- Array.isArray(d.mixColor) && typeof d.mixColor[0] == "string" && typeof d.mixColor[1] == "number" && d.mixColor[1] !== 0 && (h = h.mix(f(d.mixColor[0]), d.mixColor[1]));
3403
- const w = h.rgb(), en = w.alpha();
3404
- let M = [w.red(), w.green(), w.blue()];
3405
- if (I !== 0 && (M = yn(M, I)), Array.isArray(d.contrast) && typeof d.contrast[0] == "number" && typeof d.contrast[1] == "number" && d.contrast[0] !== 0 && (M = gn(M, d.contrast[0], d.contrast[1])), Array.isArray(d.multiplyColor) && typeof d.multiplyColor[0] == "string" && typeof d.multiplyColor[1] == "number" && d.multiplyColor[1] !== 0) {
3406
- const z = f(d.multiplyColor[0]);
3407
- M = kn(
3408
- M,
3409
- [z.red(), z.green(), z.blue()],
3410
- d.multiplyColor[1]
2404
+ const t = n.colorEdit ?? {}, _ = t.brightness ?? 0, x = t.hueRotation ?? 0, M = t.saturation ?? 0, K = t.negate ?? !1, B = t.brightnessShift ?? 0, k = t.exposure ?? 0;
2405
+ return (_ !== 0 || x !== 0 || M !== 0 || K === !0 || t.multiplyColor !== void 0 || t.mixColor !== void 0 || B !== 0 || t.contrast !== void 0 || k !== 0) && S(s, (a) => {
2406
+ let l = f(a);
2407
+ if (K && (l = l.negate()), x !== 0 && (l = l.rotate(x)), M !== 0 && (l = l.saturate(M)), _ > 0 ? l = l.lighten(_) : _ < 0 && (l = l.darken(_ * -1)), B !== 0) {
2408
+ const y = l.hsl().array();
2409
+ y[2] += B * 100, l = f.hsl(...y);
2410
+ }
2411
+ Array.isArray(t.mixColor) && typeof t.mixColor[0] == "string" && typeof t.mixColor[1] == "number" && t.mixColor[1] !== 0 && (l = l.mix(f(t.mixColor[0]), t.mixColor[1]));
2412
+ const p = l.rgb(), G = p.alpha();
2413
+ let d = [p.red(), p.green(), p.blue()];
2414
+ if (k !== 0 && (d = D(d, k)), Array.isArray(t.contrast) && typeof t.contrast[0] == "number" && typeof t.contrast[1] == "number" && t.contrast[0] !== 0 && (d = $(d, t.contrast[0], t.contrast[1])), Array.isArray(t.multiplyColor) && typeof t.multiplyColor[0] == "string" && typeof t.multiplyColor[1] == "number" && t.multiplyColor[1] !== 0) {
2415
+ const y = f(t.multiplyColor[0]);
2416
+ d = P(
2417
+ d,
2418
+ [y.red(), y.green(), y.blue()],
2419
+ t.multiplyColor[1]
3411
2420
  );
3412
2421
  }
3413
- const L = f({ r: M[0], g: M[1], b: M[2], alpha: en });
3414
- return k.startsWith("rgba(") || k.startsWith("rgb(") ? L.rgb().toString() : k.startsWith("hsl(") || k.startsWith("hsla(") ? L.hsl().toString() : L.hexa();
2422
+ const v = f({ r: d[0], g: d[1], b: d[2], alpha: G });
2423
+ return a.startsWith("rgba(") || a.startsWith("rgb(") ? v.rgb().toString() : a.startsWith("hsl(") || a.startsWith("hsla(") ? v.hsl().toString() : v.hexa();
3415
2424
  }), {
3416
2425
  version: 8,
3417
- ...n.sprite && !N ? { sprite: n.sprite } : {},
2426
+ ...n.sprite && !R ? { sprite: n.sprite } : {},
3418
2427
  glyphs: n.glyphs,
3419
2428
  sources: {
3420
- [H]: {
2429
+ [L]: {
3421
2430
  type: "vector",
3422
- url: r,
2431
+ url: g,
3423
2432
  attribution: "<a href='https://openstreetmap.org/copyright'>© OpenStreetMap Contributors</a>"
3424
2433
  },
3425
2434
  // Add the terrain source if terrain source is provided and the hillshading
3426
2435
  // or terrain is enabled.
3427
- ...a && (y || s) ? {
3428
- [T]: {
3429
- url: a,
2436
+ ...u && (h || m) ? {
2437
+ [w]: {
2438
+ url: u,
3430
2439
  type: "raster-dem",
3431
- encoding: u
2440
+ encoding: C
3432
2441
  }
3433
2442
  } : {}
3434
2443
  },
3435
- layers: _,
2444
+ layers: s,
3436
2445
  projection: { type: ["interpolate", ["linear"], ["zoom"], 7, "vertical-perspective", 8, "mercator"] },
3437
2446
  // Add the terrain if the terrain source is provided and the exaggeration is superior to 0
3438
- ...a && y ? {
2447
+ ...u && h ? {
3439
2448
  terrain: {
3440
- source: T,
3441
- exaggeration: y
2449
+ source: w,
2450
+ exaggeration: h
3442
2451
  }
3443
2452
  } : {}
3444
2453
  };
3445
2454
  }
3446
2455
  export {
3447
- H as BASEMAPKIT_BASEMAP_SOURCE_ID,
3448
- T as BASEMAPKIT_TERRAIN_SOURCE_ID,
3449
- V as buildStyle,
3450
- Sn as getStyle,
3451
- zn as getStyleList
2456
+ L as BASEMAPKIT_BASEMAP_SOURCE_ID,
2457
+ w as BASEMAPKIT_TERRAIN_SOURCE_ID,
2458
+ T as buildStyle,
2459
+ X as getStyle,
2460
+ V as getStyleList
3452
2461
  };
3453
2462
  //# sourceMappingURL=basemapkit.js.map