88 ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝
99
1010 * Metro UI v5.1.17 Components Library (https://metroui.org.ua)
11- * Build: 19.08.2025, 09:35:25
11+ * Build: 19.08.2025, 11:53:09
1212 * Copyright 2012-2025 by Serhii Pimenov
1313 * Licensed under MIT
1414 */
1130811308 (($7) => {
1130911309 "use strict";
1131011310 globalThis["__version__"] = "5.1.17";
11311- globalThis["__build_time__"] = "19.08.2025, 09:35:25 ";
11311+ globalThis["__build_time__"] = "19.08.2025, 11:53:09 ";
1131211312 const meta_init = $7.meta("metro:init").attr("content");
1131311313 const meta_cloak = $7.meta("metro:cloak").attr("content");
1131411314 const meta_cloak_duration = $7.meta("metro:cloak_duration").attr("content");
1165711657 const normalizeComponentName2 = (name2) => typeof name2 !== "string" ? void 0 : name2.replace(/-/g, "").toLowerCase();
1165811658 const Metro2 = {
1165911659 version: "5.1.17",
11660- build_time: "19.08.2025, 09:35:25 ",
11660+ build_time: "19.08.2025, 11:53:09 ",
1166111661 buildNumber: 0,
1166211662 isTouchable: isTouch3,
1166311663 fullScreenEnabled: document.fullscreenEnabled,
3137831378 this._super(elem, options, ConnectorDefaultConfig, {
3137931379 connections: /* @__PURE__ */ new Map(),
3138031380 svgElement: null,
31381- observers: /* @__PURE__ */ new Map()
31381+ observers: /* @__PURE__ */ new Map(),
31382+ deleteButton: null
3138231383 });
3138331384 return this;
3138431385 },
@@ -31409,22 +31410,33 @@
3140931410 console.warn("Connector: PointA and PointB are required to create connection");
3141031411 return;
3141131412 }
31412- this.svgElement = this._createSVG (o2.id, o2.type );
31413- $7(o2.container).append( this.svgElement) ;
31414- this.update( );
31413+ const sharedSvg = this._getOrCreateSharedSVG (o2.container );
31414+ this.svgElement = sharedSvg ;
31415+ const shape = this._createShape(o2.id, o2.type, sharedSvg );
3141531416 this.connections.set(o2.id, {
3141631417 pointA: o2.pointA,
3141731418 pointB: o2.pointB,
3141831419 type: o2.type,
31419- svg: this.svgElement
31420+ svg: sharedSvg,
31421+ shape
3142031422 });
31423+ this.update();
3142131424 },
3142231425 _createEvents: function() {
3142331426 const element2 = this.element;
3142431427 const o2 = this.options;
31428+ const self = this;
3142531429 if (o2.autoUpdate) {
3142631430 this._setupAutoUpdate();
3142731431 }
31432+ $7(document).on("click", ".cl-curve, .cl-line", (e2) => {
31433+ const target = $7(e2.target);
31434+ $7(target).toggleClass("selected-path");
31435+ e2.stopPropagation();
31436+ });
31437+ $7(document).on("click", (e2) => {
31438+ $7(".cl-line, .cl-curve").removeClass("selected-path");
31439+ });
3142831440 },
3142931441 _setupAutoUpdate: function() {
3143031442 const o2 = this.options;
@@ -31462,42 +31474,75 @@
3146231474 setTimeout(() => self.update(), 10);
3146331475 });
3146431476 },
31477+ // ... existing code ...
3146531478 _createSVG: (id, type) => {
3146631479 let svg;
3146731480 if (type === "line") {
3146831481 svg = $7(`
3146931482 <svg id="${id}" class="connection-line">
31470- <line class="cl-line"
31471- stroke="var(--linked-block-line-color)"
31472- stroke-width="var(--linked-block-line-width)"/>
31483+ <line class="cl-line"/>
3147331484 </svg>
3147431485 `);
3147531486 } else {
3147631487 svg = $7(`
3147731488 <svg id="${id}" class="connection-line">
31478- <path class="cl-curve"
31479- stroke="var(--linked-block-line-color)"
31480- stroke-width="var(--linked-block-line-width)"
31481- fill="none"/>
31489+ <path class="cl-curve"/>
3148231490 </svg>
3148331491 `);
3148431492 }
3148531493 return svg;
3148631494 },
31495+ _getOrCreateSharedSVG: (container) => {
31496+ const $container = $7(container);
31497+ let svg = $container.children("svg.connection-line").first();
31498+ if (!svg.length) {
31499+ if ($container.css("position") === "static") {
31500+ $container.css("position", "relative");
31501+ }
31502+ const ns = "http://www.w3.org/2000/svg";
31503+ const svgEl = document.createElementNS(ns, "svg");
31504+ svgEl.setAttribute("xmlns", ns);
31505+ svgEl.setAttribute("class", "connection-line");
31506+ svg = $7(svgEl).css({
31507+ position: "absolute",
31508+ top: 0,
31509+ left: 0,
31510+ width: "100%",
31511+ height: "100%",
31512+ zIndex: 0
31513+ });
31514+ $container.append(svg);
31515+ }
31516+ return svg;
31517+ },
31518+ _createShape: (id, type, svg) => {
31519+ const ns = "http://www.w3.org/2000/svg";
31520+ let el;
31521+ if (type === "line") {
31522+ el = document.createElementNS(ns, "line");
31523+ el.setAttribute("class", "cl-line");
31524+ } else {
31525+ el = document.createElementNS(ns, "path");
31526+ el.setAttribute("class", "cl-curve");
31527+ }
31528+ el.setAttribute("data-conn-id", id);
31529+ svg[0].appendChild(el);
31530+ return $7(el);
31531+ },
3148731532 // Публічні методи
3148831533 update: function() {
3148931534 const o2 = this.options;
3149031535 const connection = this.connections.get(o2.id);
3149131536 if (!connection) return;
3149231537 switch (o2.type) {
3149331538 case "line":
31494- this._updateLine(connection.pointA, connection.pointB, connection.svg );
31539+ this._updateLine(connection.pointA, connection.pointB, connection.shape );
3149531540 break;
3149631541 case "curve":
31497- this._updateCurve(connection.pointA, connection.pointB, connection.svg );
31542+ this._updateCurve(connection.pointA, connection.pointB, connection.shape );
3149831543 break;
3149931544 case "zigzag":
31500- this._updateZigzag(connection.pointA, connection.pointB, connection.svg );
31545+ this._updateZigzag(connection.pointA, connection.pointB, connection.shape );
3150131546 break;
3150231547 }
3150331548 this._fireEvent("connector-update", {
@@ -31513,14 +31558,19 @@
3151331558 const o2 = this.options;
3151431559 const oldType = o2.type;
3151531560 o2.type = type;
31516- const oldSvg = this.svgElement;
31517- this.svgElement = this._createSVG(o2.id, type);
31518- oldSvg.replaceWith(this.svgElement);
31561+ const connection = this.connections.get(o2.id);
31562+ const oldShape = connection?.shape;
31563+ const svg = connection?.svg || this.svgElement || this._getOrCreateSharedSVG(o2.container);
31564+ const newShape = this._createShape(o2.id, type, svg);
31565+ if (oldShape && oldShape.length) {
31566+ oldShape.remove();
31567+ }
3151931568 this.connections.set(o2.id, {
31520- ...this.connections.get(o2.id) ,
31569+ ...connection ,
3152131570 type,
3152231571 old: oldType,
31523- svg: this.svgElement
31572+ svg,
31573+ shape: newShape
3152431574 });
3152531575 this.update();
3152631576 },
@@ -31540,10 +31590,11 @@
3154031590 this.update();
3154131591 },
3154231592 // Приватні методи оновлення
31543- _updateLine: (pointA, pointB, svg ) => {
31593+ _updateLine: (pointA, pointB, shape ) => {
3154431594 const point1 = $7(pointA);
3154531595 const point2 = $7(pointB);
31546- const line = svg.find(".cl-line");
31596+ const line = shape;
31597+ const svg = line.closest("svg");
3154731598 const rect1 = point1.offset();
3154831599 const rect2 = point2.offset();
3154931600 const svgRect = svg.offset();
@@ -31562,12 +31613,13 @@
3156231613 y2: y22
3156331614 });
3156431615 },
31565- _updateCurve: function(pointA, pointB, svg ) {
31616+ _updateCurve: function(pointA, pointB, shape ) {
3156631617 const point1 = $7(pointA);
3156731618 const point2 = $7(pointB);
3156831619 const parent1 = point1.parent();
3156931620 const parent2 = point2.parent();
31570- const path = svg.find(".cl-curve");
31621+ const path = shape;
31622+ const svg = path.closest("svg");
3157131623 const coords = this._getCoordinates(point1, point2, svg);
3157231624 const { x1, y1, x2: x22, y2: y22 } = coords;
3157331625 const dx = x22 - x1;
@@ -31623,12 +31675,13 @@
3162331675 const pathData = `M ${x1} ${y1} C ${cp1x} ${cp1y} ${cp2x} ${cp2y} ${x22} ${y22}`;
3162431676 path.attr("d", pathData);
3162531677 },
31626- _updateZigzag: function(pointA, pointB, svg ) {
31678+ _updateZigzag: function(pointA, pointB, shape ) {
3162731679 const point1 = $7(pointA);
3162831680 const point2 = $7(pointB);
3162931681 const parent1 = point1.parent();
3163031682 const parent2 = point2.parent();
31631- const path = svg.find(".cl-curve");
31683+ const path = shape;
31684+ const svg = path.closest("svg");
3163231685 const coords = this._getCoordinates(point1, point2, svg);
3163331686 const { x1, y1, x2: x22, y2: y22 } = coords;
3163431687 let pathData;
3179331846 destroy: function() {
3179431847 const o2 = this.options;
3179531848 this._cleanupAutoUpdate();
31849+ const connection = this.connections.get(o2.id);
31850+ if (connection?.shape) {
31851+ const svg = connection.svg || this.svgElement;
31852+ connection.shape.remove();
31853+ if (svg && svg.find(".cl-line, .cl-curve").length === 0) {
31854+ svg.remove();
31855+ }
31856+ }
3179631857 if (this.svgElement) {
31797- this.svgElement.remove() ;
31858+ this.svgElement = null ;
3179831859 }
3179931860 this.connections.delete(o2.id);
3180031861 this._fireEvent("connector-destroy", {
0 commit comments