ts-maps 0.0.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.
Files changed (57) hide show
  1. package/README.md +284 -0
  2. package/dist/apply-transform.d.ts +47 -0
  3. package/dist/base-element.d.ts +5 -0
  4. package/dist/base.d.ts +19 -0
  5. package/dist/brasil.d.ts +1 -0
  6. package/dist/canada.d.ts +1 -0
  7. package/dist/canvas-element.d.ts +8 -0
  8. package/dist/coords-to-point.d.ts +26 -0
  9. package/dist/create-lines.d.ts +39 -0
  10. package/dist/create-markers.d.ts +51 -0
  11. package/dist/create-regions.d.ts +19 -0
  12. package/dist/create-series.d.ts +20 -0
  13. package/dist/data-visualization.d.ts +99 -0
  14. package/dist/deep-merge.d.ts +44 -0
  15. package/dist/event-handler.d.ts +12 -0
  16. package/dist/events.d.ts +14 -0
  17. package/dist/get-inset-for-point.d.ts +24 -0
  18. package/dist/get-marker-position.d.ts +15 -0
  19. package/dist/image-element.d.ts +7 -0
  20. package/dist/index.d.ts +12 -0
  21. package/dist/index.js +2027 -0
  22. package/dist/interactable.d.ts +7 -0
  23. package/dist/italy.d.ts +1 -0
  24. package/dist/legend.d.ts +6 -0
  25. package/dist/line.d.ts +29 -0
  26. package/dist/map.d.ts +422 -0
  27. package/dist/marker.d.ts +31 -0
  28. package/dist/options.d.ts +5 -0
  29. package/dist/ordinal-scale.d.ts +32 -0
  30. package/dist/projection.d.ts +18 -0
  31. package/dist/region.d.ts +21 -0
  32. package/dist/reposition-labels.d.ts +27 -0
  33. package/dist/reposition-lines.d.ts +32 -0
  34. package/dist/reposition-markers.d.ts +26 -0
  35. package/dist/resize.d.ts +5 -0
  36. package/dist/series.d.ts +4 -0
  37. package/dist/set-focus.d.ts +58 -0
  38. package/dist/set-scale.d.ts +80 -0
  39. package/dist/setup-container-events.d.ts +48 -0
  40. package/dist/setup-container-touch-events.d.ts +68 -0
  41. package/dist/setup-element-events.d.ts +125 -0
  42. package/dist/setup-zoom-buttons.d.ts +21 -0
  43. package/dist/shape-element.d.ts +10 -0
  44. package/dist/spain.d.ts +1 -0
  45. package/dist/text-element.d.ts +1 -0
  46. package/dist/tooltip.d.ts +80 -0
  47. package/dist/types.d.ts +398 -0
  48. package/dist/update-size.d.ts +6 -0
  49. package/dist/us-aea-en.d.ts +266 -0
  50. package/dist/us-lcc-en.d.ts +266 -0
  51. package/dist/us-merc-en.d.ts +266 -0
  52. package/dist/us-mill-en.d.ts +266 -0
  53. package/dist/utils.d.ts +21 -0
  54. package/dist/vector-map.d.ts +15 -0
  55. package/dist/world-merc.d.ts +1 -0
  56. package/dist/world.d.ts +1 -0
  57. package/package.json +57 -0
