@drghaliasri/butex 6.0.0 → 6.1.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.
@@ -970,6 +970,76 @@ function applyFloatMetaPatch(block, patch) {
970
970
  }
971
971
  }
972
972
 
973
+ // src/document2/inlineIdentity.ts
974
+ function createDocument2IdentityState() {
975
+ return {
976
+ blockIds: /* @__PURE__ */ new Set(),
977
+ itemIds: /* @__PURE__ */ new Set(),
978
+ fieldIds: /* @__PURE__ */ new Set(),
979
+ tokenIds: /* @__PURE__ */ new Set()
980
+ };
981
+ }
982
+ function importedOrGeneratedId(value, prefix, used) {
983
+ const imported = typeof value === "string" ? value.trim() : "";
984
+ if (imported.length > 0 && !used.has(imported)) {
985
+ used.add(imported);
986
+ return imported;
987
+ }
988
+ let generated = document2Id(prefix);
989
+ while (used.has(generated)) {
990
+ generated = document2Id(prefix);
991
+ }
992
+ used.add(generated);
993
+ return generated;
994
+ }
995
+ function inlineTokenSource(token) {
996
+ if (token.kind === "text") {
997
+ return token.text;
998
+ }
999
+ if (token.kind === "math") {
1000
+ return token.source;
1001
+ }
1002
+ if (token.kind === "cite") {
1003
+ return citeTokenLatex(token.keys);
1004
+ }
1005
+ return refTokenLatex(token.keys, token.refCommand);
1006
+ }
1007
+ function inlineIdsFromField(field) {
1008
+ let offset = 0;
1009
+ const tokens = field.tokens.map((token) => {
1010
+ const start = offset;
1011
+ offset += inlineTokenSource(token).length;
1012
+ return { id: token.id, kind: token.kind, start, end: offset };
1013
+ });
1014
+ return { field_id: field.id, tokens };
1015
+ }
1016
+ function isAlignedSidecar(value, field) {
1017
+ if (typeof value !== "object" || value === null || !Array.isArray(value.tokens)) {
1018
+ return false;
1019
+ }
1020
+ const tokens = value.tokens;
1021
+ const expected = inlineIdsFromField(field).tokens;
1022
+ if (tokens.length !== expected.length) {
1023
+ return false;
1024
+ }
1025
+ return tokens.every((token, index) => {
1026
+ const expectedToken = expected[index];
1027
+ return typeof token === "object" && token !== null && expectedToken !== void 0 && token.kind === expectedToken.kind && token.start === expectedToken.start && token.end === expectedToken.end;
1028
+ });
1029
+ }
1030
+ function applyImportedInlineIds(field, sidecar, state) {
1031
+ field.id = importedOrGeneratedId(
1032
+ typeof sidecar === "object" && sidecar !== null ? sidecar.field_id : void 0,
1033
+ "field",
1034
+ state.fieldIds
1035
+ );
1036
+ const aligned = isAlignedSidecar(sidecar, field);
1037
+ field.tokens.forEach((token, index) => {
1038
+ token.id = importedOrGeneratedId(aligned ? sidecar.tokens[index]?.id : void 0, token.kind, state.tokenIds);
1039
+ });
1040
+ return field;
1041
+ }
1042
+
973
1043
  // src/document2/inlineScanner.ts
