@diagrammo/dgmo 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1275,6 +1275,67 @@ var init_palettes = __esm({
1275
1275
  }
1276
1276
  });
1277
1277
 
1278
+ // src/utils/parsing.ts
1279
+ function measureIndent(line7) {
1280
+ let indent = 0;
1281
+ for (const ch of line7) {
1282
+ if (ch === " ") indent++;
1283
+ else if (ch === " ") indent += 4;
1284
+ else break;
1285
+ }
1286
+ return indent;
1287
+ }
1288
+ function extractColor(label, palette) {
1289
+ const m = label.match(COLOR_SUFFIX_RE);
1290
+ if (!m) return { label };
1291
+ const colorName = m[1].trim();
1292
+ return {
1293
+ label: label.substring(0, m.index).trim(),
1294
+ color: resolveColor(colorName, palette)
1295
+ };
1296
+ }
1297
+ function collectIndentedValues(lines, startIndex) {
1298
+ const values = [];
1299
+ let j = startIndex + 1;
1300
+ for (; j < lines.length; j++) {
1301
+ const raw = lines[j];
1302
+ const trimmed = raw.trim();
1303
+ if (!trimmed) continue;
1304
+ if (trimmed.startsWith("//")) continue;
1305
+ if (raw[0] !== " " && raw[0] !== " ") break;
1306
+ values.push(trimmed.replace(/,\s*$/, ""));
1307
+ }
1308
+ return { values, newIndex: j - 1 };
1309
+ }
1310
+ function parsePipeMetadata(segments, aliasMap = /* @__PURE__ */ new Map()) {
1311
+ const metadata = {};
1312
+ for (let j = 1; j < segments.length; j++) {
1313
+ for (const part of segments[j].split(",")) {
1314
+ const trimmedPart = part.trim();
1315
+ if (!trimmedPart) continue;
1316
+ const colonIdx = trimmedPart.indexOf(":");
1317
+ if (colonIdx > 0) {
1318
+ const rawKey = trimmedPart.substring(0, colonIdx).trim().toLowerCase();
1319
+ const key = aliasMap.get(rawKey) ?? rawKey;
1320
+ const value = trimmedPart.substring(colonIdx + 1).trim();
1321
+ metadata[key] = value;
1322
+ }
1323
+ }
1324
+ }
1325
+ return metadata;
1326
+ }
1327
+ var COLOR_SUFFIX_RE, CHART_TYPE_RE, TITLE_RE, OPTION_RE;
1328
+ var init_parsing = __esm({
1329
+ "src/utils/parsing.ts"() {
1330
+ "use strict";
1331
+ init_colors();
1332
+ COLOR_SUFFIX_RE = /\(([^)]+)\)\s*$/;
1333
+ CHART_TYPE_RE = /^chart\s*:\s*(.+)/i;
1334
+ TITLE_RE = /^title\s*:\s*(.+)/i;
1335
+ OPTION_RE = /^([a-z][a-z0-9-]*)\s*:\s*(.+)$/i;
1336
+ }
1337
+ });
1338
+
1278
1339
  // src/sequence/participant-inference.ts
1279
1340
  function inferParticipantType(name) {
1280
1341
  for (const rule of PARTICIPANT_RULES) {
@@ -1591,54 +1652,6 @@ var init_arrows = __esm({
1591
1652
  }
1592
1653
  });
1593
1654
 
1594
- // src/utils/parsing.ts
1595
- function measureIndent(line7) {
1596
- let indent = 0;
1597
- for (const ch of line7) {
1598
- if (ch === " ") indent++;
1599
- else if (ch === " ") indent += 4;
1600
- else break;
1601
- }
1602
- return indent;
1603
- }
1604
- function extractColor(label, palette) {
1605
- const m = label.match(COLOR_SUFFIX_RE);
1606
- if (!m) return { label };
1607
- const colorName = m[1].trim();
1608
- return {
1609
- label: label.substring(0, m.index).trim(),
1610
- color: resolveColor(colorName, palette)
1611
- };
1612
- }
1613
- function parsePipeMetadata(segments, aliasMap = /* @__PURE__ */ new Map()) {
1614
- const metadata = {};
1615
- for (let j = 1; j < segments.length; j++) {
1616
- for (const part of segments[j].split(",")) {
1617
- const trimmedPart = part.trim();
1618
- if (!trimmedPart) continue;
1619
- const colonIdx = trimmedPart.indexOf(":");
1620
- if (colonIdx > 0) {
1621
- const rawKey = trimmedPart.substring(0, colonIdx).trim().toLowerCase();
1622
- const key = aliasMap.get(rawKey) ?? rawKey;
1623
- const value = trimmedPart.substring(colonIdx + 1).trim();
1624
- metadata[key] = value;
1625
- }
1626
- }
1627
- }
1628
- return metadata;
1629
- }
1630
- var COLOR_SUFFIX_RE, CHART_TYPE_RE, TITLE_RE, OPTION_RE;
1631
- var init_parsing = __esm({
1632
- "src/utils/parsing.ts"() {
1633
- "use strict";
1634
- init_colors();
1635
- COLOR_SUFFIX_RE = /\(([^)]+)\)\s*$/;
1636
- CHART_TYPE_RE = /^chart\s*:\s*(.+)/i;
1637
- TITLE_RE = /^title\s*:\s*(.+)/i;
1638
- OPTION_RE = /^([a-z][a-z0-9-]*)\s*:\s*(.+)$/i;
1639
- }
1640
- });
1641
-
1642
1655
  // src/sequence/parser.ts
