yumiamd 0.1.32 → 0.1.34

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/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runCli
4
- } from "./chunk-Y2OWK5OP.js";
4
+ } from "./chunk-VTY4XT47.js";
5
5
 
6
6
  // src/bin.ts
7
7
  var result = await runCli(process.argv);
@@ -1781,14 +1781,14 @@ var NativeYumiaParser = class {
1781
1781
  const baseIndent = tok.indent;
1782
1782
  switch (tok.command) {
1783
1783
  case "hero": {
1784
- const titleMatch = tok.args.match(/^(?:title=)?["']([^"']+)["']/);
1785
- const subMatch = tok.args.match(/\bsubtitle=["']([^"']+)["']/);
1786
- const tagMatch = tok.args.match(/\btagline=["']([^"']+)["']/);
1787
- const badgeMatch = tok.args.match(/\bbadge=["']([^"']+)["']/);
1788
- const alignMatch = tok.args.match(/\balign=["']?([^"'\s]+)["']?/);
1789
- const emphMatch = tok.args.match(/\bemphasis=["']?([^"'\s]+)["']?/);
1790
- const densMatch = tok.args.match(/\bdensity=["']?([^"'\s]+)["']?/);
1791
- const title = titleMatch ? titleMatch[1] : this.stripQuotes(tok.args) || "Hero";
1784
+ const titleVal = this.extractAttr(tok.args, "title") ?? this.extractAttr(tok.args);
1785
+ const subVal = this.extractAttr(tok.args, "subtitle");
1786
+ const tagVal = this.extractAttr(tok.args, "tagline");
1787
+ const badgeVal = this.extractAttr(tok.args, "badge");
1788
+ const alignVal = this.extractAttr(tok.args, "align");
1789
+ const emphVal = this.extractAttr(tok.args, "emphasis");
1790
+ const densVal = this.extractAttr(tok.args, "density");
1791
+ const title = (titleVal ?? this.stripQuotes(tok.args)) || "Hero";
1792
1792
  const children = [];
1793
1793
  let nextIdx = idx + 1;
1794
1794
  while (nextIdx < tokens.length && tokens[nextIdx].indent > baseIndent) {
@@ -1800,12 +1800,12 @@ var NativeYumiaParser = class {
1800
1800
  nextIdx++;
1801
1801
  }
1802
1802
  }
1803
- const heroEl = createHero(title, subMatch ? subMatch[1] : void 0, children.length > 0 ? children : void 0, {
1804
- tagline: tagMatch ? tagMatch[1] : void 0,
1805
- badge: badgeMatch ? badgeMatch[1] : void 0,
1806
- align: alignMatch ? alignMatch[1] : void 0,
1807
- emphasis: emphMatch ? emphMatch[1] : void 0,
1808
- density: densMatch ? densMatch[1] : void 0
1803
+ const heroEl = createHero(title, subVal, children.length > 0 ? children : void 0, {
1804
+ tagline: tagVal,
1805
+ badge: badgeVal,
1806
+ align: alignVal,
1807
+ emphasis: emphVal,
1808
+ density: densVal
1809
1809
  });
1810
1810
  heroEl.loc = {
1811
1811
  start: { line: tok.lineNum, column: 1 },
@@ -2598,6 +2598,15 @@ var NativeYumiaParser = class {
2598
2598
  return template;
2599
2599
  }
2600
2600
  }
2601
+ extractAttr(argsStr, key) {
2602
+ if (!argsStr)
2603
+ return void 0;
2604
+ const pattern = key ? new RegExp(`\\b${key}=(?:"([^"]*)"|'([^']*)'|([^\\s"']+))`) : /^(?:"([^"]*)"|'([^']*)')/;
2605
+ const m = argsStr.match(pattern);
2606
+ if (!m)
2607
+ return void 0;
2608
+ return m[1] ?? m[2] ?? m[3];
2609
+ }
2601
2610
  stripQuotes(str) {
2602
2611
  if (!str)
2603
2612
  return "";
@@ -10780,6 +10789,10 @@ var PdfRenderer = class {
10780
10789
  }
10781
10790
  return;
10782
10791
  }
10792
+ if (el.type === "diagram") {
10793
+ this.renderDiagram(doc, el, x, y, w, h, theme);
10794
+ return;
10795
+ }
10783
10796
  this.renderElement(doc, el, x, y, w, theme, presentation);
10784
10797
  }
10785
10798
  paintCardFrame(doc, card, x, y, width, height, theme) {
@@ -11671,7 +11684,7 @@ var PdfRenderer = class {
11671
11684
  return curY;
11672
11685
  }
11673
11686
  case "diagram": {
11674
- return this.renderDiagram(doc, element, x, y, width, theme);
11687
+ return this.renderDiagram(doc, element, x, y, width, void 0, theme);
11675
11688
  }
11676
11689
  case "sequence": {
11677
11690
  return this.renderSequence(doc, element, x, y, width, theme);
@@ -11683,19 +11696,46 @@ var PdfRenderer = class {
11683
11696
  return y;
11684
11697
  }
11685
11698
  }
11686
- renderDiagram(doc, diagram, x, y, width, theme) {
11699
+ renderDiagram(doc, diagram, x, y, width, height, theme) {
11687
11700
  const isLR = (diagram.direction || "LR").toUpperCase() === "LR";
11688
11701
  if (diagram.nodes.length === 0)
11689
11702
  return y;
11690
- const layout = computeDiagramLayout(diagram, width, isLR, {
11691
- originX: x,
11692
- originY: y,
11693
- titleHeight: 24
11703
+ const layout = computeDiagramLayout(diagram, 1e3, isLR, {
11704
+ originX: 0,
11705
+ originY: diagram.title ? 30 : 0,
11706
+ titleHeight: diagram.title ? 30 : 0
11694
11707
  });
11695
- const { nodeWidth: nodeW, nodeHeight: nodeH, positions } = layout;
11708
+ const { nodeWidth: rawNodeW, nodeHeight: rawNodeH, positions: rawPositions } = layout;
11709
+ let minX = Infinity;
11710
+ let minY = Infinity;
11711
+ let maxX = 0;
11712
+ let maxY = 0;
11713
+ for (const p of Object.values(rawPositions)) {
11714
+ minX = Math.min(minX, p.x);
11715
+ minY = Math.min(minY, p.y);
11716
+ maxX = Math.max(maxX, p.x + rawNodeW);
11717
+ maxY = Math.max(maxY, p.y + rawNodeH);
11718
+ }
11719
+ const contentW = Math.max(1, maxX - minX);
11720
+ const contentH = Math.max(1, maxY - minY);
11721
+ const titleH = diagram.title ? 18 : 0;
11696
11722
  if (diagram.title) {
11697
11723
  doc.font(this.getPdfFont(theme, "bold")).fontSize(14).fillColor(theme.colors.primary).text(this.stripFormatting(diagram.title), x, y, { width, align: "center" });
11698
11724
  }
11725
+ const drawY = y + titleH;
11726
+ const drawH = height !== void 0 ? Math.max(24, height - titleH) : contentH;
11727
+ const scale = Math.min(width / contentW, drawH / contentH, 1);
11728
+ const nodeW = rawNodeW * scale;
11729
+ const nodeH = rawNodeH * scale;
11730
+ const offsetX = x + (width - contentW * scale) / 2;
11731
+ const offsetY = drawY + (drawH - contentH * scale) / 2;
11732
+ const positions = {};
11733
+ for (const [id, p] of Object.entries(rawPositions)) {
11734
+ positions[id] = {
11735
+ x: offsetX + (p.x - minX) * scale,
11736
+ y: offsetY + (p.y - minY) * scale
11737
+ };
11738
+ }
11699
11739
  const arrowColor = theme.colors.accent || theme.colors.primary;
11700
11740
  diagram.edges.forEach((e) => {
11701
11741
  const p1 = positions[e.from];
@@ -11708,7 +11748,7 @@ var PdfRenderer = class {
11708
11748
  const last = pts[pts.length - 1];
11709
11749
  const prev = pts[pts.length - 2];
11710
11750
  doc.save();
11711
- doc.lineWidth(1.5).strokeColor(arrowColor);
11751
+ doc.lineWidth(Math.max(1, 1.5 * scale)).strokeColor(arrowColor);
11712
11752
  if (e.style === "dashed")
11713
11753
  doc.dash(4, { space: 3 });
11714
11754
  doc.moveTo(pts[0].x, pts[0].y);
@@ -11717,7 +11757,7 @@ var PdfRenderer = class {
11717
11757
  doc.stroke();
11718
11758
  doc.restore();
11719
11759
  const angle = Math.atan2(last.y - prev.y, last.x - prev.x);
11720
- const headLen = 6;
11760
+ const headLen = Math.max(4, 6 * scale);
11721
11761
  doc.save();
11722
11762
  doc.fillColor(arrowColor);
11723
11763
  doc.moveTo(last.x, last.y).lineTo(last.x - headLen * Math.cos(angle - Math.PI / 6), last.y - headLen * Math.sin(angle - Math.PI / 6)).lineTo(last.x - headLen * Math.cos(angle + Math.PI / 6), last.y - headLen * Math.sin(angle + Math.PI / 6)).fill();
@@ -11727,15 +11767,19 @@ var PdfRenderer = class {
11727
11767
  const midX = mid.x;
11728
11768
  const midY = mid.y;
11729
11769
  const labelText = this.stripFormatting(e.label);
11730
- const labelW = Math.min(90, Math.max(45, labelText.length * 5.5 + 16));
11770
+ const labelW = Math.min(90 * scale, Math.max(45 * scale, labelText.length * 5.5 * scale + 16));
11771
+ const labelH = Math.max(12, 16 * scale);
11731
11772
  doc.save();
11732
- doc.roundedRect(midX - labelW / 2, midY - 8, labelW, 16, 4).fill(theme.colors.surface || "#151522");
11733
- doc.roundedRect(midX - labelW / 2, midY - 8, labelW, 16, 4).lineWidth(0.8).strokeColor(theme.colors.border || "#334155").stroke();
11773
+ doc.roundedRect(midX - labelW / 2, midY - labelH / 2, labelW, labelH, 4).fill(theme.colors.surface || "#151522");
11774
+ doc.roundedRect(midX - labelW / 2, midY - labelH / 2, labelW, labelH, 4).lineWidth(0.8).strokeColor(theme.colors.border || "#334155").stroke();
11734
11775
  doc.restore();
11735
- doc.font(this.getPdfFont(theme, "bold")).fontSize(7.5).fillColor(theme.colors.muted || "#888888").text(labelText, midX - labelW / 2, midY - 5, { width: labelW, align: "center" });
11776
+ doc.font(this.getPdfFont(theme, "bold")).fontSize(Math.max(6, 7.5 * scale)).fillColor(theme.colors.muted || "#888888").text(labelText, midX - labelW / 2, midY - labelH / 2 + 2, {
11777
+ width: labelW,
11778
+ align: "center"
11779
+ });
11736
11780
  }
11737
11781
  });
11738
- const maxChars = Math.max(6, Math.floor((nodeW - 10) / 6));
11782
+ const maxChars = Math.max(6, Math.floor((nodeW - 10) / Math.max(4, 6 * scale)));
11739
11783
  diagram.nodes.forEach((n) => {
11740
11784
  const p = positions[n.id];
11741
11785
  if (!p)
@@ -11753,18 +11797,18 @@ var PdfRenderer = class {
11753
11797
  else if (variant === "info")
11754
11798
  nodeColor = theme.colors.info || theme.colors.primary;
11755
11799
  doc.save();
11756
- doc.roundedRect(p.x, p.y, nodeW, nodeH, 6).fill(theme.colors.surface || "#151522");
11757
- doc.roundedRect(p.x, p.y, nodeW, nodeH, 6).lineWidth(1.5).strokeColor(nodeColor).stroke();
11800
+ doc.roundedRect(p.x, p.y, nodeW, nodeH, Math.max(3, 6 * scale)).fill(theme.colors.surface || "#151522");
11801
+ doc.roundedRect(p.x, p.y, nodeW, nodeH, Math.max(3, 6 * scale)).lineWidth(Math.max(1, 1.5 * scale)).strokeColor(nodeColor).stroke();
11758
11802
  doc.restore();
11759
11803
  const label = fitDiagramLabel(this.stripFormatting(n.label), maxChars);
11760
- doc.font(this.getPdfFont(theme, "bold")).fontSize(Math.min(10, Math.max(7.5, nodeH / 4))).fillColor(theme.colors.text).text(label, p.x + 4, p.y + Math.max(4, nodeH / 2 - 6), {
11804
+ doc.font(this.getPdfFont(theme, "bold")).fontSize(Math.min(10, Math.max(6.5, nodeH / 4))).fillColor(theme.colors.text).text(label, p.x + 4, p.y + Math.max(3, nodeH / 2 - 5), {
11761
11805
  width: nodeW - 8,
11762
- height: nodeH - 8,
11806
+ height: nodeH - 6,
11763
11807
  align: "center",
11764
11808
  ellipsis: true
11765
11809
  });
11766
11810
  });
11767
- return y + layout.height + 8;
11811
+ return height !== void 0 ? y + height : y + titleH + contentH * scale + 8;
11768
11812
  }
11769
11813
  renderSequence(doc, s, x, y, width, theme) {
11770
11814
  const participants = s.participants || [];
@@ -12017,7 +12061,7 @@ function startDevServer(filePath, options = {}) {
12017
12061
  // src/cli.ts
12018
12062
  import { mkdirSync, readFileSync as readFileSync3, watch as fsWatch, writeFileSync } from "fs";
12019
12063
  import { basename, dirname, extname, join, resolve as resolve3 } from "path";
12020
- var VERSION = "0.1.32";
12064
+ var VERSION = "0.1.34";
12021
12065
  function printHelp() {
12022
12066
  return `
12023
12067
  YumiaMD \u2014 Markdown-based presentation compiler (v${VERSION})
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export * from '@yumiamd/renderer-pptx';
9
9
  export * from '@yumiamd/renderer-html';
10
10
  export * from '@yumiamd/renderer-pdf';
11
11
 
12
- declare const VERSION = "0.1.32";
12
+ declare const VERSION = "0.1.34";
13
13
  declare function printHelp(): string;
14
14
  declare function runCli(argv: string[]): Promise<{
15
15
  exitCode: number;
package/dist/index.js CHANGED
@@ -92,7 +92,7 @@ import {
92
92
  themeSizeToPptxPoints,
93
93
  tokyoNightTheme,
94
94
  validate
95
- } from "./chunk-Y2OWK5OP.js";
95
+ } from "./chunk-VTY4XT47.js";
96
96
  export {
97
97
  DEFAULT_VIEWPORT,
98
98
  DefaultLayoutEngine,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yumiamd",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "Command line interface and compiler for YumiaMD presentations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,15 +22,15 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "tsup": "^8.5.1",
25
- "@yumiamd/layout": "0.1.32",
26
- "@yumiamd/ast": "0.1.32",
27
- "@yumiamd/renderer-pdf": "0.1.32",
28
- "@yumiamd/parser": "0.1.32",
29
- "@yumiamd/renderer": "0.1.32",
30
- "@yumiamd/theme": "0.1.32",
31
- "@yumiamd/renderer-html": "0.1.32",
32
- "@yumiamd/renderer-pptx": "0.1.32",
33
- "@yumiamd/core": "0.1.32"
25
+ "@yumiamd/ast": "0.1.34",
26
+ "@yumiamd/parser": "0.1.34",
27
+ "@yumiamd/layout": "0.1.34",
28
+ "@yumiamd/core": "0.1.34",
29
+ "@yumiamd/renderer-pdf": "0.1.34",
30
+ "@yumiamd/renderer": "0.1.34",
31
+ "@yumiamd/renderer-pptx": "0.1.34",
32
+ "@yumiamd/renderer-html": "0.1.34",
33
+ "@yumiamd/theme": "0.1.34"
34
34
  },
35
35
  "keywords": [
36
36
  "yumia",