974
1044
  var MATH_ENVIRONMENTS = /* @__PURE__ */ new Set([
975
1045
  "equation",
@@ -1048,17 +1118,13 @@ function citeSpan(value, start) {
1048
1118
  function refSpan(value, start) {
1049
1119
  const eqrefPrefix = "\\eqref{";
1050
1120
  const refPrefix = "\\ref{";
1051
- let refCommand = "ref";
1052
- let prefix = refPrefix;
1053
- if (value.startsWith(eqrefPrefix, start) && !isEscaped(value, start)) {
1054
- refCommand = "eqref";
1055
- prefix = eqrefPrefix;
1056
- } else if (value.startsWith(refPrefix, start) && !isEscaped(value, start)) {
1057
- refCommand = "ref";
1058
- prefix = refPrefix;
1059
- } else {
1121
+ const isEqref = value.startsWith(eqrefPrefix, start) && !isEscaped(value, start);
1122
+ const isRef = value.startsWith(refPrefix, start) && !isEscaped(value, start);
1123
+ if (!isEqref && !isRef) {
1060
1124
  return null;
1061
1125
  }
1126
+ const refCommand = isEqref ? "eqref" : "ref";
1127
+ const prefix = isEqref ? eqrefPrefix : refPrefix;
1062
1128
  const openBrace = start + prefix.length - 1;
1063
1129
  if (value[openBrace] !== "{") {
1064
1130
  return null;
@@ -1117,7 +1183,14 @@ function mathSpanAt(value, i) {
1117
1183
  return null;
1118
1184
  }
1119
1185
  function detectMathSpans2(value) {
1120
- return detectInlineSpans2(value).filter((span) => span.kind === "math").map(({ kind: _kind, ...span }) => span);
1186
+ return detectInlineSpans2(value).filter((span) => span.kind === "math").map((span) => ({
1187
+ start: span.start,
1188
+ end: span.end,
1189
+ source: span.source,
1190
+ opening: span.opening,
1191
+ closing: span.closing,
1192
+ display: span.display
1193
+ }));
1121
1194
  }
1122
1195
  function detectInlineSpans2(value) {
1123
1196
  const spans = [];
@@ -1171,17 +1244,13 @@ function asBlockJson(value) {
1171
1244
  return value;
1172
1245
  }
1173
1246
  function blockIdFromJson(json, state) {
1174
- const imported = typeof json.id === "string" ? json.id.trim() : "";
1175
- if (imported.length > 0 && !state.used.has(imported)) {
1176
- state.used.add(imported);
1177
- return imported;
1178
- }
1179
- let generated = document2Id("block");
1180
- while (state.used.has(generated)) {
1181
- generated = document2Id("block");
1247
+ return importedOrGeneratedId(json.id, "block", state.blockIds);
1248
+ }
1249
+ function metadataFromJson(value) {
1250
+ if (!isObject2(value) || value.source !== "agent" && value.source !== "user") {
1251
+ return {};
1182
1252
  }
1183
- state.used.add(generated);
1184
- return generated;
1253
+ return { metadata: { source: value.source } };
1185
1254
  }
1186
1255
  function pushDiagnostic(diagnostics, options, path, message) {
1187
1256
  if (options.strict) {
@@ -1364,44 +1433,54 @@ function pushFormattedTextTokens(tokens, text, sourceStart, formats) {
1364
1433
  function closingForList(command) {
1365
1434
  return command === "\\begin{itemize}" ? "\\end{itemize}" : "\\end{enumerate}";
1366
1435
  }
1367
- function parseTextBlock(json, options, path, diagnostics, blockIds) {
1436
+ function parseTextBlock(json, options, path, diagnostics, identities) {
1368
1437
  const value = requireString(json.value, `${json.command} requires string value`);
1369
1438
  return {
1370
- id: blockIdFromJson(json, blockIds),
1439
+ id: blockIdFromJson(json, identities),
1371
1440
  kind: "textBlock",
1372
1441
  command: json.command,
1373
- field: createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.command === "\\paragraph" ? json.formats ?? [] : []),
1442
+ field: applyImportedInlineIds(
1443
+ createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.command === "\\paragraph" ? json.formats ?? [] : []),
1444
+ json.inline_ids,
1445
+ identities
1446
+ ),
1447
+ ...metadataFromJson(json.metadata),
1374
1448
  ...json.centered === true ? { centered: true } : {}
1375
1449
  };
1376
1450
  }
1377
- function parseListItem(json, options, path, diagnostics, blockIds) {
1451
+ function parseListItem(json, options, path, diagnostics, identities) {
1378
1452
  const value = requireString(json.value, "Document list item requires string value");
1379
1453
  const blocksJson = Array.isArray(json.blocks) ? json.blocks : [];
1380
1454
  return {
1381
- id: document2Id("item"),
1382
- field: createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.formats ?? []),
1455
+ id: importedOrGeneratedId(json.id, "item", identities.itemIds),
1456
+ field: applyImportedInlineIds(
1457
+ createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.formats ?? []),
1458
+ json.inline_ids,
1459
+ identities
1460
+ ),
1383
1461
  blocks: blocksJson.map(
1384
- (block, index) => parseBlock(asBlockJson(block), options, `${path}.blocks[${String(index)}]`, diagnostics, blockIds)
1462
+ (block, index) => parseBlock(asBlockJson(block), options, `${path}.blocks[${String(index)}]`, diagnostics, identities)
1385
1463
  )
1386
1464
  };
1387
1465
  }
1388
- function parseListBlock(json, options, path, diagnostics, blockIds) {
1466
+ function parseListBlock(json, options, path, diagnostics, identities) {
1389
1467
  if (!Array.isArray(json.items)) {
1390
1468
  throw new Error(`${json.command} requires items array`);
1391
1469
  }
1392
1470
  const command = json.command;
1393
1471
  const closing = closingForList(command);
1394
1472
  return {
1395
- id: blockIdFromJson(json, blockIds),
1473
+ id: blockIdFromJson(json, identities),
1396
1474
  kind: "list",
1397
1475
  command,
1398
1476
  closing,
1399
1477
  items: json.items.map(
1400
- (item, index) => parseListItem(item, options, `${path}.items[${String(index)}]`, diagnostics, blockIds)
1401
- )
1478
+ (item, index) => parseListItem(item, options, `${path}.items[${String(index)}]`, diagnostics, identities)
1479
+ ),
1480
+ ...metadataFromJson(json.metadata)
1402
1481
  };
1403
1482
  }
1404
- function parseTableBlock(json, options, path, diagnostics, blockIds) {
1483
+ function parseTableBlock(json, options, path, diagnostics, identities) {
1405
1484
  if (!Array.isArray(json.rows)) {
1406
1485
  throw new Error("\\begin{tabular} requires rows array");
1407
1486
  }
@@ -1417,75 +1496,84 @@ function parseTableBlock(json, options, path, diagnostics, blockIds) {
1417
1496
  const cellMathObjects = mathObjects.slice(mathObjectIndex, mathObjectIndex + spanCount);
1418
1497
  mathObjectIndex += spanCount;
1419
1498
  const cellFormats = json.cell_formats?.[rowIndex]?.[columnIndex] ?? [];
1420
- return createInlineField2(value, cellMathObjects, options, `${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`, diagnostics, cellFormats);
1499
+ return applyImportedInlineIds(
1500
+ createInlineField2(value, cellMathObjects, options, `${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`, diagnostics, cellFormats),
1501
+ json.cell_inline_ids?.[rowIndex]?.[columnIndex],
1502
+ identities
1503
+ );
1421
1504
  });
1422
1505
  });
1423
1506
  if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
1424
1507
  pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
1425
1508
  }
1426
1509
  return {
1427
- id: blockIdFromJson(json, blockIds),
1510
+ id: blockIdFromJson(json, identities),
1428
1511
  kind: "table",
1429
1512
  command: "\\begin{tabular}",
1430
1513
  closing: "\\end{tabular}",
1431
1514
  columns: typeof json.columns === "string" ? json.columns : "",
1432
1515
  rows,
1433
- ...parseFloatMetaFromJson(json)
1516
+ ...parseFloatMetaFromJson(json),
1517
+ ...metadataFromJson(json.metadata)
1434
1518
  };
1435
1519
  }
1436
- function parseImageBlock(json, blockIds) {
1520
+ function parseImageBlock(json, identities) {
1437
1521
  const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
1438
1522
  const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
1439
1523
  return {
1440
- id: blockIdFromJson(json, blockIds),
1524
+ id: blockIdFromJson(json, identities),
1441
1525
  kind: "image",
1442
1526
  command: "\\includegraphics",
1443
1527
  value,
1444
1528
  ...assetId !== void 0 ? { assetId } : {},
1445
1529
  options: isRecordOfStrings(json.options) ? json.options : {},
1446
- ...parseFloatMetaFromJson(json)
1530
+ ...parseFloatMetaFromJson(json),
1531
+ ...metadataFromJson(json.metadata)
1447
1532
  };
1448
1533
  }
1449
- function parseRawBlock(json, blockIds) {
1534
+ function parseRawBlock(json, identities) {
1450
1535
  return {
1451
- id: blockIdFromJson(json, blockIds),
1536
+ id: blockIdFromJson(json, identities),
1452
1537
  kind: "raw",
1453
1538
  command: "\\raw",
1454
- value: typeof json.value === "string" ? json.value : ""
1539
+ value: typeof json.value === "string" ? json.value : "",
1540
+ ...metadataFromJson(json.metadata)
1455
1541
  };
1456
1542
  }
1457
- function parseBibliographyBlock(json, blockIds) {
1543
+ function parseBibliographyBlock(json, identities) {
1458
1544
  return {
1459
- id: blockIdFromJson(json, blockIds),
1545
+ id: blockIdFromJson(json, identities),
1460
1546
  kind: "bibliography",
1461
1547
  command: "\\begin{thebibliography}",
1462
- closing: "\\end{thebibliography}"
1548
+ closing: "\\end{thebibliography}",
1549
+ ...metadataFromJson(json.metadata)
1463
1550
  };
1464
1551
  }
1465
- function parseBlock(json, options, path, diagnostics, blockIds) {
1552
+ function parseBlock(json, options, path, diagnostics, identities) {
1466
1553
  if (TEXT_COMMANDS.has(json.command)) {
1467
- return parseTextBlock(json, options, path, diagnostics, blockIds);
1554
+ return parseTextBlock(json, options, path, diagnostics, identities);
1468
1555
  }
1469
1556
  if (LIST_COMMANDS.has(json.command)) {
1470
- return parseListBlock(json, options, path, diagnostics, blockIds);
1557
+ return parseListBlock(json, options, path, diagnostics, identities);
1471
1558
  }
1472
1559
  if (json.command === "\\begin{tabular}") {
1473
- return parseTableBlock(json, options, path, diagnostics, blockIds);
1560
+ return parseTableBlock(json, options, path, diagnostics, identities);
1474
1561
  }
1475
1562
  if (json.command === "\\includegraphics") {
1476
- return parseImageBlock(json, blockIds);
1563
+ return parseImageBlock(json, identities);
1477
1564
  }
1478
1565
  if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
1479
- return parseBibliographyBlock(json, blockIds);
1566
+ return parseBibliographyBlock(json, identities);
1480
1567
  }
1481
1568
  if (json.command === "\\raw") {
1482
- return parseRawBlock(json, blockIds);
1569
+ return parseRawBlock(json, identities);
1483
1570
  }
1484
1571
  return {
1485
- id: blockIdFromJson(json, blockIds),
1572
+ id: blockIdFromJson(json, identities),
1486
1573
  kind: "raw",
1487
1574
  command: "\\raw",
1488
- value: typeof json.value === "string" ? json.value : json.command
1575
+ value: typeof json.value === "string" ? json.value : json.command,
1576
+ ...metadataFromJson(json.metadata)
1489
1577
  };
1490
1578
  }
1491
1579
  function fromDocumentJson2(json, options = {}) {
@@ -1496,13 +1584,13 @@ function fromDocumentJson2(json, options = {}) {
1496
1584
  throw new Error("DocumentObject requires blocks array");
1497
1585
  }
1498
1586
  const diagnostics = [];
1499
- const blockIds = { used: /* @__PURE__ */ new Set() };
1587
+ const identities = createDocument2IdentityState();
1500
1588
  return {
1501
1589
  nodeType: "DocumentObject",
1502
1590
  meta: normalizeDocument2Meta(json.meta),
1503
1591
  references: parseReferences(json.references),
1504
1592
  blocks: json.blocks.map(
1505
- (block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics, blockIds)
1593
+ (block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics, identities)
1506
1594
  ),
1507
1595
  diagnostics
1508
1596
  };
@@ -8323,12 +8411,14 @@ function cloneField(field) {
8323
8411
  return { id: field.id, tokens: field.tokens.map(cloneToken) };
8324
8412
  }
8325
8413
  function cloneBlock(block) {
8414
+ const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
8326
8415
  if (block.kind === "textBlock") {
8327
- return { ...block, field: cloneField(block.field) };
8416
+ return { ...block, ...metadata, field: cloneField(block.field) };
8328
8417
  }
8329
8418
  if (block.kind === "list") {
8330
8419
  return {
8331
8420
  ...block,
8421
+ ...metadata,
8332
8422
  items: block.items.map((item) => ({
8333
8423
  ...item,
8334
8424
  field: cloneField(item.field),
@@ -8337,12 +8427,12 @@ function cloneBlock(block) {
8337
8427
  };
8338
8428
  }
8339
8429
  if (block.kind === "table") {
8340
- return { ...block, rows: block.rows.map((row) => row.map(cloneField)) };
8430
+ return { ...block, ...metadata, rows: block.rows.map((row) => row.map(cloneField)) };
8341
8431
  }
8342
8432
  if (block.kind === "image") {
8343
- return { ...block, options: { ...block.options } };
8433
+ return { ...block, ...metadata, options: { ...block.options } };
8344
8434
  }
8345
- return { ...block };
8435
+ return { ...block, ...metadata };
8346
8436
  }
8347
8437
  function cloneDocument(document2) {
8348
8438
  return {
@@ -9115,12 +9205,13 @@ function serializeField(field) {
9115
9205
  ...token.label !== void 0 ? { label: token.label } : {}
9116
9206
  });
9117
9207
  }
9118
- return { value, formats, mathObjects, hasPersistedMath };
9208
+ return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
9119
9209
  }
9120
9210
  function fieldJson(field) {
9121
9211
  const serialized = serializeField(field);
9122
9212
  return {
9123
9213
  value: serialized.value,
9214
+ inline_ids: serialized.inlineIds,
9124
9215
  ...serialized.formats.length > 0 ? { formats: serialized.formats } : {},
9125
9216
  ...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
9126
9217
  };
@@ -9128,7 +9219,9 @@ function fieldJson(field) {
9128
9219
  function listItemJson(item) {
9129
9220
  const field = fieldJson(item.field);
9130
9221
  return {
9222
+ id: item.id,
9131
9223
  value: field.value ?? "",
9224
+ inline_ids: field.inline_ids,
9132
9225
  ...field.formats ? { formats: field.formats } : {},
9133
9226
  ...field.math_objects ? { math_objects: field.math_objects } : {},
9134
9227
  ...item.blocks.length > 0 ? { blocks: item.blocks.map(blockJson) } : {}
@@ -9140,6 +9233,7 @@ function blockJson(block) {
9140
9233
  id: block.id,
9141
9234
  command: block.command,
9142
9235
  ...fieldJson(block.field),
9236
+ ...block.metadata ? { metadata: { ...block.metadata } } : {},
9143
9237
  ...block.command === "\\paragraph" ? { centered: block.centered === true } : {}
9144
9238
  };
9145
9239
  }
@@ -9148,7 +9242,8 @@ function blockJson(block) {
9148
9242
  id: block.id,
9149
9243
  command: block.command,
9150
9244
  closing: block.closing,
9151
- items: block.items.map(listItemJson)
9245
+ items: block.items.map(listItemJson),
9246
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9152
9247
  };
9153
9248
  }
9154
9249
  if (block.kind === "table") {
@@ -9160,13 +9255,15 @@ function blockJson(block) {
9160
9255
  closing: block.closing,
9161
9256
  columns: block.columns,
9162
9257
  rows: fields.map((row) => row.map((field) => field.value)),
9258
+ cell_inline_ids: fields.map((row) => row.map((field) => field.inlineIds)),
9163
9259
  ...fields.some((row) => row.some((field) => field.formats.length > 0)) ? { cell_formats: fields.map((row) => row.map((field) => field.formats)) } : {},
9164
9260
  ...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
9165
9261
  centered: block.centered,
9166
9262
  caption_enabled: block.captionEnabled,
9167
9263
  caption: block.caption,
9168
9264
  label_enabled: block.labelEnabled,
9169
- label: block.label
9265
+ label: block.label,
9266
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9170
9267
  };
9171
9268
  }
9172
9269
  if (block.kind === "image") {
@@ -9180,13 +9277,24 @@ function blockJson(block) {
9180
9277
  caption_enabled: block.captionEnabled,
9181
9278
  caption: block.caption,
9182
9279
  label_enabled: block.labelEnabled,
9183
- label: block.label
9280
+ label: block.label,
9281
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9184
9282
  };
9185
9283
  }
9186
9284
  if (block.kind === "bibliography") {
9187
- return { id: block.id, command: block.command, closing: block.closing };
9285
+ return {
9286
+ id: block.id,
9287
+ command: block.command,
9288
+ closing: block.closing,
9289
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9290
+ };
9188
9291
  }
9189
- return { id: block.id, command: block.command, value: block.value };
9292
+ return {
9293
+ id: block.id,
9294
+ command: block.command,
9295
+ value: block.value,
9296
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9297
+ };
9190
9298
  }
9191
9299
  function referenceJson(reference) {
9192
9300
  return {
@@ -9835,19 +9943,21 @@ function previewInlines(field, islands, output, equationSide, document2, preview
9835
9943
  }
9836
9944
  function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
9837
9945
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
9946
+ const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
9838
9947
  if (block.command === "\\section") {
9839
- return { kind: "heading", id: block.id, level: 1, inlines };
9948
+ return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
9840
9949
  }
9841
9950
  if (block.command === "\\subsection") {
9842
- return { kind: "heading", id: block.id, level: 2, inlines };
9951
+ return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
9843
9952
  }
9844
9953
  if (block.command === "\\subsubsection") {
9845
- return { kind: "heading", id: block.id, level: 3, inlines };
9954
+ return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
9846
9955
  }
9847
9956
  return {
9848
9957
  kind: "paragraph",
9849
9958
  id: block.id,
9850
9959
  inlines,
9960
+ ...metadata,
9851
9961
  ...block.centered ? { centered: true } : {}
9852
9962
  };
9853
9963
  }
@@ -9878,7 +9988,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9878
9988
  id: item.id,
9879
9989
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
9880
9990
  blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
9881
- }))
9991
+ })),
9992
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9882
9993
  };
9883
9994
  }
9884
9995
  if (block.kind === "table") {
@@ -9888,7 +9999,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9888
9999
  id: block.id,
9889
10000
  rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
9890
10001
  ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
9891
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {}
10002
+ ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
10003
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9892
10004
  };
9893
10005
  }
9894
10006
  if (block.kind === "image") {
@@ -9900,7 +10012,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9900
10012
  ...block.assetId !== void 0 ? { assetId: block.assetId } : {},
9901
10013
  options: block.options,
9902
10014
  ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
9903
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {}
10015
+ ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
10016
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9904
10017
  };
9905
10018
  }
9906
10019
  if (block.kind === "bibliography") {
@@ -9920,10 +10033,11 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9920
10033
  url: reference.url,
9921
10034
  venue: reference.venue,
9922
10035
  fieldSeparator: reference.fieldSeparator
9923
- }))
10036
+ })),
10037
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9924
10038
  };
