chunk-7FXQS3I2.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. import {
  2. isConnection
  3. } from "./chunk-RL3RINWF.js";
  4. import {
  5. every,
  6. isObject,
  7. sortBy
  8. } from "./chunk-4AK4GF4H.js";
  9. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/util/Geometry.js
  10. function pointDistance(a, b) {
  11. if (!a || !b) {
  12. return -1;
  13. }
  14. return Math.sqrt(
  15. Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)
  16. );
  17. }
  18. function pointsOnLine(p, q, r, accuracy) {
  19. if (typeof accuracy === "undefined") {
  20. accuracy = 5;
  21. }
  22. if (!p || !q || !r) {
  23. return false;
  24. }
  25. var val = (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x), dist = pointDistance(p, q);
  26. return Math.abs(val / dist) <= accuracy;
  27. }
  28. var ALIGNED_THRESHOLD = 2;
  29. function pointsAligned(a, b) {
  30. var points = Array.from(arguments).flat();
  31. const axisMap = {
  32. "x": "v",
  33. "y": "h"
  34. };
  35. for (const [axis, orientation] of Object.entries(axisMap)) {
  36. if (pointsAlignedOnAxis(axis, points)) {
  37. return orientation;
  38. }
  39. }
  40. return false;
  41. }
  42. function pointsAlignedOnAxis(axis, points) {
  43. const referencePoint = points[0];
  44. return every(points, function(point) {
  45. return Math.abs(referencePoint[axis] - point[axis]) <= ALIGNED_THRESHOLD;
  46. });
  47. }
  48. function pointInRect(p, rect, tolerance) {
  49. tolerance = tolerance || 0;
  50. return p.x > rect.x - tolerance && p.y > rect.y - tolerance && p.x < rect.x + rect.width + tolerance && p.y < rect.y + rect.height + tolerance;
  51. }
  52. function getMidPoint(p, q) {
  53. return {
  54. x: Math.round(p.x + (q.x - p.x) / 2),
  55. y: Math.round(p.y + (q.y - p.y) / 2)
  56. };
  57. }
  58. // node_modules/.pnpm/path-intersection@3.1.0/node_modules/path-intersection/intersect.js
  59. var p2s = /,?([a-z]),?/gi;
  60. var toFloat = parseFloat;
  61. var math = Math;
  62. var PI = math.PI;
  63. var mmin = math.min;
  64. var mmax = math.max;
  65. var pow = math.pow;
  66. var abs = math.abs;
  67. var pathCommand = /([a-z])[\s,]*((-?\d*\.?\d*(?:e[-+]?\d+)?[\s]*,?[\s]*)+)/ig;
  68. var pathValues = /(-?\d*\.?\d*(?:e[-+]?\d+)?)[\s]*,?[\s]*/ig;
  69. var isArray = Array.isArray || function(o) {
  70. return o instanceof Array;
  71. };
  72. function hasProperty(obj, property) {
  73. return Object.prototype.hasOwnProperty.call(obj, property);
  74. }
  75. function clone(obj) {
  76. if (typeof obj == "function" || Object(obj) !== obj) {
  77. return obj;
  78. }
  79. var res = new obj.constructor();
  80. for (var key in obj) {
  81. if (hasProperty(obj, key)) {
  82. res[key] = clone(obj[key]);
  83. }
  84. }
  85. return res;
  86. }
  87. function repush(array, item) {
  88. for (var i = 0, ii = array.length; i < ii; i++)
  89. if (array[i] === item) {
  90. return array.push(array.splice(i, 1)[0]);
  91. }
  92. }
  93. function cacher(f) {
  94. function newf() {
  95. var arg = Array.prototype.slice.call(arguments, 0), args = arg.join("␀"), cache = newf.cache = newf.cache || {}, count = newf.count = newf.count || [];
  96. if (hasProperty(cache, args)) {
  97. repush(count, args);
  98. return cache[args];
  99. }
  100. count.length >= 1e3 && delete cache[count.shift()];
  101. count.push(args);
  102. cache[args] = f(...arguments);
  103. return cache[args];
  104. }
  105. return newf;
  106. }
  107. function parsePathString(pathString) {
  108. if (!pathString) {
  109. return null;
  110. }
  111. var pth = paths(pathString);
  112. if (pth.arr) {
  113. return clone(pth.arr);
  114. }
  115. var paramCounts = { a: 7, c: 6, h: 1, l: 2, m: 2, q: 4, s: 4, t: 2, v: 1, z: 0 }, data = [];
  116. if (isArray(pathString) && isArray(pathString[0])) {
  117. data = clone(pathString);
  118. }
  119. if (!data.length) {
  120. String(pathString).replace(pathCommand, function(a, b, c) {
  121. var params = [], name = b.toLowerCase();
  122. c.replace(pathValues, function(a2, b2) {
  123. b2 && params.push(+b2);
  124. });
  125. if (name == "m" && params.length > 2) {
  126. data.push([b, ...params.splice(0, 2)]);
  127. name = "l";
  128. b = b == "m" ? "l" : "L";
  129. }
  130. while (params.length >= paramCounts[name]) {
  131. data.push([b, ...params.splice(0, paramCounts[name])]);
  132. if (!paramCounts[name]) {
  133. break;
  134. }
  135. }
  136. });
  137. }
  138. data.toString = paths.toString;
  139. pth.arr = clone(data);
  140. return data;
  141. }
  142. function paths(ps) {
  143. var p = paths.ps = paths.ps || {};
  144. if (p[ps]) {
  145. p[ps].sleep = 100;
  146. } else {
  147. p[ps] = {
  148. sleep: 100
  149. };
  150. }
  151. setTimeout(function() {
  152. for (var key in p) {
  153. if (hasProperty(p, key) && key != ps) {
  154. p[key].sleep--;
  155. !p[key].sleep && delete p[key];
  156. }
  157. }
  158. });
  159. return p[ps];
  160. }
  161. function rectBBox(x, y, width, height) {
  162. if (arguments.length === 1) {
  163. y = x.y;
  164. width = x.width;
  165. height = x.height;
  166. x = x.x;
  167. }
  168. return {
  169. x,
  170. y,
  171. width,
  172. height,
  173. x2: x + width,
  174. y2: y + height
  175. };
  176. }
  177. function pathToString() {
  178. return this.join(",").replace(p2s, "$1");
  179. }
  180. function pathClone(pathArray) {
  181. var res = clone(pathArray);
  182. res.toString = pathToString;
  183. return res;
  184. }
  185. function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) {
  186. var t1 = 1 - t, t13 = pow(t1, 3), t12 = pow(t1, 2), t2 = t * t, t3 = t2 * t, x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x, y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y;
  187. return {
  188. x: fixError(x),
  189. y: fixError(y)
  190. };
  191. }
  192. function bezierBBox(points) {
  193. var bbox = curveBBox(...points);
  194. return rectBBox(
  195. bbox.x0,
  196. bbox.y0,
  197. bbox.x1 - bbox.x0,
  198. bbox.y1 - bbox.y0
  199. );
  200. }
  201. function isPointInsideBBox(bbox, x, y) {
  202. return x >= bbox.x && x <= bbox.x + bbox.width && y >= bbox.y && y <= bbox.y + bbox.height;
  203. }
  204. function isBBoxIntersect(bbox1, bbox2) {
  205. bbox1 = rectBBox(bbox1);
  206. bbox2 = rectBBox(bbox2);
  207. return isPointInsideBBox(bbox2, bbox1.x, bbox1.y) || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y) || isPointInsideBBox(bbox2, bbox1.x, bbox1.y2) || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y2) || isPointInsideBBox(bbox1, bbox2.x, bbox2.y) || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y) || isPointInsideBBox(bbox1, bbox2.x, bbox2.y2) || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y2) || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x) && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y);
  208. }
  209. function base3(t, p1, p2, p3, p4) {
  210. var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4, t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3;
  211. return t * t2 - 3 * p1 + 3 * p2;
  212. }
  213. function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) {
  214. if (z == null) {
  215. z = 1;
  216. }
  217. z = z > 1 ? 1 : z < 0 ? 0 : z;
  218. var z2 = z / 2, n = 12, Tvalues = [-0.1252, 0.1252, -0.3678, 0.3678, -0.5873, 0.5873, -0.7699, 0.7699, -0.9041, 0.9041, -0.9816, 0.9816], Cvalues = [0.2491, 0.2491, 0.2335, 0.2335, 0.2032, 0.2032, 0.1601, 0.1601, 0.1069, 0.1069, 0.0472, 0.0472], sum = 0;
  219. for (var i = 0; i < n; i++) {
  220. var ct = z2 * Tvalues[i] + z2, xbase = base3(ct, x1, x2, x3, x4), ybase = base3(ct, y1, y2, y3, y4), comb = xbase * xbase + ybase * ybase;
  221. sum += Cvalues[i] * math.sqrt(comb);
  222. }
  223. return z2 * sum;
  224. }
  225. function intersectLines(x1, y1, x2, y2, x3, y3, x4, y4) {
  226. if (mmax(x1, x2) < mmin(x3, x4) || mmin(x1, x2) > mmax(x3, x4) || mmax(y1, y2) < mmin(y3, y4) || mmin(y1, y2) > mmax(y3, y4)) {
  227. return;
  228. }
  229. var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4), ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4), denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  230. if (!denominator) {
  231. return;
  232. }
  233. var px = fixError(nx / denominator), py = fixError(ny / denominator), px2 = +px.toFixed(2), py2 = +py.toFixed(2);
  234. if (px2 < +mmin(x1, x2).toFixed(2) || px2 > +mmax(x1, x2).toFixed(2) || px2 < +mmin(x3, x4).toFixed(2) || px2 > +mmax(x3, x4).toFixed(2) || py2 < +mmin(y1, y2).toFixed(2) || py2 > +mmax(y1, y2).toFixed(2) || py2 < +mmin(y3, y4).toFixed(2) || py2 > +mmax(y3, y4).toFixed(2)) {
  235. return;
  236. }
  237. return { x: px, y: py };
  238. }
  239. function fixError(number) {
  240. return Math.round(number * 1e11) / 1e11;
  241. }
  242. function findBezierIntersections(bez1, bez2, justCount) {
  243. var bbox1 = bezierBBox(bez1), bbox2 = bezierBBox(bez2);
  244. if (!isBBoxIntersect(bbox1, bbox2)) {
  245. return justCount ? 0 : [];
  246. }
  247. var l1 = bezlen(...bez1), l2 = bezlen(...bez2), n1 = isLine(bez1) ? 1 : ~~(l1 / 5) || 1, n2 = isLine(bez2) ? 1 : ~~(l2 / 5) || 1, dots1 = [], dots2 = [], xy = {}, res = justCount ? 0 : [];
  248. for (var i = 0; i < n1 + 1; i++) {
  249. var p = findDotsAtSegment(...bez1, i / n1);
  250. dots1.push({ x: p.x, y: p.y, t: i / n1 });
  251. }
  252. for (i = 0; i < n2 + 1; i++) {
  253. p = findDotsAtSegment(...bez2, i / n2);
  254. dots2.push({ x: p.x, y: p.y, t: i / n2 });
  255. }
  256. for (i = 0; i < n1; i++) {
  257. for (var j = 0; j < n2; j++) {
  258. var di = dots1[i], di1 = dots1[i + 1], dj = dots2[j], dj1 = dots2[j + 1], ci = abs(di1.x - di.x) < 0.01 ? "y" : "x", cj = abs(dj1.x - dj.x) < 0.01 ? "y" : "x", is = intersectLines(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y), key;
  259. if (is) {
  260. key = is.x.toFixed(9) + "#" + is.y.toFixed(9);
  261. if (xy[key]) {
  262. continue;
  263. }
  264. xy[key] = true;
  265. var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t), t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t);
  266. if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) {
  267. if (justCount) {
  268. res++;
  269. } else {
  270. res.push({
  271. x: is.x,
  272. y: is.y,
  273. t1,
  274. t2
  275. });
  276. }
  277. }
  278. }
  279. }
  280. }
  281. return res;
  282. }
  283. function findPathIntersections(path1, path2, justCount) {
  284. path1 = pathToCurve(path1);
  285. path2 = pathToCurve(path2);
  286. var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2, res = justCount ? 0 : [];
  287. for (var i = 0, ii = path1.length; i < ii; i++) {
  288. var pi = path1[i];
  289. if (pi[0] == "M") {
  290. x1 = x1m = pi[1];
  291. y1 = y1m = pi[2];
  292. } else {
  293. if (pi[0] == "C") {
  294. bez1 = [x1, y1, ...pi.slice(1)];
  295. x1 = bez1[6];
  296. y1 = bez1[7];
  297. } else {
  298. bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m];
  299. x1 = x1m;
  300. y1 = y1m;
  301. }
  302. for (var j = 0, jj = path2.length; j < jj; j++) {
  303. var pj = path2[j];
  304. if (pj[0] == "M") {
  305. x2 = x2m = pj[1];
  306. y2 = y2m = pj[2];
  307. } else {
  308. if (pj[0] == "C") {
  309. bez2 = [x2, y2, ...pj.slice(1)];
  310. x2 = bez2[6];
  311. y2 = bez2[7];
  312. } else {
  313. bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m];
  314. x2 = x2m;
  315. y2 = y2m;
  316. }
  317. var intr = findBezierIntersections(bez1, bez2, justCount);
  318. if (justCount) {
  319. res += intr;
  320. } else {
  321. for (var k = 0, kk = intr.length; k < kk; k++) {
  322. intr[k].segment1 = i;
  323. intr[k].segment2 = j;
  324. intr[k].bez1 = bez1;
  325. intr[k].bez2 = bez2;
  326. }
  327. res = res.concat(intr);
  328. }
  329. }
  330. }
  331. }
  332. }
  333. return res;
  334. }
  335. function pathToAbsolute(pathArray) {
  336. var pth = paths(pathArray);
  337. if (pth.abs) {
  338. return pathClone(pth.abs);
  339. }
  340. if (!isArray(pathArray) || !isArray(pathArray && pathArray[0])) {
  341. pathArray = parsePathString(pathArray);
  342. }
  343. if (!pathArray || !pathArray.length) {
  344. return [["M", 0, 0]];
  345. }
  346. var res = [], x = 0, y = 0, mx = 0, my = 0, start = 0, pa0;
  347. if (pathArray[0][0] == "M") {
  348. x = +pathArray[0][1];
  349. y = +pathArray[0][2];
  350. mx = x;
  351. my = y;
  352. start++;
  353. res[0] = ["M", x, y];
  354. }
  355. for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) {
  356. res.push(r = []);
  357. pa = pathArray[i];
  358. pa0 = pa[0];
  359. if (pa0 != pa0.toUpperCase()) {
  360. r[0] = pa0.toUpperCase();
  361. switch (r[0]) {
  362. case "A":
  363. r[1] = pa[1];
  364. r[2] = pa[2];
  365. r[3] = pa[3];
  366. r[4] = pa[4];
  367. r[5] = pa[5];
  368. r[6] = +pa[6] + x;
  369. r[7] = +pa[7] + y;
  370. break;
  371. case "V":
  372. r[1] = +pa[1] + y;
  373. break;
  374. case "H":
  375. r[1] = +pa[1] + x;
  376. break;
  377. case "M":
  378. mx = +pa[1] + x;
  379. my = +pa[2] + y;
  380. default:
  381. for (var j = 1, jj = pa.length; j < jj; j++) {
  382. r[j] = +pa[j] + (j % 2 ? x : y);
  383. }
  384. }
  385. } else {
  386. for (var k = 0, kk = pa.length; k < kk; k++) {
  387. r[k] = pa[k];
  388. }
  389. }
  390. pa0 = pa0.toUpperCase();
  391. switch (r[0]) {
  392. case "Z":
  393. x = +mx;
  394. y = +my;
  395. break;
  396. case "H":
  397. x = r[1];
  398. break;
  399. case "V":
  400. y = r[1];
  401. break;
  402. case "M":
  403. mx = r[r.length - 2];
  404. my = r[r.length - 1];
  405. default:
  406. x = r[r.length - 2];
  407. y = r[r.length - 1];
  408. }
  409. }
  410. res.toString = pathToString;
  411. pth.abs = pathClone(res);
  412. return res;
  413. }
  414. function isLine(bez) {
  415. return bez[0] === bez[2] && bez[1] === bez[3] && bez[4] === bez[6] && bez[5] === bez[7];
  416. }
  417. function lineToCurve(x1, y1, x2, y2) {
  418. return [
  419. x1,
  420. y1,
  421. x2,
  422. y2,
  423. x2,
  424. y2
  425. ];
  426. }
  427. function qubicToCurve(x1, y1, ax, ay, x2, y2) {
  428. var _13 = 1 / 3, _23 = 2 / 3;
  429. return [
  430. _13 * x1 + _23 * ax,
  431. _13 * y1 + _23 * ay,
  432. _13 * x2 + _23 * ax,
  433. _13 * y2 + _23 * ay,
  434. x2,
  435. y2
  436. ];
  437. }
  438. function arcToCurve(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) {
  439. var _120 = PI * 120 / 180, rad = PI / 180 * (+angle || 0), res = [], xy, rotate = cacher(function(x3, y3, rad2) {
  440. var X = x3 * math.cos(rad2) - y3 * math.sin(rad2), Y = x3 * math.sin(rad2) + y3 * math.cos(rad2);
  441. return { x: X, y: Y };
  442. });
  443. if (!recursive) {
  444. xy = rotate(x1, y1, -rad);
  445. x1 = xy.x;
  446. y1 = xy.y;
  447. xy = rotate(x2, y2, -rad);
  448. x2 = xy.x;
  449. y2 = xy.y;
  450. var x = (x1 - x2) / 2, y = (y1 - y2) / 2;
  451. var h = x * x / (rx * rx) + y * y / (ry * ry);
  452. if (h > 1) {
  453. h = math.sqrt(h);
  454. rx = h * rx;
  455. ry = h * ry;
  456. }
  457. var rx2 = rx * rx, ry2 = ry * ry, k = (large_arc_flag == sweep_flag ? -1 : 1) * math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))), cx = k * rx * y / ry + (x1 + x2) / 2, cy = k * -ry * x / rx + (y1 + y2) / 2, f1 = math.asin(((y1 - cy) / ry).toFixed(9)), f2 = math.asin(((y2 - cy) / ry).toFixed(9));
  458. f1 = x1 < cx ? PI - f1 : f1;
  459. f2 = x2 < cx ? PI - f2 : f2;
  460. f1 < 0 && (f1 = PI * 2 + f1);
  461. f2 < 0 && (f2 = PI * 2 + f2);
  462. if (sweep_flag && f1 > f2) {
  463. f1 = f1 - PI * 2;
  464. }
  465. if (!sweep_flag && f2 > f1) {
  466. f2 = f2 - PI * 2;
  467. }
  468. } else {
  469. f1 = recursive[0];
  470. f2 = recursive[1];
  471. cx = recursive[2];
  472. cy = recursive[3];
  473. }
  474. var df = f2 - f1;
  475. if (abs(df) > _120) {
  476. var f2old = f2, x2old = x2, y2old = y2;
  477. f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1);
  478. x2 = cx + rx * math.cos(f2);
  479. y2 = cy + ry * math.sin(f2);
  480. res = arcToCurve(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]);
  481. }
  482. df = f2 - f1;
  483. var c1 = math.cos(f1), s1 = math.sin(f1), c2 = math.cos(f2), s2 = math.sin(f2), t = math.tan(df / 4), hx = 4 / 3 * rx * t, hy = 4 / 3 * ry * t, m1 = [x1, y1], m2 = [x1 + hx * s1, y1 - hy * c1], m3 = [x2 + hx * s2, y2 - hy * c2], m4 = [x2, y2];
  484. m2[0] = 2 * m1[0] - m2[0];
  485. m2[1] = 2 * m1[1] - m2[1];
  486. if (recursive) {
  487. return [m2, m3, m4].concat(res);
  488. } else {
  489. res = [m2, m3, m4].concat(res).join().split(",");
  490. var newres = [];
  491. for (var i = 0, ii = res.length; i < ii; i++) {
  492. newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
  493. }
  494. return newres;
  495. }
  496. }
  497. function curveBBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  498. var tvalues = [], bounds = [[], []], a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  499. for (var i = 0; i < 2; ++i) {
  500. if (i == 0) {
  501. b = 6 * x0 - 12 * x1 + 6 * x2;
  502. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  503. c = 3 * x1 - 3 * x0;
  504. } else {
  505. b = 6 * y0 - 12 * y1 + 6 * y2;
  506. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  507. c = 3 * y1 - 3 * y0;
  508. }
  509. if (abs(a) < 1e-12) {
  510. if (abs(b) < 1e-12) {
  511. continue;
  512. }
  513. t = -c / b;
  514. if (0 < t && t < 1) {
  515. tvalues.push(t);
  516. }
  517. continue;
  518. }
  519. b2ac = b * b - 4 * c * a;
  520. sqrtb2ac = math.sqrt(b2ac);
  521. if (b2ac < 0) {
  522. continue;
  523. }
  524. t1 = (-b + sqrtb2ac) / (2 * a);
  525. if (0 < t1 && t1 < 1) {
  526. tvalues.push(t1);
  527. }
  528. t2 = (-b - sqrtb2ac) / (2 * a);
  529. if (0 < t2 && t2 < 1) {
  530. tvalues.push(t2);
  531. }
  532. }
  533. var j = tvalues.length, jlen = j, mt;
  534. while (j--) {
  535. t = tvalues[j];
  536. mt = 1 - t;
  537. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  538. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  539. }
  540. bounds[0][jlen] = x0;
  541. bounds[1][jlen] = y0;
  542. bounds[0][jlen + 1] = x3;
  543. bounds[1][jlen + 1] = y3;
  544. bounds[0].length = bounds[1].length = jlen + 2;
  545. return {
  546. x0: mmin(...bounds[0]),
  547. y0: mmin(...bounds[1]),
  548. x1: mmax(...bounds[0]),
  549. y1: mmax(...bounds[1])
  550. };
  551. }
  552. function pathToCurve(path) {
  553. var pth = paths(path);
  554. if (pth.curve) {
  555. return pathClone(pth.curve);
  556. }
  557. var curvedPath = pathToAbsolute(path), attrs = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null }, processPath = function(path2, d, pathCommand3) {
  558. var nx, ny;
  559. if (!path2) {
  560. return ["C", d.x, d.y, d.x, d.y, d.x, d.y];
  561. }
  562. !(path2[0] in { T: 1, Q: 1 }) && (d.qx = d.qy = null);
  563. switch (path2[0]) {
  564. case "M":
  565. d.X = path2[1];
  566. d.Y = path2[2];
  567. break;
  568. case "A":
  569. path2 = ["C", ...arcToCurve(d.x, d.y, ...path2.slice(1))];
  570. break;
  571. case "S":
  572. if (pathCommand3 == "C" || pathCommand3 == "S") {
  573. nx = d.x * 2 - d.bx;
  574. ny = d.y * 2 - d.by;
  575. } else {
  576. nx = d.x;
  577. ny = d.y;
  578. }
  579. path2 = ["C", nx, ny, ...path2.slice(1)];
  580. break;
  581. case "T":
  582. if (pathCommand3 == "Q" || pathCommand3 == "T") {
  583. d.qx = d.x * 2 - d.qx;
  584. d.qy = d.y * 2 - d.qy;
  585. } else {
  586. d.qx = d.x;
  587. d.qy = d.y;
  588. }
  589. path2 = ["C", ...qubicToCurve(d.x, d.y, d.qx, d.qy, path2[1], path2[2])];
  590. break;
  591. case "Q":
  592. d.qx = path2[1];
  593. d.qy = path2[2];
  594. path2 = ["C", ...qubicToCurve(d.x, d.y, path2[1], path2[2], path2[3], path2[4])];
  595. break;
  596. case "L":
  597. path2 = ["C", ...lineToCurve(d.x, d.y, path2[1], path2[2])];
  598. break;
  599. case "H":
  600. path2 = ["C", ...lineToCurve(d.x, d.y, path2[1], d.y)];
  601. break;
  602. case "V":
  603. path2 = ["C", ...lineToCurve(d.x, d.y, d.x, path2[1])];
  604. break;
  605. case "Z":
  606. path2 = ["C", ...lineToCurve(d.x, d.y, d.X, d.Y)];
  607. break;
  608. }
  609. return path2;
  610. }, fixArc = function(pp, i2) {
  611. if (pp[i2].length > 7) {
  612. pp[i2].shift();
  613. var pi = pp[i2];
  614. while (pi.length) {
  615. pathCommands[i2] = "A";
  616. pp.splice(i2++, 0, ["C", ...pi.splice(0, 6)]);
  617. }
  618. pp.splice(i2, 1);
  619. ii = curvedPath.length;
  620. }
  621. }, pathCommands = [], pfirst = "", pathCommand2 = "";
  622. for (var i = 0, ii = curvedPath.length; i < ii; i++) {
  623. curvedPath[i] && (pfirst = curvedPath[i][0]);
  624. if (pfirst != "C") {
  625. pathCommands[i] = pfirst;
  626. i && (pathCommand2 = pathCommands[i - 1]);
  627. }
  628. curvedPath[i] = processPath(curvedPath[i], attrs, pathCommand2);
  629. if (pathCommands[i] != "A" && pfirst == "C")
  630. pathCommands[i] = "C";
  631. fixArc(curvedPath, i);
  632. var seg = curvedPath[i], seglen = seg.length;
  633. attrs.x = seg[seglen - 2];
  634. attrs.y = seg[seglen - 1];
  635. attrs.bx = toFloat(seg[seglen - 4]) || attrs.x;
  636. attrs.by = toFloat(seg[seglen - 3]) || attrs.y;
  637. }
  638. pth.curve = pathClone(curvedPath);
  639. return curvedPath;
  640. }
  641. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/layout/LayoutUtil.js
  642. function roundBounds(bounds) {
  643. return {
  644. x: Math.round(bounds.x),
  645. y: Math.round(bounds.y),
  646. width: Math.round(bounds.width),
  647. height: Math.round(bounds.height)
  648. };
  649. }
  650. function roundPoint(point) {
  651. return {
  652. x: Math.round(point.x),
  653. y: Math.round(point.y)
  654. };
  655. }
  656. function asTRBL(bounds) {
  657. return {
  658. top: bounds.y,
  659. right: bounds.x + (bounds.width || 0),
  660. bottom: bounds.y + (bounds.height || 0),
  661. left: bounds.x
  662. };
  663. }
  664. function asBounds(trbl) {
  665. return {
  666. x: trbl.left,
  667. y: trbl.top,
  668. width: trbl.right - trbl.left,
  669. height: trbl.bottom - trbl.top
  670. };
  671. }
  672. function getBoundsMid(bounds) {
  673. return roundPoint({
  674. x: bounds.x + (bounds.width || 0) / 2,
  675. y: bounds.y + (bounds.height || 0) / 2
  676. });
  677. }
  678. function getConnectionMid(connection) {
  679. var waypoints = connection.waypoints;
  680. var parts = waypoints.reduce(function(parts2, point, index) {
  681. var lastPoint = waypoints[index - 1];
  682. if (lastPoint) {
  683. var lastPart = parts2[parts2.length - 1];
  684. var startLength = lastPart && lastPart.endLength || 0;
  685. var length = distance(lastPoint, point);
  686. parts2.push({
  687. start: lastPoint,
  688. end: point,
  689. startLength,
  690. endLength: startLength + length,
  691. length
  692. });
  693. }
  694. return parts2;
  695. }, []);
  696. var totalLength = parts.reduce(function(length, part) {
  697. return length + part.length;
  698. }, 0);
  699. var midLength = totalLength / 2;
  700. var i = 0;
  701. var midSegment = parts[i];
  702. while (midSegment.endLength < midLength) {
  703. midSegment = parts[++i];
  704. }
  705. var segmentProgress = (midLength - midSegment.startLength) / midSegment.length;
  706. var midPoint = {
  707. x: midSegment.start.x + (midSegment.end.x - midSegment.start.x) * segmentProgress,
  708. y: midSegment.start.y + (midSegment.end.y - midSegment.start.y) * segmentProgress
  709. };
  710. return midPoint;
  711. }
  712. function getMid(element) {
  713. if (isConnection(element)) {
  714. return getConnectionMid(element);
  715. }
  716. return getBoundsMid(element);
  717. }
  718. function getOrientation(rect, reference, padding) {
  719. padding = padding || 0;
  720. if (!isObject(padding)) {
  721. padding = { x: padding, y: padding };
  722. }
  723. var rectOrientation = asTRBL(rect), referenceOrientation = asTRBL(reference);
  724. var top = rectOrientation.bottom + padding.y <= referenceOrientation.top, right = rectOrientation.left - padding.x >= referenceOrientation.right, bottom = rectOrientation.top - padding.y >= referenceOrientation.bottom, left = rectOrientation.right + padding.x <= referenceOrientation.left;
  725. var vertical = top ? "top" : bottom ? "bottom" : null, horizontal = left ? "left" : right ? "right" : null;
  726. if (horizontal && vertical) {
  727. return vertical + "-" + horizontal;
  728. } else {
  729. return horizontal || vertical || "intersect";
  730. }
  731. }
  732. function getElementLineIntersection(elementPath, linePath, cropStart) {
  733. var intersections = getIntersections(elementPath, linePath);
  734. if (intersections.length === 1) {
  735. return roundPoint(intersections[0]);
  736. } else if (intersections.length === 2 && pointDistance(intersections[0], intersections[1]) < 1) {
  737. return roundPoint(intersections[0]);
  738. } else if (intersections.length > 1) {
  739. intersections = sortBy(intersections, function(i) {
  740. var distance2 = Math.floor(i.t2 * 100) || 1;
  741. distance2 = 100 - distance2;
  742. distance2 = (distance2 < 10 ? "0" : "") + distance2;
  743. return i.segment2 + "#" + distance2;
  744. });
  745. return roundPoint(intersections[cropStart ? 0 : intersections.length - 1]);
  746. }
  747. return null;
  748. }
  749. function getIntersections(a, b) {
  750. return findPathIntersections(a, b);
  751. }
  752. function filterRedundantWaypoints(waypoints) {
  753. waypoints = waypoints.slice();
  754. var idx = 0, point, previousPoint, nextPoint;
  755. while (waypoints[idx]) {
  756. point = waypoints[idx];
  757. previousPoint = waypoints[idx - 1];
  758. nextPoint = waypoints[idx + 1];
  759. if (pointDistance(point, nextPoint) === 0 || pointsOnLine(previousPoint, nextPoint, point)) {
  760. waypoints.splice(idx, 1);
  761. } else {
  762. idx++;
  763. }
  764. }
  765. return waypoints;
  766. }
  767. function distance(a, b) {
  768. return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
  769. }
  770. export {
  771. pointDistance,
  772. pointsOnLine,
  773. pointsAligned,
  774. pointInRect,
  775. getMidPoint,
  776. findPathIntersections,
  777. roundBounds,
  778. roundPoint,
  779. asTRBL,
  780. asBounds,
  781. getMid,
  782. getOrientation,
  783. getElementLineIntersection,
  784. filterRedundantWaypoints
  785. };
  786. //# sourceMappingURL=chunk-7FXQS3I2.js.map