@euphrasiologist/lwphylo 1.1.14 → 1.2.1

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1278 @@
1
+ 'use strict';
2
+
3
+ var d3 = require('d3');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var d3__namespace = /*#__PURE__*/_interopNamespaceDefault(d3);
23
+
24
+ // Based on the archived d3 fisheye plugin, modernized & hardened.
25
+ // - Works in screen/pixel space (set xscale/yscale).
26
+ // - O(1) math with precomputed constants; avoids unnecessary sqrt.
27
+ // - Stable API: .radius(), .distortion(), .focus(), .scales()
28
+ // - Returns { x, y, z } where z ~= local magnification (clamped).
29
+ // - Adds small ergonomics: .setScales(), .focusFromEvent(), .clampZ()
30
+
31
+ const phisheye = {
32
+ circular: () => {
33
+ let radius = 200; // pixels
34
+ let distortion = 2; // dimensionless
35
+ let focus = [0, 0]; // [fx, fy] in pixels
36
+ let scales = {}; // { xscale, yscale }
37
+ let k0 = 0, k1 = 0; // precomputed factors
38
+ let radius2 = radius * radius;
39
+ let zClamp = 10; // max z (magnification) for stability
40
+
41
+ function ensureScales() {
42
+ if (!scales || typeof scales.xscale !== "function" || typeof scales.yscale !== "function") {
43
+ throw new Error("phisheye.circular: call .scales(xscale, yscale) before using the fisheye.");
44
+ }
45
+ }
46
+
47
+ function rescale() {
48
+ // Same functional form as the classic plugin:
49
+ // k = ((e^d) / (e^d - 1)) * R * (1 - exp(-d * r / R)) / r
50
+ // where d=distortion, R=radius, r=distance to focus.
51
+ const e = Math.exp(distortion);
52
+ k0 = (e / (e - 1)) * radius; // constant multiplier
53
+ k1 = distortion / radius; // exponent scale
54
+ radius2 = radius * radius;
55
+ return fisheye;
56
+ }
57
+
58
+ function fisheye(d) {
59
+ ensureScales();
60
+
61
+ const x0 = scales.xscale(d.x);
62
+ const y0 = scales.yscale(d.y);
63
+
64
+ const dx = x0 - focus[0];
65
+ const dy = y0 - focus[1];
66
+ const dd2 = dx * dx + dy * dy;
67
+
68
+ // At the focus or outside radius -> identity mapping, z ~ 1
69
+ if (dd2 === 0 || dd2 >= radius2) {
70
+ return { x: x0, y: y0, z: dd2 >= radius2 ? 1 : zClamp };
71
+ }
72
+
73
+ const dd = Math.sqrt(dd2);
74
+ // Classic mapping (with a slight blend for gentler core)
75
+ const k = ((k0 * (1 - Math.exp(-dd * k1))) / dd) * 0.75 + 0.25;
76
+
77
+ // New position
78
+ const x = focus[0] + dx * k;
79
+ const y = focus[1] + dy * k;
80
+
81
+ // Local magnification proxy (clamped)
82
+ const z = Math.min(k, zClamp);
83
+
84
+ return { x, y, z };
85
+ }
86
+
87
+ // --- Public API ---
88
+
89
+ fisheye.radius = function(_) {
90
+ if (!arguments.length) return radius;
91
+ radius = Math.max(0, +_);
92
+ return rescale();
93
+ };
94
+
95
+ fisheye.distortion = function(_) {
96
+ if (!arguments.length) return distortion;
97
+ distortion = Math.max(0, +_);
98
+ return rescale();
99
+ };
100
+
101
+ fisheye.focus = function(_) {
102
+ if (!arguments.length) return focus.slice();
103
+ if (!Array.isArray(_) || _.length !== 2) throw new Error("focus expects [x, y] in pixels.");
104
+ focus = [+_[0], +_[1]];
105
+ return fisheye;
106
+ };
107
+
108
+ fisheye.scales = function(xscale, yscale) {
109
+ if (!arguments.length) return scales;
110
+ scales = { xscale, yscale };
111
+ return fisheye;
112
+ };
113
+
114
+ // Convenience alias
115
+ fisheye.setScales = fisheye.scales;
116
+
117
+ // Clamp maximum z (magnification) returned; defaults to 10
118
+ fisheye.clampZ = function(_) {
119
+ if (!arguments.length) return zClamp;
120
+ zClamp = Math.max(1, +_);
121
+ return fisheye;
122
+ };
123
+
124
+ // Convenience: set focus from a pointer event relative to an HTMLElement/SVG
125
+ // Example: svg.on("pointermove", (e) => fe.focusFromEvent(e, svg.node()))
126
+ fisheye.focusFromEvent = function(event, element) {
127
+ const rect = element.getBoundingClientRect();
128
+ const fx = event.clientX - rect.left;
129
+ const fy = event.clientY - rect.top;
130
+ return fisheye.focus([fx, fy]);
131
+ };
132
+
133
+ return rescale();
134
+ }
135
+ };
136
+
137
+ // src/radial/polarToCartesian.js
138
+ function polarToCartesian (cx, cy, r, t) {
139
+ return { x: cx + r * Math.cos(t), y: cy - r * Math.sin(t) };
140
+ }
141
+
142
+ /**
143
+ * Draw the shortest arc between startAngle and endAngle (radians), CCW.
144
+ * If the CW path is shorter, swap start/end so the CCW path is still shortest.
145
+ * Works with Y-inverted screen coords (polarToCartesian already inverts Y).
146
+ */
147
+ function describeArc(cx, cy, radius, startAngle, endAngle) {
148
+ const TAU = Math.PI * 2;
149
+ const norm = (t) => ((t % TAU) + TAU) % TAU;
150
+ let a0 = norm(startAngle);
151
+ let a1 = norm(endAngle);
152
+
153
+ // CCW and CW spans
154
+ const ccw = (a1 - a0 + TAU) % TAU;
155
+ const cw = (a0 - a1 + TAU) % TAU;
156
+
157
+ // Ensure we always take the shorter span *in CCW* by swapping if needed
158
+ if (cw < ccw) {
159
+ const tmp = a0; a0 = a1; a1 = tmp;
160
+ }
161
+
162
+ const delta = (a1 - a0 + TAU) % TAU; // now the shorter CCW span
163
+ if (delta < 1e-9) {
164
+ const p = polarToCartesian(cx, cy, radius, a0);
165
+ return `M ${p.x} ${p.y}`; // degenerate span → no arc
166
+ }
167
+
168
+ const largeArcFlag = delta > Math.PI ? 1 : 0; // should be 0 for “shortest”, but keep for safety
169
+ const sweepFlag = 0; // CCW
170
+
171
+ const p0 = polarToCartesian(cx, cy, radius, a0);
172
+ const p1 = polarToCartesian(cx, cy, radius, a1);
173
+
174
+ return `M ${p0.x} ${p0.y} A ${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${p1.x} ${p1.y}`;
175
+ }
176
+
177
+ /**
178
+ * Recursive function for pre-order traversal of tree (returns array)
179
+ */
180
+ function preorder(node, list = []) {
181
+ list.push(node);
182
+ for (let i = 0; i < (node.children?.length || 0); i++) {
183
+ list = preorder(node.children[i], list);
184
+ }
185
+ return list;
186
+ }
187
+
188
+ /**
189
+ * Convert parsed Newick tree from readTree() into data
190
+ * frame.
191
+ * this is akin to a "phylo" object in R.
192
+ */
193
+
194
+ function fortify (tree, sort = true) {
195
+ var df = [];
196
+
197
+ for (const node of preorder(tree)) {
198
+ if (node.parent === null) {
199
+ df.push({
200
+ 'parentId': null,
201
+ 'parentLabel': null,
202
+ 'thisId': node.id,
203
+ 'thisLabel': node.label,
204
+ 'children': node.children.map(x => x.id),
205
+ 'branchLength': 0.,
206
+ 'isTip': false,
207
+ 'x': node.x,
208
+ 'y': node.y,
209
+ 'angle': node.angle
210
+ });
211
+ }
212
+ else {
213
+ df.push({
214
+ 'parentId': node.parent.id,
215
+ 'parentLabel': node.parent.label,
216
+ 'thisId': node.id,
217
+ 'thisLabel': node.label,
218
+ 'children': node.children.map(x => x.id),
219
+ 'branchLength': node.branchLength,
220
+ 'isTip': (node.children.length == 0),
221
+ 'x': node.x,
222
+ 'y': node.y,
223
+ 'angle': node.angle
224
+ });
225
+ }
226
+ }
227
+
228
+ if (sort) {
229
+ df = df.sort(function (a, b) {
230
+ return a.thisId - b.thisId;
231
+ });
232
+ }
233
+ return (df);
234
+ }
235
+
236
+ /**
237
+ * Compute per-node polar coordinates for radial layout:
238
+ * - Tip angles: evenly spaced 0..2π in tip DFS order
239
+ * - Internal angles: circular mean of child angles
240
+ * - Radii: cumulative branch length from root
241
+ * - x,y: cartesian projection
242
+ *
243
+ * Returns the fortified array with added {angle, r, x, y}.
244
+ */
245
+ function radialData(node) {
246
+ const TAU = Math.PI * 2;
247
+ const norm = (t) => ((t % TAU) + TAU) % TAU;
248
+
249
+ const pd = fortify(node, /*sort*/ true);
250
+ const byId = new Map(pd.map(d => [d.thisId, d]));
251
+ const kids = new Map(pd.map(d => [d.thisId, d.children || []]));
252
+
253
+ // Find root id
254
+ let root = null;
255
+ for (const d of pd) {
256
+ if (d.parentId == null) { root = d.thisId; break; }
257
+ }
258
+
259
+ // Collect tip ids in DFS left->right order to preserve input ordering
260
+ const tipIds = [];
261
+ (function dfs(id) {
262
+ const c = kids.get(id) || [];
263
+ if (c.length === 0) {
264
+ tipIds.push(id);
265
+ return;
266
+ }
267
+ for (const ch of c) dfs(ch);
268
+ })(root);
269
+
270
+ // Assign tip angles evenly spaced 0..2π
271
+ const N = Math.max(1, tipIds.length);
272
+ const angle = new Map();
273
+ tipIds.forEach((id, i) => {
274
+ angle.set(id, (i / N) * TAU);
275
+ });
276
+
277
+ // Internal node angles: circular mean of child angles (post-order)
278
+ (function setInternalAngles(id) {
279
+ const c = kids.get(id) || [];
280
+ for (const ch of c) setInternalAngles(ch);
281
+ if (c.length > 0) {
282
+ let sx = 0, sy = 0;
283
+ for (const ch of c) {
284
+ const th = angle.get(ch);
285
+ sx += Math.cos(th);
286
+ sy += Math.sin(th);
287
+ }
288
+ angle.set(id, norm(Math.atan2(sy, sx)));
289
+ }
290
+ })(root);
291
+
292
+ // Radii: cumulative branch lengths from root (root r=0)
293
+ const radius = new Map();
294
+ radius.set(root, 0);
295
+ (function setR(id) {
296
+ const c = kids.get(id) || [];
297
+ const r0 = radius.get(id) || 0;
298
+ for (const ch of c) {
299
+ const child = byId.get(ch);
300
+ const bl = child?.branchLength ?? 0;
301
+ radius.set(ch, r0 + bl);
302
+ setR(ch);
303
+ }
304
+ })(root);
305
+
306
+ // Enrich pd rows with angle, r, x, y
307
+ for (const d of pd) {
308
+ const th = angle.get(d.thisId) ?? 0;
309
+ const r = radius.get(d.thisId) ?? 0;
310
+ d.angle = th;
311
+ d.r = r;
312
+ d.x = r * Math.cos(th);
313
+ d.y = r * Math.sin(th);
314
+ }
315
+
316
+ return pd;
317
+ }
318
+
319
+ /**
320
+ * Per-edge radial segments (for highlighting and drawing).
321
+ * For each non-root node, draw a radial line from the parent radius to the child radius
322
+ * at the CHILD'S angle.
323
+ *
324
+ * Output: [{ parentId, childId, x0, y0, x1, y1, isTip }]
325
+ */
326
+ function getRadii(node) {
327
+ const data = radialData(node);
328
+ const byId = new Map(data.map(d => [d.thisId, d]));
329
+ const root = data.find(d => d.parentId == null)?.thisId;
330
+
331
+ const segments = [];
332
+ for (const d of data) {
333
+ if (d.thisId === root) continue;
334
+ const parent = byId.get(d.parentId);
335
+ if (!parent) continue;
336
+
337
+ const theta = d.angle;
338
+ const r0 = parent.r;
339
+ const r1 = d.r;
340
+
341
+ segments.push({
342
+ parentId: parent.thisId,
343
+ childId: d.thisId,
344
+ x0: r0 * Math.cos(theta),
345
+ y0: r0 * Math.sin(theta),
346
+ x1: r1 * Math.cos(theta),
347
+ y1: r1 * Math.sin(theta),
348
+ isTip: !!d.isTip
349
+ });
350
+ }
351
+ return segments;
352
+ }
353
+
354
+ /**
355
+ * Build arc descriptors for each internal parent:
356
+ * - One arc per internal node at radius = parent.r
357
+ * - Start/end angles choose the *shortest* wrap-aware span covering the children
358
+ * - Skips degenerate spans (delta ~ 0)
359
+ */
360
+ function getArcs(pd) {
361
+ const TAU = Math.PI * 2;
362
+ const norm = (t) => ((t % TAU) + TAU) % TAU;
363
+ const EPS = 1e-6;
364
+
365
+ // Quick lookups
366
+ new Map(pd.map(d => [d.thisId, d]));
367
+ const childrenByParent = new Map();
368
+ let root = null;
369
+
370
+ for (const d of pd) {
371
+ if (d.parentId == null) root = d.thisId;
372
+ if (!childrenByParent.has(d.parentId)) childrenByParent.set(d.parentId, []);
373
+ childrenByParent.get(d.parentId).push(d);
374
+ }
375
+
376
+ const arcs = [];
377
+
378
+ for (const parent of pd) {
379
+ const pid = parent.thisId;
380
+ if (pid === root) continue; // no arc above root
381
+ const kids = childrenByParent.get(pid) || [];
382
+ if (kids.length < 2) continue; // need at least two children
383
+
384
+ // Collect & sort child angles
385
+ const A = kids.map(k => norm(k.angle)).sort((a, b) => a - b);
386
+ const aMin = A[0], aMax = A[A.length - 1];
387
+
388
+ // Two candidate spans: direct (aMin -> aMax) and wrapped (aMax -> aMin across 2π)
389
+ const direct = aMax - aMin;
390
+ const wrapped = TAU - direct;
391
+
392
+ // Choose the shorter span. We'll draw **CCW** (sweepFlag = 0) in describeArc.
393
+ let start, end, span;
394
+ if (direct <= wrapped) {
395
+ start = aMin;
396
+ end = aMax;
397
+ span = direct;
398
+ } else {
399
+ // wrapped is shorter: go CCW from aMax up through 2π to aMin
400
+ start = aMax;
401
+ end = aMin;
402
+ span = wrapped;
403
+ }
404
+
405
+ if (span < EPS || !isFinite(parent.r) || parent.r <= 0) continue;
406
+
407
+ arcs.push({
408
+ start,
409
+ end,
410
+ radius: parent.r,
411
+ thisId: pid,
412
+ parentId: parent.parentId
413
+ });
414
+ }
415
+
416
+ return arcs;
417
+ }
418
+
419
+ /**
420
+ * Simple wrapper for radial layout:
421
+ * - data: per-node { angle, r, x, y, ... }
422
+ * - radii: per-edge radial spokes (parent.r → child.r)
423
+ * - arcs: per-internal-node arcs spanning its children at parent radius
424
+ */
425
+ function radialLayout(node) {
426
+ const data = {};
427
+ data.data = radialData(node);
428
+ data.radii = getRadii(node);
429
+ data.arcs = getArcs(data.data);
430
+ return data;
431
+ }
432
+
433
+ /**
434
+ * Iterable mean
435
+ * Poached from https://github.com/d3/d3-array/blob/master/src/mean.js
436
+ * (Other array means buggered up the tree)
437
+ */
438
+
439
+ function mean (values, valueof) {
440
+ let count = 0;
441
+ let sum = 0;
442
+ {
443
+ for (let value of values) {
444
+ if (value != null && (value = +value) >= value) {
445
+ ++count, sum += value;
446
+ }
447
+ }
448
+ }
449
+ if (count) return sum / count;
450
+ }
451
+
452
+ /**
453
+ * Rectangle layout: compute per-node x0,x1 and y0=y1
454
+ * - Tip y is assigned by input order (preserves ladderize/order)
455
+ * - Internal node y is mean of child y's
456
+ * - x1 accumulates branch lengths from root
457
+ */
458
+
459
+ function getHorizontal(node) {
460
+ const pd = fortify(node);
461
+
462
+ // Fast lookup from id -> pd index
463
+ const idIndex = new Map(pd.map((d, i) => [d.thisId, i]));
464
+
465
+ // 1) Leaf order from the INPUT TREE (respects your child order / ladderize)
466
+ const leafIds = [];
467
+ (function dfs(n) {
468
+ if (!n.children || n.children.length === 0) { leafIds.push(n.id); return; }
469
+ n.children.forEach(dfs);
470
+ })(node);
471
+
472
+ // Map each leaf id to a vertical slot (1..N)
473
+ const tipSlot = new Map(leafIds.map((id, i) => [id, i + 1]));
474
+
475
+ // 2) Set Y for tips directly from that order; internal node Y via children mean
476
+ (function setY(n) {
477
+ const i = idIndex.get(n.id);
478
+ if (!n.children || n.children.length === 0) {
479
+ const y = tipSlot.get(n.id);
480
+ pd[i].y0 = y; pd[i].y1 = y;
481
+ return y;
482
+ }
483
+ const ys = n.children.map(setY);
484
+ const y = mean(ys);
485
+ pd[i].y0 = y; pd[i].y1 = y;
486
+ return y;
487
+ })(node);
488
+
489
+ // 3) Set X by accumulating branch lengths down the tree
490
+ (function setX(n, xParent) {
491
+ const i = idIndex.get(n.id);
492
+ const bl = pd[i].branchLength ?? 0;
493
+ const x0 = xParent ?? 0;
494
+ const x1 = x0 + bl;
495
+ pd[i].x0 = x0; pd[i].x1 = x1;
496
+ if (n.children && n.children.length) n.children.forEach(c => setX(c, x1));
497
+ })(node, 0);
498
+
499
+ // Clean up: remove fields not needed downstream without triggering no-unused-vars
500
+ return pd.map((row) => {
501
+ const { y: _y, x: _x, angle: _angle, ...item } = row;
502
+ return item;
503
+ });
504
+ }
505
+
506
+ function getVertical(node) {
507
+ const data = getHorizontal(node);
508
+
509
+ // Group rows by parentId (children that share a parent)
510
+ const byParent = new Map();
511
+ for (const row of data) {
512
+ if (row.parentId == null) continue;
513
+ const a = byParent.get(row.parentId);
514
+ if (a) a.push(row); else byParent.set(row.parentId, [row]);
515
+ }
516
+
517
+ const verticals = [];
518
+ for (const [parentId, kids] of byParent.entries()) {
519
+ if (!kids.length) continue;
520
+ // Works for binary and multifurcations:
521
+ const yvals = kids.map(d => d.y0);
522
+ const y0 = Math.min(...yvals);
523
+ const y1 = Math.max(...yvals);
524
+ // All children share the same junction x (their x0)
525
+ const x = kids[0].x0;
526
+
527
+ verticals.push({
528
+ parentId,
529
+ x0: x,
530
+ x1: x,
531
+ y0,
532
+ y1,
533
+ heights: y1 - y0
534
+ });
535
+ }
536
+
537
+ return verticals;
538
+ }
539
+
540
+ /**
541
+ * Build per-child vertical segments for a rectangular tree:
542
+ * For each non-root node (child), draw a vertical from (parent.x, child.y) to (parent.x, parent.y).
543
+ * This yields exactly one vertical per edge (child->parent), making highlighting trivial.
544
+ *
545
+ * Returns an array of:
546
+ * {
547
+ * parentId: number,
548
+ * childId: number,
549
+ * x: number, // x of the parent junction
550
+ * y0: number, // min(child.y, parent.y)
551
+ * y1: number, // max(child.y, parent.y)
552
+ * }
553
+ */
554
+ function getChildVerticals(node) {
555
+ const data = getHorizontal(node); // has parentId, thisId, x0,x1,y0=y1
556
+
557
+ // Build a quick index to access parent's y by id
558
+ const byId = new Map(data.map(d => [d.thisId, d]));
559
+
560
+ const childVerticals = [];
561
+
562
+ for (const d of data) {
563
+ if (d.parentId == null) continue;
564
+ const parent = byId.get(d.parentId);
565
+ if (!parent) continue;
566
+
567
+ const x = d.x0; // child’s vertical sits at parent.x == child.x0
568
+ const yc = d.y0; // child y
569
+ const yp = parent.y0; // parent y
570
+ const y0 = Math.min(yc, yp);
571
+ const y1 = Math.max(yc, yp);
572
+
573
+ childVerticals.push({
574
+ parentId: d.parentId,
575
+ childId: d.thisId,
576
+ x,
577
+ y0,
578
+ y1
579
+ });
580
+ }
581
+
582
+ return childVerticals;
583
+ }
584
+
585
+ /**
586
+ * Rectangle layout wrapper.
587
+ * Returns:
588
+ * - data: per-node rows (x0,x1,y0=y1,...)
589
+ * - vertical_lines: single spanning vertical per parent (baseline draw)
590
+ * - child_vertical_lines: one vertical per edge (for highlighting)
591
+ * - horizontal_lines: per-edge child horizontals (x0->x1 at y), with labels & tip flags
592
+ */
593
+ function rectangleLayout(node) {
594
+ const data = getHorizontal(node); // per-node
595
+ const vertical_lines = getVertical(node); // parent spans
596
+ const child_vertical_lines = getChildVerticals(node); // per-edge verticals
597
+
598
+ // IMPORTANT: include y0 & y1, and carry isTip/labels for the renderer
599
+ new Map(data.map(d => [d.thisId, d]));
600
+ const horizontal_lines = data
601
+ .filter(d => d.parentId != null)
602
+ .map(d => ({
603
+ parentId: d.parentId,
604
+ childId: d.thisId,
605
+ thisId: d.thisId,
606
+ thisLabel: d.thisLabel,
607
+ isTip: d.isTip,
608
+ x0: d.x0,
609
+ x1: d.x1,
610
+ y0: d.y0,
611
+ y1: d.y0
612
+ }));
613
+
614
+ return { data, vertical_lines, child_vertical_lines, horizontal_lines };
615
+ }
616
+
617
+ /**
618
+ * Convert parsed Newick tree from fortify() into data frame of edges
619
+ * this is akin to a "phylo" object in R, where thisID and parentId
620
+ * are the $edge slot. I think.
621
+ */
622
+
623
+ function edges(df, rectangular = false) {
624
+ const rows = [...df].sort((a, b) => a.thisId - b.thisId);
625
+ const byId = new Map(rows.map((r) => [r.thisId, r]));
626
+ const result = [];
627
+
628
+ for (const row of rows) {
629
+ if (row.parentId == null) continue;
630
+ const parent = byId.get(row.parentId);
631
+ if (!parent) continue;
632
+
633
+ if (rectangular) {
634
+ result.push({ x1: row.x, y1: row.y, id1: row.thisId, x2: parent.x, y2: row.y, id2: undefined });
635
+ result.push({ x1: parent.x, y1: row.y, id1: undefined, x2: parent.x, y2: parent.y, id2: row.parentId });
636
+ } else {
637
+ result.push({ x1: row.x, y1: row.y, id1: row.thisId, x2: parent.x, y2: parent.y, id2: row.parentId });
638
+ }
639
+ }
640
+ return result;
641
+ }
642
+
643
+ /**
644
+ * Recursive function for breadth-first search of a tree
645
+ * the root node is visited first.
646
+ */
647
+
648
+ function levelorder(root) {
649
+ const queue = [root], result = [];
650
+ while (queue.length) {
651
+ const curnode = queue.shift(); // <- FIFO
652
+ result.push(curnode);
653
+ for (const child of curnode.children) queue.push(child);
654
+ }
655
+ return result;
656
+ }
657
+
658
+
659
+ /**
660
+ * Count the number of tips that descend from this node
661
+ */
662
+
663
+ function numTips(thisnode) {
664
+ var result = 0;
665
+ for (const node of levelorder(thisnode)) {
666
+ if (node.children.length == 0) result++;
667
+ }
668
+ return (result);
669
+ }
670
+
671
+ /**
672
+ * Equal-angle layout for unrooted trees.
673
+ * - Precomputes ntips in O(n) to avoid repeated subtree counts
674
+ * - Uses angles in "π units" (0..2) to match existing API
675
+ * - Populates x,y positions from branchLength and angle
676
+ */
677
+
678
+ function annotateTipCounts(root) {
679
+ (function post(n) {
680
+ if (!n.children || n.children.length === 0) {
681
+ n.ntips = 1; return 1;
682
+ }
683
+ let sum = 0;
684
+ for (const c of n.children) sum += post(c);
685
+ n.ntips = sum;
686
+ return sum;
687
+ })(root);
688
+ return root;
689
+ }
690
+
691
+ function equalAngleLayout(node) {
692
+ if (node.parent === null) {
693
+ annotateTipCounts(node);
694
+ node.start = 0.; // guarantees no arcs overlap 0
695
+ node.end = 2.; // *π
696
+ node.angle = 0.; // irrelevant at root
697
+ node.ntips = numTips(node); // safe (already computed), left for compatibility
698
+ node.x = 0;
699
+ node.y = 0;
700
+ }
701
+
702
+ let lastStart = node.start;
703
+
704
+ for (let i = 0; i < node.children.length; i++) {
705
+ const child = node.children[i];
706
+ const arc = (node.end - node.start) * (child.ntips / node.ntips);
707
+
708
+ child.start = lastStart;
709
+ child.end = lastStart + arc;
710
+
711
+ // bisect the arc in π-units
712
+ child.angle = child.start + (child.end - child.start) / 2.;
713
+ lastStart = child.end;
714
+
715
+ // map to coordinates (convert π-units to radians by multiplying by Math.PI)
716
+ const theta = child.angle * Math.PI;
717
+ const bl = (child.branchLength ?? 0);
718
+ child.x = node.x + bl * Math.sin(theta);
719
+ child.y = node.y + bl * Math.cos(theta);
720
+
721
+ equalAngleLayout(child);
722
+ }
723
+
724
+ return node;
725
+ }
726
+
727
+ /**
728
+ * Simple wrapper function for equalAngleLayout()
729
+ */
730
+
731
+ function unrooted (node) {
732
+ var data = {};
733
+ // use the Felsenstein equal angle layout algorithm
734
+ var eq = fortify(equalAngleLayout(node));
735
+ data.data = eq;
736
+ // make the edges dataset
737
+ data.edges = edges(eq);
738
+
739
+ return data;
740
+ }
741
+
742
+ function makeIndexById(rows, key = "thisId") {
743
+ return new Map(rows.map(d => [d[key], d]));
744
+ }
745
+ function parentFisheye(d, data) {
746
+ const byId = makeIndexById(data);
747
+ const parent = byId.get(d.parentId);
748
+ return parent ? { px: parent.fisheye.x, py: parent.fisheye.y } : null;
749
+ }
750
+
751
+ /**
752
+ * Parse a Newick tree string into a doubly-linked list of JS Objects.
753
+ * Assigns labels, branch lengths, and node IDs (tips before internals if input emits them that way).
754
+ *
755
+ * Notes / limitations:
756
+ * - Quoted labels and NHX annotations are not fully supported.
757
+ * - Branch lengths in scientific notation are supported (parseFloat).
758
+ */
759
+
760
+ function readTree(text) {
761
+ // Remove all whitespace (space, tabs, newlines)
762
+ text = String(text).replace(/\s+/g, '');
763
+
764
+ const tokens = text.split(/(;|\(|\)|,)/);
765
+ const root = { parent: null, children: [] };
766
+ let curnode = root;
767
+ let nodeId = 0;
768
+
769
+ for (const token of tokens) {
770
+ if (!token || token === ';') continue;
771
+
772
+ if (token === '(') {
773
+ const child = { parent: curnode, children: [] };
774
+ curnode.children.push(child);
775
+ curnode = child; // descend
776
+ } else if (token === ',') {
777
+ // back to parent, then create sibling
778
+ curnode = curnode.parent;
779
+ const child = { parent: curnode, children: [] };
780
+ curnode.children.push(child);
781
+ curnode = child;
782
+ } else if (token === ')') {
783
+ // ascend one level
784
+ curnode = curnode.parent;
785
+ if (curnode === null) break;
786
+ } else {
787
+ // label/branch-length chunk (e.g., "A:0.01" or "A")
788
+ const nodeinfo = token.split(':');
789
+ if (nodeinfo.length === 1) {
790
+ if (token.startsWith(':')) {
791
+ curnode.label = '';
792
+ curnode.branchLength = parseFloat(nodeinfo[0]);
793
+ } else {
794
+ curnode.label = nodeinfo[0];
795
+ curnode.branchLength = null;
796
+ }
797
+ } else if (nodeinfo.length === 2) {
798
+ curnode.label = nodeinfo[0];
799
+ curnode.branchLength = parseFloat(nodeinfo[1]);
800
+ } else {
801
+ console.warn(token, "Unhandled token with multiple ':' characters");
802
+ curnode.label = nodeinfo[0] || '';
803
+ curnode.branchLength = parseFloat(nodeinfo[nodeinfo.length - 1]);
804
+ }
805
+ curnode.id = nodeId++; // assign then increment
806
+ }
807
+ }
808
+
809
+ // Ensure root has an id if not assigned during parsing
810
+ if (root.id == null) root.id = nodeId;
811
+
812
+ return root;
813
+ }
814
+
815
+ /**
816
+ * Subset a tree given a node - i.e. the node of interests and all the descendents
817
+ */
818
+
819
+ function subTree (tree, node) {
820
+ // Thanks Richard Challis!
821
+ let fullTree = {};
822
+ tree.data.forEach(obj => {
823
+ fullTree[obj.thisId] = { ...obj };
824
+ });
825
+
826
+ let subTree = {};
827
+ const getDescendants = function (rootNodeId) {
828
+ if (fullTree[rootNodeId]) {
829
+ subTree[rootNodeId] = fullTree[rootNodeId];
830
+ if (fullTree[rootNodeId].children) {
831
+ fullTree[rootNodeId].children.forEach(childNodeId => {
832
+ getDescendants(childNodeId);
833
+ });
834
+ }
835
+ }
836
+ };
837
+ // call the recursive function
838
+ getDescendants(node);
839
+
840
+ // in each of the functions, data contains the children key
841
+ const data = [["data", Object.values(subTree)]];
842
+
843
+ const nodes = data[0][1].map(d => d.thisId);
844
+
845
+ var res = [];
846
+ // in all keys except data, push to new array
847
+ for (const node in tree) {
848
+ if (node === "data") continue;
849
+ res.push([node, tree[node]]);
850
+ }
851
+
852
+ var filtered = res.map(d => [
853
+ d[0],
854
+ d[1].filter(d => nodes.includes(d.thisId))
855
+ ]);
856
+
857
+ return Object.fromEntries(data.concat(filtered));
858
+ }
859
+
860
+ function drawPhylogeny(
861
+ treeText,
862
+ {
863
+ layout = "rect", // "rect" or "radial"
864
+ width = 800,
865
+ height = 800,
866
+ margin = { top: 20, right: 300, bottom: 20, left: 50 },
867
+ radialMargin = 80,
868
+ strokeWidth = 1,
869
+ radialMode = "outer" // or "align"
870
+ } = {}
871
+ ) {
872
+ if (layout === "rect") {
873
+ // RECTANGULAR LAYOUT
874
+ const tree_df = rectangleLayout(readTree(treeText));
875
+ const horizontal = tree_df.horizontal_lines;
876
+ const vertical = tree_df.vertical_lines;
877
+ const tips = horizontal.filter((d) => d.isTip);
878
+
879
+ const maxY = d3__namespace.max(horizontal, (d) => d.y1);
880
+ const minY = d3__namespace.min(horizontal, (d) => d.y1);
881
+ const maxX = d3__namespace.max(horizontal, (d) => d.x1);
882
+
883
+ const yScale = d3__namespace
884
+ .scaleLinear()
885
+ .domain([minY - 1, maxY + 1])
886
+ .range([margin.top, height - margin.bottom]);
887
+
888
+ const xScale = d3__namespace
889
+ .scaleLinear()
890
+ .domain([0, maxX])
891
+ .range([margin.left, width - margin.right]);
892
+
893
+ const svg = d3__namespace
894
+ .create("svg")
895
+ .attr("width", width)
896
+ .attr("height", height)
897
+ .attr("font-family", "sans-serif")
898
+ .attr("font-size", 10);
899
+
900
+ const group = svg.append("g");
901
+
902
+ group
903
+ .selectAll(".hline")
904
+ .data(horizontal)
905
+ .join("line")
906
+ .attr("x1", (d) => xScale(d.x0))
907
+ .attr("y1", (d) => yScale(d.y0))
908
+ .attr("x2", (d) => xScale(d.x1))
909
+ .attr("y2", (d) => yScale(d.y1))
910
+ .attr("stroke", "#555")
911
+ .attr("stroke-width", strokeWidth);
912
+
913
+ group
914
+ .selectAll(".vline")
915
+ .data(vertical)
916
+ .join("line")
917
+ .attr("x1", (d) => xScale(d.x0))
918
+ .attr("y1", (d) => yScale(d.y0))
919
+ .attr("x2", (d) => xScale(d.x1))
920
+ .attr("y2", (d) => yScale(d.y1))
921
+ .attr("stroke", "#555")
922
+ .attr("stroke-width", strokeWidth);
923
+
924
+ group
925
+ .selectAll(".tip-dot")
926
+ .data(tips)
927
+ .join("circle")
928
+ .attr("cx", (d) => xScale(d.x1))
929
+ .attr("cy", (d) => yScale(d.y1))
930
+ .attr("r", 2)
931
+ .attr("fill", "black");
932
+
933
+ svg
934
+ .append("g")
935
+ .selectAll("text")
936
+ .data(tips)
937
+ .join("text")
938
+ .attr("x", (d) => xScale(d.x1) + 4)
939
+ .attr("y", (d) => yScale(d.y1))
940
+ .attr("dy", "0.32em")
941
+ .attr("font-size", 10)
942
+ .text((d) => d.thisLabel?.replace(/_/g, " ") ?? "");
943
+
944
+ return svg.node();
945
+ } else if (layout === "radial") {
946
+ const parsedTree = readTree(treeText);
947
+ const rad = radialLayout(parsedTree);
948
+
949
+ // ===== MODE / DEBUG =====
950
+ const TIP_MODE = radialMode; // "align" (shorten to original tips) or "outer" (project to one circle)
951
+ const isOuter = TIP_MODE === "outer";
952
+
953
+ // visuals (0 = let spokes reach the dots)
954
+ const DOT_R = 3;
955
+ const END_CAP = 0;
956
+
957
+ // ===== SCALES / BOUNDS =====
958
+ const maxRadius = d3__namespace.max(rad.data, (d) => d.r) ?? 0;
959
+ const scaleRadial = maxRadius + 2 * radialMargin;
960
+ const w = width,
961
+ h = height;
962
+ const centerX = w / 2,
963
+ centerY = h / 2;
964
+
965
+ const xScaleRadial = d3__namespace
966
+ .scaleLinear()
967
+ .domain([-scaleRadial, scaleRadial])
968
+ .range([0, w]);
969
+ const yScaleRadial = d3__namespace
970
+ .scaleLinear()
971
+ .domain([-scaleRadial, scaleRadial])
972
+ .range([h, 0]);
973
+ const radiusPx = (r) => r * (w / (2 * scaleRadial));
974
+
975
+ // ===== INDEXES / HELPERS =====
976
+ const byId = new Map(rad.data.map((d) => [d.thisId, d]));
977
+ const tips = rad.data.filter((d) => d.isTip);
978
+ const tipMaxR = tips.length ? d3__namespace.max(tips, (d) => d.r) : 0;
979
+
980
+ // Robust child-id extractor (handles multiple shapes)
981
+ function childIdOf(spoke) {
982
+ // prefer explicit child id fields; fall back to thisId; last-ditch id1 (seen in some edge shapes)
983
+ return spoke.childId ?? spoke.thisId ?? spoke.id1 ?? null;
984
+ }
985
+
986
+ // Shorten the *screen-space* end of a spoke by END_CAP px
987
+ function shortenSpokePx(x0, y0, x1, y1) {
988
+ const X0 = xScaleRadial(x0),
989
+ Y0 = yScaleRadial(y0);
990
+ const X1 = xScaleRadial(x1),
991
+ Y1 = yScaleRadial(y1);
992
+ const dx = X1 - X0,
993
+ dy = Y1 - Y0;
994
+ const len = Math.hypot(dx, dy) || 1;
995
+ const t = Math.max(0, (len - END_CAP) / len);
996
+ return { X0, Y0, X1s: X0 + dx * t, Y1s: Y0 + dy * t, len };
997
+ }
998
+
999
+ // ===== SVG ROOT =====
1000
+ const svg = d3__namespace
1001
+ .create("svg")
1002
+ .attr("width", w)
1003
+ .attr("height", h)
1004
+ .attr("font-family", "sans-serif")
1005
+ .attr("font-size", 10);
1006
+
1007
+ const group = svg.append("g");
1008
+
1009
+ // ===== ARCS (parent circles) =====
1010
+ group
1011
+ .append("g")
1012
+ .attr("class", "phylo_arcs")
1013
+ .selectAll("path")
1014
+ .data(rad.arcs)
1015
+ .join("path")
1016
+ .attr("d", (d) =>
1017
+ describeArc(
1018
+ centerX,
1019
+ centerY,
1020
+ Math.max(0, radiusPx(d.radius)),
1021
+ d.start,
1022
+ d.end
1023
+ )
1024
+ )
1025
+ .attr("fill", "none")
1026
+ .attr("stroke", "#777")
1027
+ .attr("stroke-width", strokeWidth);
1028
+
1029
+ // ===== RADII (spokes) =====
1030
+ group
1031
+ .append("g")
1032
+ .attr("class", "phylo_radii")
1033
+ .selectAll("line")
1034
+ .data(rad.radii)
1035
+ .join("line")
1036
+ .each(function(s, _) {
1037
+ // parent end (data space)
1038
+ const x0 = s.x0,
1039
+ y0 = s.y0;
1040
+
1041
+ // child end (data space), shape-agnostic
1042
+ const cid = childIdOf(s);
1043
+ const node = cid != null ? byId.get(cid) : undefined;
1044
+ const isTipSpoke = !!(node && node.isTip);
1045
+
1046
+ // default to the original child endpoint from the spoke record
1047
+ let x1 = s.x1,
1048
+ y1 = s.y1;
1049
+
1050
+ // In "outer" mode, project only *tip* spokes to the common circle
1051
+ if (isOuter && isTipSpoke) {
1052
+ x1 = tipMaxR * Math.cos(node.angle);
1053
+ y1 = tipMaxR * Math.sin(node.angle);
1054
+ }
1055
+
1056
+ // Shorten in screen space so the spoke doesn’t pierce the dot (END_CAP can be 0)
1057
+ const { X0, Y0, X1s, Y1s} = shortenSpokePx(x0, y0, x1, y1);
1058
+
1059
+ d3__namespace.select(this)
1060
+ .attr("x1", X0)
1061
+ .attr("y1", Y0)
1062
+ .attr("x2", X1s)
1063
+ .attr("y2", Y1s)
1064
+ .attr("stroke", "#777")
1065
+ .attr("stroke-width", strokeWidth);
1066
+ });
1067
+
1068
+ // ===== TIP DOTS =====
1069
+ group
1070
+ .append("g")
1071
+ .attr("class", "phylo_tip_dots")
1072
+ .selectAll("circle")
1073
+ .data(tips)
1074
+ .join("circle")
1075
+ .each(function(d, _) {
1076
+ // dot at original tip (align) or projected circle (outer)
1077
+ const x = isOuter ? tipMaxR * Math.cos(d.angle) : d.x;
1078
+ const y = isOuter ? tipMaxR * Math.sin(d.angle) : d.y;
1079
+
1080
+ d3__namespace.select(this)
1081
+ .attr("cx", xScaleRadial(x))
1082
+ .attr("cy", yScaleRadial(y))
1083
+ .attr("r", DOT_R)
1084
+ .attr("fill", "black")
1085
+ .attr("stroke", "black")
1086
+ .attr("stroke-width", 1.5);
1087
+ });
1088
+
1089
+ // ===== LABELS (unchanged) =====
1090
+ // Labels — make them follow the tip position used by the current mode
1091
+ group
1092
+ .append("g")
1093
+ .attr("class", "phylo_labels")
1094
+ .selectAll("g.label")
1095
+ .data(tips) // <— bind only tip nodes
1096
+ .join("g")
1097
+ .attr("class", "label")
1098
+ .attr("transform", (d) => {
1099
+ // same tip position rule as dots/spokes:
1100
+ // - "outer": snap to common ring (tipMaxR)
1101
+ // - otherwise (e.g. "align"/"phylo"): true tip radius
1102
+ const r = isOuter ? tipMaxR : d.r;
1103
+ const x = r * Math.cos(d.angle);
1104
+ const y = r * Math.sin(d.angle);
1105
+ return `translate(${xScaleRadial(x)},${yScaleRadial(y)})`;
1106
+ })
1107
+ .each(function(d) {
1108
+ // rotate so text reads outward; flip when on the left side
1109
+ let angle = (-d.angle * 180) / Math.PI;
1110
+ let xoff = 10; // radial padding for text (px)
1111
+ let anchor = "start";
1112
+ if (d.angle > Math.PI / 2 && d.angle < (3 * Math.PI) / 2) {
1113
+ angle += 180;
1114
+ xoff *= -1;
1115
+ anchor = "end";
1116
+ }
1117
+ d3__namespace.select(this)
1118
+ .append("g")
1119
+ .attr("transform", `rotate(${angle})`)
1120
+ .append("text")
1121
+ .attr("x", xoff)
1122
+ .attr("alignment-baseline", "middle")
1123
+ .attr("text-anchor", anchor)
1124
+ .attr("font-size", 10)
1125
+ .attr("fill", "black")
1126
+ .text((d) => d.thisLabel?.replace(/_/g, " ") ?? "");
1127
+ });
1128
+
1129
+ return svg.node();
1130
+ } else if (layout === "unrooted") {
1131
+ // UNROOTED LAYOUT
1132
+ const parsedTree = readTree(treeText);
1133
+ const unrootedPhylo = unrooted(parsedTree);
1134
+
1135
+ const w = width;
1136
+ const h = height;
1137
+
1138
+ // Get spatial extent
1139
+ const xExtent = d3__namespace.extent(unrootedPhylo.data, (d) => d.x);
1140
+ const yExtent = d3__namespace.extent(unrootedPhylo.data, (d) => d.y);
1141
+
1142
+ // Find maximum absolute distance from center (0,0)
1143
+ const maxX = Math.max(Math.abs(xExtent[0]), Math.abs(xExtent[1]));
1144
+ const maxY = Math.max(Math.abs(yExtent[0]), Math.abs(yExtent[1]));
1145
+ const maxRadius = Math.max(maxX, maxY);
1146
+
1147
+ // Add some margin
1148
+ const scaleUnroot = maxRadius + 2 * radialMargin;
1149
+
1150
+ const xScaleUnroot = d3__namespace
1151
+ .scaleLinear()
1152
+ .domain([-scaleUnroot, scaleUnroot])
1153
+ .range([0, w]);
1154
+
1155
+ const yScaleUnroot = d3__namespace
1156
+ .scaleLinear()
1157
+ .domain([-scaleUnroot, scaleUnroot])
1158
+ .range([h, 0]);
1159
+
1160
+ const svg = d3__namespace
1161
+ .create("svg")
1162
+ .attr("width", w)
1163
+ .attr("height", h)
1164
+ .attr("font-family", "sans-serif")
1165
+ .attr("font-size", 10);
1166
+
1167
+ const group = svg.append("g");
1168
+
1169
+ // Edges
1170
+ group
1171
+ .append("g")
1172
+ .attr("class", "phylo_lines")
1173
+ .selectAll("line")
1174
+ .data(unrootedPhylo.edges)
1175
+ .join("line")
1176
+ .attr("x1", (d) => xScaleUnroot(d.x1))
1177
+ .attr("y1", (d) => yScaleUnroot(d.y1))
1178
+ .attr("x2", (d) => xScaleUnroot(d.x2))
1179
+ .attr("y2", (d) => yScaleUnroot(d.y2))
1180
+ .attr("stroke-width", strokeWidth)
1181
+ .attr("stroke", "#777");
1182
+
1183
+ // Nodes
1184
+ group
1185
+ .append("g")
1186
+ .attr("class", "phylo_points")
1187
+ .selectAll("circle")
1188
+ .data(unrootedPhylo.data)
1189
+ .join("circle")
1190
+ .attr("class", "dot")
1191
+ .attr("r", (d) => (d.isTip ? 4 : 0))
1192
+ .attr("cx", (d) => xScaleUnroot(d.x))
1193
+ .attr("cy", (d) => yScaleUnroot(d.y))
1194
+ .attr("stroke", "black")
1195
+ .attr("stroke-width", 2)
1196
+ .attr("fill", (d) => (d.isTip ? "black" : "white"));
1197
+
1198
+ // Tip labels
1199
+ const tipEdges = new Map();
1200
+ const nodesById = new Map(unrootedPhylo.data.map((d) => [d.thisId, d]));
1201
+
1202
+ unrootedPhylo.edges.forEach((edge) => {
1203
+ const tipNode = nodesById.get(edge.id1);
1204
+ if (tipNode?.isTip) {
1205
+ tipEdges.set(edge.id1, edge);
1206
+ }
1207
+ });
1208
+
1209
+ group
1210
+ .append("g")
1211
+ .attr("class", "phylo_labels")
1212
+ .selectAll("g")
1213
+ .data(unrootedPhylo.data.filter((d) => d.isTip))
1214
+ .join("g")
1215
+ .attr("transform", (d) => {
1216
+ const x = xScaleUnroot(d.x);
1217
+ const y = yScaleUnroot(d.y);
1218
+ return `translate(${x},${y})`;
1219
+ })
1220
+ .each(function(d) {
1221
+ const edge = tipEdges.get(d.thisId);
1222
+ if (!edge) {
1223
+ console.warn(
1224
+ "No incoming edge found for tip node:",
1225
+ d.thisId,
1226
+ d.thisLabel
1227
+ );
1228
+ return;
1229
+ }
1230
+
1231
+ // Compute angle of the incoming edge (screen coords)
1232
+ const x1 = xScaleUnroot(edge.x1);
1233
+ const y1 = yScaleUnroot(edge.y1);
1234
+ const x2 = xScaleUnroot(edge.x2);
1235
+ const y2 = yScaleUnroot(edge.y2);
1236
+
1237
+ const dx = x2 - x1;
1238
+ const dy = y2 - y1;
1239
+ let angle = (Math.atan2(dy, dx) * 180) / Math.PI;
1240
+
1241
+ // Flip label if upside down
1242
+ let xOffset = -10;
1243
+ let anchor = "end";
1244
+ if (angle > 90 || angle < -90) {
1245
+ angle += 180;
1246
+ anchor = "start";
1247
+ xOffset = 10;
1248
+ }
1249
+
1250
+ // Draw label rotated along branch direction
1251
+ d3__namespace.select(this)
1252
+ .append("g")
1253
+ .attr("transform", `rotate(${angle})`)
1254
+ .append("text")
1255
+ .attr("x", xOffset)
1256
+ .attr("alignment-baseline", "middle")
1257
+ .attr("text-anchor", anchor)
1258
+ .attr("font-size", 10)
1259
+ .attr("fill", "black")
1260
+ .text(d.thisLabel?.replace(/_/g, " ") ?? "");
1261
+ });
1262
+
1263
+ return svg.node();
1264
+ } else {
1265
+ throw new Error("Unsupported layout type. Use 'rect' or 'radial'.");
1266
+ }
1267
+ }
1268
+
1269
+ exports.describeArc = describeArc;
1270
+ exports.drawPhylogeny = drawPhylogeny;
1271
+ exports.parentFisheye = parentFisheye;
1272
+ exports.phisheye = phisheye;
1273
+ exports.radialLayout = radialLayout;
1274
+ exports.readTree = readTree;
1275
+ exports.rectangleLayout = rectangleLayout;
1276
+ exports.subTree = subTree;
1277
+ exports.unrooted = unrooted;
1278
+ //# sourceMappingURL=index.cjs.map