@x-cmd/draw 0.4.7 → 0.5.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.
- package/README.md +3 -3
- package/dist/client.d.ts +42 -0
- package/dist/client.js +267 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +132 -0
- package/dist/globe.d.ts +4 -0
- package/dist/globe.js +6 -0
- package/dist/layout/cluster.d.ts +2 -0
- package/dist/layout/cluster.js +228 -0
- package/dist/layout/index.d.ts +2 -0
- package/dist/layout/index.js +6 -0
- package/dist/layout/layered.d.ts +51 -0
- package/dist/layout/layered.js +433 -0
- package/dist/layout/portsize.d.ts +18 -0
- package/dist/layout/portsize.js +34 -0
- package/dist/lib.d.ts +17 -4
- package/dist/lib.js +20 -4
- package/dist/node/cmd.d.ts +1 -0
- package/dist/node/cmd.js +3 -0
- package/dist/render/abc-parse.d.ts +75 -0
- package/dist/render/abc-parse.js +345 -0
- package/dist/render/abcjs.d.ts +10 -0
- package/dist/render/abcjs.js +90 -0
- package/dist/render/anno.d.ts +48 -2
- package/dist/render/anno.js +171 -17
- package/dist/render/ansi.d.ts +15 -0
- package/dist/render/ansi.js +142 -0
- package/dist/render/arch.js +8 -3
- package/dist/render/arch3d.d.ts +31 -0
- package/dist/render/arch3d.js +294 -0
- package/dist/render/archmap.js +2 -2
- package/dist/render/area.js +42 -11
- package/dist/render/bar-grid.js +1 -1
- package/dist/render/bar-grouped.js +25 -7
- package/dist/render/bar-stacked.js +22 -6
- package/dist/render/bar.js +27 -6
- package/dist/render/block.d.ts +56 -0
- package/dist/render/block.js +361 -0
- package/dist/render/butterfly.js +4 -1
- package/dist/render/calendar.js +49 -14
- package/dist/render/center.d.ts +26 -0
- package/dist/render/center.js +108 -0
- package/dist/render/chem.d.ts +22 -0
- package/dist/render/chem.js +205 -0
- package/dist/render/chord.d.ts +17 -0
- package/dist/render/chord.js +141 -0
- package/dist/render/combo.js +7 -7
- package/dist/render/compass.js +59 -13
- package/dist/render/echarts-ssr.d.ts +36 -2
- package/dist/render/echarts-ssr.js +77 -18
- package/dist/render/gauge.js +17 -9
- package/dist/render/gitgraph.d.ts +53 -0
- package/dist/render/gitgraph.js +324 -0
- package/dist/render/globe-areas.d.ts +21 -0
- package/dist/render/globe-areas.js +40 -0
- package/dist/render/globe-earth.d.ts +78 -0
- package/dist/render/globe-earth.js +464 -0
- package/dist/render/globe-keys.d.ts +34 -0
- package/dist/render/globe-keys.js +71 -0
- package/dist/render/globe-proj.d.ts +102 -0
- package/dist/render/globe-proj.js +332 -0
- package/dist/render/globe-regions.d.ts +23 -0
- package/dist/render/globe-regions.js +60 -0
- package/dist/render/globe.d.ts +15 -0
- package/dist/render/globe.js +306 -0
- package/dist/render/globe3d.d.ts +113 -0
- package/dist/render/globe3d.js +285 -0
- package/dist/render/hbar-spec.js +23 -10
- package/dist/render/hbar.js +30 -11
- package/dist/render/jianpu.d.ts +10 -0
- package/dist/render/jianpu.js +190 -0
- package/dist/render/journey.d.ts +54 -0
- package/dist/render/journey.js +277 -0
- package/dist/render/kanban.d.ts +50 -0
- package/dist/render/kanban.js +240 -0
- package/dist/render/kinds.js +19 -0
- package/dist/render/line-multi.js +27 -8
- package/dist/render/line.js +32 -14
- package/dist/render/maps.js +4 -2
- package/dist/render/mermaid/block.d.ts +2 -0
- package/dist/render/mermaid/block.js +256 -0
- package/dist/render/mermaid/c4.d.ts +3 -0
- package/dist/render/mermaid/c4.js +165 -0
- package/dist/render/mermaid/class.d.ts +2 -0
- package/dist/render/mermaid/class.js +185 -0
- package/dist/render/mermaid/common.d.ts +34 -0
- package/dist/render/mermaid/common.js +81 -0
- package/dist/render/mermaid/erd.d.ts +2 -0
- package/dist/render/mermaid/erd.js +103 -0
- package/dist/render/mermaid/gitgraph.d.ts +2 -0
- package/dist/render/mermaid/gitgraph.js +139 -0
- package/dist/render/mermaid/journey.d.ts +7 -0
- package/dist/render/mermaid/journey.js +68 -0
- package/dist/render/mermaid/kanban.d.ts +2 -0
- package/dist/render/mermaid/kanban.js +86 -0
- package/dist/render/mermaid/mindmap.d.ts +7 -0
- package/dist/render/mermaid/mindmap.js +74 -0
- package/dist/render/mermaid/packet.d.ts +2 -0
- package/dist/render/mermaid/packet.js +35 -0
- package/dist/render/mermaid/pie.d.ts +7 -0
- package/dist/render/mermaid/pie.js +58 -0
- package/dist/render/mermaid/quadrant.d.ts +8 -0
- package/dist/render/mermaid/quadrant.js +137 -0
- package/dist/render/mermaid/radar.d.ts +8 -0
- package/dist/render/mermaid/radar.js +69 -0
- package/dist/render/mermaid/requirement.d.ts +2 -0
- package/dist/render/mermaid/requirement.js +100 -0
- package/dist/render/mermaid/sankey.d.ts +7 -0
- package/dist/render/mermaid/sankey.js +54 -0
- package/dist/render/mermaid/seq.d.ts +2 -0
- package/dist/render/mermaid/seq.js +147 -0
- package/dist/render/mermaid/state.d.ts +2 -0
- package/dist/render/mermaid/state.js +168 -0
- package/dist/render/mermaid/timeline.d.ts +7 -0
- package/dist/render/mermaid/timeline.js +63 -0
- package/dist/render/mermaid/xychart.d.ts +7 -0
- package/dist/render/mermaid/xychart.js +94 -0
- package/dist/render/mermaid.d.ts +22 -4
- package/dist/render/mermaid.js +173 -7
- package/dist/render/mindmap.js +12 -2
- package/dist/render/nomnoml.d.ts +8 -0
- package/dist/render/nomnoml.js +47 -0
- package/dist/render/packet.d.ts +39 -0
- package/dist/render/packet.js +232 -0
- package/dist/render/params-dispatch.d.ts +20 -0
- package/dist/render/params-dispatch.js +192 -0
- package/dist/render/pie.js +29 -22
- package/dist/render/quadrant.js +38 -9
- package/dist/render/query.d.ts +11 -1
- package/dist/render/query.js +92 -16
- package/dist/render/radar.js +7 -6
- package/dist/render/requirement.d.ts +61 -0
- package/dist/render/requirement.js +355 -0
- package/dist/render/sankey.js +4 -4
- package/dist/render/scatter.js +25 -9
- package/dist/render/scene3d.d.ts +188 -0
- package/dist/render/scene3d.js +433 -0
- package/dist/render/seq.js +13 -8
- package/dist/render/simplify.d.ts +12 -0
- package/dist/render/simplify.js +105 -0
- package/dist/render/source-theme.d.ts +104 -0
- package/dist/render/source-theme.js +261 -0
- package/dist/render/svg.d.ts +81 -1
- package/dist/render/svg.js +259 -2
- package/dist/render/svgdom.d.ts +74 -0
- package/dist/render/svgdom.js +198 -0
- package/dist/render/timeline.d.ts +54 -0
- package/dist/render/timeline.js +290 -0
- package/dist/render/tty.d.ts +17 -0
- package/dist/render/tty.js +173 -0
- package/dist/render/ttycmd.d.ts +7 -0
- package/dist/render/ttycmd.js +152 -0
- package/dist/render/vendor/au.js +1 -1
- package/dist/render/vendor/br.js +1 -1
- package/dist/render/vendor/china-counties.d.ts +32 -0
- package/dist/render/vendor/china-counties.js +8 -0
- package/dist/render/vendor/china-provinces.d.ts +16 -0
- package/dist/render/vendor/china-provinces.js +8 -0
- package/dist/render/vendor/china.js +1 -1
- package/dist/render/vendor/country-aliases.d.ts +207 -0
- package/dist/render/vendor/country-aliases.js +7 -0
- package/dist/render/vendor/de.js +1 -1
- package/dist/render/vendor/eu.js +1 -1
- package/dist/render/vendor/japan.js +1 -1
- package/dist/render/vendor/kr.js +1 -1
- package/dist/render/vendor/world-geo.js +1 -1
- package/dist/render/vendor/world-ne.d.ts +18 -0
- package/dist/render/vendor/world-ne.js +8 -0
- package/dist/render/vendor/world.js +1 -1
- package/dist/render/vexflow.d.ts +10 -0
- package/dist/render/vexflow.js +189 -0
- package/dist/render/wavedrom.d.ts +14 -0
- package/dist/render/wavedrom.js +113 -0
- package/dist/source.d.ts +20 -0
- package/dist/source.js +27 -0
- package/dist/specs/base.js +9 -4
- package/dist/specs/combo.d.ts +1 -0
- package/dist/specs/combo.js +8 -1
- package/dist/specs/gauge.d.ts +1 -0
- package/dist/specs/gauge.js +14 -2
- package/dist/specs/multi.d.ts +3 -0
- package/dist/specs/multi.js +29 -3
- package/dist/specs/quadrant.js +5 -4
- package/dist/specs/scatter.d.ts +1 -0
- package/dist/specs/scatter.js +7 -0
- package/dist/styles/bar.js +3 -0
- package/dist/styles/baseline.d.ts +47 -0
- package/dist/styles/baseline.js +48 -0
- package/dist/styles/hbar.js +3 -0
- package/dist/styles/index.d.ts +1 -1
- package/dist/styles/index.js +16 -4
- package/dist/styles/line.js +9 -0
- package/dist/styles/pie.js +4 -0
- package/dist/styles/sankey.js +4 -0
- package/dist/styles/skins.d.ts +23 -0
- package/dist/styles/skins.js +349 -0
- package/dist/styles/types.d.ts +20 -0
- package/dist/styles/types.js +17 -1
- package/dist/world-data.d.ts +12 -0
- package/dist/world-data.js +192 -0
- package/package.json +38 -5
package/dist/render/anno.js
CHANGED
|
@@ -386,20 +386,107 @@ function clsTag(text, x, y, color, k, dataI = -1) {
|
|
|
386
386
|
return `<rect${tag} x="${r2(x)}" y="${r2(by)}" width="${r2(bw)}" height="${r2(bh)}" rx="${r2(bh / 2)}" fill="#0b0c0f" fill-opacity="0.86" stroke="${color}" stroke-opacity="0.6" stroke-width="${r2(k)}"/>`
|
|
387
387
|
+ `<text${tag} x="${r2(x + bw / 2)}" y="${r2(by + bh / 2 + fs * 0.35)}" text-anchor="middle" font-size="${r2(fs)}" fill="${color}">${esc(text)}</text>`;
|
|
388
388
|
}
|
|
389
|
+
/** 从 SVG 里读 dscale ✓(没有 ⇒ 这张图没有值映射 ⇒ 标注走几何 ✓) */
|
|
390
|
+
export function dscaleOf(svg) {
|
|
391
|
+
const m = /<metadata id="dscale">([^<]*)<\/metadata>/.exec(svg);
|
|
392
|
+
if (!m)
|
|
393
|
+
return null;
|
|
394
|
+
try {
|
|
395
|
+
const j = JSON.parse(m[1]);
|
|
396
|
+
const { v0, p0, v1, p1 } = j.y ?? {};
|
|
397
|
+
if (![v0, p0, v1, p1].every((v) => Number.isFinite(v)))
|
|
398
|
+
return null;
|
|
399
|
+
if (v1 === v0)
|
|
400
|
+
return null;
|
|
401
|
+
return j;
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
389
407
|
/**
|
|
390
|
-
*
|
|
391
|
-
* frame 是画布在 viewBox 里的位置与大小(标注的百分比按它换算)。
|
|
408
|
+
* 标注的 y:值 ⇒ 绘图区的百分比 ✓(图有值映射时 ✓)
|
|
392
409
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
* 不一定一样(化学结构那张:viewBox 只有 119 个单位,画布 560 像素),
|
|
397
|
-
* 不按它折算,标注会跟着图一起被放大四倍(字变得比分子还大)。
|
|
410
|
+
* 按图种定锚(用户定的 ✓):**有值映射的图,y 用数据值** —— 数据改了、轴量程变了,
|
|
411
|
+
* 标注还指着同一段数据 ✓;**没有值映射的图**走几何 ✓。
|
|
412
|
+
* x 一律用绘图区的百分比 ✓(横向跟着柱子走 ✓)。
|
|
398
413
|
*/
|
|
399
|
-
|
|
414
|
+
/** 值 → 绘图区的百分比(从顶算 ✓:v0 ↔ 底部 100%、v1 ↔ 顶部 0%) ✓ */
|
|
415
|
+
export function yValueToPct(v, d) {
|
|
416
|
+
const { v0, v1 } = d.y;
|
|
417
|
+
if (v1 === v0)
|
|
418
|
+
return 0;
|
|
419
|
+
return 100 - (100 * (v - v0)) / (v1 - v0);
|
|
420
|
+
}
|
|
421
|
+
/** 绘图区的百分比 → 值 ✓ */
|
|
422
|
+
export function yPctToValue(p, d) {
|
|
423
|
+
const { v0, v1 } = d.y;
|
|
424
|
+
if (v1 === v0)
|
|
425
|
+
return v0;
|
|
426
|
+
return v0 + ((100 - p) / 100) * (v1 - v0);
|
|
427
|
+
}
|
|
428
|
+
/** 值的跨度 → 百分比的跨度 ✓ */
|
|
429
|
+
export function yValueSpanToPct(s, d) {
|
|
430
|
+
const { v0, v1 } = d.y;
|
|
431
|
+
if (v1 === v0)
|
|
432
|
+
return 0;
|
|
433
|
+
return (Math.abs(s) * 100) / Math.abs(v1 - v0);
|
|
434
|
+
}
|
|
435
|
+
/** 百分比的跨度 → 值的跨度 ✓ */
|
|
436
|
+
export function yPctSpanToValue(s, d) {
|
|
437
|
+
const { v0, v1 } = d.y;
|
|
438
|
+
if (v1 === v0)
|
|
439
|
+
return 0;
|
|
440
|
+
return (s / 100) * Math.abs(v1 - v0) * Math.sign(v1 - v0 || 1);
|
|
441
|
+
}
|
|
442
|
+
export function annoValuesToPct(annos, d) {
|
|
443
|
+
if (!d)
|
|
444
|
+
return annos;
|
|
445
|
+
const pct = (v) => yValueToPct(v, d);
|
|
446
|
+
const pctSpan = (s) => yValueSpanToPct(s, d);
|
|
447
|
+
const n = (v) => Number(v) || 0;
|
|
448
|
+
return annos.map((a) => {
|
|
449
|
+
switch (a.kind) {
|
|
450
|
+
case 'oval':
|
|
451
|
+
return { ...a, y: pct(a.y), ry: pctSpan(a.ry ?? 0) };
|
|
452
|
+
case 'hl':
|
|
453
|
+
return { ...a, y: pct(a.y), h: pctSpan(a.h ?? 0) };
|
|
454
|
+
case 'arrow':
|
|
455
|
+
// 终点存的是**偏移** ⇒ y 的偏移是**值的跨度** ✓
|
|
456
|
+
return { ...a, y2: pctSpan(a.y2 ?? 0) };
|
|
457
|
+
case 'path': {
|
|
458
|
+
// 第一个点是锚(位置 ✓),其余是偏移 ✓
|
|
459
|
+
const pts = a.pts ?? [];
|
|
460
|
+
if (pts.length < 2)
|
|
461
|
+
return a;
|
|
462
|
+
const out = [[pts[0][0], pct(pts[0][1])]];
|
|
463
|
+
for (let i = 1; i < pts.length; i++)
|
|
464
|
+
out.push([pts[i][0], pctSpan(pts[i][1])]);
|
|
465
|
+
return { ...a, pts: out };
|
|
466
|
+
}
|
|
467
|
+
case 'text':
|
|
468
|
+
case 'note':
|
|
469
|
+
return { ...a, ty: a.ty === undefined ? a.ty : pct(a.ty) };
|
|
470
|
+
default:
|
|
471
|
+
return a;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
export function annoLayer(annos, frame, k = 1, opts) {
|
|
400
476
|
if (!annos.length)
|
|
401
477
|
return '';
|
|
402
478
|
const parts = [];
|
|
479
|
+
// 一把**统一**的尺:√(宽 × 高)—— 与长宽比无关 ✓
|
|
480
|
+
//
|
|
481
|
+
// 位置用画布的宽、高各算各的(位置要跟着数据区走 ✓);
|
|
482
|
+
// **尺寸**用它:画布的长宽比一变(改窗口、改侧栏宽度),宽按宽缩、高按高缩
|
|
483
|
+
// ⇒ 一个圆就变成了椭圆 ✗。统一尺 ⇒ 圆得一直是圆 ✓
|
|
484
|
+
// (站上那层实时画板用同一把尺 ⇒ 编辑器里与导出的图一模一样 ✓)
|
|
485
|
+
// 统一尺:y 用值时**不要**再统一缩放(y 已经是「数据形状」了 ✓)⇒ 传 uniform:false ✓
|
|
486
|
+
// ⇒ 有值映射时:x 尺寸按绘图区宽、y 尺寸按绘图区高 ⇒ 形状跟着**数据的长宽比**走 ✓
|
|
487
|
+
const uu = Math.sqrt(Math.max(1, frame.w * frame.h));
|
|
488
|
+
const mx = opts?.uniform === false ? frame.w : uu; // x 尺寸的尺
|
|
489
|
+
const my = opts?.uniform === false ? frame.h : uu; // y 尺寸的尺
|
|
403
490
|
// of():连**序号**一起给 ✓ —— 画出来的每一笔都带 data-i ✓
|
|
404
491
|
// (客户端靠它知道「点中的是第几条」✓ —— 悬停、拖动、双击编辑都靠它 ✓)
|
|
405
492
|
const of = (kind) => annos.map((a, i) => ({ a, i })).filter((x) => x.a.kind === kind);
|
|
@@ -408,8 +495,8 @@ export function annoLayer(annos, frame, k = 1) {
|
|
|
408
495
|
const color = a.color ?? HL_COLOR;
|
|
409
496
|
const x = frame.x + (a.x / 100) * frame.w;
|
|
410
497
|
const y = frame.y + (a.y / 100) * frame.h;
|
|
411
|
-
const w = ((a.w ?? 0) / 100) *
|
|
412
|
-
const h = ((a.h ?? 0) / 100) *
|
|
498
|
+
const w = ((a.w ?? 0) / 100) * mx;
|
|
499
|
+
const h = ((a.h ?? 0) / 100) * my;
|
|
413
500
|
parts.push(`<rect data-i="${i}" x="${r2(x)}" y="${r2(y)}" width="${r2(w)}" height="${r2(h)}" rx="${r2(10 * k)}" fill="${color}" fill-opacity="0.13" stroke="${color}" stroke-opacity="0.85" stroke-width="${r2(1.5 * k)}"/>`);
|
|
414
501
|
if (a.cls)
|
|
415
502
|
parts.push(clsTag(a.cls, x, y - 4 * k, color, k, i));
|
|
@@ -419,8 +506,8 @@ export function annoLayer(annos, frame, k = 1) {
|
|
|
419
506
|
const color = a.color ?? DEFAULT_COLOR;
|
|
420
507
|
const cx = frame.x + (a.x / 100) * frame.w;
|
|
421
508
|
const cy = frame.y + (a.y / 100) * frame.h;
|
|
422
|
-
const rx = ((a.rx ?? 0) / 100) *
|
|
423
|
-
const ry = ((a.ry ?? 0) / 100) *
|
|
509
|
+
const rx = ((a.rx ?? 0) / 100) * mx;
|
|
510
|
+
const ry = ((a.ry ?? 0) / 100) * my;
|
|
424
511
|
parts.push(`<ellipse data-i="${i}" cx="${r2(cx)}" cy="${r2(cy)}" rx="${r2(rx)}" ry="${r2(ry)}" fill="${color}" fill-opacity="0.08" stroke="${color}" stroke-width="${r2(2.5 * k)}" stroke-opacity="0.95"/>`);
|
|
425
512
|
if (a.cls)
|
|
426
513
|
parts.push(clsTag(a.cls, cx - rx, cy - ry - 4 * k, color, k, i));
|
|
@@ -431,8 +518,12 @@ export function annoLayer(annos, frame, k = 1) {
|
|
|
431
518
|
const pts = a.pts ?? [];
|
|
432
519
|
if (pts.length < 2)
|
|
433
520
|
continue;
|
|
521
|
+
// 第一个点是**锚**(位置照旧 ✓);其余点存的是**统一尺上的偏移** ⇒ 笔迹形状不随长宽比变 ✓
|
|
522
|
+
const [ax0, ay0] = pts[0];
|
|
434
523
|
const d = pts
|
|
435
|
-
.map(([px, py], i) =>
|
|
524
|
+
.map(([px, py], i) => (i
|
|
525
|
+
? `L${r2(frame.x + (ax0 / 100) * frame.w + (px / 100) * mx)},${r2(frame.y + (ay0 / 100) * frame.h + (py / 100) * my)}`
|
|
526
|
+
: `M${r2(frame.x + (ax0 / 100) * frame.w)},${r2(frame.y + (ay0 / 100) * frame.h)}`))
|
|
436
527
|
.join(' ');
|
|
437
528
|
parts.push(`<path data-i="${i}" d="${d}" fill="none" stroke="${color}" stroke-width="${r2(2.2 * k)}" stroke-opacity="0.95" stroke-linecap="round" stroke-linejoin="round"/>`);
|
|
438
529
|
if (a.cls) {
|
|
@@ -446,8 +537,9 @@ export function annoLayer(annos, frame, k = 1) {
|
|
|
446
537
|
const color = a.color ?? ARROW_COLOR;
|
|
447
538
|
const x1 = frame.x + (a.x / 100) * frame.w;
|
|
448
539
|
const y1 = frame.y + (a.y / 100) * frame.h;
|
|
449
|
-
|
|
450
|
-
const
|
|
540
|
+
// 终点存的是**统一尺上的偏移**(起点是锚 ✓)⇒ 箭头的角度不随长宽比变 ✓
|
|
541
|
+
const x2 = x1 + ((a.x2 ?? 0) / 100) * mx;
|
|
542
|
+
const y2 = y1 + ((a.y2 ?? 0) / 100) * my;
|
|
451
543
|
const dx = x2 - x1;
|
|
452
544
|
const dy = y2 - y1;
|
|
453
545
|
const len = Math.hypot(dx, dy);
|
|
@@ -542,9 +634,67 @@ export function annoLayer(annos, frame, k = 1) {
|
|
|
542
634
|
}
|
|
543
635
|
return `<g class="anno" data-anno="1">${parts.join('')}</g>`;
|
|
544
636
|
}
|
|
637
|
+
/**
|
|
638
|
+
* 图里的**绘图区**(数据区)✓ —— 标注的百分比要按它换算,不是按整个画布 ✓
|
|
639
|
+
*
|
|
640
|
+
* 为什么:画布的左边距是**固定的像素**(轴标签那一条 ✓),画布一变宽,
|
|
641
|
+
* 「画布的百分之多少」跟「数据的百分之多少」就对不上了 ⇒ 锚在画布上的标注
|
|
642
|
+
* 会相对数据漂走(实测:988 宽时 Apple 在 22%,568 宽时 25.9% ⇒ 差 4% ✗)。
|
|
643
|
+
* 锚在绘图区上,画布怎么变,标注都指着同一根柱子 ✓
|
|
644
|
+
*
|
|
645
|
+
* 找法:横跨绘图区的**网格线**(含基线)的左右端 = 绘图区的左右 ✓;
|
|
646
|
+
* 上下用 dscale 的映射(精确 ✓)。找不到就退回整个画布 ✓。
|
|
647
|
+
*/
|
|
648
|
+
export function plotAreaOf(svg) {
|
|
649
|
+
let left = Infinity;
|
|
650
|
+
let right = -Infinity;
|
|
651
|
+
let top = Infinity;
|
|
652
|
+
let bottom = -Infinity;
|
|
653
|
+
const line = /<line[^>]*x1="(-?[\d.]+)"[^>]*y1="(-?[\d.]+)"[^>]*x2="(-?[\d.]+)"[^>]*y2="(-?[\d.]+)"[^>]*stroke="var\(--d-grid\)"[^>]*\/?>/g;
|
|
654
|
+
for (let m = line.exec(svg); m; m = line.exec(svg)) {
|
|
655
|
+
const x1 = Number(m[1]);
|
|
656
|
+
const x2 = Number(m[3]);
|
|
657
|
+
const y1 = Number(m[2]);
|
|
658
|
+
const y2 = Number(m[4]);
|
|
659
|
+
if (!Number.isFinite(x1) || !Number.isFinite(x2))
|
|
660
|
+
continue;
|
|
661
|
+
if (x1 < left)
|
|
662
|
+
left = x1;
|
|
663
|
+
if (x2 > right)
|
|
664
|
+
right = x2;
|
|
665
|
+
if (Math.min(y1, y2) < top)
|
|
666
|
+
top = Math.min(y1, y2);
|
|
667
|
+
if (Math.max(y1, y2) > bottom)
|
|
668
|
+
bottom = Math.max(y1, y2);
|
|
669
|
+
}
|
|
670
|
+
if (!Number.isFinite(left) || right <= left)
|
|
671
|
+
return null;
|
|
672
|
+
// 上下:dscale 的映射(精确 ✓ —— 网格线只到刻度,不到绘图区顶 ✓)
|
|
673
|
+
const ds = /<metadata id="dscale">([^<]*)<\/metadata>/.exec(svg);
|
|
674
|
+
if (ds) {
|
|
675
|
+
try {
|
|
676
|
+
const j = JSON.parse(ds[1]);
|
|
677
|
+
const p0 = Number(j.y?.p0);
|
|
678
|
+
const p1 = Number(j.y?.p1);
|
|
679
|
+
if (Number.isFinite(p0) && Number.isFinite(p1) && p0 > p1) {
|
|
680
|
+
top = p1;
|
|
681
|
+
bottom = p0;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
catch {
|
|
685
|
+
/* 解析不了就用网格线的范围 ✓ */
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (!Number.isFinite(top) || !Number.isFinite(bottom) || bottom <= top) {
|
|
689
|
+
top = 0;
|
|
690
|
+
bottom = Number.NaN;
|
|
691
|
+
}
|
|
692
|
+
const h = Number.isFinite(bottom) ? bottom - top : 0;
|
|
693
|
+
return h > 0 ? { x: left, y: top, w: right - left, h } : null;
|
|
694
|
+
}
|
|
545
695
|
/**
|
|
546
696
|
* 把标注层塞进一张已经画好的 SVG(盖在最后面 = 最上面)。
|
|
547
|
-
*
|
|
697
|
+
* 坐标按**绘图区**换算 —— 画布尺寸变了,百分比的位置不变 ✓。
|
|
548
698
|
*/
|
|
549
699
|
export function injectAnnos(svg, annos) {
|
|
550
700
|
if (!annos?.length)
|
|
@@ -581,7 +731,11 @@ export function injectAnnos(svg, annos) {
|
|
|
581
731
|
const scale = px && vw > 0 ? Number(px[1]) / vw : 1;
|
|
582
732
|
const k = scale > 0 ? 1 / scale : 1;
|
|
583
733
|
// 百分比按 viewBox 换算(viewBox 原点不一定在 0,0)
|
|
584
|
-
|
|
734
|
+
// 锚在**绘图区**(数据区 ✓)—— 不是整个画布 ✓(画布的固定边距会让它相对数据漂 ✗)
|
|
735
|
+
const plot = plotAreaOf(svg);
|
|
736
|
+
// 图有值映射 ⇒ 标注的 y 是**数据值** ⇒ 先换算成绘图区的百分比 ✓
|
|
737
|
+
const d = dscaleOf(svg);
|
|
738
|
+
const layer = annoLayer(d ? annoValuesToPct(annos, d) : annos, plot ?? { x: x0, y: y0, w: vw, h: vh }, k, { uniform: !d });
|
|
585
739
|
const at = svg.lastIndexOf('</svg>');
|
|
586
740
|
if (at < 0)
|
|
587
741
|
return svg;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AnsRun {
|
|
2
|
+
text: string;
|
|
3
|
+
fg?: string;
|
|
4
|
+
bg?: string;
|
|
5
|
+
bold?: boolean;
|
|
6
|
+
dim?: boolean;
|
|
7
|
+
italic?: boolean;
|
|
8
|
+
underline?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** 解析一段带 ANSI 的文本 → 片段列表 */
|
|
11
|
+
export declare function parseAnsi(input: string): AnsRun[];
|
|
12
|
+
/** 片段列表 → HTML(给网页里的终端用) */
|
|
13
|
+
export declare function ansiToHtml(runs: AnsRun[]): string;
|
|
14
|
+
/** 把纯文本里的其它控制字符清掉(剩下能显示的) */
|
|
15
|
+
export declare function stripAnsi(input: string): string;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// ANSI 转义序列 → 一段段带样式的文本。
|
|
2
|
+
//
|
|
3
|
+
// 命令行的输出里带 ESC[31m 这样的颜色码,网页上要把它还原成颜色。
|
|
4
|
+
// 这里只认 SGR(选图形)那几类 —— 光标移动、清屏之类在静态图里没意义。
|
|
5
|
+
//
|
|
6
|
+
// 输出是一串「片段」(run):一段同样式的一段文字。渲染器(HTML / SVG)各自决定
|
|
7
|
+
// 怎么画 —— 这里只管把样式解析出来。
|
|
8
|
+
/** xterm 的 16 色(标准色 + 亮色) */
|
|
9
|
+
const PALETTE = [
|
|
10
|
+
'#000000', '#cd3131', '#0dbc79', '#e5e510', '#2472c8', '#bc3fbc', '#11a8cd', '#e5e5e5',
|
|
11
|
+
'#666666', '#f14c4c', '#23d18b', '#f5f543', '#3b8eea', '#d670d6', '#29b8db', '#ffffff',
|
|
12
|
+
];
|
|
13
|
+
/** 256 色:0-15 是上面的调色板,16-231 是 6×6×6 的立方,232-255 是灰阶 */
|
|
14
|
+
function color256(n) {
|
|
15
|
+
if (n < 16)
|
|
16
|
+
return PALETTE[n];
|
|
17
|
+
if (n < 232) {
|
|
18
|
+
const i = n - 16;
|
|
19
|
+
const steps = [0, 95, 135, 175, 215, 255];
|
|
20
|
+
const r = steps[Math.floor(i / 36) % 6];
|
|
21
|
+
const g = steps[Math.floor(i / 6) % 6];
|
|
22
|
+
const b = steps[i % 6];
|
|
23
|
+
return `#${[r, g, b].map((v) => v.toString(16).padStart(2, '0')).join('')}`;
|
|
24
|
+
}
|
|
25
|
+
const v = 8 + (n - 232) * 10;
|
|
26
|
+
return `#${v.toString(16).padStart(2, '0').repeat(3)}`;
|
|
27
|
+
}
|
|
28
|
+
/** 解析一段带 ANSI 的文本 → 片段列表 */
|
|
29
|
+
export function parseAnsi(input) {
|
|
30
|
+
const runs = [];
|
|
31
|
+
let style = {};
|
|
32
|
+
let buf = '';
|
|
33
|
+
// eslint-disable-next-line no-control-regex
|
|
34
|
+
const re = /\x1b\[([0-9;]*)m/g;
|
|
35
|
+
let last = 0;
|
|
36
|
+
let m;
|
|
37
|
+
const flush = () => {
|
|
38
|
+
if (!buf)
|
|
39
|
+
return;
|
|
40
|
+
runs.push({ text: buf, ...style });
|
|
41
|
+
buf = '';
|
|
42
|
+
};
|
|
43
|
+
while ((m = re.exec(input)) !== null) {
|
|
44
|
+
buf += input.slice(last, m.index);
|
|
45
|
+
last = m.index + m[0].length;
|
|
46
|
+
flush();
|
|
47
|
+
style = applySgr(style, m[1]);
|
|
48
|
+
}
|
|
49
|
+
buf += input.slice(last);
|
|
50
|
+
flush();
|
|
51
|
+
return runs;
|
|
52
|
+
}
|
|
53
|
+
/** 一条 SGR 序列作用到当前样式上 */
|
|
54
|
+
function applySgr(style, params) {
|
|
55
|
+
const s = { ...style };
|
|
56
|
+
const nums = params === '' ? [0] : params.split(';').map((p) => Number.parseInt(p, 10) || 0);
|
|
57
|
+
for (let i = 0; i < nums.length; i++) {
|
|
58
|
+
const n = nums[i];
|
|
59
|
+
if (n === 0) {
|
|
60
|
+
s.fg = undefined;
|
|
61
|
+
s.bg = undefined;
|
|
62
|
+
s.bold = false;
|
|
63
|
+
s.dim = false;
|
|
64
|
+
s.italic = false;
|
|
65
|
+
s.underline = false;
|
|
66
|
+
}
|
|
67
|
+
else if (n === 1)
|
|
68
|
+
s.bold = true;
|
|
69
|
+
else if (n === 2)
|
|
70
|
+
s.dim = true;
|
|
71
|
+
else if (n === 3)
|
|
72
|
+
s.italic = true;
|
|
73
|
+
else if (n === 4)
|
|
74
|
+
s.underline = true;
|
|
75
|
+
else if (n === 22) {
|
|
76
|
+
s.bold = false;
|
|
77
|
+
s.dim = false;
|
|
78
|
+
}
|
|
79
|
+
else if (n === 23)
|
|
80
|
+
s.italic = false;
|
|
81
|
+
else if (n === 24)
|
|
82
|
+
s.underline = false;
|
|
83
|
+
else if (n >= 30 && n <= 37)
|
|
84
|
+
s.fg = PALETTE[n - 30];
|
|
85
|
+
else if (n === 39)
|
|
86
|
+
s.fg = undefined;
|
|
87
|
+
else if (n >= 40 && n <= 47)
|
|
88
|
+
s.bg = PALETTE[n - 40];
|
|
89
|
+
else if (n === 49)
|
|
90
|
+
s.bg = undefined;
|
|
91
|
+
else if (n >= 90 && n <= 97)
|
|
92
|
+
s.fg = PALETTE[n - 90 + 8];
|
|
93
|
+
else if (n >= 100 && n <= 107)
|
|
94
|
+
s.bg = PALETTE[n - 100 + 8];
|
|
95
|
+
else if (n === 38 || n === 48) {
|
|
96
|
+
// 38;5;n(256 色)/ 38;2;r;g;b(真彩)
|
|
97
|
+
const mode = nums[i + 1];
|
|
98
|
+
let color;
|
|
99
|
+
if (mode === 5) {
|
|
100
|
+
color = color256(nums[i + 2] ?? 0);
|
|
101
|
+
i += 2;
|
|
102
|
+
}
|
|
103
|
+
else if (mode === 2) {
|
|
104
|
+
const [r, g, b] = [nums[i + 2] ?? 0, nums[i + 3] ?? 0, nums[i + 4] ?? 0];
|
|
105
|
+
color = `#${[r, g, b].map((v) => Math.max(0, Math.min(255, v)).toString(16).padStart(2, '0')).join('')}`;
|
|
106
|
+
i += 4;
|
|
107
|
+
}
|
|
108
|
+
if (n === 38)
|
|
109
|
+
s.fg = color;
|
|
110
|
+
else
|
|
111
|
+
s.bg = color;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return s;
|
|
115
|
+
}
|
|
116
|
+
/** 片段列表 → HTML(给网页里的终端用) */
|
|
117
|
+
export function ansiToHtml(runs) {
|
|
118
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
119
|
+
return runs.map((r) => {
|
|
120
|
+
const st = [];
|
|
121
|
+
if (r.fg)
|
|
122
|
+
st.push(`color:${r.fg}`);
|
|
123
|
+
if (r.bg)
|
|
124
|
+
st.push(`background:${r.bg}`);
|
|
125
|
+
if (r.bold)
|
|
126
|
+
st.push('font-weight:700');
|
|
127
|
+
if (r.dim)
|
|
128
|
+
st.push('opacity:.65');
|
|
129
|
+
if (r.italic)
|
|
130
|
+
st.push('font-style:italic');
|
|
131
|
+
if (r.underline)
|
|
132
|
+
st.push('text-decoration:underline');
|
|
133
|
+
if (!st.length)
|
|
134
|
+
return esc(r.text);
|
|
135
|
+
return `<span style="${st.join(';')}">${esc(r.text)}</span>`;
|
|
136
|
+
}).join('');
|
|
137
|
+
}
|
|
138
|
+
/** 把纯文本里的其它控制字符清掉(剩下能显示的) */
|
|
139
|
+
export function stripAnsi(input) {
|
|
140
|
+
// eslint-disable-next-line no-control-regex
|
|
141
|
+
return input.replace(/\x1b\[[0-9;?]*[a-zA-Z]/g, '').replace(/\r/g, '');
|
|
142
|
+
}
|
package/dist/render/arch.js
CHANGED
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
//
|
|
11
11
|
// 老路径 /draw/archmap 一行未动(它的输出与 v2 之前逐字节相同)。
|
|
12
12
|
import { ApiError } from '../specs/index.js';
|
|
13
|
+
import { BASELINE } from '../styles/baseline.js';
|
|
13
14
|
import { packGrid, parseBoundaries, parseEdges, parseNodes, TYPE_COLOR, } from './archmap.js';
|
|
14
15
|
import { gridLayout, labelGaps } from './layout.js';
|
|
15
16
|
import { routeEdges } from './route.js';
|
|
16
17
|
import { resolveSkin } from '../styles/index.js';
|
|
18
|
+
import { card } from '../theme.js';
|
|
17
19
|
import { clampInt, dirParam, schemeParam } from './query.js';
|
|
18
20
|
import { esc, r2, roundedPath, svgDoc, textW, trunc } from './svg.js';
|
|
19
21
|
import { iconOf } from './icons.js';
|
|
@@ -32,7 +34,7 @@ const LEGEND_H = 46; // 图例带的高度
|
|
|
32
34
|
const NODE_MIN_W = 176;
|
|
33
35
|
const NODE_R = 12; // 节点圆角
|
|
34
36
|
const BADGE = 20; // 角标边长
|
|
35
|
-
const LABEL_FS =
|
|
37
|
+
const LABEL_FS = BASELINE.pointName; // 节点标题字号
|
|
36
38
|
const SUB_FS = 11.5; // 节点副标题字号
|
|
37
39
|
const EDGE_FS = 11.5; // 边标签字号
|
|
38
40
|
/** 语义类型 → (展示名, 角标字母) */
|
|
@@ -934,9 +936,12 @@ export function renderArchCore(o) {
|
|
|
934
936
|
? `<text x="${PAD}" y="${PAD + 16}" font-size="19" font-weight="600" letter-spacing="-0.02em" fill="var(--d-ink)">${esc(o.title)}</text>`
|
|
935
937
|
: '';
|
|
936
938
|
const bColors = boundaryColors(o.boundaries, types);
|
|
937
|
-
|
|
939
|
+
// 皮肤带卡(macaron 暖白/侘寂石灰墙)→ 画卡底;primer 等透明皮肤(prime 语义是
|
|
940
|
+
// 融入宿主页)不画 —— 架构图从此也吃 ?t= 的 canvas 规则(#133 架构图多风格探索)
|
|
941
|
+
const cardSvg = o.skin.rules.canvas === 'card' ? card(width, height) : '';
|
|
942
|
+
const paperSvg = cardSvg + (o.paper
|
|
938
943
|
? `<rect x="0" y="0" width="${r2(width)}" height="${r2(height)}" fill="url(#am-paper)"/>`
|
|
939
|
-
: '';
|
|
944
|
+
: '');
|
|
940
945
|
const body = iStyle + DEFS
|
|
941
946
|
+ drawBoundariesV2(o.boundaries, bboxes, o.interactive, bColors, o.boundaryStyle)
|
|
942
947
|
+ drawRoutesV2(routed, o.interactive, types)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ArchNode, type ArchEdge, type ArchBoundary } from './archmap.js';
|
|
2
|
+
import { type Camera, type Scene } from './scene3d.js';
|
|
3
|
+
export interface Arch3dOpts {
|
|
4
|
+
/** 相机(默认等轴测那一眼) */
|
|
5
|
+
camera?: Partial<Camera>;
|
|
6
|
+
/** 要不要带交互标记(data-node/data-from) */
|
|
7
|
+
interactive?: boolean;
|
|
8
|
+
/** 画布宽(高按场景比例算) */
|
|
9
|
+
width?: number;
|
|
10
|
+
/** 分组的辅助线怎么画:plain(默认,只留牌子)/ tint / dash */
|
|
11
|
+
bstyle?: 'plain' | 'tint' | 'dash';
|
|
12
|
+
/** 各层的平面要不要画(默认不要 —— 那些板是多余的) */
|
|
13
|
+
planes?: boolean;
|
|
14
|
+
/** 辅助线(地板网格 + 分组的线框)要不要画(默认不要) */
|
|
15
|
+
aux?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 解析 URL → 场景。
|
|
19
|
+
*/
|
|
20
|
+
/** 分组的辅助线怎么画:plain(默认,只留牌子)/ tint / dash —— 那些线框是多余的,要做再要 */
|
|
21
|
+
export declare function bstyleOf(url: URL): 'plain' | 'tint' | 'dash';
|
|
22
|
+
/** 各层的平面要不要画(默认不要):planes=1 才有 */
|
|
23
|
+
export declare function planesOf(url: URL): boolean;
|
|
24
|
+
/** 辅助线(地板网格 + 分组的线框)要不要画(默认不要):aux=1 才有 */
|
|
25
|
+
export declare function auxOf(url: URL): boolean;
|
|
26
|
+
export declare function sceneFromUrl(url: URL): Scene;
|
|
27
|
+
/** 节点/边/分组 → 场景 */
|
|
28
|
+
export declare function sceneOf(nodes: ArchNode[], edges: ArchEdge[], groups: ArchBoundary[]): Scene;
|
|
29
|
+
/** 场景 → SVG(默认相机) */
|
|
30
|
+
export declare function renderArch3d(scene: Scene, opts?: Arch3dOpts): string;
|
|
31
|
+
export declare function renderArch3dFlat(scene: Scene, opts?: Arch3dOpts): string;
|