@x12i/reportic-render-html 0.2.4 → 0.2.6
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.d.ts +14 -1
- package/dist/index.js +452 -82
- package/dist/index.js.map +1 -1
- package/package.json +35 -34
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/reportic-render-html/src/index.ts
|
|
2
2
|
import { marked } from "marked";
|
|
3
3
|
import sanitizeHtml from "sanitize-html";
|
|
4
|
-
import { escapeHtml as
|
|
4
|
+
import { escapeHtml as h4, escapeMd as md, themeTokens as themeTokens5, semanticColors as semanticColors3, walkNodes as walkNodes2, formatValue as formatValue3, safeUrl, safeRelative, fail as fail4, figureSpec as figureSpec2 } from "@x12i/reportic-core";
|
|
5
5
|
|
|
6
6
|
// packages/reportic-render-html/src/visuals.ts
|
|
7
7
|
import { readFile } from "fs/promises";
|
|
@@ -236,7 +236,7 @@ function draw(f, c, locale) {
|
|
|
236
236
|
});
|
|
237
237
|
return { fills, defs: defs.length ? `<defs>${defs.join("")}</defs>` : "" };
|
|
238
238
|
};
|
|
239
|
-
const
|
|
239
|
+
const legend2 = (series, x, y, fills) => {
|
|
240
240
|
let out = "";
|
|
241
241
|
series.forEach((s, j) => {
|
|
242
242
|
out += el("rect", { x, y: y - 9, width: 12, height: 12, rx: 2, fill: fills[j], stroke: fills[j].startsWith("url(") ? tone2(s.tone, j === 0 ? c.accent : c.grey) : null, "stroke-width": fills[j].startsWith("url(") ? 1 : null }) + el("text", { x: x + 17, y: y + 1, "font-size": 11.5, fill: c.body }, s.name);
|
|
@@ -322,7 +322,7 @@ function draw(f, c, locale) {
|
|
|
322
322
|
const ry = yOf(f.reference.value);
|
|
323
323
|
body2 += el("line", { x1: x0, x2: x1, y1: ry, y2: ry, stroke: c.bad, "stroke-dasharray": "5 4" }) + el("text", { x: x1, y: ry - 5, "font-size": 11, fill: c.bad, "text-anchor": "end" }, f.reference.label ?? "");
|
|
324
324
|
}
|
|
325
|
-
if (S.length > 1) body2 +=
|
|
325
|
+
if (S.length > 1) body2 += legend2(S, 16, top - 10, fills);
|
|
326
326
|
body2 += note(H2 + 32);
|
|
327
327
|
return { svg: body2, height: H2 + 40 + noteHeight };
|
|
328
328
|
}
|
|
@@ -360,7 +360,7 @@ function draw(f, c, locale) {
|
|
|
360
360
|
});
|
|
361
361
|
if (last !== null) body2 += el("text", { x: xOf(last) + 8, y: yOf(s.values[last]) + 4, "font-size": 11.5, fill: t, "font-weight": 600 }, fmt(s.values[last]) + (S.length > 1 ? " " + s.name : ""));
|
|
362
362
|
});
|
|
363
|
-
if (S.length > 1) body2 +=
|
|
363
|
+
if (S.length > 1) body2 += legend2(S, 16, top - 10, seriesFills(S, false).fills);
|
|
364
364
|
body2 += note(H2 + 32);
|
|
365
365
|
return { svg: body2, height: H2 + 40 + noteHeight };
|
|
366
366
|
}
|
|
@@ -430,6 +430,219 @@ function figureSvg(node, report, options = {}) {
|
|
|
430
430
|
return `<svg xmlns="http://www.w3.org/2000/svg" role="img" aria-label="${h2(node.props.alt)}" viewBox="0 0 ${W} ${h22}" width="${W}" height="${h22}" font-family="${h2(t.fontFamily)}">${svg}</svg>`;
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
+
// packages/reportic-render-html/src/kit-chart.ts
|
|
434
|
+
import { AXIS_FONT_SIZE, TICK_PADDING, TICK_SIZE, buildChartModel, describeChart, isOpenMarker, layoutChart, markerPath, modelToTable } from "@x12i/charts";
|
|
435
|
+
import { escapeHtml as h3, semanticColors as semanticColors2, themeTokens as themeTokens3 } from "@x12i/reportic-core";
|
|
436
|
+
var MIDDLE_OFFSET = 4;
|
|
437
|
+
var TALL = /* @__PURE__ */ new Set(["sankey", "timeline", "gantt", "architecture", "swimlane", "network-map", "screen-frame", "cell-table", "chain-cards", "treemap"]);
|
|
438
|
+
var ORDER = { area: 0, bar: 1, cell: 1, arc: 1, connector: 2, stem: 2, line: 3, point: 4 };
|
|
439
|
+
function chartHeight(mark) {
|
|
440
|
+
if (mark === "sparkline") return 48;
|
|
441
|
+
if (mark === "gauge" || mark === "progress-ring") return 220;
|
|
442
|
+
if (TALL.has(mark)) return 420;
|
|
443
|
+
return 320;
|
|
444
|
+
}
|
|
445
|
+
function hex(input) {
|
|
446
|
+
const s = input.replace("#", "");
|
|
447
|
+
const full = s.length <= 4 ? s.slice(0, 3).split("").map((c) => c + c).join("") : s.slice(0, 6);
|
|
448
|
+
return "#" + full;
|
|
449
|
+
}
|
|
450
|
+
function rgb(color) {
|
|
451
|
+
const h5 = hex(color).slice(1);
|
|
452
|
+
return [0, 2, 4].map((i) => parseInt(h5.slice(i, i + 2), 16));
|
|
453
|
+
}
|
|
454
|
+
function mix(from, to, t) {
|
|
455
|
+
const a = rgb(from), b = rgb(to), u = Math.min(1, Math.max(0, t));
|
|
456
|
+
return "#" + a.map((v, i) => Math.round(v + (b[i] - v) * u).toString(16).padStart(2, "0")).join("");
|
|
457
|
+
}
|
|
458
|
+
function toneColor(tone2, paint) {
|
|
459
|
+
switch (tone2) {
|
|
460
|
+
case "accent":
|
|
461
|
+
return paint.accent;
|
|
462
|
+
case "muted":
|
|
463
|
+
return paint.muted;
|
|
464
|
+
case "reference":
|
|
465
|
+
return paint.grey;
|
|
466
|
+
case "good":
|
|
467
|
+
return paint.ok;
|
|
468
|
+
case "warning":
|
|
469
|
+
return paint.warn;
|
|
470
|
+
case "critical":
|
|
471
|
+
return paint.bad;
|
|
472
|
+
default: {
|
|
473
|
+
const slot = Number(String(tone2).replace("categorical-", "")) - 1;
|
|
474
|
+
return paint.palette[(Number.isFinite(slot) && slot >= 0 ? slot : 0) % paint.palette.length] ?? paint.accent;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function rampColor(kind, t, paint) {
|
|
479
|
+
const u = Math.min(1, Math.max(0, t ?? 0));
|
|
480
|
+
if (kind === "diverging") return u < 0.5 ? mix(paint.bad, paint.grey, u * 2) : mix(paint.grey, paint.ok, (u - 0.5) * 2);
|
|
481
|
+
return mix(paint.muted, paint.accent, u);
|
|
482
|
+
}
|
|
483
|
+
var num = (v) => Number.isFinite(v) ? String(Math.round(v * 100) / 100) : "0";
|
|
484
|
+
var rtl = /[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/;
|
|
485
|
+
function textDir(text2, numeric) {
|
|
486
|
+
const flip = !numeric && rtl.test(text2);
|
|
487
|
+
return { direction: flip ? "rtl" : "ltr", flip };
|
|
488
|
+
}
|
|
489
|
+
function anchorOf(anchor, flip) {
|
|
490
|
+
if (!flip) return anchor;
|
|
491
|
+
return anchor === "start" ? "end" : anchor === "end" ? "start" : anchor;
|
|
492
|
+
}
|
|
493
|
+
var PATTERN_BODY = {
|
|
494
|
+
0: { size: 6, body: (c) => `<path d="M-1,1L1,-1M0,6L6,0M5,7L7,5" stroke="${c}" fill="none" stroke-width="1"/>` },
|
|
495
|
+
1: { size: 6, body: (c) => `<path d="M-1,5L1,7M0,0L6,6M5,-1L7,1" stroke="${c}" fill="none" stroke-width="1"/>` },
|
|
496
|
+
2: { size: 6, body: (c) => `<circle cx="3" cy="3" r="1" fill="${c}"/>` },
|
|
497
|
+
3: { size: 6, body: (c) => `<path d="M0,3H6" stroke="${c}" fill="none" stroke-width="1"/>` },
|
|
498
|
+
4: { size: 6, body: (c) => `<path d="M3,0V6" stroke="${c}" fill="none" stroke-width="1"/>` },
|
|
499
|
+
5: { size: 6, body: (c) => `<path d="M0,3H6M3,0V6" stroke="${c}" fill="none" stroke-width="1"/>` },
|
|
500
|
+
6: { size: 8, body: (c) => `<path d="M-1,1L1,-1M0,8L8,0M7,9L9,7" stroke="${c}" fill="none" stroke-width="1"/>` },
|
|
501
|
+
7: { size: 6, body: (c) => `<rect x="0" y="0" width="3" height="3" fill="${c}"/><rect x="3" y="3" width="3" height="3" fill="${c}"/>` }
|
|
502
|
+
};
|
|
503
|
+
function patternDefs(indices, color, prefix) {
|
|
504
|
+
return indices.map((index) => {
|
|
505
|
+
const tile = PATTERN_BODY[index % 8] ?? PATTERN_BODY[0];
|
|
506
|
+
return `<pattern id="${prefix}-p${index}" patternUnits="userSpaceOnUse" width="${tile.size}" height="${tile.size}">${tile.body(color)}</pattern>`;
|
|
507
|
+
}).join("");
|
|
508
|
+
}
|
|
509
|
+
function axes(layout, paint) {
|
|
510
|
+
return layout.axes.map((axis) => {
|
|
511
|
+
const vertical = axis.orient === "left" || axis.orient === "right";
|
|
512
|
+
const sign = axis.orient === "left" || axis.orient === "top" ? -1 : 1;
|
|
513
|
+
const ticks = axis.ticks.filter((tick) => tick.visible).map((tick) => {
|
|
514
|
+
const tickLine = vertical ? { x1: axis.line.x1, y1: tick.position, x2: axis.line.x1 + sign * TICK_SIZE, y2: tick.position } : { x1: tick.position, y1: axis.line.y1, x2: tick.position, y2: axis.line.y1 + sign * TICK_SIZE };
|
|
515
|
+
const gap = TICK_SIZE + TICK_PADDING;
|
|
516
|
+
let x, y;
|
|
517
|
+
if (vertical) {
|
|
518
|
+
x = axis.line.x1 + sign * gap;
|
|
519
|
+
y = tick.position + MIDDLE_OFFSET;
|
|
520
|
+
} else {
|
|
521
|
+
x = tick.position;
|
|
522
|
+
y = axis.line.y1 + sign * gap + (sign > 0 ? axis.labelAngle === 0 ? AXIS_FONT_SIZE * 0.8 : AXIS_FONT_SIZE * 0.35 : 0);
|
|
523
|
+
}
|
|
524
|
+
const text2 = String(tick.label);
|
|
525
|
+
const dir = textDir(text2, axis.numeric);
|
|
526
|
+
const grid = axis.grid ? vertical ? `<line x1="${num(layout.plot.x)}" y1="${num(tick.position)}" x2="${num(layout.plot.x + layout.plot.width)}" y2="${num(tick.position)}" stroke="${paint.border}" stroke-width="1"/>` : `<line x1="${num(tick.position)}" y1="${num(layout.plot.y)}" x2="${num(tick.position)}" y2="${num(layout.plot.y + layout.plot.height)}" stroke="${paint.border}" stroke-width="1"/>` : "";
|
|
527
|
+
const rotate = axis.labelAngle !== 0 && !vertical ? ` transform="rotate(${axis.labelAngle} ${num(x)} ${num(y)})"` : "";
|
|
528
|
+
return `${grid}<line x1="${num(tickLine.x1)}" y1="${num(tickLine.y1)}" x2="${num(tickLine.x2)}" y2="${num(tickLine.y2)}" stroke="${paint.muted}" stroke-width="1"/><text x="${num(x)}" y="${num(y)}" text-anchor="${anchorOf(axis.labelAnchor, dir.flip)}" direction="${dir.direction}" fill="${paint.muted}" font-size="${AXIS_FONT_SIZE}"${rotate}>${h3(text2)}</text>`;
|
|
529
|
+
}).join("");
|
|
530
|
+
const spine = axis.id === "x" ? `<line x1="${num(axis.line.x1)}" y1="${num(axis.line.y1)}" x2="${num(axis.line.x2)}" y2="${num(axis.line.y2)}" stroke="${paint.muted}" stroke-width="1"/>` : "";
|
|
531
|
+
const title = axis.title && axis.titlePosition ? `<text x="${num(axis.titlePosition.x)}" y="${num(axis.titlePosition.y)}" text-anchor="middle" fill="${paint.text}" font-size="${AXIS_FONT_SIZE}"${axis.titlePosition.rotate ? ` transform="rotate(${axis.titlePosition.rotate} ${num(axis.titlePosition.x)} ${num(axis.titlePosition.y)})"` : ""}>${h3(axis.title)}</text>` : "";
|
|
532
|
+
return `${spine}${ticks}${title}`;
|
|
533
|
+
}).join("");
|
|
534
|
+
}
|
|
535
|
+
function marks(layout, paint, prefix) {
|
|
536
|
+
return [...layout.marks].sort((a, b) => ORDER[a.kind] - ORDER[b.kind]).map((mark) => {
|
|
537
|
+
const color = mark.kind === "cell" ? rampColor(mark.ramp, mark.t, paint) : mark.role === "track" ? paint.border : toneColor(mark.tone, paint);
|
|
538
|
+
const opacity = mark.muted ? ' opacity="0.4"' : "";
|
|
539
|
+
const overlay = mark.pattern >= 0 ? ` fill="url(#${prefix}-p${mark.pattern})"` : "";
|
|
540
|
+
if (mark.kind === "bar" || mark.kind === "cell") {
|
|
541
|
+
if (![mark.x, mark.y, mark.width, mark.height].every((v) => Number.isFinite(v))) return "";
|
|
542
|
+
const rect = `<rect x="${num(mark.x)}" y="${num(mark.y)}" width="${num(mark.width)}" height="${num(mark.height)}" fill="${color}"${opacity}/>`;
|
|
543
|
+
return overlay ? `${rect}<rect x="${num(mark.x)}" y="${num(mark.y)}" width="${num(mark.width)}" height="${num(mark.height)}"${overlay}/>` : rect;
|
|
544
|
+
}
|
|
545
|
+
if (mark.kind === "area" || mark.kind === "arc" || mark.kind === "line") {
|
|
546
|
+
if (!mark.d) return "";
|
|
547
|
+
const fill = mark.kind === "line" ? "none" : color;
|
|
548
|
+
const stroke = mark.kind === "line" ? color : "none";
|
|
549
|
+
const dash = mark.dash ? ` stroke-dasharray="${h3(mark.dash)}"` : "";
|
|
550
|
+
const path = `<path d="${h3(mark.d)}" fill="${fill}" stroke="${stroke}" stroke-width="${mark.kind === "line" ? 2 : 0}"${dash}${opacity}/>`;
|
|
551
|
+
return overlay && mark.kind !== "line" ? `${path}<path d="${h3(mark.d)}"${overlay}/>` : path;
|
|
552
|
+
}
|
|
553
|
+
if (mark.kind === "stem" || mark.kind === "connector") {
|
|
554
|
+
if (![mark.x1, mark.y1, mark.x2, mark.y2].every((v) => Number.isFinite(v))) return "";
|
|
555
|
+
return `<line x1="${num(mark.x1)}" y1="${num(mark.y1)}" x2="${num(mark.x2)}" y2="${num(mark.y2)}" stroke="${color}" stroke-width="1.5"${opacity}/>`;
|
|
556
|
+
}
|
|
557
|
+
const shape = mark.shape ?? "circle";
|
|
558
|
+
if (shape === "circle") return `<circle cx="${num(mark.cx)}" cy="${num(mark.cy)}" r="${num(mark.r)}" fill="${color}"${opacity}/>`;
|
|
559
|
+
const d = markerPath(shape, mark.cx ?? 0, mark.cy ?? 0, mark.r ?? 4);
|
|
560
|
+
return isOpenMarker(shape) ? `<path d="${h3(d)}" fill="none" stroke="${color}" stroke-width="1.5"${opacity}/>` : `<path d="${h3(d)}" fill="${color}"${opacity}/>`;
|
|
561
|
+
}).join("");
|
|
562
|
+
}
|
|
563
|
+
function annotations(layout, paint) {
|
|
564
|
+
return layout.annotations.map((note) => {
|
|
565
|
+
const color = toneColor(note.tone, paint);
|
|
566
|
+
if ((note.kind === "band" || note.kind === "forecast") && note.box) return `<rect x="${num(note.box.x)}" y="${num(note.box.y)}" width="${num(note.box.width)}" height="${num(note.box.height)}" fill="${color}" opacity="0.15"/>`;
|
|
567
|
+
if (note.kind === "line") return `<line x1="${num(note.x1)}" y1="${num(note.y1)}" x2="${num(note.x2)}" y2="${num(note.y2)}" stroke="${color}" stroke-width="1" stroke-dasharray="4 3"/>`;
|
|
568
|
+
if (note.kind === "point") return `<circle cx="${num(note.cx)}" cy="${num(note.cy)}" r="5" fill="${color}"/>`;
|
|
569
|
+
return "";
|
|
570
|
+
}).join("");
|
|
571
|
+
}
|
|
572
|
+
function labels(layout, paint) {
|
|
573
|
+
const all2 = [...layout.labels, ...layout.annotations.map((note) => note.label).filter((label) => !!label)];
|
|
574
|
+
return all2.map((label) => {
|
|
575
|
+
const dir = textDir(label.text, label.numeric);
|
|
576
|
+
const dy = label.baseline === "above" ? -3 : label.baseline === "below" ? 11 : 4;
|
|
577
|
+
const fill = label.tone ? toneColor(label.tone, paint) : paint.text;
|
|
578
|
+
return `<text x="${num(label.x)}" y="${num(label.y + dy)}" text-anchor="${anchorOf(label.anchor, dir.flip)}" direction="${dir.direction}" fill="${fill}" font-size="11">${h3(label.text)}</text>`;
|
|
579
|
+
}).join("");
|
|
580
|
+
}
|
|
581
|
+
function legend(layout, paint, y) {
|
|
582
|
+
const entries = layout.legend.filter((entry) => entry.visible);
|
|
583
|
+
if (!entries.length) return "";
|
|
584
|
+
const gap = layout.width / Math.max(entries.length, 1);
|
|
585
|
+
return entries.map((entry, index) => {
|
|
586
|
+
const color = toneColor(entry.tone, paint);
|
|
587
|
+
const x = 16 + index * Math.min(gap, 160);
|
|
588
|
+
const glyph2 = entry.glyph === "line" || entry.glyph === "area" ? `<line x1="${num(x)}" y1="${num(y)}" x2="${num(x + 16)}" y2="${num(y)}" stroke="${color}" stroke-width="2"/>` : `<rect x="${num(x)}" y="${num(y - 6)}" width="12" height="12" fill="${color}"/>`;
|
|
589
|
+
return `${glyph2}<text x="${num(x + 20)}" y="${num(y + 4)}" fill="${paint.text}" font-size="11">${h3(entry.label)}</text>`;
|
|
590
|
+
}).join("");
|
|
591
|
+
}
|
|
592
|
+
function colorScale(layout, paint, y) {
|
|
593
|
+
const scale = layout.colorScale;
|
|
594
|
+
if (!scale) return "";
|
|
595
|
+
const steps = 9;
|
|
596
|
+
const width = 140;
|
|
597
|
+
const bars = Array.from({ length: steps }, (_, i) => `<rect x="${num(16 + width / steps * i)}" y="${num(y)}" width="${num(width / steps + 0.5)}" height="8" fill="${rampColor(scale.kind, i / (steps - 1), paint)}"/>`).join("");
|
|
598
|
+
return `${bars}<text x="${num(16 + width + 8)}" y="${num(y + 8)}" fill="${paint.muted}" font-size="11">${h3(String(scale.min))} \u2013 ${h3(String(scale.max))}</text>`;
|
|
599
|
+
}
|
|
600
|
+
function paintChart(layout, paint, prefix) {
|
|
601
|
+
const showLegend = layout.legend.some((entry) => entry.visible);
|
|
602
|
+
const extra = (showLegend ? 28 : 0) + (layout.colorScale ? 24 : 0);
|
|
603
|
+
const height = layout.height + extra;
|
|
604
|
+
const font = "sans-serif";
|
|
605
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${height}" viewBox="0 0 ${layout.width} ${height}" role="img" font-family="${font}"><rect width="100%" height="100%" fill="${paint.background}"/><defs>${patternDefs(layout.patterns, paint.text, prefix)}</defs>${axes(layout, paint)}${annotations(layout, paint)}${marks(layout, paint, prefix)}${labels(layout, paint)}${legend(layout, paint, layout.height + 16)}${colorScale(layout, paint, layout.height + (showLegend ? 28 : 8))}</svg>`;
|
|
606
|
+
}
|
|
607
|
+
function colorsOf(tokens) {
|
|
608
|
+
const semantic = semanticColors2(tokens);
|
|
609
|
+
return { accent: tokens.accent, text: tokens.text, muted: tokens.muted, border: tokens.border, background: tokens.background, ok: semantic.ok, warn: semantic.warn, bad: semantic.bad, grey: semantic.grey, palette: tokens.chartPalette };
|
|
610
|
+
}
|
|
611
|
+
function specOf(node) {
|
|
612
|
+
return node.props.spec ? structuredClone(node.props.spec) : void 0;
|
|
613
|
+
}
|
|
614
|
+
function layoutOf(node, report, options) {
|
|
615
|
+
const spec = specOf(node);
|
|
616
|
+
if (!spec || node.props.empty) return void 0;
|
|
617
|
+
const model = buildChartModel(spec);
|
|
618
|
+
if (model.status !== "ok") return void 0;
|
|
619
|
+
const patterns = spec.a11y?.patterns === true || spec.a11y?.patterns === "auto";
|
|
620
|
+
return layoutChart(model, { width: 640, height: chartHeight(spec.mark), patterns, locale: report.locale || options.locale });
|
|
621
|
+
}
|
|
622
|
+
function kitChartSvg(node, report, options = {}) {
|
|
623
|
+
const layout = layoutOf(node, report, options);
|
|
624
|
+
const tokens = themeTokens3(options.theme ?? report.theme);
|
|
625
|
+
if (!layout) {
|
|
626
|
+
const message = h3(node.props.message ?? "No data to display.");
|
|
627
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="640" height="80" viewBox="0 0 640 80" role="img"><rect width="100%" height="100%" fill="${tokens.background}"/><text x="24" y="46" fill="${tokens.muted}" font-size="14" font-family="sans-serif">${message}</text></svg>`;
|
|
628
|
+
}
|
|
629
|
+
const prefix = "k" + String(node.occurrenceId).replace(/[^A-Za-z0-9]/g, "");
|
|
630
|
+
return paintChart(layout, colorsOf(tokens), prefix);
|
|
631
|
+
}
|
|
632
|
+
function kitChartTable(node, report) {
|
|
633
|
+
const spec = specOf(node);
|
|
634
|
+
if (!spec || node.props.empty) return { columns: [], cells: [] };
|
|
635
|
+
const model = buildChartModel(spec);
|
|
636
|
+
if (model.status !== "ok") return { columns: [], cells: [] };
|
|
637
|
+
const table = modelToTable(model, { locale: report.locale });
|
|
638
|
+
return { columns: table.columns.map((column) => ({ label: column.label, ...column.numeric ? { align: "right" } : {} })), cells: table.rows.map((row) => row.map((cell) => cell.text)) };
|
|
639
|
+
}
|
|
640
|
+
function kitChartDescription(node, report) {
|
|
641
|
+
const spec = specOf(node);
|
|
642
|
+
if (!spec || node.props.empty) return String(node.props.message ?? "");
|
|
643
|
+
return describeChart(spec, { locale: report.locale }).text;
|
|
644
|
+
}
|
|
645
|
+
|
|
433
646
|
// packages/reportic-render-html/src/import/index.ts
|
|
434
647
|
import { fail as fail3 } from "@x12i/reportic-core";
|
|
435
648
|
|
|
@@ -982,6 +1195,22 @@ var Exact = class {
|
|
|
982
1195
|
return make("reportic.checklist.v1", this.checklist(sec));
|
|
983
1196
|
case "code":
|
|
984
1197
|
return make("reportic.code.v1", this.code(sec));
|
|
1198
|
+
case "kit-chart":
|
|
1199
|
+
return this.kitChart(sec, id);
|
|
1200
|
+
case "divider":
|
|
1201
|
+
return make("reportic.divider.v1", {});
|
|
1202
|
+
case "footnote":
|
|
1203
|
+
return make("reportic.footnote.v1", { text: textOf(find(sec, (e) => e.tagName === "p") ?? sec, true) });
|
|
1204
|
+
case "badge":
|
|
1205
|
+
return make("reportic.badge.v1", this.badges(sec));
|
|
1206
|
+
case "columns":
|
|
1207
|
+
return make("reportic.columns.v1", this.columnStacks(sec));
|
|
1208
|
+
case "page-break":
|
|
1209
|
+
return make("reportic.page-break.v1", {});
|
|
1210
|
+
case "toc":
|
|
1211
|
+
return make("reportic.toc.v1", this.toc(sec));
|
|
1212
|
+
case "cover":
|
|
1213
|
+
return make("reportic.cover.v1", this.cover(sec));
|
|
985
1214
|
case "group": {
|
|
986
1215
|
const h22 = this.members(sec)[0];
|
|
987
1216
|
const titled = h22?.tagName === "h2";
|
|
@@ -1046,12 +1275,14 @@ var Exact = class {
|
|
|
1046
1275
|
}
|
|
1047
1276
|
metrics(sec) {
|
|
1048
1277
|
const holder = find(sec, (e) => hasClass(e, "metrics"));
|
|
1049
|
-
const
|
|
1278
|
+
const model = json(sec, "data-reportic-model");
|
|
1279
|
+
const items = (holder ? elements(holder) : []).map((div, i) => {
|
|
1050
1280
|
const part = (cls) => {
|
|
1051
1281
|
const e = find(div, (x) => hasClass(x, cls));
|
|
1052
1282
|
return e ? textOf(e) : void 0;
|
|
1053
1283
|
};
|
|
1054
|
-
|
|
1284
|
+
const extra = model?.items?.[i];
|
|
1285
|
+
return nonEmpty({ label: part("metric-label"), value: part("metric-value"), comparison: part("metric-comparison"), tone: tone(div), trend: extra?.trend, intent: extra?.intent });
|
|
1055
1286
|
});
|
|
1056
1287
|
return { items };
|
|
1057
1288
|
}
|
|
@@ -1125,9 +1356,41 @@ var Exact = class {
|
|
|
1125
1356
|
return { records };
|
|
1126
1357
|
}
|
|
1127
1358
|
callout(sec) {
|
|
1128
|
-
const aside = find(sec, (e) => e.tagName === "aside") ?? sec, strong = child(aside, (e) => e.tagName === "strong"),
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1359
|
+
const aside = find(sec, (e) => e.tagName === "aside") ?? sec, strong = child(aside, (e) => e.tagName === "strong"), paragraphs = elements(aside).filter((e) => e.tagName === "p");
|
|
1360
|
+
const model = json(sec, "data-reportic-model");
|
|
1361
|
+
const tones = ["info", "success", "warning", "danger", "neutral"];
|
|
1362
|
+
const t = tones.find((x) => hasClass(aside, `tone-${x}`));
|
|
1363
|
+
return { title: strong ? textOf(strong) : "", text: paragraphs[0] ? textOf(paragraphs[0], true) : "", ...model?.items?.length ? { items: model.items } : {}, ...t && t !== "info" ? { tone: t } : {} };
|
|
1364
|
+
}
|
|
1365
|
+
kitChart(sec, id) {
|
|
1366
|
+
const spec = json(sec, "data-reportic-spec");
|
|
1367
|
+
if (!spec) {
|
|
1368
|
+
this.ctx.warn("CHART_SPEC_LOST", "A chart has no spec on the page. It was kept as an image.", { elementId: id });
|
|
1369
|
+
return this.image(sec, id, false);
|
|
1370
|
+
}
|
|
1371
|
+
const alt = attr(find(sec, (e) => e.tagName === "img") ?? sec, "alt");
|
|
1372
|
+
return [{ id, type: "reportic.chart.v1", props: { spec, ...alt ? { alt } : {} } }];
|
|
1373
|
+
}
|
|
1374
|
+
badges(sec) {
|
|
1375
|
+
const tones = ["neutral", "accent", "success", "warning", "danger", "info"];
|
|
1376
|
+
return { items: findAll(sec, (e) => hasClass(e, "rpt-badge")).map((el2) => nonEmpty({ label: textOf(el2), tone: tones.find((t) => hasClass(el2, `rpt-${t}`)) })) };
|
|
1377
|
+
}
|
|
1378
|
+
columnStacks(sec) {
|
|
1379
|
+
const grid = find(sec, (e) => hasClass(e, "rpt-columns")) ?? sec;
|
|
1380
|
+
const columns = kids(grid).filter(isEl).map((col) => kids(col).filter(isEl).flatMap((e) => this.member(e)));
|
|
1381
|
+
return { count: columns.length, columns };
|
|
1382
|
+
}
|
|
1383
|
+
toc(sec) {
|
|
1384
|
+
const heading = find(sec, (e) => e.tagName === "h2");
|
|
1385
|
+
return nonEmpty({ title: heading ? textOf(heading) : void 0 });
|
|
1386
|
+
}
|
|
1387
|
+
cover(sec) {
|
|
1388
|
+
const header = find(sec, (e) => e.tagName === "header") ?? sec;
|
|
1389
|
+
const by = (cls) => {
|
|
1390
|
+
const e = find(header, (x) => hasClass(x, cls));
|
|
1391
|
+
return e ? textOf(e) : void 0;
|
|
1392
|
+
};
|
|
1393
|
+
return nonEmpty({ marking: by("rpt-marking"), kicker: by("rpt-kicker"), title: textOf(find(header, (e) => e.tagName === "h1") ?? header), subtitle: by("rpt-subtitle") });
|
|
1131
1394
|
}
|
|
1132
1395
|
progress(sec) {
|
|
1133
1396
|
return { items: findAll(sec, (e) => hasClass(e, "progress-item")).map((item) => {
|
|
@@ -1480,16 +1743,16 @@ var Effort = class {
|
|
|
1480
1743
|
} else if (!["p", "ul"].includes(s.tagName)) break;
|
|
1481
1744
|
}
|
|
1482
1745
|
if (run.length < 3) return false;
|
|
1483
|
-
const items = run.map((
|
|
1484
|
-
const full = text(
|
|
1485
|
-
const after = siblings.slice(siblings.indexOf(
|
|
1746
|
+
const items = run.map((h5) => {
|
|
1747
|
+
const full = text(h5), date = DATE.exec(full)[1], title = full.slice(date.length).replace(/^\s*[:\-–—·|]\s*/, "");
|
|
1748
|
+
const after = siblings.slice(siblings.indexOf(h5) + 1).find(isEl);
|
|
1486
1749
|
const body = after && after.tagName === "p" ? text(after) : "";
|
|
1487
1750
|
return { date, title, ...body ? { text: body } : {} };
|
|
1488
1751
|
});
|
|
1489
1752
|
const consumed = /* @__PURE__ */ new Set();
|
|
1490
|
-
for (const
|
|
1491
|
-
consumed.add(
|
|
1492
|
-
const after = siblings.slice(siblings.indexOf(
|
|
1753
|
+
for (const h5 of run) {
|
|
1754
|
+
consumed.add(h5);
|
|
1755
|
+
const after = siblings.slice(siblings.indexOf(h5) + 1).find(isEl);
|
|
1493
1756
|
if (after && after.tagName === "p") consumed.add(after);
|
|
1494
1757
|
}
|
|
1495
1758
|
this.emit({ id: this.ctx.uid("timeline"), type: "reportic.timeline.v1", props: { items } });
|
|
@@ -1544,9 +1807,9 @@ function importBestEffort(doc, ctx) {
|
|
|
1544
1807
|
}
|
|
1545
1808
|
|
|
1546
1809
|
// packages/reportic-render-html/src/import/theme.ts
|
|
1547
|
-
import { themeTokens as
|
|
1810
|
+
import { themeTokens as themeTokens4 } from "@x12i/reportic-core";
|
|
1548
1811
|
var PRESETS = ["editorial", "forest", "midnight", "minimal"];
|
|
1549
|
-
var
|
|
1812
|
+
var hex2 = /^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i;
|
|
1550
1813
|
var RULE_PROPS = { color: "color", "background-color": "backgroundColor", "font-size": "fontSize", "font-family": "fontFamily", "font-weight": "fontWeight", "text-align": "textAlign", "margin-top": "marginTop", "margin-bottom": "marginBottom", padding: "padding", "border-color": "borderColor", "border-width": "borderWidth" };
|
|
1551
1814
|
var unsafe = /@import|url\s*\(|expression\s*\(|<\/?style|behavior\s*:|[<>]|\\/i;
|
|
1552
1815
|
var strip = (css) => css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
@@ -1612,7 +1875,7 @@ var NAMED = { white: "#ffffff", black: "#000000", red: "#ff0000", green: "#00800
|
|
|
1612
1875
|
function toHex(value) {
|
|
1613
1876
|
if (!value) return void 0;
|
|
1614
1877
|
const v = value.trim().toLowerCase();
|
|
1615
|
-
if (
|
|
1878
|
+
if (hex2.test(v)) return v.length === 4 ? "#" + [...v.slice(1)].map((c) => c + c).join("") : v;
|
|
1616
1879
|
if (NAMED[v]) return NAMED[v];
|
|
1617
1880
|
const m = /^rgba?\(\s*(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)[ ,]+(\d+(?:\.\d+)?)(?:[ ,/]+([\d.]+%?))?\s*\)$/.exec(v);
|
|
1618
1881
|
if (!m) return void 0;
|
|
@@ -1632,9 +1895,9 @@ function px(value, base = 16) {
|
|
|
1632
1895
|
const n = Number(m[1]);
|
|
1633
1896
|
return Math.round({ px: n, pt: n * 4 / 3, em: n * base, rem: n * 16, "%": n / 100 * base }[m[2] ?? "px"] * 10) / 10;
|
|
1634
1897
|
}
|
|
1635
|
-
var
|
|
1898
|
+
var rgb2 = (h5) => [1, 3, 5].map((i) => parseInt(h5.slice(i, i + 2), 16));
|
|
1636
1899
|
var distance = (a, b) => {
|
|
1637
|
-
const x =
|
|
1900
|
+
const x = rgb2(a), y = rgb2(b);
|
|
1638
1901
|
return Math.hypot(x[0] - y[0], x[1] - y[1], x[2] - y[2]);
|
|
1639
1902
|
};
|
|
1640
1903
|
var cleanFont = (f) => {
|
|
@@ -1644,11 +1907,11 @@ var cleanFont = (f) => {
|
|
|
1644
1907
|
function match(found) {
|
|
1645
1908
|
let best = "editorial", bestScore = Infinity;
|
|
1646
1909
|
for (const name of PRESETS) {
|
|
1647
|
-
const base2 =
|
|
1910
|
+
const base2 = themeTokens4({ name });
|
|
1648
1911
|
let score = 0;
|
|
1649
1912
|
for (const k of ["accent", "text", "background", "muted", "border"]) {
|
|
1650
1913
|
const f = found[k];
|
|
1651
|
-
if (f &&
|
|
1914
|
+
if (f && hex2.test(f) && hex2.test(base2[k])) score += distance(toHex(f), toHex(base2[k]));
|
|
1652
1915
|
}
|
|
1653
1916
|
for (const k of ["fontFamily", "headingFont"]) if (found[k] && found[k] !== base2[k]) score += 60;
|
|
1654
1917
|
for (const k of ["bodySize", "headingSize", "contentWidth", "logoWidth"]) if (found[k] !== void 0 && found[k] !== base2[k]) score += 25;
|
|
@@ -1657,7 +1920,7 @@ function match(found) {
|
|
|
1657
1920
|
best = name;
|
|
1658
1921
|
}
|
|
1659
1922
|
}
|
|
1660
|
-
const base =
|
|
1923
|
+
const base = themeTokens4({ name: best }), tokens = {};
|
|
1661
1924
|
for (const [k, v] of Object.entries(found)) if (v !== void 0 && JSON.stringify(v) !== JSON.stringify(base[k])) tokens[k] = v;
|
|
1662
1925
|
return { name: best, tokens, exact: !Object.keys(tokens).length };
|
|
1663
1926
|
}
|
|
@@ -1858,14 +2121,14 @@ function readPageStyle(doc, css, ctx) {
|
|
|
1858
2121
|
const { name, tokens } = match(found);
|
|
1859
2122
|
const dropped = ["accent", "text", "background"].filter((k) => !found[k]);
|
|
1860
2123
|
ctx.note("THEME_REDUCED", `Reduced the page's design to the ${name} preset${Object.keys(tokens).length ? ` with overrides for ${Object.keys(tokens).join(", ")}` : ""}${dropped.length ? `; ${dropped.join(", ")} not found, so the preset's value is used` : ""}.`);
|
|
1861
|
-
const base =
|
|
2124
|
+
const base = themeTokens4({ name, tokens }), rules = {};
|
|
1862
2125
|
const rule = (key2, props) => {
|
|
1863
2126
|
const clean2 = Object.fromEntries(Object.entries(props).filter(([, v]) => v !== void 0));
|
|
1864
2127
|
if (Object.keys(clean2).length) rules[key2] = clean2;
|
|
1865
2128
|
};
|
|
1866
2129
|
const headings = all(doc, (e) => /^h[1-4]$/.test(e.tagName)), paragraphs = all(doc, (e) => e.tagName === "p"), tables = all(doc, (e) => e.tagName === "table");
|
|
1867
2130
|
const diff = (v, expected) => v && v !== expected ? v : void 0;
|
|
1868
|
-
rule("heading", { color: diff(same(headings.map((
|
|
2131
|
+
rule("heading", { color: diff(same(headings.map((h5) => toHex(cascade.get(h5, "color")))), base.text), textAlign: /* @__PURE__ */ ((a) => a && a !== "left" && a !== "start" ? a : void 0)(same(headings.map((h5) => cascade.get(h5, "text-align")))) });
|
|
1869
2132
|
rule("paragraph", { color: diff(same(paragraphs.map((p) => toHex(cascade.get(p, "color")))), base.text), textAlign: ((a) => a && ["center", "right", "justify"].includes(a) ? a : void 0)(same(paragraphs.map((p) => cascade.get(p, "text-align")))), fontSize: ((s) => s && Math.abs(s - base.bodySize) > 0.5 ? s : void 0)(same(paragraphs.map((p) => px(cascade.get(p, "font-size"), base.bodySize)))) });
|
|
1870
2133
|
rule("table", { backgroundColor: ((c) => c && c !== base.background ? c : void 0)(same(tables.map((t) => colorIn(cascade.get(t, "background-color"))))) });
|
|
1871
2134
|
const rulesCount = Object.keys(rules).length;
|
|
@@ -2116,7 +2379,7 @@ var clone = (v) => structuredClone(v);
|
|
|
2116
2379
|
function uniqueList(view, test) {
|
|
2117
2380
|
const hits = view.arrays.map((a) => ({ ...a, result: test(a) })).filter((a) => a.result !== void 0);
|
|
2118
2381
|
if (hits.length === 1) return { hit: hits[0] };
|
|
2119
|
-
if (hits.length > 1) return { collision: hits.map((
|
|
2382
|
+
if (hits.length > 1) return { collision: hits.map((h5) => h5.path).slice(0, 6) };
|
|
2120
2383
|
return void 0;
|
|
2121
2384
|
}
|
|
2122
2385
|
var withFormats = (columns, el2) => columns.map((c, i) => ({ ...c, ...c.format === void 0 && el2.meta?.formats?.[i] ? { format: el2.meta.formats[i] } : {} }));
|
|
@@ -2313,7 +2576,7 @@ function bindSpec(el2, view, st) {
|
|
|
2313
2576
|
return false;
|
|
2314
2577
|
}
|
|
2315
2578
|
});
|
|
2316
|
-
const paths = [...new Set(hits.map((
|
|
2579
|
+
const paths = [...new Set(hits.map((h5) => h5.path))];
|
|
2317
2580
|
if (paths.length === 1) {
|
|
2318
2581
|
el2.props.spec = { $bind: paths[0] };
|
|
2319
2582
|
st.bound.n++;
|
|
@@ -2566,8 +2829,8 @@ function importHtml(html, options = {}) {
|
|
|
2566
2829
|
}
|
|
2567
2830
|
|
|
2568
2831
|
// packages/reportic-render-html/src/index.ts
|
|
2569
|
-
var darken = (
|
|
2570
|
-
const s =
|
|
2832
|
+
var darken = (hex3, amount) => {
|
|
2833
|
+
const s = hex3.replace("#", "");
|
|
2571
2834
|
const full = s.length <= 4 ? s.slice(0, 3).split("").map((c) => c + c).join("") : s.slice(0, 6);
|
|
2572
2835
|
return "#" + [0, 2, 4].map((i) => Math.round(parseInt(full.slice(i, i + 2), 16) * (1 - amount)).toString(16).padStart(2, "0")).join("");
|
|
2573
2836
|
};
|
|
@@ -2589,18 +2852,30 @@ function featureCss(report, t, c) {
|
|
|
2589
2852
|
if (uses((n) => n.type === "metrics" && n.props.items.some((i) => i.tone))) {
|
|
2590
2853
|
css += `${scope} .rpt-metric.rpt-ok .metric-value{color:${tone2("ok")}}${scope} .rpt-metric.rpt-warn .metric-value{color:${tone2("warn")}}${scope} .rpt-metric.rpt-bad .metric-value{color:${tone2("bad")}}${scope} .rpt-metric.rpt-na .metric-value{color:${tone2("na")}}`;
|
|
2591
2854
|
}
|
|
2855
|
+
if (uses((n) => n.type === "metrics" && n.props.items.some((i) => i.intent || i.trend))) {
|
|
2856
|
+
css += `${scope} .metric-trend{font-size:11px;margin-top:4px}${scope} .rpt-intent-positive .metric-trend{color:${tone2("ok")}}${scope} .rpt-intent-negative .metric-trend{color:${tone2("bad")}}${scope} .rpt-intent-neutral .metric-trend{color:${t.muted}}`;
|
|
2857
|
+
}
|
|
2592
2858
|
if (uses((n) => n.type === "list" && n.props.variant === "callout")) {
|
|
2593
2859
|
css += `${scope} .callout.rpt-clauses strong{font-size:inherit;letter-spacing:inherit;text-transform:none}${scope} .callout.rpt-clauses p{margin:6px 0}${scope} .callout.rpt-clauses p:first-child{margin-top:0}${scope} .callout.rpt-clauses p:last-child{margin-bottom:0}`;
|
|
2594
2860
|
}
|
|
2595
|
-
if (uses((n) => n.type === "masthead")) {
|
|
2861
|
+
if (uses((n) => n.type === "masthead" || n.type === "cover")) {
|
|
2596
2862
|
css += `${scope} .rpt-masthead{margin:0 0 8px}${scope} .rpt-marking{display:inline-block;border:1.5px solid ${tone2("bad")};color:${tone2("bad")};font-weight:600;padding:2px 8px;border-radius:5px;font-size:12.5px;line-height:1.6;margin:0 0 14px}${scope} .rpt-kicker{font-size:12px;letter-spacing:.1em;text-transform:uppercase;color:${t.accent};font-weight:600;margin:0 0 10px}${scope} .rpt-masthead h1{margin-top:0}${scope} .rpt-byline{font-size:.93em;color:${t.muted};margin:0 0 18px}${scope} .rpt-byline .rpt-chip{margin-right:2px}${scope} .rpt-lead{font-size:1.13em;line-height:1.55;color:${c.ink};margin:0 0 18px}`;
|
|
2597
2863
|
}
|
|
2598
2864
|
if (uses((n) => n.type === "footer")) {
|
|
2599
2865
|
css += `${scope} .rpt-footer{margin:28px 0 0;padding:16px 0 0;font-size:12.5px;line-height:1.5;color:${t.muted};border-top:1px solid ${t.border};break-inside:avoid}${scope} .rpt-footer img{height:18px;width:auto;max-width:none;vertical-align:middle;margin-right:8px}`;
|
|
2600
2866
|
}
|
|
2601
|
-
if (uses((n) => n.type === "figure")) {
|
|
2867
|
+
if (uses((n) => n.type === "figure" || n.type === "kit-chart")) {
|
|
2602
2868
|
css += `${scope} .rpt-figure{margin:18px 0 22px;break-inside:avoid}${scope} .rpt-figure-box{border:1px solid ${t.border};border-radius:8px;background:${t.background};padding:10px 8px 4px}${scope} .rpt-figure img{display:block;width:100%;height:auto;max-height:none}${scope} .rpt-figure figcaption{font-size:12.5px;color:${t.muted};margin:6px 0 0;padding-left:2px}${scope} .rpt-figure figcaption:before{content:"Source: ";font-weight:600;color:${t.text}}${scope} .rpt-sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}`;
|
|
2603
2869
|
}
|
|
2870
|
+
if (uses((n) => n.type === "badge")) {
|
|
2871
|
+
css += `${scope} .rpt-badges{margin:8px 0 12px}${scope} .rpt-badge{display:inline-block;padding:0 7px;border-radius:5px;font-size:.92em;line-height:1.5;white-space:nowrap;margin:0 6px 6px 0}${scope} .rpt-badge.rpt-neutral{background:${c.head};color:${t.muted};border:1px solid ${t.border}}${scope} .rpt-badge.rpt-accent,${scope} .rpt-badge.rpt-info{background:${c.accentSoft};color:${t.accent};border:1px solid ${t.accent}44}${scope} .rpt-badge.rpt-success{background:${c.okSoft};color:${c.ok};border:1px solid ${c.ok}55}${scope} .rpt-badge.rpt-warning{background:${c.warnSoft};color:${darken(c.warn, 0.45)};border:1px solid ${c.warn}55}${scope} .rpt-badge.rpt-danger{background:${c.badSoft};color:${c.bad};border:1px solid ${c.bad}55}`;
|
|
2872
|
+
}
|
|
2873
|
+
if (uses((n) => n.type === "columns")) css += `${scope} .rpt-columns{display:grid;grid-template-columns:repeat(var(--cols,2),minmax(0,1fr));gap:22px;margin:12px 0;align-items:start}${scope} .rpt-columns>div>:first-child{margin-top:0}`;
|
|
2874
|
+
if (uses((n) => n.type === "footnote")) css += `${scope} .rpt-footnote{margin:8px 0 16px;font-size:12.5px;line-height:1.45;color:${t.muted}}${scope} .rpt-footnote p{margin:0}`;
|
|
2875
|
+
if (uses((n) => n.type === "toc")) css += `${scope} .rpt-toc ol{list-style:none;padding:0;margin:8px 0 0}${scope} .rpt-toc li{margin:4px 0}${scope} .rpt-toc-l2{padding-left:16px}${scope} .rpt-toc-l3{padding-left:32px}${scope} .rpt-toc-l4,${scope} .rpt-toc-l5,${scope} .rpt-toc-l6{padding-left:48px}`;
|
|
2876
|
+
if (uses((n) => n.type === "page-break")) css += `${scope} [data-reportic-type=page-break]{margin:0}${scope} .rpt-break{break-before:page;page-break-before:always;height:0}`;
|
|
2877
|
+
if (uses((n) => n.type === "cover")) css += `${scope} [data-reportic-type=cover]{break-after:page;page-break-after:always}${scope} .rpt-subtitle{font-size:1.15em;color:${t.muted}}`;
|
|
2878
|
+
if (uses((n) => n.type === "callout" && n.props.tone === "neutral")) css += `${scope} .callout.tone-neutral{border-left-color:${t.border};background:${t.background}}`;
|
|
2604
2879
|
if (t.layout === "card") css += cardCss(t, c);
|
|
2605
2880
|
return css;
|
|
2606
2881
|
}
|
|
@@ -2613,8 +2888,8 @@ function cardCss(t, c) {
|
|
|
2613
2888
|
return `@media screen{body{background:${c.page}}}${s}{background:${t.background};border:1px solid ${rule};border-top:5px solid ${t.accent};border-radius:12px;padding:36px 36px 28px;margin:32px auto 48px;line-height:1.6}${s} h1,${s} h2,${s} h3{color:${c.ink};font-weight:600;letter-spacing:0}${s} h1{line-height:1.15;margin:0 0 10px}${s} h2{font-size:22px;line-height:1.3;margin:34px 0 10px;padding-top:14px;border-top:1px solid ${rule}}${s} h3{font-family:${t.fontFamily};font-size:16.5px;margin:24px 0 8px}${s} h2:first-child{border-top:0;padding-top:0;margin-top:0}${s} p{margin:0 0 12px}${s} strong{color:${c.ink};font-weight:600}${s} code{background:${c.head};color:${c.ink};padding:1px 5px;border-radius:4px}${s} pre{background:${c.head};border-radius:8px;padding:12px 14px;font-size:13px}${s} li::marker{color:${t.muted}}${s} ul,${s} ol{margin:0 0 14px;padding-left:22px}${s} li{margin:4px 0}${s},${s} td,${s} th{overflow-wrap:break-word}${s} th{vertical-align:top}${s} th.rpt-rowheader{padding:8px 11px}${s} table{border-collapse:separate;border-spacing:0;border:1px solid ${rule};border-radius:8px;overflow:hidden;font-size:13.5px;line-height:1.45;font-variant-numeric:tabular-nums;margin:14px 0 20px}${s} th{background:${c.head};color:${c.ink};padding:8px 11px;border-bottom:1px solid ${strong}}${s} td{padding:8px 11px;border-bottom:1px solid ${rule}}${s} tbody tr:last-child td{border-bottom:0}${s} tr:nth-child(even) td{background:${c.zebra}}${s} blockquote{background:${c.accentSoft}}${s} .callout{margin:16px 0 18px;padding:14px 18px;background:${t.accent}0d;border:0;border-left:4px solid ${t.accent};border-radius:0 8px 8px 0}${s} .callout.tone-warning{background:${c.warnSoft};border-left-color:${c.warn}}${s} .callout.tone-danger{background:${c.badSoft};border-left-color:${c.bad}}${s} .callout.tone-success{background:${c.okSoft};border-left-color:${c.ok}}${s} .callout p{margin:0 0 8px}${s} .callout p:last-child{margin-bottom:0}${s} .metrics{border:0;padding:0;margin:14px 0 18px;gap:12px;grid-template-columns:repeat(auto-fit,minmax(150px,1fr))}${s} .metrics>div{display:flex;flex-direction:column;border:1px solid ${rule};border-radius:8px;padding:12px 14px;background:${c.zebra}}${s} .metric-value{order:1;font-family:${t.headingFont};font-size:var(--metric-size,28px);line-height:1.1;color:${c.ink};letter-spacing:0}${s} .metric-label{order:2;font-size:12.5px;letter-spacing:0;text-transform:none;color:${t.muted};margin:4px 0 0;line-height:1.35}${s} .metric-comparison{order:3;font-size:12.5px;color:${t.text};margin-top:4px}${s} .rpt-lead{font-size:17px}${s} .rpt-byline{font-size:14px}${s} [data-reportic-type=logo]{margin:0 0 16px}${s} [data-reportic-type=logo] figure{margin:0}${s} [data-reportic-type=logo] img{display:block;height:44px;width:auto;max-width:none;max-height:none}@media(max-width:600px){${s}{padding:22px 18px 18px;border-radius:10px;margin:14px auto 32px}${s} h1{font-size:26px}${s} h2{font-size:19.5px}${s} table{font-size:13px}${s} th,${s} td{padding:7px 9px}}@media print{body{background:#fff}${s}{border:0;border-top:4px solid ${t.accent};border-radius:0;padding:12px 0 0;margin:0;max-width:none;font-size:10.5pt}${s} table{font-size:9pt}${s} tr,${s} .callout{break-inside:avoid}${s} [data-reportic-type=logo] img{height:12mm}${s} .rpt-footer img{height:4mm}}`;
|
|
2614
2889
|
}
|
|
2615
2890
|
function reportCss(report, options = {}) {
|
|
2616
|
-
const t =
|
|
2617
|
-
const feature = tokenProperties((options.theme ?? report.theme).tokens) + featureCss(report, t,
|
|
2891
|
+
const t = themeTokens5(options.theme ?? report.theme);
|
|
2892
|
+
const feature = tokenProperties((options.theme ?? report.theme).tokens) + featureCss(report, t, semanticColors3(t));
|
|
2618
2893
|
const rules = Object.entries((options.theme ?? report.theme).rules ?? {}).sort(([a], [b]) => Number(!["document", "heading", "paragraph", "table", "metric", "chart", "diagram", "image", "logo"].includes(a)) - Number(!["document", "heading", "paragraph", "table", "metric", "chart", "diagram", "image", "logo"].includes(b))).map(([key2, value]) => {
|
|
2619
2894
|
const selector = key2 === "document" ? ".reportic-report" : key2 === "heading" ? ".reportic-report :is(h1,h2,h3,h4)" : key2 === "paragraph" ? ".reportic-report p" : ["table", "metric", "chart", "diagram", "image", "logo"].includes(key2) ? `.reportic-report [data-reportic-type="${key2 === "metric" ? "metrics" : key2}"]` : `.reportic-report [data-reportic-id="${key2}"]`;
|
|
2620
2895
|
return `${selector}{${Object.entries(value).map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())}:${typeof v === "number" && !["fontWeight", "lineHeight"].includes(k) ? v + "px" : v}`).join(";")}}`;
|
|
@@ -2627,7 +2902,7 @@ function assetData(asset) {
|
|
|
2627
2902
|
}
|
|
2628
2903
|
function cleanMarkdownHtml(markdown, report, options = {}) {
|
|
2629
2904
|
const renderer = new marked.Renderer();
|
|
2630
|
-
renderer.html = ({ text: text2 }) =>
|
|
2905
|
+
renderer.html = ({ text: text2 }) => h4(text2);
|
|
2631
2906
|
renderer.image = ({ href, text: text2 }) => {
|
|
2632
2907
|
let src = href;
|
|
2633
2908
|
if (/^https:\/\//.test(src)) {
|
|
@@ -2639,29 +2914,30 @@ function cleanMarkdownHtml(markdown, report, options = {}) {
|
|
|
2639
2914
|
if (asset) src = options.html?.assetMode === "bundled" ? asset.path : assetData(asset);
|
|
2640
2915
|
else fail4("ASSET_MISSING", `Markdown image "${src}" needs a registered asset for portable export.`);
|
|
2641
2916
|
}
|
|
2642
|
-
return `<img src="${
|
|
2917
|
+
return `<img src="${h4(src)}" alt="${h4(text2)}">`;
|
|
2643
2918
|
};
|
|
2644
2919
|
return sanitizeHtml(marked.parse(markdown, { async: false, gfm: true, renderer }), { allowedTags: [...sanitizeHtml.defaults.allowedTags, "img", "del", "input"], allowedAttributes: { a: ["href", "title"], img: ["src", "alt"], th: ["align", "style"], td: ["align", "style"], input: ["type", "checked", "disabled"] }, allowedStyles: { "*": { "text-align": [/^left$/, /^right$/, /^center$/] } }, allowedSchemes: ["https", "http", "mailto"], allowedSchemesByTag: { img: ["data", "https"] }, allowProtocolRelative: false });
|
|
2645
2920
|
}
|
|
2646
|
-
var codeHtml = (raw) => raw.length > 16 ? `<code class="rpt-long">${
|
|
2921
|
+
var codeHtml = (raw) => raw.length > 16 ? `<code class="rpt-long">${h4(raw).replace(/([_\-/.,])(?=\S)/g, "$1<wbr>")}</code>` : `<code>${h4(raw)}</code>`;
|
|
2647
2922
|
var runHtml = (run) => {
|
|
2648
|
-
const text2 =
|
|
2649
|
-
return run.tone ? `<span class="rpt-rating rpt-${
|
|
2923
|
+
const text2 = h4(run.text).replace(/\n/g, "<br>");
|
|
2924
|
+
return run.tone ? `<span class="rpt-rating rpt-${h4(run.tone)}">${text2}</span>` : run.code ? codeHtml(String(run.text)) : run.strong ? `<strong>${text2}</strong>` : text2;
|
|
2650
2925
|
};
|
|
2651
2926
|
var cellInner = (cell) => {
|
|
2652
2927
|
if (cell && typeof cell === "object") {
|
|
2653
2928
|
if (cell.runs) return cell.runs.map(runHtml).join("");
|
|
2654
|
-
if (cell.kind === "rating" && cell.tone) return `<span class="rpt-rating rpt-${
|
|
2655
|
-
if (cell.kind === "status" && cell.text) return `<span class="rpt-chip rpt-status${cell.status ? ` rpt-${
|
|
2656
|
-
if (cell.kind === "date" && cell.text) return `<span class="rpt-chip rpt-date">${
|
|
2929
|
+
if (cell.kind === "rating" && cell.tone) return `<span class="rpt-rating rpt-${h4(cell.tone)}">${h4(cell.text)}</span>`;
|
|
2930
|
+
if (cell.kind === "status" && cell.text) return `<span class="rpt-chip rpt-status${cell.status ? ` rpt-${h4(cell.status)}` : ""}">${h4(cell.text)}</span>`;
|
|
2931
|
+
if (cell.kind === "date" && cell.text) return `<span class="rpt-chip rpt-date">${h4(cell.text)}</span>`;
|
|
2657
2932
|
if (cell.kind === "code" && cell.text) return codeHtml(String(cell.text));
|
|
2658
2933
|
}
|
|
2659
|
-
return
|
|
2934
|
+
return h4(cell.text ?? cell);
|
|
2660
2935
|
};
|
|
2661
|
-
var rawAttr = (cell) => cell && typeof cell === "object" && cell.text ? cell.kind === "date" && typeof cell.raw === "string" ? ` data-reportic-raw="${
|
|
2662
|
-
var kindAttr = (c) => `${c.kind ? ` data-reportic-kind="${
|
|
2663
|
-
var tableHtml = (columns, cells, className = "", options = {}) => `<table class="${className}">${options.headers === false ? "" : `<thead><tr>${columns.map((c) => `<th scope="col" style="text-align:${c.align ?? "left"}"${kindAttr(c)}>${
|
|
2664
|
-
var stamp = (name, value) => ` data-reportic-${name}="${
|
|
2936
|
+
var rawAttr = (cell) => cell && typeof cell === "object" && cell.text ? cell.kind === "date" && typeof cell.raw === "string" ? ` data-reportic-raw="${h4(cell.raw)}"` : cell.kind === "list" && Array.isArray(cell.raw) && cell.raw.length ? ` data-reportic-raw="${h4(JSON.stringify(cell.raw))}"` : "" : "";
|
|
2937
|
+
var kindAttr = (c) => `${c.kind ? ` data-reportic-kind="${h4(c.kind)}"` : ""}${c.format ? ` data-reportic-format="${h4(c.format)}"` : ""}`;
|
|
2938
|
+
var tableHtml = (columns, cells, className = "", options = {}) => `<table class="${className}">${options.headers === false ? "" : `<thead><tr>${columns.map((c) => `<th scope="col" style="text-align:${c.align ?? "left"}"${kindAttr(c)}>${h4(c.label)}</th>`).join("")}</tr></thead>`}<tbody>${cells.map((row) => `<tr${row[0]?.total ? ' class="rpt-total"' : ""}>${row.map((cell, i) => options.rowHeader && i === 0 ? `<th scope="row" class="rpt-rowheader" style="text-align:${columns[i].align ?? "left"}"${rawAttr(cell)}>${cellInner(cell)}</th>` : `<td style="text-align:${columns[i].align ?? "left"}${columns[i].nowrap ? ";white-space:nowrap" : ""}"${rawAttr(cell)}>${cellInner(cell)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
|
|
2939
|
+
var stamp = (name, value) => ` data-reportic-${name}="${h4(typeof value === "string" ? value : JSON.stringify(value))}"`;
|
|
2940
|
+
var trendWord = (trend) => trend === "up" ? "Up" : trend === "down" ? "Down" : trend === "flat" ? "Flat" : "";
|
|
2665
2941
|
function chartTable(node, report) {
|
|
2666
2942
|
const p = node.props;
|
|
2667
2943
|
return { columns: [{ label: p.x.label }, ...p.series.map((s) => ({ label: s.label, align: "right" }))], cells: p.categories.map((c, i) => [c, ...p.series.map((s) => formatValue3(s.values[i], s.format, report.locale, report.timezone))]) };
|
|
@@ -2681,91 +2957,144 @@ async function renderHtml(report, options = {}) {
|
|
|
2681
2957
|
};
|
|
2682
2958
|
const render = (node) => {
|
|
2683
2959
|
const p = node.props;
|
|
2684
|
-
let content = "",
|
|
2960
|
+
let content = "", marks2 = "";
|
|
2685
2961
|
switch (node.type) {
|
|
2686
|
-
case "markdown":
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2962
|
+
case "markdown": {
|
|
2963
|
+
const html2 = cleanMarkdownHtml(p.markdown, report, options);
|
|
2964
|
+
return p.token?.type === "heading" ? html2.replace(/<h([1-6])(?![^>]*\sid=)/, `<h$1 id="${h4(node.occurrenceId)}"`) : html2;
|
|
2965
|
+
}
|
|
2966
|
+
case "metrics": {
|
|
2967
|
+
const extra = p.items.some((i) => i.trend || i.intent);
|
|
2968
|
+
if (extra) marks2 = stamp("model", { items: p.items.map((i) => ({ ...i.trend ? { trend: i.trend } : {}, ...i.intent ? { intent: i.intent } : {} })) });
|
|
2969
|
+
content = `<div class="metrics" style="--metric-count:${Math.min(p.items.length, 4)}">${p.items.map((i) => {
|
|
2970
|
+
const cls = [i.tone ? `rpt-metric rpt-${h4(i.tone)}` : "", i.intent ? `rpt-intent-${h4(i.intent)}` : ""].filter(Boolean).join(" ");
|
|
2971
|
+
return `<div${cls ? ` class="${cls}"` : ""}><p class="metric-label">${h4(i.label)}</p><div class="metric-value" style="--metric-size:${Math.min(28, Math.max(12, Math.floor(222 / Math.max(1, i.display.length))))}px">${h4(i.display)}</div>${i.comparison ? `<div class="metric-comparison">${h4(i.comparison)}</div>` : ""}${i.trend ? `<div class="metric-trend">${h4(trendWord(i.trend))}</div>` : ""}</div>`;
|
|
2972
|
+
}).join("")}</div>`;
|
|
2690
2973
|
break;
|
|
2974
|
+
}
|
|
2691
2975
|
case "table":
|
|
2692
|
-
content = p.rows.length ? tableHtml(p.columns, p.cells, "", { headers: p.headers, rowHeader: p.rowHeader }) : `<p class="empty">${
|
|
2976
|
+
content = p.rows.length ? tableHtml(p.columns, p.cells, "", { headers: p.headers, rowHeader: p.rowHeader }) : `<p class="empty">${h4(p.empty ?? "No rows to display.")}</p>`;
|
|
2693
2977
|
break;
|
|
2694
2978
|
case "chart": {
|
|
2695
2979
|
if (!p.categories.length) {
|
|
2696
|
-
content = `<p class="empty">${
|
|
2980
|
+
content = `<p class="empty">${h4(p.empty ?? "No data to display.")}</p>`;
|
|
2697
2981
|
break;
|
|
2698
2982
|
}
|
|
2699
2983
|
const data = chartTable(node, report);
|
|
2700
|
-
|
|
2701
|
-
content = `<figure class="chart"><h3>${
|
|
2984
|
+
marks2 = stamp("kind", p.kind) + stamp("model", { title: p.title, alt: p.alt, x: { label: p.x.label }, categories: p.categories, series: p.series.map((s) => ({ label: s.label, ...s.format ? { format: s.format } : {}, values: s.values })) });
|
|
2985
|
+
content = `<figure class="chart"><h3>${h4(p.title)}</h3><img src="${image(node, chartSvg(node, report, options))}" alt="${h4(p.alt)}"/></figure>${tableHtml(data.columns, data.cells, "chart-data")}`;
|
|
2702
2986
|
break;
|
|
2703
2987
|
}
|
|
2704
2988
|
case "diagram":
|
|
2705
|
-
|
|
2706
|
-
content = `<figure class="diagram"><img src="${image(node, diagrams.get(node.occurrenceId))}" alt="${
|
|
2989
|
+
marks2 = stamp("model", { ...p.adapter ? { adapter: p.adapter, model: p.model } : { source: p.source }, alt: p.alt, ...p.caption ? { caption: p.caption } : {} });
|
|
2990
|
+
content = `<figure class="diagram"><img src="${image(node, diagrams.get(node.occurrenceId))}" alt="${h4(p.alt)}"/><figcaption>${h4(p.caption ?? p.alt)}</figcaption></figure>`;
|
|
2707
2991
|
break;
|
|
2708
2992
|
case "logo":
|
|
2709
2993
|
case "image":
|
|
2710
|
-
content = `<figure><img src="${
|
|
2994
|
+
content = `<figure><img src="${h4(image(node))}" alt="${h4(p.alt)}"/>${p.caption ? `<figcaption>${h4(p.caption)}</figcaption>` : ""}</figure>`;
|
|
2711
2995
|
break;
|
|
2712
2996
|
case "narrative":
|
|
2713
|
-
content = `${p.heading ? `<h3>${
|
|
2997
|
+
content = `${p.heading ? `<h3>${h4(p.heading)}</h3>` : ""}<p>${h4(p.text).replace(/\n/g, "<br>")}${(p.citations ?? []).map((n) => `<a class="evidence" href="#source-${n}">[${n}]</a>`).join("")}</p>`;
|
|
2714
2998
|
break;
|
|
2715
2999
|
case "list": {
|
|
2716
|
-
const lead = (i) => p.leads?.[i] ? `<strong>${
|
|
2717
|
-
content = !p.items.length ? `<p class="empty">${
|
|
3000
|
+
const lead = (i) => p.leads?.[i] ? `<strong>${h4(p.leads[i])}</strong> ` : "";
|
|
3001
|
+
content = !p.items.length ? `<p class="empty">${h4(p.empty ?? "No items to display.")}</p>` : p.variant === "callout" ? `<aside class="callout rpt-clauses">${p.items.map((s, i) => `<p>${lead(i)}${h4(s)}</p>`).join("")}</aside>` : p.variant === "paragraphs" ? p.items.map((s, i) => `<p>${lead(i)}${h4(s)}</p>`).join("") : `<${p.ordered ? "ol" : "ul"}>${p.items.map((s, i) => `<li>${lead(i)}${h4(s)}</li>`).join("")}</${p.ordered ? "ol" : "ul"}>`;
|
|
2718
3002
|
break;
|
|
2719
3003
|
}
|
|
2720
3004
|
case "sources":
|
|
2721
|
-
content = `<ol class="source-list">${p.citations.map((s) => `<li id="source-${s.number}" value="${s.number}">${s.url ? `<a href="${
|
|
3005
|
+
content = `<ol class="source-list">${p.citations.map((s) => `<li id="source-${s.number}" value="${s.number}">${s.url ? `<a href="${h4(s.url)}">${h4(s.label)}</a>` : h4(s.label)}</li>`).join("")}</ol>`;
|
|
2722
3006
|
break;
|
|
2723
3007
|
case "group":
|
|
2724
|
-
content = `${p.heading ? `<h2>${
|
|
3008
|
+
content = `${p.heading ? `<h2>${h4(p.heading)}</h2>` : ""}${(node.children ?? []).map(render).join("")}`;
|
|
2725
3009
|
break;
|
|
2726
3010
|
case "repeat":
|
|
2727
|
-
content = node.children?.length ? node.children.map(render).join("") : `<p class="empty">${
|
|
3011
|
+
content = node.children?.length ? node.children.map(render).join("") : `<p class="empty">${h4(p.empty ?? "No items to display.")}</p>`;
|
|
2728
3012
|
break;
|
|
2729
|
-
case "callout":
|
|
2730
|
-
|
|
3013
|
+
case "callout": {
|
|
3014
|
+
const items = Array.isArray(p.items) ? p.items : [];
|
|
3015
|
+
if (items.length) marks2 = stamp("model", { items, ...p.tone ? { tone: p.tone } : {} });
|
|
3016
|
+
content = `<aside class="callout tone-${h4(p.tone ?? "info")}">${p.title === "" ? "" : `<strong>${h4(p.title)}</strong>`}<p>${h4(p.text)}</p>${items.map((item) => `<p>${item.label ? `<strong>${h4(item.label)}</strong> ` : ""}${h4(item.text)}</p>`).join("")}</aside>`;
|
|
2731
3017
|
break;
|
|
3018
|
+
}
|
|
2732
3019
|
case "masthead":
|
|
2733
|
-
if (p.byline?.length)
|
|
2734
|
-
content = `<header class="rpt-masthead">${p.marking ? `<div class="rpt-marking">${
|
|
3020
|
+
if (p.byline?.length) marks2 = stamp("model", { byline: p.byline.map((i) => ({ value: i.value, ...i.format ? { format: i.format } : {}, ...i.kind ? { kind: i.kind } : {} })) });
|
|
3021
|
+
content = `<header class="rpt-masthead">${p.marking ? `<div class="rpt-marking">${h4(p.marking)}</div>` : ""}${p.kicker ? `<p class="rpt-kicker">${h4(p.kicker)}</p>` : ""}<h1>${h4(p.title)}</h1>${p.byline?.length ? `<p class="rpt-byline">${p.byline.map((i) => i.kind === "date" || i.kind === "person" ? `<span class="rpt-chip rpt-${i.kind}">${h4(i.display)}</span>` : h4(i.display)).join(" \xB7 ")}</p>` : ""}${p.lead ? `<p class="rpt-lead">${h4(p.lead)}</p>` : ""}</header>`;
|
|
2735
3022
|
break;
|
|
2736
3023
|
case "footer": {
|
|
2737
3024
|
const logo = p.logoImage;
|
|
2738
3025
|
const src = logo ? report.assets.find((a) => a.path === logo.src) ? options.html?.assetMode === "bundled" ? logo.src : assetData(report.assets.find((a) => a.path === logo.src)) : logo.src : "";
|
|
2739
|
-
content = `<footer class="rpt-footer">${logo ? `<img src="${
|
|
3026
|
+
content = `<footer class="rpt-footer">${logo ? `<img src="${h4(src)}" alt="${h4(logo.alt)}"/>` : ""}${h4(p.text)}</footer>`;
|
|
2740
3027
|
break;
|
|
2741
3028
|
}
|
|
2742
3029
|
case "figure": {
|
|
2743
3030
|
const svg = figureSvg(node, report, options);
|
|
2744
|
-
|
|
2745
|
-
content = `<figure class="rpt-figure"><div class="rpt-figure-box"><img src="${image(node, svg)}" alt="${
|
|
3031
|
+
marks2 = stamp("kind", p.figure.kind) + stamp("spec", figureSpec2(p.figure));
|
|
3032
|
+
content = `<figure class="rpt-figure"><div class="rpt-figure-box"><img src="${image(node, svg)}" alt="${h4(p.alt)}"/></div>${p.source ? `<figcaption>${h4(p.source)}</figcaption>` : ""}</figure><div class="rpt-sr-only">${tableHtml(p.table.columns, p.table.cells)}</div>`;
|
|
2746
3033
|
break;
|
|
2747
3034
|
}
|
|
2748
3035
|
case "progress":
|
|
2749
|
-
content = p.items.map((i) => `<div class="progress-item"><div class="progress-label"><span>${
|
|
3036
|
+
content = p.items.map((i) => `<div class="progress-item"><div class="progress-label"><span>${h4(i.label)}</span><strong>${formatValue3(i.value, "percent:0", report.locale)}</strong></div><div class="progress-track" role="progressbar" aria-label="${h4(i.label)}" aria-valuenow="${i.value * 100}" aria-valuemin="0" aria-valuemax="100"><span style="width:${i.value * 100}%"></span></div>${i.detail ? `<small>${h4(i.detail)}</small>` : ""}</div>`).join("");
|
|
2750
3037
|
break;
|
|
2751
3038
|
case "timeline":
|
|
2752
|
-
content = p.items.map((i) => `<div class="timeline-item"><div class="timeline-date">${
|
|
3039
|
+
content = p.items.map((i) => `<div class="timeline-item"><div class="timeline-date">${h4(i.date)}</div><strong>${h4(i.title)}</strong>${i.text ? `<p>${h4(i.text)}</p>` : ""}</div>`).join("");
|
|
2753
3040
|
break;
|
|
2754
3041
|
case "comparison":
|
|
2755
3042
|
content = tableHtml([{ label: "", align: "left" }, ...p.labels.map((s) => ({ label: s }))], p.rows.map((r) => [r.label, r.left, r.right]));
|
|
2756
3043
|
break;
|
|
2757
3044
|
case "checklist":
|
|
2758
|
-
content = `<ul class="checklist">${p.items.map((i) => `<li><span class="checkmark">${i.done ? "\u2611" : "\u2610"}</span>${
|
|
3045
|
+
content = `<ul class="checklist">${p.items.map((i) => `<li><span class="checkmark">${i.done ? "\u2611" : "\u2610"}</span>${h4(i.text)}${i.owner ? ` <small>\xB7 ${h4(i.owner)}</small>` : ""}</li>`).join("")}</ul>`;
|
|
2759
3046
|
break;
|
|
2760
3047
|
case "code":
|
|
2761
|
-
content = `${p.language ? `<small>${
|
|
3048
|
+
content = `${p.language ? `<small>${h4(p.language)}</small>` : ""}<pre><code>${h4(p.code)}</code></pre>${p.caption ? `<p>${h4(p.caption)}</p>` : ""}`;
|
|
3049
|
+
break;
|
|
3050
|
+
case "kit-chart": {
|
|
3051
|
+
if (p.empty) {
|
|
3052
|
+
content = `<p class="empty">${h4(p.message ?? "No data to display.")}</p>`;
|
|
3053
|
+
break;
|
|
3054
|
+
}
|
|
3055
|
+
const data = kitChartTable(node, report);
|
|
3056
|
+
marks2 = stamp("spec", p.spec);
|
|
3057
|
+
content = `<figure class="rpt-figure rpt-kit-chart"><div class="rpt-figure-box"><img src="${image(node, kitChartSvg(node, report, options))}" alt="${h4(p.alt)}"/></div>${p.source ? `<figcaption>${h4(p.source)}</figcaption>` : ""}<p class="rpt-sr-only">${h4(kitChartDescription(node, report))}</p></figure>${data.cells.length ? tableHtml(data.columns, data.cells, "chart-data") : ""}`;
|
|
3058
|
+
break;
|
|
3059
|
+
}
|
|
3060
|
+
case "divider":
|
|
3061
|
+
content = "<hr>";
|
|
3062
|
+
break;
|
|
3063
|
+
case "footnote":
|
|
3064
|
+
content = `<aside class="rpt-footnote"><p>${h4(p.text)}</p></aside>`;
|
|
3065
|
+
break;
|
|
3066
|
+
case "badge":
|
|
3067
|
+
content = `<p class="rpt-badges">${p.items.map((item) => `<span class="rpt-chip rpt-badge rpt-${h4(item.tone ?? "neutral")}">${h4(item.label)}</span>`).join("")}</p>`;
|
|
3068
|
+
break;
|
|
3069
|
+
case "columns": {
|
|
3070
|
+
const kids2 = node.children ?? [];
|
|
3071
|
+
const spans = Array.isArray(p.spans) && p.spans.length ? p.spans : [kids2.length];
|
|
3072
|
+
let i = 0;
|
|
3073
|
+
content = `<div class="rpt-columns" style="--cols:${spans.length}">${spans.map((span) => {
|
|
3074
|
+
const slice = kids2.slice(i, i + span);
|
|
3075
|
+
i += span;
|
|
3076
|
+
return `<div>${slice.map(render).join("")}</div>`;
|
|
3077
|
+
}).join("")}</div>`;
|
|
3078
|
+
break;
|
|
3079
|
+
}
|
|
3080
|
+
case "page-break":
|
|
3081
|
+
content = '<div class="rpt-break"></div>';
|
|
3082
|
+
break;
|
|
3083
|
+
case "toc": {
|
|
3084
|
+
const items = p.items ?? [];
|
|
3085
|
+
const title = p.title || "Contents";
|
|
3086
|
+
content = `<nav class="rpt-toc"><h2>${h4(title)}</h2>${items.length ? `<ol>${items.map((item) => `<li class="rpt-toc-l${h4(String(item.level))}"><a href="#${h4(item.anchor)}">${h4(item.text)}</a></li>`).join("")}</ol>` : `<p class="empty">No headings yet.</p>`}</nav>`;
|
|
3087
|
+
break;
|
|
3088
|
+
}
|
|
3089
|
+
case "cover":
|
|
3090
|
+
content = `<header class="rpt-cover">${p.marking ? `<div class="rpt-marking">${h4(p.marking)}</div>` : ""}${p.kicker ? `<p class="rpt-kicker">${h4(p.kicker)}</p>` : ""}<h1>${h4(p.title)}</h1>${p.subtitle ? `<p class="rpt-subtitle">${h4(p.subtitle)}</p>` : ""}</header>`;
|
|
2762
3091
|
break;
|
|
2763
3092
|
default:
|
|
2764
3093
|
fail4("RENDERER_UNAVAILABLE", `No HTML representation for semantic type ${node.type}.`, { elementId: node.id, phase: "render" });
|
|
2765
3094
|
}
|
|
2766
|
-
return `<section data-reportic-type="${
|
|
3095
|
+
return `<section data-reportic-type="${h4(node.type)}" id="${h4(node.occurrenceId)}" data-reportic-id="${h4(node.id)}" data-reportic-occurrence="${h4(node.occurrenceId)}"${marks2}>${content}</section>`;
|
|
2767
3096
|
};
|
|
2768
|
-
const html = `<!doctype html><html lang="${
|
|
3097
|
+
const html = `<!doctype html><html lang="${h4(report.locale)}"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="generator" content="Reportic 0.2"><title>${h4(report.title)}</title><style>${reportCss(report, options)}</style></head><body><main class="reportic-report">${report.nodes.map(render).join("\n")}</main></body></html>`;
|
|
2769
3098
|
return { html, assets: [...report.assets, ...generated] };
|
|
2770
3099
|
}
|
|
2771
3100
|
async function renderMarkdown(report, options = {}) {
|
|
@@ -2780,7 +3109,7 @@ ${cells.map((row) => `| ${row.map((v) => md(v.text ?? v)).join(" | ")} |`).join(
|
|
|
2780
3109
|
case "markdown":
|
|
2781
3110
|
return p.markdown;
|
|
2782
3111
|
case "metrics":
|
|
2783
|
-
return p.items.map((i) => `**${md(i.label)}:** ${md(i.display)}${i.comparison ? ` (${md(i.comparison)})` : ""}`).join("\n\n");
|
|
3112
|
+
return p.items.map((i) => `**${md(i.label)}:** ${md(i.display)}${i.comparison ? ` (${md(i.comparison)})` : ""}${i.trend ? ` (${trendWord(i.trend)})` : ""}`).join("\n\n");
|
|
2784
3113
|
case "table":
|
|
2785
3114
|
return p.rows.length ? table(p.columns, p.cells) : md(p.empty ?? "No rows to display.");
|
|
2786
3115
|
case "chart": {
|
|
@@ -2846,10 +3175,11 @@ ${table(p.table.columns, p.table.cells)}`;
|
|
|
2846
3175
|
` : ""}${(n.children ?? []).map(render).join("\n\n")}`;
|
|
2847
3176
|
case "repeat":
|
|
2848
3177
|
return n.children?.length ? n.children.map(render).join("\n\n") : md(p.empty ?? "No items to display.");
|
|
2849
|
-
case "callout":
|
|
2850
|
-
|
|
2851
|
-
>
|
|
2852
|
-
|
|
3178
|
+
case "callout": {
|
|
3179
|
+
const lines = [`> **${md(p.title)}**`, `>`, `> ${md(p.text)}`];
|
|
3180
|
+
for (const item of p.items ?? []) lines.push(">", `> ${item.label ? `**${md(item.label)}** ` : ""}${md(item.text)}`);
|
|
3181
|
+
return lines.join("\n");
|
|
3182
|
+
}
|
|
2853
3183
|
case "progress":
|
|
2854
3184
|
return p.items.map((i) => `- **${md(i.label)}:** ${formatValue3(i.value, "percent:0", report.locale)}${i.detail ? " \u2014 " + md(i.detail) : ""}`).join("\n");
|
|
2855
3185
|
case "timeline":
|
|
@@ -2864,6 +3194,43 @@ ${table(p.table.columns, p.table.cells)}`;
|
|
|
2864
3194
|
${p.code}
|
|
2865
3195
|
${ticks}`;
|
|
2866
3196
|
}
|
|
3197
|
+
case "kit-chart": {
|
|
3198
|
+
if (p.empty) return md(p.message ?? "No data to display.");
|
|
3199
|
+
const data = kitChartTable(n, report);
|
|
3200
|
+
const path = `assets/${n.occurrenceId}.svg`;
|
|
3201
|
+
assets.push({ path, mediaType: "image/svg+xml", bytes: Buffer.from(kitChartSvg(n, report, options)) });
|
|
3202
|
+
return `### ${md(p.title)}
|
|
3203
|
+
|
|
3204
|
+
${p.source ? `
|
|
3205
|
+
|
|
3206
|
+
Source: ${md(p.source)}` : ""}
|
|
3207
|
+
|
|
3208
|
+
${table(data.columns, data.cells)}`;
|
|
3209
|
+
}
|
|
3210
|
+
case "divider":
|
|
3211
|
+
return "---";
|
|
3212
|
+
case "footnote":
|
|
3213
|
+
return `*${md(p.text)}*`;
|
|
3214
|
+
case "badge":
|
|
3215
|
+
return p.items.map((item) => `**${md(item.label)}**`).join(" \xB7 ");
|
|
3216
|
+
case "columns": {
|
|
3217
|
+
const kids2 = n.children ?? [];
|
|
3218
|
+
const spans = Array.isArray(p.spans) && p.spans.length ? p.spans : [kids2.length];
|
|
3219
|
+
let i = 0;
|
|
3220
|
+
return spans.map((span) => {
|
|
3221
|
+
const slice = kids2.slice(i, i + span);
|
|
3222
|
+
i += span;
|
|
3223
|
+
return slice.map(render).join("\n\n");
|
|
3224
|
+
}).filter(Boolean).join("\n\n");
|
|
3225
|
+
}
|
|
3226
|
+
case "page-break":
|
|
3227
|
+
return "<!-- pagebreak -->";
|
|
3228
|
+
case "toc": {
|
|
3229
|
+
const items = p.items ?? [];
|
|
3230
|
+
return [`## ${md(p.title || "Contents")}`, ...items.map((item) => `${" ".repeat(Math.max(0, Number(item.level) - 1))}- [${md(item.text)}](#${item.anchor})`)].join("\n");
|
|
3231
|
+
}
|
|
3232
|
+
case "cover":
|
|
3233
|
+
return [p.marking ? `**${md(p.marking)}**` : "", p.kicker ? md(p.kicker) : "", `# ${md(p.title)}`, p.subtitle ? md(p.subtitle) : "", "<!-- pagebreak -->"].filter(Boolean).join("\n\n");
|
|
2867
3234
|
default:
|
|
2868
3235
|
return fail4("RENDERER_UNAVAILABLE", `No Markdown representation for ${n.type}.`);
|
|
2869
3236
|
}
|
|
@@ -2890,6 +3257,9 @@ export {
|
|
|
2890
3257
|
findBrowser,
|
|
2891
3258
|
guideFor,
|
|
2892
3259
|
importHtml,
|
|
3260
|
+
kitChartDescription,
|
|
3261
|
+
kitChartSvg,
|
|
3262
|
+
kitChartTable,
|
|
2893
3263
|
renderHtml,
|
|
2894
3264
|
renderMarkdown,
|
|
2895
3265
|
reportCss,
|