9925
10039
  }
9926
- return { kind: "omit", id: block.id };
10040
+ return { kind: "omit", id: block.id, ...block.metadata ? { metadata: { ...block.metadata } } : {} };
9927
10041
  }
9928
10042
  function articleChromePreview(document2, uiLocale, previewOptions) {
9929
10043
  const meta = document2.meta ?? emptyDocument2Meta();
@@ -11993,13 +12107,13 @@ function BlockEditor({
11993
12107
  }
11994
12108
  ) : null;
11995
12109
  if (isCollapsed && showChrome) {
11996
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12110
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
11997
12111
  header,
11998
12112
  /* @__PURE__ */ jsx7("div", { className: "butex-document2-widget__block-summary", children: blockSummary(block, references.length, messages) })
11999
12113
  ] });
12000
12114
  }
12001
12115
  if (block.kind === "textBlock") {
12002
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12116
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12003
12117
  header,
12004
12118
  /* @__PURE__ */ jsx7(InlineField, { field: block.field, ...fieldProps }),
12005
12119
  block.command === "\\paragraph" ? /* @__PURE__ */ jsx7("div", { className: "butex-document2-widget__float-meta butex-document2-widget__float-meta--compact", children: /* @__PURE__ */ jsxs5("label", { className: "butex-document2-widget__float-meta-toggle", children: [
@@ -12019,7 +12133,7 @@ function BlockEditor({
12019
12133
  ] });
12020
12134
  }
12021
12135
  if (block.kind === "list") {
12022
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12136
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12023
12137
  header,
12024
12138
  block.items.map((item, index) => /* @__PURE__ */ jsxs5("div", { className: "butex-document2-widget__field", dir: "rtl", children: [
12025
12139
  /* @__PURE__ */ jsx7("span", { className: "butex-document2-widget__toolbar-label", children: block.command === "\\begin{enumerate}" ? `${messages.item} ${String(index + 1)}` : messages.item }),
@@ -12070,7 +12184,7 @@ function BlockEditor({
12070
12184
  ] });
12071
12185
  }
12072
12186
  if (block.kind === "table") {
12073
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12187
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12074
12188
  header,
12075
12189
  block.rows.map((row, rowIndex) => /* @__PURE__ */ jsx7("div", { className: "butex-document2-widget__row", dir: documentDirection, children: row.map((cell) => /* @__PURE__ */ jsx7("div", { className: "butex-document2-widget__table-cell", dir: documentDirection, children: /* @__PURE__ */ jsx7(InlineField, { field: cell, ...fieldProps }) }, cell.id)) }, rowIndex)),
12076
12190
  /* @__PURE__ */ jsx7(
@@ -12092,7 +12206,7 @@ function BlockEditor({
12092
12206
  ] });
12093
12207
  }
12094
12208
  if (block.kind === "image") {
12095
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12209
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12096
12210
  header,
12097
12211
  /* @__PURE__ */ jsx7(
12098
12212
  ImageAssetEditor,
@@ -12129,7 +12243,7 @@ function BlockEditor({
12129
12243
  ] });
12130
12244
  }
12131
12245
  if (block.kind === "bibliography") {
12132
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12246
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12133
12247
  header,
12134
12248
  /* @__PURE__ */ jsx7("ol", { className: "butex-document2-widget__bibliography-editor", dir: documentDirection, children: referenceList.map((reference, index) => /* @__PURE__ */ jsxs5("li", { children: [
12135
12249
  /* @__PURE__ */ jsxs5("strong", { children: [
@@ -12145,7 +12259,7 @@ function BlockEditor({
12145
12259
  onManageReferences ? /* @__PURE__ */ jsx7("button", { type: "button", onClick: onManageReferences, children: messages.manageReferences }) : null
12146
12260
  ] });
12147
12261
  }
12148
- return /* @__PURE__ */ jsxs5("section", { className: chromeClass, children: [
12262
+ return /* @__PURE__ */ jsxs5("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12149
12263
  header,
12150
12264
  /* @__PURE__ */ jsx7("pre", { className: "butex-document2-widget__raw", children: block.value })
12151
12265
  ] });
@@ -12634,6 +12748,7 @@ function PreviewBlock({
12634
12748
  }) {
12635
12749
  const messages = document2Messages(uiLocale);
12636
12750
  const floatCaptionSeparator = uiLocale === "ar" ? ": " : ". ";
12751
+ const source = "metadata" in block ? block.metadata?.source : void 0;
12637
12752
  function FloatCaption({ numberLabel, caption }) {
12638
12753
  if (!numberLabel && !caption) {
12639
12754
  return null;
@@ -12673,14 +12788,14 @@ function PreviewBlock({
12673
12788
  }
12674
12789
  if (block.kind === "heading") {
12675
12790
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
12676
- return /* @__PURE__ */ jsx11(Tag, { children: /* @__PURE__ */ jsx11(PreviewInlines, { inlines: block.inlines, output }) });
12791
+ return /* @__PURE__ */ jsx11(Tag, { "data-butex-block-source": source, children: /* @__PURE__ */ jsx11(PreviewInlines, { inlines: block.inlines, output }) });
12677
12792
  }
12678
12793
  if (block.kind === "paragraph") {
12679
- return /* @__PURE__ */ jsx11("p", { className: block.centered ? "butex-document2-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ jsx11(PreviewInlines, { inlines: block.inlines, output }) });
12794
+ return /* @__PURE__ */ jsx11("p", { "data-butex-block-source": source, className: block.centered ? "butex-document2-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ jsx11(PreviewInlines, { inlines: block.inlines, output }) });
12680
12795
  }
12681
12796
  if (block.kind === "list") {
12682
12797
  const Tag = block.ordered ? "ol" : "ul";
12683
- return /* @__PURE__ */ jsx11(Tag, { children: block.items.map((item) => /* @__PURE__ */ jsxs9("li", { children: [
12798
+ return /* @__PURE__ */ jsx11(Tag, { "data-butex-block-source": source, children: block.items.map((item) => /* @__PURE__ */ jsxs9("li", { children: [
12684
12799
  /* @__PURE__ */ jsx11(PreviewInlines, { inlines: item.inlines, output }),
12685
12800
  item.blocks.map((child) => /* @__PURE__ */ jsx11(
12686
12801
  PreviewBlock,
@@ -12700,20 +12815,20 @@ function PreviewBlock({
12700
12815
  return null;
12701
12816
  }
12702
12817
  if (block.kind === "table") {
12703
- return /* @__PURE__ */ jsxs9("figure", { className: "butex-document2-widget__preview-float", children: [
12818
+ return /* @__PURE__ */ jsxs9("figure", { className: "butex-document2-widget__preview-float", "data-butex-block-source": source, children: [
12704
12819
  /* @__PURE__ */ jsx11("table", { children: /* @__PURE__ */ jsx11("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ jsx11("tr", { children: row.map((cell, columnIndex) => /* @__PURE__ */ jsx11("td", { children: /* @__PURE__ */ jsx11(PreviewInlines, { inlines: cell, output }) }, columnIndex)) }, rowIndex)) }) }),
12705
12820
  /* @__PURE__ */ jsx11(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption })
12706
12821
  ] });
12707
12822
  }
12708
12823
  if (block.kind === "image") {
12709
12824
  const src = resolveImageUrl ? resolveImageUrl({ assetId: block.assetId, value: block.src }) : block.src;
12710
- return /* @__PURE__ */ jsxs9("figure", { className: "butex-document2-widget__preview-float", children: [
12825
+ return /* @__PURE__ */ jsxs9("figure", { className: "butex-document2-widget__preview-float", "data-butex-block-source": source, children: [
12711
12826
  /* @__PURE__ */ jsx11("img", { src, alt: block.caption ?? "" }),
12712
12827
  /* @__PURE__ */ jsx11(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption })
12713
12828
  ] });
12714
12829
  }
12715
12830
  if (block.kind === "bibliography") {
12716
- return /* @__PURE__ */ jsx11("ol", { className: "butex-document2-widget__preview-bibliography", children: block.items.map((item) => /* @__PURE__ */ jsxs9("li", { children: [
12831
+ return /* @__PURE__ */ jsx11("ol", { className: "butex-document2-widget__preview-bibliography", "data-butex-block-source": source, children: block.items.map((item) => /* @__PURE__ */ jsxs9("li", { children: [
12717
12832
  /* @__PURE__ */ jsxs9("span", { className: "butex-document2-widget__preview-bib-number", children: [
12718
12833
  item.numberLabel,
12719
12834
  "."