1643
1656
  var parser_exports = {};
1644
1657
  __export(parser_exports, {
@@ -1659,6 +1672,13 @@ function isSequenceNote(el) {
1659
1672
  }
1660
1673
  function parseReturnLabel(rawLabel) {
1661
1674
  if (!rawLabel) return { label: "" };
1675
+ const standaloneMatch = rawLabel.match(/^<-\s*(.*)$/);
1676
+ if (standaloneMatch) {
1677
+ return {
1678
+ label: standaloneMatch[1].trim(),
1679
+ standaloneReturn: true
1680
+ };
1681
+ }
1662
1682
  const arrowReturn = rawLabel.match(ARROW_RETURN_PATTERN);
1663
1683
  if (arrowReturn) {
1664
1684
  return { label: arrowReturn[1].trim(), returnLabel: arrowReturn[2].trim() };
@@ -1996,14 +2016,15 @@ function parseSequenceDgmo(content) {
1996
2016
  const to = arrowMatch[2];
1997
2017
  lastMsgFrom = from;
1998
2018
  const rawLabel = arrowMatch[3]?.trim() || "";
1999
- const { label, returnLabel } = isAsync ? { label: rawLabel, returnLabel: void 0 } : parseReturnLabel(rawLabel);
2019
+ const { label, returnLabel, standaloneReturn } = isAsync ? { label: rawLabel, returnLabel: void 0, standaloneReturn: void 0 } : parseReturnLabel(rawLabel);
2000
2020
  const msg = {
2001
2021
  from,
2002
2022
  to,
2003
2023
  label,
2004
2024
  returnLabel,
2005
2025
  lineNumber,
2006
- ...isAsync ? { async: true } : {}
2026
+ ...isAsync ? { async: true } : {},
2027
+ ...standaloneReturn ? { standaloneReturn: true } : {}
2007
2028
  };
2008
2029
  result.messages.push(msg);
2009
2030
  currentContainer().push(msg);
@@ -3143,8 +3164,16 @@ function parseChart(content, palette) {
3143
3164
  continue;
3144
3165
  }
3145
3166
  if (key === "series") {
3146
- result.series = value;
3147
- const rawNames = value.split(",").map((s) => s.trim()).filter(Boolean);
3167
+ let rawNames;
3168
+ if (value) {
3169
+ result.series = value;
3170
+ rawNames = value.split(",").map((s) => s.trim()).filter(Boolean);
3171
+ } else {
3172
+ const collected = collectIndentedValues(lines, i);
3173
+ i = collected.newIndex;
3174
+ rawNames = collected.values;
3175
+ result.series = rawNames.join(", ");
3176
+ }
3148
3177
  const names = [];
3149
3178
  const nameColors = [];
3150
3179
  for (const raw of rawNames) {
@@ -3223,6 +3252,7 @@ var init_chart = __esm({
3223
3252
  "use strict";
3224
3253
  init_colors();
3225
3254
  init_diagnostics();
3255
+ init_parsing();
3226
3256
  VALID_TYPES = /* @__PURE__ */ new Set([
3227
3257
  "bar",
3228
3258
  "line",
@@ -3298,8 +3328,16 @@ function parseEChart(content, palette) {
3298
3328
  continue;
3299
3329
  }
3300
3330
  if (key === "series") {
3301
- result.series = value;
3302
- const rawNames = value.split(",").map((s) => s.trim()).filter(Boolean);
3331
+ let rawNames;
3332
+ if (value) {
3333
+ result.series = value;
3334
+ rawNames = value.split(",").map((s) => s.trim()).filter(Boolean);
3335
+ } else {
3336
+ const collected = collectIndentedValues(lines, i);
3337
+ i = collected.newIndex;
3338
+ rawNames = collected.values;
3339
+ result.series = rawNames.join(", ");
3340
+ }
3303
3341
  const names = [];
3304
3342
  const nameColors = [];
3305
3343
  for (const raw of rawNames) {
@@ -3335,11 +3373,23 @@ function parseEChart(content, palette) {
3335
3373
  continue;
3336
3374
  }
3337
3375
  if (key === "columns") {
3338
- result.columns = value.split(",").map((s) => s.trim());
3376
+ if (value) {
3377
+ result.columns = value.split(",").map((s) => s.trim());
3378
+ } else {
3379
+ const collected = collectIndentedValues(lines, i);
3380
+ i = collected.newIndex;
3381
+ result.columns = collected.values;
3382
+ }
3339
3383
  continue;
3340
3384
  }
3341
3385
  if (key === "rows") {
3342
- result.rows = value.split(",").map((s) => s.trim());
3386
+ if (value) {
3387
+ result.rows = value.split(",").map((s) => s.trim());
3388
+ } else {
3389
+ const collected = collectIndentedValues(lines, i);
3390
+ i = collected.newIndex;
3391
+ result.rows = collected.values;
3392
+ }
3343
3393
  continue;
3344
3394
  }
3345
3395
  if (key === "x") {
@@ -4655,6 +4705,7 @@ var init_echarts = __esm({
4655
4705
  init_palettes();
4656
4706
  init_chart();
4657
4707
  init_diagnostics();
4708
+ init_parsing();
4658
4709
  ECHART_EXPORT_WIDTH = 1200;
4659
4710
  ECHART_EXPORT_HEIGHT = 800;
4660
4711
  STANDARD_CHART_TYPES = /* @__PURE__ */ new Set([
@@ -12140,6 +12191,22 @@ function buildRenderSequence(messages) {
12140
12191
  messageIndex: top.messageIndex
12141
12192
  });
12142
12193
  }
12194
+ if (msg.standaloneReturn) {
12195
+ for (let si = stack.length - 1; si >= 0; si--) {
12196
+ if (stack[si].from === msg.to && stack[si].to === msg.from) {
12197
+ stack.splice(si, 1);
12198
+ break;
12199
+ }
12200
+ }
12201
+ steps.push({
12202
+ type: "return",
12203
+ from: msg.from,
12204
+ to: msg.to,
12205
+ label: msg.label,
12206
+ messageIndex: mi
12207
+ });
12208
+ continue;
12209
+ }
12143
12210
  steps.push({
12144
12211
  type: "call",
12145
12212
  from: msg.from,
@@ -13421,18 +13488,34 @@ function parseD3(content, palette) {
13421
13488
  }
13422
13489
  }
13423
13490
  if (result.type === "quadrant") {
13424
- const xAxisMatch = line7.match(/^x-axis\s*:\s*(.+)/i);
13491
+ const xAxisMatch = line7.match(/^x-axis\s*:\s*(.*)/i);
13425
13492
  if (xAxisMatch) {
13426
- const parts = xAxisMatch[1].split(",").map((s) => s.trim());
13493
+ const val = xAxisMatch[1].trim();
13494
+ let parts;
13495
+ if (val) {
13496
+ parts = val.split(",").map((s) => s.trim());
13497
+ } else {
13498
+ const collected = collectIndentedValues(lines, i);
13499
+ i = collected.newIndex;
13500
+ parts = collected.values;
13501
+ }
13427
13502
  if (parts.length >= 2) {
13428
13503
  result.quadrantXAxis = [parts[0], parts[1]];
13429
13504
  result.quadrantXAxisLineNumber = lineNumber;
13430
13505
  }
13431
13506
  continue;
13432
13507
  }
13433
- const yAxisMatch = line7.match(/^y-axis\s*:\s*(.+)/i);
13508
+ const yAxisMatch = line7.match(/^y-axis\s*:\s*(.*)/i);
13434
13509
  if (yAxisMatch) {
13435
- const parts = yAxisMatch[1].split(",").map((s) => s.trim());
13510
+ const val = yAxisMatch[1].trim();
13511
+ let parts;
13512
+ if (val) {
13513
+ parts = val.split(",").map((s) => s.trim());
13514
+ } else {
13515
+ const collected = collectIndentedValues(lines, i);
13516
+ i = collected.newIndex;
13517
+ parts = collected.values;
13518
+ }
13436
13519
  if (parts.length >= 2) {
13437
13520
  result.quadrantYAxis = [parts[0], parts[1]];
13438
13521
  result.quadrantYAxisLineNumber = lineNumber;
@@ -16248,6 +16331,7 @@ var init_d3 = __esm({
16248
16331
  init_colors();
16249
16332
  init_palettes();
16250
16333
  init_diagnostics();
16334
+ init_parsing();
16251
16335
  DEFAULT_CLOUD_OPTIONS = {
16252
16336
  rotate: "none",
16253
16337
  max: 0,