package/dist/index.js ADDED
@@ -0,0 +1,2027 @@
1
+ // src/util/deep-merge.ts
2
+ var deepmerge = function deepmerge2(target, source, options = {}) {
3
+ options.arrayMerge = options.arrayMerge || defaultArrayMerge;
4
+ options.isMergeableObject = options.isMergeableObject || isMergeableObject;
5
+ options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
6
+ const sourceIsArray = Array.isArray(source);
7
+ const targetIsArray = Array.isArray(target);
8
+ const sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
9
+ if (!sourceAndTargetTypesMatch) {
10
+ return cloneUnlessOtherwiseSpecified(source, options);
11
+ }
12
+ if (sourceIsArray) {
13
+ return options.arrayMerge(target, source, options);
14
+ }
15
+ return mergeObject(target, source, options);
16
+ };
17
+ function isMergeableObject(value) {
18
+ return isNonNullObject(value) && !isSpecial(value);
19
+ }
20
+ function isNonNullObject(value) {
21
+ return !!value && typeof value === "object";
22
+ }
23
+ function isSpecial(value) {
24
+ const stringValue = Object.prototype.toString.call(value);
25
+ return stringValue === "[object RegExp]" || stringValue === "[object Date]" || isNode(value) || isReactElement(value);
26
+ }
27
+ var canUseSymbol = typeof Symbol === "function" && Symbol.for;
28
+ var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for("react.element") : 60103;
29
+ function isReactElement(value) {
30
+ return value.$$typeof === REACT_ELEMENT_TYPE;
31
+ }
32
+ function isNode(value) {
33
+ return value instanceof Node;
34
+ }
35
+ function emptyTarget(val) {
36
+ return Array.isArray(val) ? [] : {};
37
+ }
38
+ function cloneUnlessOtherwiseSpecified(value, options) {
39
+ const mergeable = (options.isMergeableObject || isMergeableObject)(value);
40
+ return options.clone !== false && mergeable ? deepmerge(emptyTarget(value), value, options) : value;
41
+ }
42
+ function defaultArrayMerge(target, source, options) {
43
+ return target.concat(source).map((element) => {
44
+ return cloneUnlessOtherwiseSpecified(element, options);
45
+ });
46
+ }
47
+ function getMergeFunction(key, options) {
48
+ if (!options.customMerge) {
49
+ return deepmerge;
50
+ }
51
+ const customMerge = options.customMerge(key);
52
+ return typeof customMerge === "function" ? customMerge : deepmerge;
53
+ }
54
+ function getEnumerableOwnPropertySymbols(target) {
55
+ return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter((symbol) => {
56
+ return Object.prototype.propertyIsEnumerable.call(target, symbol);
57
+ }) : [];
58
+ }
59
+ function getKeys(target) {
60
+ const symbols = getEnumerableOwnPropertySymbols(target);
61
+ const keys = Object.keys(target);
62
+ return [...keys, ...symbols];
63
+ }
64
+ function propertyIsOnObject(object, property) {
65
+ try {
66
+ return property in object;
67
+ } catch {
68
+ return false;
69
+ }
70
+ }
71
+ function propertyIsUnsafe(target, key) {
72
+ return propertyIsOnObject(target, key) && !(Object.hasOwnProperty.call(target, key) && Object.propertyIsEnumerable.call(target, key));
73
+ }
74
+ function mergeObject(target, source, options) {
75
+ const destination = {};
76
+ const mergeableObject = options.isMergeableObject || isMergeableObject;
77
+ if (mergeableObject(target)) {
78
+ getKeys(target).forEach((key) => {
79
+ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
80
+ });
81
+ }
82
+ getKeys(source).forEach((key) => {
83
+ if (propertyIsUnsafe(target, key)) {
84
+ return;
85
+ }
86
+ if (propertyIsOnObject(target, key) && mergeableObject(source[key])) {
87
+ destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
88
+ } else {
89
+ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
90
+ }
91
+ });
92
+ return destination;
93
+ }
94
+ var deep_merge_default = deepmerge;
95
+
96
+ // src/util/index.ts
97
+ function getElement(selector) {
98
+ if (typeof selector === "object" && typeof selector.nodeType !== "undefined") {
99
+ return selector;
100
+ }
101
+ if (typeof selector === "string") {
102
+ return document.querySelector(selector);
103
+ }
104
+ return null;
105
+ }
106
+ function createElement(type, classes, content, html = false) {
107
+ const el = document.createElement(type);
108
+ if (content) {
109
+ el[!html ? "textContent" : "innerHTML"] = content;
110
+ }
111
+ if (classes) {
112
+ el.className = classes;
113
+ }
114
+ return el;
115
+ }
116
+ function removeElement(target) {
117
+ target.parentNode?.removeChild(target);
118
+ }
119
+ function isImageUrl(url) {
120
+ return /\.[jpe?g|ifn]$/i.test(url);
121
+ }
122
+ function hyphenate(str) {
123
+ return str.replace(/\w([A-Z])/g, (m) => `${m[0]}-${m[1]}`).toLowerCase();
124
+ }
125
+ function merge(target, source, deep = false) {
126
+ if (deep) {
127
+ return deep_merge_default(target, source);
128
+ }
129
+ return Object.assign({}, target, source);
130
+ }
131
+ function getLineUid(from, to) {
132
+ return `${from.toLowerCase()}:to:${to.toLowerCase()}`;
133
+ }
134
+ function inherit(target, source) {
135
+ Object.assign(target.prototype, source);
136
+ }
137
+
138
+ // src/components/base.ts
139
+ class BaseComponent {
140
+ _tooltip;
141
+ shape;
142
+ dispose() {
143
+ if (this._tooltip) {
144
+ removeElement(this._tooltip);
145
+ } else if (this.shape) {
146
+ this.shape.remove();
147
+ }
148
+ for (const propertyName of Object.getOwnPropertyNames(this)) {
149
+ this[propertyName] = null;
150
+ }
151
+ }
152
+ }
153
+ var base_default = BaseComponent;
154
+
155
+ // src/components/tooltip.ts
156
+ class Tooltip extends base_default {
157
+ _map;
158
+ _tooltip;
159
+ _hoveredRegion = null;
160
+ _hoveredMarker = null;
161
+ _customPositioning = true;
162
+ constructor(map) {
163
+ super();
164
+ this._map = map;
165
+ this._tooltip = createElement("div", "jvm-tooltip", "");
166
+ this._tooltip.style.display = "none";
167
+ this._map.container.appendChild(this._tooltip);
168
+ return this;
169
+ }
170
+ getElement() {
171
+ return this._tooltip;
172
+ }
173
+ show(text) {
174
+ this._tooltip.style.display = "block";
175
+ this._tooltip.innerHTML = text;
176
+ this._tooltip.classList.add("active");
177
+ }
178
+ hide() {
179
+ this._tooltip.style.display = "none";
180
+ this._tooltip.classList.remove("active");
181
+ this._hoveredRegion = null;
182
+ this._hoveredMarker = null;
183
+ }
184
+ text(text) {
185
+ if (this._tooltip) {
186
+ this._tooltip.innerHTML = text;
187
+ }
188
+ }
189
+ html(html) {
190
+ if (this._tooltip) {
191
+ this._tooltip.innerHTML = html;
192
+ }
193
+ }
194
+ css(css) {
195
+ if (this._customPositioning && (css.top || css.left)) {
196
+ return this;
197
+ }
198
+ for (const style in css) {
199
+ this._tooltip.style[style] = css[style];
200
+ }
201
+ return this;
202
+ }
203
+ setHoveredRegion(code) {
204
+ this._hoveredRegion = code;
205
+ }
206
+ getHoveredRegion() {
207
+ return this._hoveredRegion;
208
+ }
209
+ setHoveredMarker(index) {
210
+ this._hoveredMarker = index;
211
+ }
212
+ getHoveredMarker() {
213
+ return this._hoveredMarker;
214
+ }
215
+ }
216
+ var tooltip_default = Tooltip;
217
+
218
+ // src/core/apply-transform.ts
219
+ function applyTransform() {
220
+ let maxTransX, maxTransY, minTransX, minTransY;
221
+ if (this._defaultWidth * this.scale <= this._width) {
222
+ maxTransX = (this._width - this._defaultWidth * this.scale) / (2 * this.scale);
223
+ minTransX = (this._width - this._defaultWidth * this.scale) / (2 * this.scale);
224
+ } else {
225
+ maxTransX = 0;
226
+ minTransX = (this._width - this._defaultWidth * this.scale) / this.scale;
227
+ }
228
+ if (this._defaultHeight * this.scale <= this._height) {
229
+ maxTransY = (this._height - this._defaultHeight * this.scale) / (2 * this.scale);
230
+ minTransY = (this._height - this._defaultHeight * this.scale) / (2 * this.scale);
231
+ } else {
232
+ maxTransY = 0;
233
+ minTransY = (this._height - this._defaultHeight * this.scale) / this.scale;
234
+ }
235
+ if (this.transY > maxTransY) {
236
+ this.transY = maxTransY;
237
+ } else if (this.transY < minTransY) {
238
+ this.transY = minTransY;
239
+ }
240
+ if (this.transX > maxTransX) {
241
+ this.transX = maxTransX;
242
+ } else if (this.transX < minTransX) {
243
+ this.transX = minTransX;
244
+ }
245
+ this.canvas.applyTransformParams(this.scale, this.transX, this.transY);
246
+ if (this._markers) {
247
+ this._repositionMarkers();
248
+ }
249
+ if (this._lines) {
250
+ this._repositionLines();
251
+ }
252
+ this._repositionLabels();
253
+ }
254
+
255
+ // src/core/coords-to-point.ts
256
+ function coordsToPoint(lat, lng) {
257
+ const projection = this.params.map?.projection || "mercator";
258
+ const coords = projection === "mercator" ? this.mercator.convert(lat, lng) : this.miller.convert(lat, lng);
259
+ if (coords === false) {
260
+ return false;
261
+ }
262
+ const inset = this.getInsetForPoint(coords.x, coords.y);
263
+ if (!inset) {
264
+ return false;
265
+ }
266
+ const x = inset.leftLng + (coords.x - inset.leftLng) / (inset.rightLng - inset.leftLng) * inset.width;
267
+ const y = inset.topLat + (coords.y - inset.topLat) / (inset.bottomLat - inset.topLat) * inset.height;
268
+ return {
269
+ x,
270
+ y
271
+ };
272
+ }
273
+
274
+ // src/components/line.ts
275
+ var LINE_CLASS = "jvm-line";
276
+
277
+ class Line extends base_default {
278
+ _options;
279
+ _style;
280
+ constructor(options, style) {
281
+ super();
282
+ this._options = options;
283
+ this._style = style;
284
+ this._draw();
285
+ }
286
+ setStyle(property, value) {
287
+ this.shape?.setStyle(property, value);
288
+ }
289
+ getConfig() {
290
+ return this._options.config;
291
+ }
292
+ _draw() {
293
+ const { index, group, map, animate } = this._options;
294
+ const config = {
295
+ d: this._getDAttribute(),
296
+ fill: "none",
297
+ dataIndex: index
298
+ };
299
+ this.shape = map.canvas.createPath(config, this._style, group);
300
+ this.shape?.addClass(LINE_CLASS);
301
+ if (animate) {
302
+ this.shape?.setStyle({ animation: true });
303
+ }
304
+ }
305
+ _getDAttribute() {
306
+ const { x1, y1, x2, y2 } = this._options;
307
+ return `M${x1},${y1}${this._getQCommand(x1, y1, x2, y2)}${x2},${y2}`;
308
+ }
309
+ _getQCommand(x1, y1, x2, y2) {
310
+ if (!this._options.curvature) {
311
+ return " ";
312
+ }
313
+ const curvature = this._options.curvature || 0.6;
314
+ const curveX = (x1 + x2) / 2 + curvature * (y2 - y1);
315
+ const curveY = (y1 + y2) / 2 - curvature * (x2 - x1);
316
+ return ` Q${curveX},${curveY} `;
317
+ }
318
+ }
319
+ var line_default = Line;
320
+
321
+ // src/core/create-lines.ts
322
+ function createLines(lines) {
323
+ const markers = this._markers || {};
324
+ const { style, elements: _, ...rest } = this.params.lines || {};
325
+ let point1 = false;
326
+ let point2 = false;
327
+ for (const index in lines) {
328
+ const lineConfig = lines[index];
329
+ for (const { config: markerConfig } of Object.values(markers)) {
330
+ if (markerConfig.name === lineConfig.from) {
331
+ point1 = this.getMarkerPosition(markerConfig);
332
+ }
333
+ if (markerConfig.name === lineConfig.to) {
334
+ point2 = this.getMarkerPosition(markerConfig);
335
+ }
336
+ }
337
+ if (point1 !== false && point2 !== false) {
338
+ this._lines = this._lines || {};
339
+ this._lines[getLineUid(lineConfig.from, lineConfig.to)] = new line_default({
340
+ index,
341
+ map: this,
342
+ group: this._linesGroup,
343
+ config: lineConfig,
344
+ x1: point1.x,
345
+ y1: point1.y,
346
+ x2: point2.x,
347
+ y2: point2.y,
348
+ ...rest
349
+ }, merge({ initial: style }, { initial: lineConfig.style || {} }, true));
350
+ }
351
+ }
352
+ }
353
+
354
+ // src/components/concerns/interactable.ts
355
+ var Interactable = {
356
+ getLabelText(key, label) {
357
+ if (!label) {
358
+ return;
359
+ }
360
+ if (typeof label.render === "function") {
361
+ const params = [];
362
+ if (this.constructor.Name === "marker") {
363
+ params.push(this.getConfig());
364
+ }
365
+ params.push(key);
366
+ return label.render.apply(this, params);
367
+ }
368
+ return key;
369
+ },
370
+ getLabelOffsets(key, label) {
371
+ if (label && typeof label.offsets === "function") {
372
+ return label.offsets(key);
373
+ }
374
+ if (label && Array.isArray(label.offsets)) {
375
+ return label.offsets[key] || [0, 0];
376
+ }
377
+ return [0, 0];
378
+ },
379
+ setStyle(property, value) {
380
+ this.shape.setStyle(property, value);
381
+ },
382
+ remove() {
383
+ this.shape.remove();
384
+ if (this.label) {
385
+ this.label.remove();
386
+ }
387
+ },
388
+ hover(state) {
389
+ this._setStatus("isHovered", state);
390
+ },
391
+ select(state) {
392
+ this._setStatus("isSelected", state);
393
+ },
394
+ _setStatus(property, state) {
395
+ this.shape[property] = state;
396
+ this.shape.updateStyle();
397
+ this[property] = state;
398
+ if (this.label) {
399
+ this.label[property] = state;
400
+ this.label.updateStyle();
401
+ }
402
+ }
403
+ };
404
+ var interactable_default = Interactable;
405
+
406
+ // src/components/marker.ts
407
+ var NAME = "marker";
408
+ var JVM_PREFIX = "jvm-";
409
+ var MARKER_CLASS = `${JVM_PREFIX}element ${JVM_PREFIX}marker`;
410
+ var MARKER_LABEL_CLASS = `${JVM_PREFIX}element ${JVM_PREFIX}label`;
411
+
412
+ class Marker extends base_default {
413
+ _options;
414
+ _style;
415
+ _labelX = null;
416
+ _labelY = null;
417
+ _offsets = null;
418
+ _isImage;
419
+ label;
420
+ isHovered;
421
+ isSelected = false;
422
+ static get Name() {
423
+ return NAME;
424
+ }
425
+ constructor(options, style) {
426
+ super();
427
+ this._options = options;
428
+ this._style = style;
429
+ this._isImage = !!style.initial.image;
430
+ this._draw();
431
+ if (this._options.label) {
432
+ this._drawLabel();
433
+ }
434
+ if (this._isImage) {
435
+ this.updateLabelPosition();
436
+ }
437
+ }
438
+ getConfig() {
439
+ return this._options.config;
440
+ }
441
+ updateLabelPosition() {
442
+ const map = this._options.map;
443
+ if (this.label && this._labelX !== null && this._labelY !== null && this._offsets) {
444
+ this.label.set({
445
+ x: this._labelX * map.scale + this._offsets[0] + map.transX * map.scale + 5 + (this._isImage ? (this.shape?.width || 0) / 2 : this.shape?.node?.r?.baseVal?.value || 0),
446
+ y: this._labelY * map.scale + map.transY * this._options.map.scale + this._offsets[1]
447
+ });
448
+ }
449
+ }
450
+ _draw() {
451
+ const { index, map, group, cx, cy } = this._options;
452
+ const shapeType = this._isImage ? "createImage" : "createCircle";
453
+ this.shape = map.canvas[shapeType]({ dataIndex: index, cx, cy }, this._style, group);
454
+ this.shape?.addClass(MARKER_CLASS);
455
+ }
456
+ _drawLabel() {
457
+ const {
458
+ index,
459
+ map,
460
+ label,
461
+ labelsGroup,
462
+ cx,
463
+ cy,
464
+ config,
465
+ isRecentlyCreated
466
+ } = this._options;
467
+ const labelText = this.getLabelText(index, label);
468
+ this._labelX = cx / map.scale - map.transX;
469
+ this._labelY = cy / map.scale - map.transY;
470
+ this._offsets = isRecentlyCreated && config?.offsets ? config.offsets : this.getLabelOffsets(index, label);
471
+ this.label = map.canvas.createText({
472
+ text: labelText,
473
+ dataIndex: index,
474
+ x: this._labelX,
475
+ y: this._labelY,
476
+ dy: "0.6ex"
477
+ }, map.params.markerLabelStyle, labelsGroup);
478
+ this.label.addClass(MARKER_LABEL_CLASS);
479
+ if (isRecentlyCreated) {
480
+ this.updateLabelPosition();
481
+ }
482
+ }
483
+ getLabelText(key, label) {
484
+ if (!label) {
485
+ return;
486
+ }
487
+ if (typeof label.render === "function") {
488
+ return label.render(this.getConfig(), key);
489
+ }
490
+ return key;
491
+ }
492
+ getLabelOffsets(key, label) {
493
+ if (label && typeof label.offsets === "function") {
494
+ return label.offsets(key);
495
+ }
496
+ if (label && Array.isArray(label.offsets)) {
497
+ return label.offsets[key] || [0, 0];
498
+ }
499
+ return [0, 0];
500
+ }
501
+ setStyle;
502
+ remove;
503
+ hover;
504
+ select;
505
+ _setStatus;
506
+ }
507
+ inherit(Marker, interactable_default);
508
+ var marker_default = Marker;
509
+
510
+ // src/core/create-markers.ts
511
+ function createMarkers(markers = {}, isRecentlyCreated = false) {
512
+ for (let index in markers) {
513
+ const config = markers[index];
514
+ const point = this.getMarkerPosition(config);
515
+ const uid = config.coords.join(":");
516
+ if (!point) {
517
+ continue;
518
+ }
519
+ if (isRecentlyCreated) {
520
+ if (Object.keys(this._markers || {}).filter((i) => this._markers?.[i]._uid === uid).length) {
521
+ continue;
522
+ }
523
+ index = String(Object.keys(this._markers || {}).length);
524
+ }
525
+ const marker = new marker_default({
526
+ index,
527
+ map: this,
528
+ label: this.params.labels?.markers ? {} : undefined,
529
+ labelsGroup: this._markerLabelsGroup,
530
+ cx: point.x,
531
+ cy: point.y,
532
+ group: this._markersGroup,
533
+ config,
534
+ isRecentlyCreated
535
+ }, merge(this.params.markerStyle || {}, { ...config.style || {} }, true));
536
+ if (this._markers?.[index]) {
537
+ this.removeMarkers([index]);
538
+ }
539
+ this._markers = this._markers || {};
540
+ this._markers[index] = {
541
+ _uid: uid,
542
+ config,
543
+ element: marker
544
+ };
545
+ }
546
+ }
547
+
548
+ // src/components/region.ts
549
+ class Region extends base_default {
550
+ _map;
551
+ labelX = 0;
552
+ labelY = 0;
553
+ label;
554
+ isHovered;
555
+ isSelected = false;
556
+ shape;
557
+ constructor({ map, code, path, style, label, labelStyle, labelsGroup }) {
558
+ super();
559
+ this._map = map;
560
+ this.shape = this._createRegion(path, code, style);
561
+ const text = this.getLabelText(code, label);
562
+ if (label && text) {
563
+ const bbox = this.shape?.getBBox();
564
+ const offsets = this.getLabelOffsets(code, label);
565
+ this.labelX = (bbox?.x ?? 0) + (bbox?.width ?? 0) / 2 + offsets[0];
566
+ this.labelY = (bbox?.y ?? 0) + (bbox?.height ?? 0) / 2 + offsets[1];
567
+ this.label = this._map.canvas.createText({
568
+ text,
569
+ textAnchor: "middle",
570
+ alignmentBaseline: "central",
571
+ dataCode: code,
572
+ x: this.labelX,
573
+ y: this.labelY
574
+ }, labelStyle, labelsGroup);
575
+ this.label.addClass("jvm-region jvm-element");
576
+ }
577
+ }
578
+ _createRegion(path, code, style) {
579
+ const regionPath = this._map.canvas.createPath({ d: path, dataCode: code }, style);
580
+ regionPath.addClass("jvm-region jvm-element");
581
+ return regionPath;
582
+ }
583
+ updateLabelPosition() {
584
+ if (this.label) {
585
+ this.label.set({
586
+ x: this.labelX * this._map.scale + this._map.transX * this._map.scale,
587
+ y: this.labelY * this._map.scale + this._map.transY * this._map.scale
588
+ });
589
+ }
590
+ }
591
+ getLabelText(key, label) {
592
+ if (!label) {
593
+ return;
594
+ }
595
+ if (typeof label.render === "function") {
596
+ return label.render(key);
597
+ }
598
+ return key;
599
+ }
600
+ getLabelOffsets(key, label) {
601
+ if (label && typeof label.offsets === "function") {
602
+ return label.offsets(key);
603
+ }
604
+ if (label && Array.isArray(label.offsets)) {
605
+ return label.offsets[key] || [0, 0];
606
+ }
607
+ return [0, 0];
608
+ }
609
+ setStyle;
610
+ remove;
611
+ hover;
612
+ select;
613
+ _setStatus;
614
+ }
615
+ inherit(Region, interactable_default);
616
+ var region_default = Region;
617
+
618
+ // src/core/create-regions.ts
619
+ function createRegions() {
620
+ this._regionLabelsGroup = this._regionLabelsGroup || this.canvas.createGroup("jvm-regions-labels-group");
621
+ for (const code in this._mapData.paths) {
622
+ const region = new region_default({
623
+ map: this,
624
+ code,
625
+ path: this._mapData.paths[code].path,
626
+ style: merge({}, this.params.regionStyle || {}),
627
+ labelStyle: this.params.regionLabelStyle,
628
+ labelsGroup: this._regionLabelsGroup,
629
+ label: this.params.labels?.regions ? {} : undefined
630
+ });
631
+ this.regions[code] = {
632
+ element: region
633
+ };
634
+ }
635
+ }
636
+
637
+ // src/legend.ts
638
+ class Legend {
639
+ _options;
640
+ _map;
641
+ _series;
642
+ _body;
643
+ constructor(options) {
644
+ this._options = options;
645
+ this._map = this._options.map;
646
+ this._series = this._options.series;
647
+ this._body = createElement("div", "jvm-legend");
648
+ if (this._options.cssClass) {
649
+ this._body.setAttribute("class", this._options.cssClass);
650
+ }
651
+ if (options.vertical) {
652
+ this._map.legendVertical.appendChild(this._body);
653
+ } else {
654
+ this._map.legendHorizontal.appendChild(this._body);
655
+ }
656
+ this.render();
657
+ }
658
+ render() {
659
+ const ticks = this._series.scale.getTicks();
660
+ const inner = createElement("div", "jvm-legend-inner");
661
+ this._body.innerHTML = "";
662
+ if (this._options.title) {
663
+ const legendTitle = createElement("div", "jvm-legend-title", this._options.title);
664
+ this._body.appendChild(legendTitle);
665
+ }
666
+ this._body.appendChild(inner);
667
+ for (let i = 0;i < ticks.length; i++) {
668
+ const tick = createElement("div", "jvm-legend-tick");
669
+ const sample = createElement("div", "jvm-legend-tick-sample");
670
+ switch (this._series.config.attribute) {
671
+ case "fill":
672
+ if (isImageUrl(ticks[i].value)) {
673
+ sample.style.background = `url(${ticks[i].value})`;
674
+ } else {
675
+ sample.style.background = ticks[i].value;
676
+ }
677
+ break;
678
+ case "stroke":
679
+ sample.style.background = ticks[i].value;
680
+ break;
681
+ case "image":
682
+ sample.style.background = `url(${ticks[i].value}) no-repeat center center`;
683
+ sample.style.backgroundSize = "cover";
684
+ break;
685
+ }
686
+ tick.appendChild(sample);
687
+ let label = ticks[i].label;
688
+ if (this._options.labelRender) {
689
+ label = this._options.labelRender(label);
690
+ }
691
+ const tickText = createElement("div", "jvm-legend-tick-text", label);
692
+ tick.appendChild(tickText);
693
+ inner.appendChild(tick);
694
+ }
695
+ }
696
+ }
697
+ var legend_default = Legend;
698
+
699
+ // src/scales/ordinal-scale.ts
700
+ class OrdinalScale {
701
+ _scale;
702
+ constructor(options) {
703
+ this._scale = options.scale;
704
+ }
705
+ getValue(value) {
706
+ return this._scale[String(value)];
707
+ }
708
+ getTicks() {
709
+ const ticks = [];
710
+ for (const key in this._scale) {
711
+ ticks.push({
712
+ value: this._scale[key],
713
+ label: key
714
+ });
715
+ }
716
+ return ticks;
717
+ }
718
+ }
719
+ var ordinal_scale_default = OrdinalScale;
720
+
721
+ // src/series.ts
722
+ class Series {
723
+ _map;
724
+ _elements;
725
+ _values;
726
+ config;
727
+ scale;
728
+ legend;
729
+ constructor(config, elements, map) {
730
+ this._map = map;
731
+ this._elements = elements;
732
+ this._values = config.values || {};
733
+ this.config = config;
734
+ this.config.attribute = config.attribute || "fill";
735
+ if (config.attributes) {
736
+ this.setAttributes(config.attributes);
737
+ }
738
+ if (typeof config.scale === "object") {
739
+ this.scale = new ordinal_scale_default(config.scale);
740
+ }
741
+ if (this.config.legend) {
742
+ this.legend = new legend_default(merge({ map: this._map, series: this }, this.config.legend));
743
+ }
744
+ this.setValues(this._values);
745
+ }
746
+ setValues(values) {
747
+ const attrs = {};
748
+ for (const key in values) {
749
+ if (values[key]) {
750
+ attrs[key] = this.scale.getValue(values[key]);
751
+ }
752
+ }
753
+ this.setAttributes(attrs);
754
+ }
755
+ setAttributes(attrs) {
756
+ for (const code in attrs) {
757
+ if (this._elements[code]) {
758
+ this._elements[code].element.setStyle(this.config.attribute || "fill", attrs[code]);
759
+ }
760
+ }
761
+ }
762
+ clear() {
763
+ const attrs = {};
764
+ for (const key in this._values) {
765
+ if (this._elements[key]) {
766
+ attrs[key] = this._elements[key].element.shape.style.initial[this.config.attribute || "fill"];
767
+ }
768
+ }
769
+ this.setAttributes(attrs);
770
+ this._values = {};
771
+ }
772
+ }
773
+ var series_default = Series;
774
+
775
+ // src/core/create-series.ts
776
+ function createSeries() {
777
+ this.series = { markers: [], regions: [] };
778
+ for (const key in this.params.series) {
779
+ const seriesKey = key;
780
+ if (this.params.series[seriesKey]) {
781
+ for (let i = 0;i < this.params.series[seriesKey].length; i++) {
782
+ this.series[seriesKey][i] = new series_default(this.params.series[seriesKey][i], seriesKey === "markers" ? this._markers || {} : this.regions, this);
783
+ }
784
+ }
785
+ }
786
+ }
787
+
788
+ // src/core/get-inset-for-point.ts
789
+ function getInsetForPoint(x, y) {
790
+ const insets = map_default.maps[this.params.map.name].insets;
791
+ for (let index = 0;index < insets.length; index++) {
792
+ const [start, end] = insets[index].bbox;
793
+ if (x > start.x && x < end.x && y > start.y && y < end.y) {
794
+ return insets[index];
795
+ }
796
+ }
797
+ }
798
+
799
+ // src/core/get-marker-position.ts
800
+ function getMarkerPosition({ coords }) {
801
+ if (map_default.maps[this.params.map.name].projection) {
802
+ return this.coordsToPoint(...coords);
803
+ }
804
+ return {
805
+ x: coords[0] * this.scale + this.transX * this.scale,
806
+ y: coords[1] * this.scale + this.transY * this.scale
807
+ };
808
+ }
809
+
810
+ // src/core/reposition-labels.ts
811
+ function repositionLabels() {
812
+ const labels = this.params.labels || {};
813
+ if (labels.regions) {
814
+ for (const code in this.regions) {
815
+ const region = this.regions[code];
816
+ if (region.label) {
817
+ const x = region.labelX * this.scale + this.transX * this.scale;
818
+ const y = region.labelY * this.scale + this.transY * this.scale;
819
+ region.label.set({
820
+ x: Number.isNaN(x) ? 0 : x,
821
+ y: Number.isNaN(y) ? 0 : y
822
+ });
823
+ }
824
+ }
825
+ }
826
+ if (labels.markers) {
827
+ for (const index in this._markers) {
828
+ const marker = this._markers[index];
829
+ if (marker && typeof marker.updateLabelPosition === "function") {
830
+ marker.updateLabelPosition();
831
+ }
832
+ }
833
+ }
834
+ }
835
+
836
+ // src/core/reposition-lines.ts
837
+ function repositionLines() {
838
+ const curvature = this.params.lines?.curvature || 0.5;
839
+ Object.values(this._lines || {}).forEach((line) => {
840
+ const startMarker = Object.values(this._markers || {}).find(({ config }) => config.name === line.getConfig().from);
841
+ const endMarker = Object.values(this._markers || {}).find(({ config }) => config.name === line.getConfig().to);
842
+ if (startMarker && endMarker) {
843
+ const point1 = this.getMarkerPosition(startMarker.config);
844
+ const point2 = this.getMarkerPosition(endMarker.config);
845
+ if (point1 && point2) {
846
+ const { x: x1, y: y1 } = point1;
847
+ const { x: x2, y: y2 } = point2;
848
+ const midX = (x1 + x2) / 2;
849
+ const midY = (y1 + y2) / 2;
850
+ const curveX = midX + curvature * (y2 - y1);
851
+ const curveY = midY - curvature * (x2 - x1);
852
+ line.setStyle({
853
+ d: `M${x1},${y1} Q${curveX},${curveY} ${x2},${y2}`
854
+ });
855
+ }
856
+ }
857
+ });
858
+ }
859
+
860
+ // src/core/reposition-markers.ts
861
+ function repositionMarkers() {
862
+ if (!this._markers)
863
+ return;
864
+ for (const index in this._markers) {
865
+ const marker = this._markers[index];
866
+ if (!marker || !marker.shape)
867
+ continue;
868
+ const point = this.getMarkerPosition(marker.config);
869
+ if (point !== false) {
870
+ const cx = Number.isNaN(point.x) ? 0 : point.x;
871
+ const cy = Number.isNaN(point.y) ? 0 : point.y;
872
+ marker.shape.set({
873
+ cx,
874
+ cy
875
+ });
876
+ if (marker.label) {
877
+ marker.updateLabelPosition();
878
+ }
879
+ }
880
+ }
881
+ }
882
+
883
+ // src/core/resize.ts
884
+ function resize() {
885
+ const curBaseScale = this._baseScale;
886
+ if (this._width / this._height > this._defaultWidth / this._defaultHeight) {
887
+ this._baseScale = this._height / this._defaultHeight;
888
+ this._baseTransX = Math.abs(this._width - this._defaultWidth * this._baseScale) / (2 * this._baseScale);
889
+ } else {
890
+ this._baseScale = this._width / this._defaultWidth;
891
+ this._baseTransY = Math.abs(this._height - this._defaultHeight * this._baseScale) / (2 * this._baseScale);
892
+ }
893
+ this.scale *= this._baseScale / curBaseScale;
894
+ this.transX *= this._baseScale / curBaseScale;
895
+ this.transY *= this._baseScale / curBaseScale;
896
+ }
897
+ var resize_default = resize;
898
+
899
+ // src/core/set-focus.ts
900
+ function setFocus(config = {}) {
901
+ let bbox;
902
+ let codes = [];
903
+ if (config.region) {
904
+ codes.push(config.region);
905
+ } else if (config.regions) {
906
+ codes = config.regions;
907
+ }
908
+ if (codes.length) {
909
+ codes.forEach((code) => {
910
+ if (this.regions[code]) {
911
+ const itemBbox = this.regions[code].element.shape.getBBox();
912
+ if (itemBbox) {
913
+ if (typeof bbox === "undefined") {
914
+ bbox = itemBbox;
915
+ } else {
916
+ bbox = {
917
+ x: Math.min(bbox.x, itemBbox.x),
918
+ y: Math.min(bbox.y, itemBbox.y),
919
+ width: Math.max(bbox.x + bbox.width, itemBbox.x + itemBbox.width) - Math.min(bbox.x, itemBbox.x),
920
+ height: Math.max(bbox.y + bbox.height, itemBbox.y + itemBbox.height) - Math.min(bbox.y, itemBbox.y)
921
+ };
922
+ }
923
+ }
924
+ }
925
+ });
926
+ if (bbox) {
927
+ return this._setScale(Math.min(this._width / bbox.width, this._height / bbox.height), -(bbox.x + bbox.width / 2), -(bbox.y + bbox.height / 2), true, config.animate);
928
+ }
929
+ } else if (config.coords) {
930
+ const point = this.coordsToPoint(config.coords[0], config.coords[1]);
931
+ if (point) {
932
+ const x = this.transX - point.x / this.scale;
933
+ const y = this.transY - point.y / this.scale;
934
+ return this._setScale(config.scale ? config.scale * this._baseScale : this._baseScale, x, y, true, config.animate);
935
+ }
936
+ }
937
+ }
938
+
939
+ // src/defaults/events.ts
940
+ var events = {
941
+ onLoaded: "map:loaded",
942
+ onViewportChange: "viewport:changed",
943
+ onRegionClick: "region:clicked",
944
+ onMarkerClick: "marker:clicked",
945
+ onRegionSelected: "region:selected",
946
+ onMarkerSelected: "marker:selected",
947
+ onRegionTooltipShow: "region.tooltip:show",
948
+ onMarkerTooltipShow: "marker.tooltip:show",
949
+ onDestroyed: "map:destroyed"
950
+ };
951
+ var events_default = events;
952
+
953
+ // src/core/set-scale.ts
954
+ function setScale(scale, anchorX, anchorY, isCentered, animate) {
955
+ let zoomStep;
956
+ let interval;
957
+ let i = 0;
958
+ const count = Math.abs(Math.round((scale - this.scale) * 60 / Math.max(scale, this.scale)));
959
+ let scaleStart;
960
+ let scaleDiff;
961
+ let transXStart;
962
+ let transXDiff;
963
+ let transYStart;
964
+ let transYDiff;
965
+ let transX = this.transX;
966
+ let transY = this.transY;
967
+ const zoomMax = this.params.zoomMax ?? 8;
968
+ const zoomMin = this.params.zoomMin ?? 1;
969
+ if (scale > zoomMax * this._baseScale) {
970
+ scale = zoomMax * this._baseScale;
971
+ } else if (scale < zoomMin * this._baseScale) {
972
+ scale = zoomMin * this._baseScale;
973
+ }
974
+ if (typeof anchorX !== "undefined" && typeof anchorY !== "undefined") {
975
+ zoomStep = scale / this.scale;
976
+ if (isCentered) {
977
+ transX = anchorX + this._defaultWidth * (this._width / (this._defaultWidth * scale)) / 2;
978
+ transY = anchorY + this._defaultHeight * (this._height / (this._defaultHeight * scale)) / 2;
979
+ } else {
980
+ transX = this.transX - (zoomStep - 1) / scale * anchorX;
981
+ transY = this.transY - (zoomStep - 1) / scale * anchorY;
982
+ }
983
+ }
984
+ if (animate && count > 0) {
985
+ scaleStart = this.scale;
986
+ scaleDiff = (scale - scaleStart) / count;
987
+ transXStart = this.transX * this.scale;
988
+ transYStart = this.transY * this.scale;
989
+ transXDiff = (transX * scale - transXStart) / count;
990
+ transYDiff = (transY * scale - transYStart) / count;
991
+ interval = setInterval(() => {
992
+ i += 1;
993
+ this.scale = scaleStart + scaleDiff * i;
994
+ this.transX = (transXStart + transXDiff * i) / this.scale;
995
+ this.transY = (transYStart + transYDiff * i) / this.scale;
996
+ this._applyTransform();
997
+ if (i === count) {
998
+ clearInterval(interval);
999
+ this._emit(events_default.onViewportChange, [
1000
+ this.scale,
1001
+ this.transX,
1002
+ this.transY
1003
+ ]);
1004
+ }
1005
+ }, 10);
1006
+ } else {
1007
+ this.transX = transX;
1008
+ this.transY = transY;
1009
+ this.scale = scale;
1010
+ this._applyTransform();
1011
+ this._emit(events_default.onViewportChange, [
1012
+ this.scale,
1013
+ this.transX,
1014
+ this.transY
1015
+ ]);
1016
+ }
1017
+ }
1018
+
1019
+ // src/event-handler.ts
1020
+ var eventRegistry = {};
1021
+ var eventUid = 1;
1022
+ var EventHandler = {
1023
+ on(element, event, handler, options = {}) {
1024
+ const uid = `jvm:${event}::${eventUid++}`;
1025
+ eventRegistry[uid] = {
1026
+ selector: element,
1027
+ handler
1028
+ };
1029
+ if (typeof handler === "function") {
1030
+ handler._uid = uid;
1031
+ } else {
1032
+ handler._uid = uid;
1033
+ }
1034
+ element.addEventListener(event, handler, options);
1035
+ },
1036
+ delegate(element, event, selector, handler) {
1037
+ const events2 = event.split(" ");
1038
+ events2.forEach((eventName) => {
1039
+ EventHandler.on(element, eventName, (e) => {
1040
+ const target = e.target;
1041
+ if (target && target.matches && target.matches(selector)) {
1042
+ handler.call(target, e);
1043
+ }
1044
+ });
1045
+ });
1046
+ },
1047
+ off(element, event, handler) {
1048
+ const eventType = event.split(":")[1];
1049
+ element.removeEventListener(eventType, handler);
1050
+ delete eventRegistry[handler._uid];
1051
+ },
1052
+ flush() {
1053
+ Object.keys(eventRegistry).forEach((event) => {
1054
+ EventHandler.off(eventRegistry[event].selector, event, eventRegistry[event].handler);
1055
+ });
1056
+ },
1057
+ getEventRegistry() {
1058
+ return eventRegistry;
1059
+ }
1060
+ };
1061
+ var event_handler_default = EventHandler;
1062
+
1063
+ // src/core/setup-container-events.ts
1064
+ function setupContainerEvents() {
1065
+ let mouseDown = false;
1066
+ let oldPageX;
1067
+ let oldPageY;
1068
+ if (this.params.draggable) {
1069
+ event_handler_default.on(this.container, "mousemove", (e) => {
1070
+ if (!mouseDown) {
1071
+ return false;
1072
+ }
1073
+ const mouseEvent = e;
1074
+ if (oldPageX !== undefined && oldPageY !== undefined) {
1075
+ this.transX -= (oldPageX - mouseEvent.pageX) / this.scale;
1076
+ this.transY -= (oldPageY - mouseEvent.pageY) / this.scale;
1077
+ this.canvas.applyTransformParams(this.scale, this.transX, this.transY);
1078
+ }
1079
+ oldPageX = mouseEvent.pageX;
1080
+ oldPageY = mouseEvent.pageY;
1081
+ });
1082
+ event_handler_default.on(this.container, "mousedown", (e) => {
1083
+ mouseDown = true;
1084
+ const mouseEvent = e;
1085
+ oldPageX = mouseEvent.pageX;
1086
+ oldPageY = mouseEvent.pageY;
1087
+ return false;
1088
+ });
1089
+ event_handler_default.on(document.body, "mouseup", () => {
1090
+ mouseDown = false;
1091
+ });
1092
+ }
1093
+ if (this.params.zoomOnScroll) {
1094
+ event_handler_default.on(this.container, "wheel", (e) => {
1095
+ const wheelEvent = e;
1096
+ const deltaY = ((wheelEvent.deltaY || 0) >> 10 || 1) * 75;
1097
+ const rect = this.container.getBoundingClientRect();
1098
+ const offsetX = wheelEvent.pageX - rect.left - window.scrollX;
1099
+ const offsetY = wheelEvent.pageY - rect.top - window.scrollY;
1100
+ const zoomStep = (1 + (this.params.zoomOnScrollSpeed || 3) / 1000) ** (-1.5 * deltaY);
1101
+ setScale.call(this, this.scale * zoomStep, offsetX, offsetY);
1102
+ e.preventDefault();
1103
+ });
1104
+ }
1105
+ }
1106
+
1107
+ // src/core/setup-container-touch-events.ts
1108
+ function setupContainerTouchEvents() {
1109
+ let touchStartScale = 1;
1110
+ let touchStartDistance = 0;
1111
+ let centerTouchX = 0;
1112
+ let centerTouchY = 0;
1113
+ let lastTouchesLength = 0;
1114
+ let touchStartX = 0;
1115
+ let touchStartY = 0;
1116
+ let offset = { top: 0, left: 0 };
1117
+ const handleTouchEvent = (e) => {
1118
+ const touches = e.touches;
1119
+ let currentScale = this.scale;
1120
+ if (touches.length === 1) {
1121
+ if (lastTouchesLength === 1) {
1122
+ const touch = touches[0];
1123
+ if (touchStartScale === currentScale) {
1124
+ this.transX -= (touchStartX - touch.pageX) / currentScale;
1125
+ this.transY -= (touchStartY - touch.pageY) / currentScale;
1126
+ this.canvas.applyTransformParams(currentScale, this.transX, this.transY);
1127
+ }
1128
+ touchStartX = touch.pageX;
1129
+ touchStartY = touch.pageY;
1130
+ }
1131
+ } else if (touches.length === 2) {
1132
+ if (lastTouchesLength === 2) {
1133
+ currentScale = Math.sqrt((touches[0].pageX - touches[1].pageX) ** 2 + (touches[0].pageY - touches[1].pageY) ** 2) / touchStartDistance;
1134
+ setScale.call(this, touchStartScale * currentScale, centerTouchX, centerTouchY, false, false);
1135
+ e.preventDefault();
1136
+ } else {
1137
+ const rect = this.container.getBoundingClientRect();
1138
+ offset = {
1139
+ top: rect.top + window.scrollY,
1140
+ left: rect.left + window.scrollX
1141
+ };
1142
+ centerTouchX = touches[0].pageX > touches[1].pageX ? touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2 : touches[0].pageX + (touches[1].pageX - touches[0].pageX) / 2;
1143
+ centerTouchY = touches[0].pageY > touches[1].pageY ? touches[1].pageY + (touches[0].pageY - touches[1].pageY) / 2 : touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2;
1144
+ centerTouchX -= offset.left;
1145
+ centerTouchY -= offset.top;
1146
+ touchStartScale = this.scale;
1147
+ touchStartDistance = Math.sqrt((touches[0].pageX - touches[1].pageX) ** 2 + (touches[0].pageY - touches[1].pageY) ** 2);
1148
+ }
1149
+ }
1150
+ lastTouchesLength = touches.length;
1151
+ };
1152
+ event_handler_default.on(this.container, "touchstart", handleTouchEvent);
1153
+ event_handler_default.on(this.container, "touchmove", handleTouchEvent);
1154
+ }
1155
+
1156
+ // src/core/setup-element-events.ts
1157
+ function parseEvent(map, selector, isTooltip) {
1158
+ const element = getElement(selector);
1159
+ const type = !element?.getAttribute("class")?.includes("jvm-region") ? "marker" : "region";
1160
+ const isRegion = type === "region";
1161
+ const code = isRegion ? element?.getAttribute("data-code") : element?.getAttribute("data-index");
1162
+ if (!code) {
1163
+ throw new Error("Element does not have required data attribute");
1164
+ }
1165
+ let event = isRegion ? events_default.onRegionSelected : events_default.onMarkerSelected;
1166
+ if (isTooltip) {
1167
+ event = isRegion ? events_default.onRegionTooltipShow : events_default.onMarkerTooltipShow;
1168
+ }
1169
+ const elementObj = isRegion ? map.regions[code] : map._markers?.[code];
1170
+ if (!elementObj) {
1171
+ throw new Error(`Element with code ${code} not found`);
1172
+ }
1173
+ return {
1174
+ type,
1175
+ code,
1176
+ event,
1177
+ element: elementObj,
1178
+ tooltipText: isRegion ? map._mapData.paths[code].name || "" : map._markers?.[code]?.config.name || ""
1179
+ };
1180
+ }
1181
+ function setupElementEvents() {
1182
+ const container = this.container;
1183
+ let pageX;
1184
+ let pageY;
1185
+ let mouseMoved = false;
1186
+ event_handler_default.on(container, "mousemove", (e) => {
1187
+ const mouseEvent = e;
1188
+ if (Math.abs((pageX || 0) - mouseEvent.pageX) + Math.abs((pageY || 0) - mouseEvent.pageY) > 2) {
1189
+ mouseMoved = true;
1190
+ }
1191
+ });
1192
+ event_handler_default.delegate(container, "mousedown", ".jvm-element", (e) => {
1193
+ const mouseEvent = e;
1194
+ pageX = mouseEvent.pageX;
1195
+ pageY = mouseEvent.pageY;
1196
+ mouseMoved = false;
1197
+ });
1198
+ event_handler_default.delegate(container, "mouseover mouseout", ".jvm-element", (e) => {
1199
+ try {
1200
+ const data = parseEvent(this, e.target, true);
1201
+ const { showTooltip } = this.params;
1202
+ const tooltip = this._tooltip;
1203
+ if (e.type === "mouseover") {
1204
+ if (typeof data.element.hover === "function") {
1205
+ data.element.hover(true);
1206
+ }
1207
+ if (showTooltip && tooltip) {
1208
+ tooltip.text(data.tooltipText);
1209
+ tooltip.show(data.tooltipText);
1210
+ this._emit(data.event, [e, tooltip.getElement(), data.code]);
1211
+ }
1212
+ } else {
1213
+ if (typeof data.element.hover === "function") {
1214
+ data.element.hover(false);
1215
+ }
1216
+ if (showTooltip && tooltip) {
1217
+ tooltip.hide();
1218
+ }
1219
+ }
1220
+ } catch (error) {
1221
+ console.error("Error in mouseover/mouseout handler:", error);
1222
+ }
1223
+ });
1224
+ event_handler_default.delegate(container, "mouseup", ".jvm-element", (e) => {
1225
+ try {
1226
+ const data = parseEvent(this, e.target, false);
1227
+ if (mouseMoved) {
1228
+ return;
1229
+ }
1230
+ if (data.type === "region" && this.params.regionsSelectable || data.type === "marker" && this.params.markersSelectable) {
1231
+ const element = data.element;
1232
+ if (this.params[`${data.type}sSelectableOne`]) {
1233
+ data.type === "region" ? this.clearSelectedRegions() : this.clearSelectedMarkers();
1234
+ }
1235
+ if (typeof element.select === "function") {
1236
+ if (element.isSelected) {
1237
+ element.select(false);
1238
+ } else {
1239
+ element.select(true);
1240
+ }
1241
+ this._emit(data.event, [
1242
+ data.code,
1243
+ element.isSelected,
1244
+ data.type === "region" ? this.getSelectedRegions() : this.getSelectedMarkers()
1245
+ ]);
1246
+ }
1247
+ }
1248
+ } catch (error) {
1249
+ console.error("Error in mouseup handler:", error);
1250
+ }
1251
+ });
1252
+ event_handler_default.delegate(container, "click", ".jvm-element", (e) => {
1253
+ try {
1254
+ const { type, code } = parseEvent(this, e.target, false);
1255
+ this._emit(type === "region" ? events_default.onRegionClick : events_default.onMarkerClick, [e, code]);
1256
+ } catch (error) {
1257
+ console.error("Error in click handler:", error);
1258
+ }
1259
+ });
1260
+ }
1261
+
1262
+ // src/core/setup-zoom-buttons.ts
1263
+ function setupZoomButtons() {
1264
+ const zoomin = createElement("div", "jvm-zoom-btn jvm-zoomin", "&#43;", true);
1265
+ const zoomout = createElement("div", "jvm-zoom-btn jvm-zoomout", "&#x2212", true);
1266
+ this.container.appendChild(zoomin);
1267
+ this.container.appendChild(zoomout);
1268
+ const handler = (zoomin2 = true) => {
1269
+ return () => setScale.call(this, zoomin2 ? this.scale * (this.params.zoomStep || 1.5) : this.scale / (this.params.zoomStep || 1.5), this._width / 2, this._height / 2, false, this.params.zoomAnimate);
1270
+ };
1271
+ event_handler_default.on(zoomin, "click", handler());
1272
+ event_handler_default.on(zoomout, "click", handler(false));
1273
+ }
1274
+
1275
+ // src/core/update-size.ts
1276
+ function updateSize() {
1277
+ this._width = this.container.offsetWidth;
1278
+ this._height = this.container.offsetHeight;
1279
+ resize_default.call(this);
1280
+ this.canvas.applyTransformParams(this.scale, this.transX, this.transY);
1281
+ }
1282
+
1283
+ // src/core/index.ts
1284
+ var core = {
1285
+ _setupContainerEvents: setupContainerEvents,
1286
+ _setupElementEvents: setupElementEvents,
1287
+ _setupZoomButtons: setupZoomButtons,
1288
+ _setupContainerTouchEvents: setupContainerTouchEvents,
1289
+ _createRegions: createRegions,
1290
+ _createLines: createLines,
1291
+ _createMarkers: createMarkers,
1292
+ _createSeries: createSeries,
1293
+ _applyTransform: applyTransform,
1294
+ _resize: resize_default,
1295
+ _setScale: setScale,
1296
+ setFocus,
1297
+ updateSize,
1298
+ coordsToPoint,
1299
+ getInsetForPoint,
1300
+ getMarkerPosition,
1301
+ _repositionLines: repositionLines,
1302
+ _repositionMarkers: repositionMarkers,
1303
+ _repositionLabels: repositionLabels
1304
+ };
1305
+ var core_default = core;
1306
+
1307
+ // src/data-visualization.ts
1308
+ class DataVisualization {
1309
+ _scale;
1310
+ _values;
1311
+ _fromColor;
1312
+ _toColor;
1313
+ _map;
1314
+ min = Number.MAX_VALUE;
1315
+ max = 0;
1316
+ constructor({ scale, values }, map) {
1317
+ this._scale = scale;
1318
+ this._values = values;
1319
+ this._fromColor = this.hexToRgb(scale[0]);
1320
+ this._toColor = this.hexToRgb(scale[1]);
1321
+ this._map = map;
1322
+ this.setMinMaxValues(values);
1323
+ this.visualize();
1324
+ }
1325
+ setMinMaxValues(values) {
1326
+ for (const key in values) {
1327
+ const value = Number.parseFloat(String(values[key]));
1328
+ if (value > this.max) {
1329
+ this.max = value;
1330
+ }
1331
+ if (value < this.min) {
1332
+ this.min = value;
1333
+ }
1334
+ }
1335
+ }
1336
+ visualize() {
1337
+ const attrs = {};
1338
+ let value;
1339
+ for (const regionCode in this._values) {
1340
+ value = Number.parseFloat(String(this._values[regionCode]));
1341
+ if (!Number.isNaN(value)) {
1342
+ attrs[regionCode] = this.getValue(value);
1343
+ }
1344
+ }
1345
+ this.setAttributes(attrs);
1346
+ }
1347
+ setAttributes(attrs) {
1348
+ for (const code in attrs) {
1349
+ if (this._map.regions[code]) {
1350
+ this._map.regions[code].element.setStyle("fill", attrs[code]);
1351
+ }
1352
+ }
1353
+ }
1354
+ getValue(value) {
1355
+ if (this.min === this.max) {
1356
+ return `#${this._toColor.join("")}`;
1357
+ }
1358
+ let hex;
1359
+ let color = "#";
1360
+ for (let i = 0;i < 3; i++) {
1361
+ hex = Math.round(this._fromColor[i] + (this._toColor[i] - this._fromColor[i]) * ((value - this.min) / (this.max - this.min))).toString(16);
1362
+ color += (hex.length === 1 ? "0" : "") + hex;
1363
+ }
1364
+ return color;
1365
+ }
1366
+ hexToRgb(h) {
1367
+ let r = "0";
1368
+ let g = "0";
1369
+ let b = "0";
1370
+ if (h.length === 4) {
1371
+ r = `0x${h[1]}${h[1]}`;
1372
+ g = `0x${h[2]}${h[2]}`;
1373
+ b = `0x${h[3]}${h[3]}`;
1374
+ } else if (h.length === 7) {
1375
+ r = `0x${h[1]}${h[2]}`;
1376
+ g = `0x${h[3]}${h[4]}`;
1377
+ b = `0x${h[5]}${h[6]}`;
1378
+ }
1379
+ return [Number.parseInt(r, 16), Number.parseInt(g, 16), Number.parseInt(b, 16)];
1380
+ }
1381
+ }
1382
+ var data_visualization_default = DataVisualization;
1383
+
1384
+ // src/defaults/options.ts
1385
+ var defaultOptions = {
1386
+ map: {
1387
+ name: "world",
1388
+ projection: "mercator"
1389
+ },
1390
+ backgroundColor: "transparent",
1391
+ draggable: true,
1392
+ zoomButtons: true,
1393
+ zoomOnScroll: true,
1394
+ zoomOnScrollSpeed: 3,
1395
+ zoomMax: 12,
1396
+ zoomMin: 1,
1397
+ zoomAnimate: true,
1398
+ showTooltip: true,
1399
+ zoomStep: 1.5,
1400
+ bindTouchEvents: true,
1401
+ selector: "",
1402
+ lines: {
1403
+ style: {
1404
+ stroke: "#808080",
1405
+ strokeWidth: 1,
1406
+ strokeLinecap: "round"
1407
+ },
1408
+ elements: []
1409
+ },
1410
+ markersSelectable: false,
1411
+ markersSelectableOne: false,
1412
+ markerStyle: {
1413
+ initial: {
1414
+ r: 7,
1415
+ fill: "#374151",
1416
+ fillOpacity: 1,
1417
+ stroke: "#FFF",
1418
+ strokeWidth: 5,
1419
+ strokeOpacity: 0.5
1420
+ },
1421
+ hover: {
1422
+ fill: "#3cc0ff",
1423
+ cursor: "pointer"
1424
+ },
1425
+ selected: {
1426
+ fill: "blue"
1427
+ },
1428
+ selectedHover: {}
1429
+ },
1430
+ markerLabelStyle: {
1431
+ initial: {
1432
+ fontFamily: "Verdana",
1433
+ fontSize: 12,
1434
+ fontWeight: 500,
1435
+ cursor: "default",
1436
+ fill: "#374151"
1437
+ },
1438
+ hover: {
1439
+ cursor: "pointer"
1440
+ },
1441
+ selected: {},
1442
+ selectedHover: {}
1443
+ },
1444
+ regionsSelectable: false,
1445
+ regionsSelectableOne: false,
1446
+ regionStyle: {
1447
+ initial: {
1448
+ fill: "#dee2e8",
1449
+ fillOpacity: 1,
1450
+ stroke: "none",
1451
+ strokeWidth: 0
1452
+ },
1453
+ hover: {
1454
+ fillOpacity: 0.7,
1455
+ cursor: "pointer"
1456
+ },
1457
+ selected: {
1458
+ fill: "#9ca3af"
1459
+ },
1460
+ selectedHover: {}
1461
+ },
1462
+ regionLabelStyle: {
1463
+ initial: {
1464
+ fontFamily: "Verdana",
1465
+ fontSize: "12",
1466
+ fontWeight: "bold",
1467
+ cursor: "default",
1468
+ fill: "#35373e"
1469
+ },
1470
+ hover: {
1471
+ cursor: "pointer"
1472
+ }
1473
+ }
1474
+ };
1475
+ var options_default = defaultOptions;
1476
+
1477
+ // src/svg/base-element.ts
1478
+ class SVGElement {
1479
+ node;
1480
+ style;
1481
+ constructor(name, config) {
1482
+ this.node = this._createElement(name);
1483
+ this.style = { initial: {} };
1484
+ if (config) {
1485
+ this.set(config);
1486
+ }
1487
+ }
1488
+ _createElement(tagName) {
1489
+ return document.createElementNS("http://www.w3.org/2000/svg", tagName);
1490
+ }
1491
+ addClass(className) {
1492
+ this.node.setAttribute("class", className);
1493
+ }
1494
+ getBBox() {
1495
+ return this.node.getBBox();
1496
+ }
1497
+ set(property, value) {
1498
+ if (typeof property === "object") {
1499
+ for (const attr in property) {
1500
+ this.applyAttr(attr, property[attr]);
1501
+ }
1502
+ } else if (value !== undefined) {
1503
+ this.applyAttr(property, value);
1504
+ }
1505
+ }
1506
+ get(property) {
1507
+ return this.style.initial[property];
1508
+ }
1509
+ applyAttr(property, value) {
1510
+ this.node.setAttribute(hyphenate(property), String(value));
1511
+ }
1512
+ remove() {
1513
+ removeElement(this.node);
1514
+ }
1515
+ }
1516
+ var base_element_default = SVGElement;
1517
+
1518
+ // src/svg/shape-element.ts
1519
+ class SVGShapeElement extends base_element_default {
1520
+ isHovered;
1521
+ isSelected;
1522
+ style;
1523
+ constructor(name, config, style = { initial: {} }) {
1524
+ super(name, config);
1525
+ this.isHovered = false;
1526
+ this.isSelected = false;
1527
+ this.style = style;
1528
+ this.style.current = {};
1529
+ this.updateStyle();
1530
+ }
1531
+ hover(state) {
1532
+ this.isHovered = state;
1533
+ this.updateStyle();
1534
+ }
1535
+ select(state) {
1536
+ this.isSelected = state;
1537
+ this.updateStyle();
1538
+ }
1539
+ setStyle(property, value) {
1540
+ if (typeof property === "object") {
1541
+ merge(this.style.current, property);
1542
+ } else {
1543
+ merge(this.style.current, { [property]: value });
1544
+ }
1545
+ this.updateStyle();
1546
+ }
1547
+ updateStyle() {
1548
+ const attrs = {};
1549
+ merge(attrs, this.style.initial);
1550
+ merge(attrs, this.style.current || {});
1551
+ if (this.isHovered) {
1552
+ merge(attrs, this.style.hover || {});
1553
+ }
1554
+ if (this.isSelected) {
1555
+ merge(attrs, this.style.selected || {});
1556
+ if (this.isHovered) {
1557
+ merge(attrs, this.style.selectedHover || {});
1558
+ }
1559
+ }
1560
+ this.set(attrs);
1561
+ }
1562
+ }
1563
+ var shape_element_default = SVGShapeElement;
1564
+
1565
+ // src/svg/image-element.ts
1566
+ class SVGImageElement extends shape_element_default {
1567
+ width = 0;
1568
+ height = 0;
1569
+ cx = 0;
1570
+ cy = 0;
1571
+ offset = [0, 0];
1572
+ constructor(config, style) {
1573
+ super("image", config, style);
1574
+ }
1575
+ applyAttr(attr, value) {
1576
+ let imageUrl;
1577
+ if (attr === "image") {
1578
+ if (typeof value === "object") {
1579
+ const config = value;
1580
+ imageUrl = config.url || "";
1581
+ this.offset = config.offset || [0, 0];
1582
+ } else {
1583
+ imageUrl = String(value);
1584
+ this.offset = [0, 0];
1585
+ }
1586
+ this.node.setAttributeNS("http://www.w3.org/1999/xlink", "href", imageUrl);
1587
+ this.width = 23;
1588
+ this.height = 23;
1589
+ this.applyAttr("width", this.width);
1590
+ this.applyAttr("height", this.height);
1591
+ this.applyAttr("x", this.cx - this.width / 2 + this.offset[0]);
1592
+ this.applyAttr("y", this.cy - this.height / 2 + this.offset[1]);
1593
+ } else if (attr === "cx") {
1594
+ this.cx = Number(value);
1595
+ if (this.width) {
1596
+ this.applyAttr("x", this.cx - this.width / 2 + this.offset[0]);
1597
+ }
1598
+ } else if (attr === "cy") {
1599
+ this.cy = Number(value);
1600
+ if (this.height) {
1601
+ this.applyAttr("y", this.cy - this.height / 2 + this.offset[1]);
1602
+ }
1603
+ } else {
1604
+ super.applyAttr(attr, value);
1605
+ }
1606
+ }
1607
+ }
1608
+ var image_element_default = SVGImageElement;
1609
+
1610
+ // src/svg/text-element.ts
1611
+ class SVGTextElement extends shape_element_default {
1612
+ constructor(config, style) {
1613
+ super("text", config, style);
1614
+ }
1615
+ applyAttr(attr, value) {
1616
+ if (attr === "text") {
1617
+ this.node.textContent = String(value);
1618
+ } else if (attr === "x" || attr === "y" || attr === "cx" || attr === "cy") {
1619
+ this.node.setAttribute(attr, `${value}`);
1620
+ } else {
1621
+ super.applyAttr(attr, value);
1622
+ }
1623
+ }
1624
+ }
1625
+ var text_element_default = SVGTextElement;
1626
+
1627
+ // src/svg/canvas-element.ts
1628
+ class SVGCanvasElement extends base_element_default {
1629
+ _container;
1630
+ _defsElement;
1631
+ _rootElement;
1632
+ constructor(container) {
1633
+ super("svg");
1634
+ this._container = container;
1635
+ this._defsElement = new base_element_default("defs");
1636
+ this._rootElement = new base_element_default("g", { id: "jvm-regions-group" });
1637
+ this.node.appendChild(this._defsElement.node);
1638
+ this.node.appendChild(this._rootElement.node);
1639
+ this._container.appendChild(this.node);
1640
+ }
1641
+ setSize(width, height) {
1642
+ this.node.setAttribute("width", String(width));
1643
+ this.node.setAttribute("height", String(height));
1644
+ }
1645
+ applyTransformParams(scale, transX, transY) {
1646
+ this._rootElement.node.setAttribute("transform", `scale(${scale}) translate(${transX}, ${transY})`);
1647
+ }
1648
+ createPath(config, style, group) {
1649
+ const path = new shape_element_default("path", config, style);
1650
+ path.node.setAttribute("fill-rule", "evenodd");
1651
+ return this._add(path, group);
1652
+ }
1653
+ createCircle(config, style, group) {
1654
+ const circle = new shape_element_default("circle", config, style);
1655
+ return this._add(circle, group);
1656
+ }
1657
+ createLine(config, style, group) {
1658
+ const line = new shape_element_default("line", config, style);
1659
+ return this._add(line, group);
1660
+ }
1661
+ createText(config, style, group) {
1662
+ const text = new text_element_default(config, style);
1663
+ return this._add(text, group);
1664
+ }
1665
+ createImage(config, style, group) {
1666
+ const image = new image_element_default(config, style);
1667
+ return this._add(image, group);
1668
+ }
1669
+ createGroup(id) {
1670
+ const group = new base_element_default("g");
1671
+ this.node.appendChild(group.node);
1672
+ if (id) {
1673
+ group.node.id = id;
1674
+ }
1675
+ group.canvas = this;
1676
+ return group;
1677
+ }
1678
+ _add(element, group) {
1679
+ group = group || this._rootElement;
1680
+ if (group && group.node) {
1681
+ group.node.appendChild(element.node);
1682
+ } else {
1683
+ this._rootElement.node.appendChild(element.node);
1684
+ }
1685
+ return element;
1686
+ }
1687
+ }
1688
+ var canvas_element_default = SVGCanvasElement;
1689
+
1690
+ // src/map.ts
1691
+ var JVM_PREFIX2 = "jvm-";
1692
+ var CONTAINER_CLASS = `${JVM_PREFIX2}container`;
1693
+ var MARKERS_GROUP_ID = `${JVM_PREFIX2}markers-group`;
1694
+ var MARKERS_LABELS_GROUP_ID = `${JVM_PREFIX2}markers-labels-group`;
1695
+ var LINES_GROUP_ID = `${JVM_PREFIX2}lines-group`;
1696
+ var SERIES_CONTAINER_CLASS = `${JVM_PREFIX2}series-container`;
1697
+ var SERIES_CONTAINER_H_CLASS = `${SERIES_CONTAINER_CLASS} ${JVM_PREFIX2}series-h`;
1698
+ var SERIES_CONTAINER_V_CLASS = `${SERIES_CONTAINER_CLASS} ${JVM_PREFIX2}series-v`;
1699
+
1700
+ class Map {
1701
+ static maps = {};
1702
+ static defaults = options_default;
1703
+ params;
1704
+ regions = {};
1705
+ scale = 1;
1706
+ transX = 0;
1707
+ transY = 0;
1708
+ container;
1709
+ canvas;
1710
+ dataVisualization;
1711
+ legendHorizontal;
1712
+ legendVertical;
1713
+ series = { markers: [], regions: [] };
1714
+ _mapData;
1715
+ _markers = {};
1716
+ _lines = {};
1717
+ _defaultWidth;
1718
+ _defaultHeight;
1719
+ _height = 0;
1720
+ _width = 0;
1721
+ _baseScale = 1;
1722
+ _baseTransX = 0;
1723
+ _baseTransY = 0;
1724
+ _tooltip;
1725
+ _linesGroup;
1726
+ _markersGroup;
1727
+ _markerLabelsGroup;
1728
+ _canvasImpl;
1729
+ constructor(options = {}) {
1730
+ this.params = merge(Map.defaults, options, true);
1731
+ const mapParam = this.params.map;
1732
+ const mapName = typeof mapParam === "string" ? mapParam : mapParam.name;
1733
+ const mapData = Map.maps[mapName];
1734
+ if (!mapData) {
1735
+ throw new Error(`Attempt to use map which was not loaded: ${mapName}`);
1736
+ }
1737
+ this._mapData = mapData;
1738
+ this._defaultWidth = this._mapData.width;
1739
+ this._defaultHeight = this._mapData.height;
1740
+ if (document.readyState !== "loading") {
1741
+ this._init();
1742
+ } else {
1743
+ window.addEventListener("DOMContentLoaded", () => this._init());
1744
+ }
1745
+ }
1746
+ _init() {
1747
+ const options = this.params;
1748
+ const element = getElement(options.selector);
1749
+ if (!element) {
1750
+ throw new Error(`Element not found: ${options.selector}`);
1751
+ }
1752
+ this.container = element;
1753
+ this.container.classList.add(CONTAINER_CLASS);
1754
+ this._canvasImpl = new canvas_element_default(this.container);
1755
+ this.canvas = this._canvasImpl;
1756
+ this.setBackgroundColor(options.backgroundColor || "");
1757
+ this._createRegions();
1758
+ this.updateSize();
1759
+ if (options.lines?.elements) {
1760
+ const group = this._canvasImpl.createGroup(LINES_GROUP_ID);
1761
+ if (!group) {
1762
+ throw new TypeError("Failed to create lines group");
1763
+ }
1764
+ this._linesGroup = group.node;
1765
+ }
1766
+ if (options.markers) {
1767
+ const markersGroup = this._canvasImpl.createGroup(MARKERS_GROUP_ID);
1768
+ const labelsGroup = this._canvasImpl.createGroup(MARKERS_LABELS_GROUP_ID);
1769
+ if (!markersGroup || !labelsGroup) {
1770
+ throw new TypeError("Failed to create markers groups");
1771
+ }
1772
+ this._markersGroup = markersGroup.node;
1773
+ this._markerLabelsGroup = labelsGroup.node;
1774
+ }
1775
+ this._createMarkers(options.markers || []);
1776
+ this._createLines(options.lines?.elements || []);
1777
+ this._repositionLabels();
1778
+ this._setupContainerEvents();
1779
+ this._setupElementEvents();
1780
+ if (options.zoomButtons) {
1781
+ this._setupZoomButtons();
1782
+ }
1783
+ if (options.showTooltip) {
1784
+ this._tooltip = new tooltip_default(this);
1785
+ }
1786
+ if (options.selectedRegions) {
1787
+ this._setSelected("regions", options.selectedRegions);
1788
+ }
1789
+ if (options.selectedMarkers) {
1790
+ this._setSelected("_markers", options.selectedMarkers);
1791
+ }
1792
+ if (options.focusOn) {
1793
+ this.setFocus(options.focusOn);
1794
+ }
1795
+ if (options.visualizeData) {
1796
+ this.dataVisualization = new data_visualization_default(options.visualizeData, this);
1797
+ }
1798
+ if (options.bindTouchEvents) {
1799
+ if ("ontouchstart" in window) {
1800
+ this._setupContainerTouchEvents();
1801
+ }
1802
+ }
1803
+ if (options.series) {
1804
+ this.container.appendChild(this.legendHorizontal = createElement("div", SERIES_CONTAINER_H_CLASS));
1805
+ this.container.appendChild(this.legendVertical = createElement("div", SERIES_CONTAINER_V_CLASS));
1806
+ this._createSeries();
1807
+ }
1808
+ this._emit(events_default.onLoaded, [this]);
1809
+ }
1810
+ setBackgroundColor(color) {
1811
+ this.container.style.backgroundColor = color;
1812
+ }
1813
+ getSelectedRegions() {
1814
+ return this._getSelected("regions");
1815
+ }
1816
+ clearSelectedRegions(regions) {
1817
+ const regionsToProcess = this._normalizeRegions(regions) || this._getSelected("regions");
1818
+ regionsToProcess.forEach((key) => {
1819
+ this.regions[key].element.select(false);
1820
+ });
1821
+ }
1822
+ setSelectedRegions(regions) {
1823
+ this.clearSelectedRegions();
1824
+ const normalizedRegions = this._normalizeRegions(regions);
1825
+ if (normalizedRegions) {
1826
+ this._setSelected("regions", normalizedRegions);
1827
+ }
1828
+ }
1829
+ getSelectedMarkers() {
1830
+ return this._getSelected("_markers");
1831
+ }
1832
+ clearSelectedMarkers() {
1833
+ this._clearSelected("_markers");
1834
+ }
1835
+ setSelectedMarkers(markers) {
1836
+ const normalizedMarkers = this._normalizeRegions(markers);
1837
+ if (normalizedMarkers) {
1838
+ this._setSelected("_markers", normalizedMarkers);
1839
+ }
1840
+ }
1841
+ addMarkers(config) {
1842
+ const configs = Array.isArray(config) ? config : [config];
1843
+ this._createMarkers(configs);
1844
+ }
1845
+ removeMarkers(markers) {
1846
+ const toRemove = markers || Object.keys(this._markers);
1847
+ toRemove.forEach((index) => {
1848
+ const marker = this._markers[index];
1849
+ if (marker) {
1850
+ if (typeof marker.remove === "function") {
1851
+ marker.remove();
1852
+ } else if (marker.shape) {
1853
+ marker.shape.remove();
1854
+ if (marker.label) {
1855
+ marker.label.remove();
1856
+ }
1857
+ }
1858
+ delete this._markers[index];
1859
+ }
1860
+ });
1861
+ }
1862
+ addLine(from, to, style = {}) {
1863
+ console.warn("`addLine` method is deprecated, please use `addLines` instead.");
1864
+ this._createLines([{ from, to, style }]);
1865
+ }
1866
+ addLines(config) {
1867
+ const uids = this._getLinesAsUids();
1868
+ const configs = Array.isArray(config) ? config : [config];
1869
+ this._createLines(configs.filter((line) => {
1870
+ return !uids.includes(getLineUid(line.from, line.to));
1871
+ }));
1872
+ }
1873
+ removeLines(lines) {
1874
+ if (Array.isArray(lines) && typeof lines[0] !== "string") {
1875
+ lines = lines.map((line) => getLineUid(line.from, line.to));
1876
+ } else if (!Array.isArray(lines)) {
1877
+ lines = this._getLinesAsUids();
1878
+ }
1879
+ lines.forEach((uid) => {
1880
+ this._lines[uid].dispose();
1881
+ delete this._lines[uid];
1882
+ });
1883
+ }
1884
+ removeLine(from, to) {
1885
+ console.warn("`removeLine` method is deprecated, please use `removeLines` instead.");
1886
+ const uid = getLineUid(from, to);
1887
+ if (Object.prototype.hasOwnProperty.call(this._lines, uid)) {
1888
+ this._lines[uid].element.remove();
1889
+ delete this._lines[uid];
1890
+ }
1891
+ }
1892
+ reset() {
1893
+ for (const key in this.series || {}) {
1894
+ for (let i = 0;i < (this.series?.[key]?.length || 0); i++) {
1895
+ this.series?.[key][i]?.clear();
1896
+ }
1897
+ }
1898
+ if (this.legendHorizontal) {
1899
+ removeElement(this.legendHorizontal);
1900
+ this.legendHorizontal = undefined;
1901
+ }
1902
+ if (this.legendVertical) {
1903
+ removeElement(this.legendVertical);
1904
+ this.legendVertical = undefined;
1905
+ }
1906
+ this.scale = this._baseScale;
1907
+ this.transX = this._baseTransX;
1908
+ this.transY = this._baseTransY;
1909
+ this._applyTransform();
1910
+ this.clearSelectedMarkers();
1911
+ this.clearSelectedRegions();
1912
+ this.removeMarkers();
1913
+ }
1914
+ destroy(destroyInstance = true) {
1915
+ event_handler_default.flush();
1916
+ this._tooltip?.dispose();
1917
+ this._emit(events_default.onDestroyed, []);
1918
+ if (destroyInstance) {
1919
+ Object.keys(this).forEach((key) => {
1920
+ try {
1921
+ delete this[key];
1922
+ } catch {}
1923
+ });
1924
+ }
1925
+ }
1926
+ extend(name, callback) {
1927
+ if (typeof this[name] === "function") {
1928
+ throw new TypeError(`The method [${name}] does already exist, please use another name.`);
1929
+ }
1930
+ Map.prototype[name] = callback;
1931
+ }
1932
+ mercator = {
1933
+ convert: (lat, lng) => {
1934
+ return { x: lng, y: lat };
1935
+ }
1936
+ };
1937
+ miller = {
1938
+ convert: (lat, lng) => {
1939
+ return { x: lng, y: lat };
1940
+ }
1941
+ };
1942
+ getInsetForPoint(_x, _y) {
1943
+ return false;
1944
+ }
1945
+ getMarkerPosition(_config) {
1946
+ return { x: 0, y: 0 };
1947
+ }
1948
+ coordsToPoint(_lat, _lng) {
1949
+ return { x: 0, y: 0 };
1950
+ }
1951
+ _repositionMarkers() {}
1952
+ _repositionLines() {}
1953
+ _setScale(_scale) {}
1954
+ _emit(eventName, args) {
1955
+ for (const event in events_default) {
1956
+ if (events_default[event] === eventName && typeof this.params[event] === "function") {
1957
+ this.params[event]?.apply(this, args);
1958
+ }
1959
+ }
1960
+ }
1961
+ _getSelected(type) {
1962
+ const selected = [];
1963
+ for (const key in this[type]) {
1964
+ if (this[type][key].element.isSelected) {
1965
+ selected.push(key);
1966
+ }
1967
+ }
1968
+ return selected;
1969
+ }
1970
+ _setSelected(type, keys) {
1971
+ keys.forEach((key) => {
1972
+ if (this[type][key]) {
1973
+ this[type][key].element.select(true);
1974
+ }
1975
+ });
1976
+ }
1977
+ _clearSelected(type) {
1978
+ this._getSelected(type).forEach((key) => {
1979
+ this[type][key].element.select(false);
1980
+ });
1981
+ }
1982
+ _getLinesAsUids() {
1983
+ return Object.keys(this._lines);
1984
+ }
1985
+ _normalizeRegions(regions) {
1986
+ if (!regions)
1987
+ return;
1988
+ return typeof regions === "string" ? [regions] : regions;
1989
+ }
1990
+ _createRegions() {}
1991
+ _createMarkers(_markers) {}
1992
+ _createLines(_lines) {}
1993
+ _createSeries() {}
1994
+ _repositionLabels() {}
1995
+ _setupContainerEvents() {}
1996
+ _setupElementEvents() {}
1997
+ _setupZoomButtons() {}
1998
+ _setupContainerTouchEvents() {}
1999
+ _applyTransform() {}
2000
+ updateSize() {}
2001
+ setFocus(_config) {}
2002
+ }
2003
+ Object.assign(Map.prototype, core_default);
2004
+ var map_default = Map;
2005
+
2006
+ // src/vector-map.ts
2007
+ class VectorMap {
2008
+ constructor(options = {}) {
2009
+ if (!options.selector) {
2010
+ throw new Error("Selector is not given.");
2011
+ }
2012
+ return new map_default(options);
2013
+ }
2014
+ static addMap(name, map) {
2015
+ map_default.maps[name] = map;
2016
+ }
2017
+ }
2018
+
2019
+ // src/index.ts
2020
+ if (typeof window !== "undefined") {
2021
+ window.VectorMap = VectorMap;
2022
+ }
2023
+ var src_default = VectorMap;
2024
+ export {
2025
+ src_default as default,
2026
+ VectorMap
2027
+ };