@drghaliasri/butex 6.0.1 → 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.
@@ -1005,6 +1005,76 @@ function applyFloatMetaPatch(block, patch) {
1005
1005
  }
1006
1006
  }
1007
1007
 
1008
+ // src/document2/inlineIdentity.ts
1009
+ function createDocument2IdentityState() {
1010
+ return {
1011
+ blockIds: /* @__PURE__ */ new Set(),
1012
+ itemIds: /* @__PURE__ */ new Set(),
1013
+ fieldIds: /* @__PURE__ */ new Set(),
1014
+ tokenIds: /* @__PURE__ */ new Set()
1015
+ };
1016
+ }
1017
+ function importedOrGeneratedId(value, prefix, used) {
1018
+ const imported = typeof value === "string" ? value.trim() : "";
1019
+ if (imported.length > 0 && !used.has(imported)) {
1020
+ used.add(imported);
1021
+ return imported;
1022
+ }
1023
+ let generated = document2Id(prefix);
1024
+ while (used.has(generated)) {
1025
+ generated = document2Id(prefix);
1026
+ }
1027
+ used.add(generated);
1028
+ return generated;
1029
+ }
1030
+ function inlineTokenSource(token) {
1031
+ if (token.kind === "text") {
1032
+ return token.text;
1033
+ }
1034
+ if (token.kind === "math") {
1035
+ return token.source;
1036
+ }
1037
+ if (token.kind === "cite") {
1038
+ return citeTokenLatex(token.keys);
1039
+ }
1040
+ return refTokenLatex(token.keys, token.refCommand);
1041
+ }
1042
+ function inlineIdsFromField(field) {
1043
+ let offset = 0;
1044
+ const tokens = field.tokens.map((token) => {
1045
+ const start = offset;
1046
+ offset += inlineTokenSource(token).length;
1047
+ return { id: token.id, kind: token.kind, start, end: offset };
1048
+ });
1049
+ return { field_id: field.id, tokens };
1050
+ }
1051
+ function isAlignedSidecar(value, field) {
1052
+ if (typeof value !== "object" || value === null || !Array.isArray(value.tokens)) {
1053
+ return false;
1054
+ }
1055
+ const tokens = value.tokens;
1056
+ const expected = inlineIdsFromField(field).tokens;
1057
+ if (tokens.length !== expected.length) {
1058
+ return false;
1059
+ }
1060
+ return tokens.every((token, index) => {
1061
+ const expectedToken = expected[index];
1062
+ return typeof token === "object" && token !== null && expectedToken !== void 0 && token.kind === expectedToken.kind && token.start === expectedToken.start && token.end === expectedToken.end;
1063
+ });
1064
+ }
1065
+ function applyImportedInlineIds(field, sidecar, state) {
1066
+ field.id = importedOrGeneratedId(
1067
+ typeof sidecar === "object" && sidecar !== null ? sidecar.field_id : void 0,
1068
+ "field",
1069
+ state.fieldIds
1070
+ );
1071
+ const aligned = isAlignedSidecar(sidecar, field);
1072
+ field.tokens.forEach((token, index) => {
1073
+ token.id = importedOrGeneratedId(aligned ? sidecar.tokens[index]?.id : void 0, token.kind, state.tokenIds);
1074
+ });
1075
+ return field;
1076
+ }
1077
+
1008
1078
  // src/document2/inlineScanner.ts
1009
1079
  var MATH_ENVIRONMENTS = /* @__PURE__ */ new Set([
1010
1080
  "equation",
@@ -1083,17 +1153,13 @@ function citeSpan(value, start) {
1083
1153
  function refSpan(value, start) {
1084
1154
  const eqrefPrefix = "\\eqref{";
1085
1155
  const refPrefix = "\\ref{";
1086
- let refCommand = "ref";
1087
- let prefix = refPrefix;
1088
- if (value.startsWith(eqrefPrefix, start) && !isEscaped(value, start)) {
1089
- refCommand = "eqref";
1090
- prefix = eqrefPrefix;
1091
- } else if (value.startsWith(refPrefix, start) && !isEscaped(value, start)) {
1092
- refCommand = "ref";
1093
- prefix = refPrefix;
1094
- } else {
1156
+ const isEqref = value.startsWith(eqrefPrefix, start) && !isEscaped(value, start);
1157
+ const isRef = value.startsWith(refPrefix, start) && !isEscaped(value, start);
1158
+ if (!isEqref && !isRef) {
1095
1159
  return null;
1096
1160
  }
1161
+ const refCommand = isEqref ? "eqref" : "ref";
1162
+ const prefix = isEqref ? eqrefPrefix : refPrefix;
1097
1163
  const openBrace = start + prefix.length - 1;
1098
1164
  if (value[openBrace] !== "{") {
1099
1165
  return null;
@@ -1152,7 +1218,14 @@ function mathSpanAt(value, i) {
1152
1218
  return null;
1153
1219
  }
1154
1220
  function detectMathSpans2(value) {
1155
- return detectInlineSpans2(value).filter((span) => span.kind === "math").map(({ kind: _kind, ...span }) => span);
1221
+ return detectInlineSpans2(value).filter((span) => span.kind === "math").map((span) => ({
1222
+ start: span.start,
1223
+ end: span.end,
1224
+ source: span.source,
1225
+ opening: span.opening,
1226
+ closing: span.closing,
1227
+ display: span.display
1228
+ }));
1156
1229
  }
1157
1230
  function detectInlineSpans2(value) {
1158
1231
  const spans = [];
@@ -1206,17 +1279,13 @@ function asBlockJson(value) {
1206
1279
  return value;
1207
1280
  }
1208
1281
  function blockIdFromJson(json, state) {
1209
- const imported = typeof json.id === "string" ? json.id.trim() : "";
1210
- if (imported.length > 0 && !state.used.has(imported)) {
1211
- state.used.add(imported);
1212
- return imported;
1213
- }
1214
- let generated = document2Id("block");
1215
- while (state.used.has(generated)) {
1216
- generated = document2Id("block");
1282
+ return importedOrGeneratedId(json.id, "block", state.blockIds);
1283
+ }
1284
+ function metadataFromJson(value) {
1285
+ if (!isObject2(value) || value.source !== "agent" && value.source !== "user") {
1286
+ return {};
1217
1287
  }
1218
- state.used.add(generated);
1219
- return generated;
1288
+ return { metadata: { source: value.source } };
1220
1289
  }
1221
1290
  function pushDiagnostic(diagnostics, options, path, message) {
1222
1291
  if (options.strict) {
@@ -1399,44 +1468,54 @@ function pushFormattedTextTokens(tokens, text, sourceStart, formats) {
1399
1468
  function closingForList(command) {
1400
1469
  return command === "\\begin{itemize}" ? "\\end{itemize}" : "\\end{enumerate}";
1401
1470
  }
1402
- function parseTextBlock(json, options, path, diagnostics, blockIds) {
1471
+ function parseTextBlock(json, options, path, diagnostics, identities) {
1403
1472
  const value = requireString(json.value, `${json.command} requires string value`);
1404
1473
  return {
1405
- id: blockIdFromJson(json, blockIds),
1474
+ id: blockIdFromJson(json, identities),
1406
1475
  kind: "textBlock",
1407
1476
  command: json.command,
1408
- field: createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.command === "\\paragraph" ? json.formats ?? [] : []),
1477
+ field: applyImportedInlineIds(
1478
+ createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.command === "\\paragraph" ? json.formats ?? [] : []),
1479
+ json.inline_ids,
1480
+ identities
1481
+ ),
1482
+ ...metadataFromJson(json.metadata),
1409
1483
  ...json.centered === true ? { centered: true } : {}
1410
1484
  };
1411
1485
  }
1412
- function parseListItem(json, options, path, diagnostics, blockIds) {
1486
+ function parseListItem(json, options, path, diagnostics, identities) {
1413
1487
  const value = requireString(json.value, "Document list item requires string value");
1414
1488
  const blocksJson = Array.isArray(json.blocks) ? json.blocks : [];
1415
1489
  return {
1416
- id: document2Id("item"),
1417
- field: createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.formats ?? []),
1490
+ id: importedOrGeneratedId(json.id, "item", identities.itemIds),
1491
+ field: applyImportedInlineIds(
1492
+ createInlineField2(value, json.math_objects ?? [], options, `${path}.value`, diagnostics, json.formats ?? []),
1493
+ json.inline_ids,
1494
+ identities
1495
+ ),
1418
1496
  blocks: blocksJson.map(
1419
- (block, index) => parseBlock(asBlockJson(block), options, `${path}.blocks[${String(index)}]`, diagnostics, blockIds)
1497
+ (block, index) => parseBlock(asBlockJson(block), options, `${path}.blocks[${String(index)}]`, diagnostics, identities)
1420
1498
  )
1421
1499
  };
1422
1500
  }
1423
- function parseListBlock(json, options, path, diagnostics, blockIds) {
1501
+ function parseListBlock(json, options, path, diagnostics, identities) {
1424
1502
  if (!Array.isArray(json.items)) {
1425
1503
  throw new Error(`${json.command} requires items array`);
1426
1504
  }
1427
1505
  const command = json.command;
1428
1506
  const closing = closingForList(command);
1429
1507
  return {
1430
- id: blockIdFromJson(json, blockIds),
1508
+ id: blockIdFromJson(json, identities),
1431
1509
  kind: "list",
1432
1510
  command,
1433
1511
  closing,
1434
1512
  items: json.items.map(
1435
- (item, index) => parseListItem(item, options, `${path}.items[${String(index)}]`, diagnostics, blockIds)
1436
- )
1513
+ (item, index) => parseListItem(item, options, `${path}.items[${String(index)}]`, diagnostics, identities)
1514
+ ),
1515
+ ...metadataFromJson(json.metadata)
1437
1516
  };
1438
1517
  }
1439
- function parseTableBlock(json, options, path, diagnostics, blockIds) {
1518
+ function parseTableBlock(json, options, path, diagnostics, identities) {
1440
1519
  if (!Array.isArray(json.rows)) {
1441
1520
  throw new Error("\\begin{tabular} requires rows array");
1442
1521
  }
@@ -1452,75 +1531,84 @@ function parseTableBlock(json, options, path, diagnostics, blockIds) {
1452
1531
  const cellMathObjects = mathObjects.slice(mathObjectIndex, mathObjectIndex + spanCount);
1453
1532
  mathObjectIndex += spanCount;
1454
1533
  const cellFormats = json.cell_formats?.[rowIndex]?.[columnIndex] ?? [];
1455
- return createInlineField2(value, cellMathObjects, options, `${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`, diagnostics, cellFormats);
1534
+ return applyImportedInlineIds(
1535
+ createInlineField2(value, cellMathObjects, options, `${path}.rows[${String(rowIndex)}][${String(columnIndex)}]`, diagnostics, cellFormats),
1536
+ json.cell_inline_ids?.[rowIndex]?.[columnIndex],
1537
+ identities
1538
+ );
1456
1539
  });
1457
1540
  });
1458
1541
  if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
1459
1542
  pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
1460
1543
  }
1461
1544
  return {
1462
- id: blockIdFromJson(json, blockIds),
1545
+ id: blockIdFromJson(json, identities),
1463
1546
  kind: "table",
1464
1547
  command: "\\begin{tabular}",
1465
1548
  closing: "\\end{tabular}",
1466
1549
  columns: typeof json.columns === "string" ? json.columns : "",
1467
1550
  rows,
1468
- ...parseFloatMetaFromJson(json)
1551
+ ...parseFloatMetaFromJson(json),
1552
+ ...metadataFromJson(json.metadata)
1469
1553
  };
1470
1554
  }
1471
- function parseImageBlock(json, blockIds) {
1555
+ function parseImageBlock(json, identities) {
1472
1556
  const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
1473
1557
  const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
1474
1558
  return {
1475
- id: blockIdFromJson(json, blockIds),
1559
+ id: blockIdFromJson(json, identities),
1476
1560
  kind: "image",
1477
1561
  command: "\\includegraphics",
1478
1562
  value,
1479
1563
  ...assetId !== void 0 ? { assetId } : {},
1480
1564
  options: isRecordOfStrings(json.options) ? json.options : {},
1481
- ...parseFloatMetaFromJson(json)
1565
+ ...parseFloatMetaFromJson(json),
1566
+ ...metadataFromJson(json.metadata)
1482
1567
  };
1483
1568
  }
1484
- function parseRawBlock(json, blockIds) {
1569
+ function parseRawBlock(json, identities) {
1485
1570
  return {
1486
- id: blockIdFromJson(json, blockIds),
1571
+ id: blockIdFromJson(json, identities),
1487
1572
  kind: "raw",
1488
1573
  command: "\\raw",
1489
- value: typeof json.value === "string" ? json.value : ""
1574
+ value: typeof json.value === "string" ? json.value : "",
1575
+ ...metadataFromJson(json.metadata)
1490
1576
  };
1491
1577
  }
1492
- function parseBibliographyBlock(json, blockIds) {
1578
+ function parseBibliographyBlock(json, identities) {
1493
1579
  return {
1494
- id: blockIdFromJson(json, blockIds),
1580
+ id: blockIdFromJson(json, identities),
1495
1581
  kind: "bibliography",
1496
1582
  command: "\\begin{thebibliography}",
1497
- closing: "\\end{thebibliography}"
1583
+ closing: "\\end{thebibliography}",
1584
+ ...metadataFromJson(json.metadata)
1498
1585
  };
1499
1586
  }
1500
- function parseBlock(json, options, path, diagnostics, blockIds) {
1587
+ function parseBlock(json, options, path, diagnostics, identities) {
1501
1588
  if (TEXT_COMMANDS.has(json.command)) {
1502
- return parseTextBlock(json, options, path, diagnostics, blockIds);
1589
+ return parseTextBlock(json, options, path, diagnostics, identities);
1503
1590
  }
1504
1591
  if (LIST_COMMANDS.has(json.command)) {
1505
- return parseListBlock(json, options, path, diagnostics, blockIds);
1592
+ return parseListBlock(json, options, path, diagnostics, identities);
1506
1593
  }
1507
1594
  if (json.command === "\\begin{tabular}") {
1508
- return parseTableBlock(json, options, path, diagnostics, blockIds);
1595
+ return parseTableBlock(json, options, path, diagnostics, identities);
1509
1596
  }
1510
1597
  if (json.command === "\\includegraphics") {
1511
- return parseImageBlock(json, blockIds);
1598
+ return parseImageBlock(json, identities);
1512
1599
  }
1513
1600
  if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
1514
- return parseBibliographyBlock(json, blockIds);
1601
+ return parseBibliographyBlock(json, identities);
1515
1602
  }
1516
1603
  if (json.command === "\\raw") {
1517
- return parseRawBlock(json, blockIds);
1604
+ return parseRawBlock(json, identities);
1518
1605
  }
1519
1606
  return {
1520
- id: blockIdFromJson(json, blockIds),
1607
+ id: blockIdFromJson(json, identities),
1521
1608
  kind: "raw",
1522
1609
  command: "\\raw",
1523
- value: typeof json.value === "string" ? json.value : json.command
1610
+ value: typeof json.value === "string" ? json.value : json.command,
1611
+ ...metadataFromJson(json.metadata)
1524
1612
  };
1525
1613
  }
1526
1614
  function fromDocumentJson2(json, options = {}) {
@@ -1531,13 +1619,13 @@ function fromDocumentJson2(json, options = {}) {
1531
1619
  throw new Error("DocumentObject requires blocks array");
1532
1620
  }
1533
1621
  const diagnostics = [];
1534
- const blockIds = { used: /* @__PURE__ */ new Set() };
1622
+ const identities = createDocument2IdentityState();
1535
1623
  return {
1536
1624
  nodeType: "DocumentObject",
1537
1625
  meta: normalizeDocument2Meta(json.meta),
1538
1626
  references: parseReferences(json.references),
1539
1627
  blocks: json.blocks.map(
1540
- (block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics, blockIds)
1628
+ (block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics, identities)
1541
1629
  ),
1542
1630
  diagnostics
1543
1631
  };
@@ -8358,12 +8446,14 @@ function cloneField(field) {
8358
8446
  return { id: field.id, tokens: field.tokens.map(cloneToken) };
8359
8447
  }
8360
8448
  function cloneBlock(block) {
8449
+ const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
8361
8450
  if (block.kind === "textBlock") {
8362
- return { ...block, field: cloneField(block.field) };
8451
+ return { ...block, ...metadata, field: cloneField(block.field) };
8363
8452
  }
8364
8453
  if (block.kind === "list") {
8365
8454
  return {
8366
8455
  ...block,
8456
+ ...metadata,
8367
8457
  items: block.items.map((item) => ({
8368
8458
  ...item,
8369
8459
  field: cloneField(item.field),
@@ -8372,12 +8462,12 @@ function cloneBlock(block) {
8372
8462
  };
8373
8463
  }
8374
8464
  if (block.kind === "table") {
8375
- return { ...block, rows: block.rows.map((row) => row.map(cloneField)) };
8465
+ return { ...block, ...metadata, rows: block.rows.map((row) => row.map(cloneField)) };
8376
8466
  }
8377
8467
  if (block.kind === "image") {
8378
- return { ...block, options: { ...block.options } };
8468
+ return { ...block, ...metadata, options: { ...block.options } };
8379
8469
  }
8380
- return { ...block };
8470
+ return { ...block, ...metadata };
8381
8471
  }
8382
8472
  function cloneDocument(document2) {
8383
8473
  return {
@@ -9150,12 +9240,13 @@ function serializeField(field) {
9150
9240
  ...token.label !== void 0 ? { label: token.label } : {}
9151
9241
  });
9152
9242
  }
9153
- return { value, formats, mathObjects, hasPersistedMath };
9243
+ return { value, formats, mathObjects, hasPersistedMath, inlineIds: inlineIdsFromField(field) };
9154
9244
  }
9155
9245
  function fieldJson(field) {
9156
9246
  const serialized = serializeField(field);
9157
9247
  return {
9158
9248
  value: serialized.value,
9249
+ inline_ids: serialized.inlineIds,
9159
9250
  ...serialized.formats.length > 0 ? { formats: serialized.formats } : {},
9160
9251
  ...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
9161
9252
  };
@@ -9163,7 +9254,9 @@ function fieldJson(field) {
9163
9254
  function listItemJson(item) {
9164
9255
  const field = fieldJson(item.field);
9165
9256
  return {
9257
+ id: item.id,
9166
9258
  value: field.value ?? "",
9259
+ inline_ids: field.inline_ids,
9167
9260
  ...field.formats ? { formats: field.formats } : {},
9168
9261
  ...field.math_objects ? { math_objects: field.math_objects } : {},
9169
9262
  ...item.blocks.length > 0 ? { blocks: item.blocks.map(blockJson) } : {}
@@ -9175,6 +9268,7 @@ function blockJson(block) {
9175
9268
  id: block.id,
9176
9269
  command: block.command,
9177
9270
  ...fieldJson(block.field),
9271
+ ...block.metadata ? { metadata: { ...block.metadata } } : {},
9178
9272
  ...block.command === "\\paragraph" ? { centered: block.centered === true } : {}
9179
9273
  };
9180
9274
  }
@@ -9183,7 +9277,8 @@ function blockJson(block) {
9183
9277
  id: block.id,
9184
9278
  command: block.command,
9185
9279
  closing: block.closing,
9186
- items: block.items.map(listItemJson)
9280
+ items: block.items.map(listItemJson),
9281
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9187
9282
  };
9188
9283
  }
9189
9284
  if (block.kind === "table") {
@@ -9195,13 +9290,15 @@ function blockJson(block) {
9195
9290
  closing: block.closing,
9196
9291
  columns: block.columns,
9197
9292
  rows: fields.map((row) => row.map((field) => field.value)),
9293
+ cell_inline_ids: fields.map((row) => row.map((field) => field.inlineIds)),
9198
9294
  ...fields.some((row) => row.some((field) => field.formats.length > 0)) ? { cell_formats: fields.map((row) => row.map((field) => field.formats)) } : {},
9199
9295
  ...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
9200
9296
  centered: block.centered,
9201
9297
  caption_enabled: block.captionEnabled,
9202
9298
  caption: block.caption,
9203
9299
  label_enabled: block.labelEnabled,
9204
- label: block.label
9300
+ label: block.label,
9301
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9205
9302
  };
9206
9303
  }
9207
9304
  if (block.kind === "image") {
@@ -9215,13 +9312,24 @@ function blockJson(block) {
9215
9312
  caption_enabled: block.captionEnabled,
9216
9313
  caption: block.caption,
9217
9314
  label_enabled: block.labelEnabled,
9218
- label: block.label
9315
+ label: block.label,
9316
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9219
9317
  };
9220
9318
  }
9221
9319
  if (block.kind === "bibliography") {
9222
- return { id: block.id, command: block.command, closing: block.closing };
9320
+ return {
9321
+ id: block.id,
9322
+ command: block.command,
9323
+ closing: block.closing,
9324
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9325
+ };
9223
9326
  }
9224
- return { id: block.id, command: block.command, value: block.value };
9327
+ return {
9328
+ id: block.id,
9329
+ command: block.command,
9330
+ value: block.value,
9331
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9332
+ };
9225
9333
  }
9226
9334
  function referenceJson(reference) {
9227
9335
  return {
@@ -9870,19 +9978,21 @@ function previewInlines(field, islands, output, equationSide, document2, preview
9870
9978
  }
9871
9979
  function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
9872
9980
  const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
9981
+ const metadata = block.metadata ? { metadata: { ...block.metadata } } : {};
9873
9982
  if (block.command === "\\section") {
9874
- return { kind: "heading", id: block.id, level: 1, inlines };
9983
+ return { kind: "heading", id: block.id, level: 1, inlines, ...metadata };
9875
9984
  }
9876
9985
  if (block.command === "\\subsection") {
9877
- return { kind: "heading", id: block.id, level: 2, inlines };
9986
+ return { kind: "heading", id: block.id, level: 2, inlines, ...metadata };
9878
9987
  }
9879
9988
  if (block.command === "\\subsubsection") {
9880
- return { kind: "heading", id: block.id, level: 3, inlines };
9989
+ return { kind: "heading", id: block.id, level: 3, inlines, ...metadata };
9881
9990
  }
9882
9991
  return {
9883
9992
  kind: "paragraph",
9884
9993
  id: block.id,
9885
9994
  inlines,
9995
+ ...metadata,
9886
9996
  ...block.centered ? { centered: true } : {}
9887
9997
  };
9888
9998
  }
@@ -9913,7 +10023,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9913
10023
  id: item.id,
9914
10024
  inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
9915
10025
  blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
9916
- }))
10026
+ })),
10027
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9917
10028
  };
9918
10029
  }
9919
10030
  if (block.kind === "table") {
@@ -9923,7 +10034,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9923
10034
  id: block.id,
9924
10035
  rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions))),
9925
10036
  ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
9926
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {}
10037
+ ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
10038
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9927
10039
  };
9928
10040
  }
9929
10041
  if (block.kind === "image") {
@@ -9935,7 +10047,8 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9935
10047
  ...block.assetId !== void 0 ? { assetId: block.assetId } : {},
9936
10048
  options: block.options,
9937
10049
  ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
9938
- ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {}
10050
+ ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
10051
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9939
10052
  };
9940
10053
  }
9941
10054
  if (block.kind === "bibliography") {
@@ -9955,10 +10068,11 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
9955
10068
  url: reference.url,
9956
10069
  venue: reference.venue,
9957
10070
  fieldSeparator: reference.fieldSeparator
9958
- }))
10071
+ })),
10072
+ ...block.metadata ? { metadata: { ...block.metadata } } : {}
9959
10073
  };
9960
10074
  }
9961
- return { kind: "omit", id: block.id };
10075
+ return { kind: "omit", id: block.id, ...block.metadata ? { metadata: { ...block.metadata } } : {} };
9962
10076
  }
9963
10077
  function articleChromePreview(document2, uiLocale, previewOptions) {
9964
10078
  const meta = document2.meta ?? emptyDocument2Meta();
@@ -12028,13 +12142,13 @@ function BlockEditor({
12028
12142
  }
12029
12143
  ) : null;
12030
12144
  if (isCollapsed && showChrome) {
12031
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12145
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12032
12146
  header,
12033
12147
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "butex-document2-widget__block-summary", children: blockSummary(block, references.length, messages) })
12034
12148
  ] });
12035
12149
  }
12036
12150
  if (block.kind === "textBlock") {
12037
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12151
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12038
12152
  header,
12039
12153
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InlineField, { field: block.field, ...fieldProps }),
12040
12154
  block.command === "\\paragraph" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "butex-document2-widget__float-meta butex-document2-widget__float-meta--compact", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { className: "butex-document2-widget__float-meta-toggle", children: [
@@ -12054,7 +12168,7 @@ function BlockEditor({
12054
12168
  ] });
12055
12169
  }
12056
12170
  if (block.kind === "list") {
12057
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12171
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12058
12172
  header,
12059
12173
  block.items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "butex-document2-widget__field", dir: "rtl", children: [
12060
12174
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "butex-document2-widget__toolbar-label", children: block.command === "\\begin{enumerate}" ? `${messages.item} ${String(index + 1)}` : messages.item }),
@@ -12105,7 +12219,7 @@ function BlockEditor({
12105
12219
  ] });
12106
12220
  }
12107
12221
  if (block.kind === "table") {
12108
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12222
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12109
12223
  header,
12110
12224
  block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "butex-document2-widget__row", dir: documentDirection, children: row.map((cell) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "butex-document2-widget__table-cell", dir: documentDirection, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(InlineField, { field: cell, ...fieldProps }) }, cell.id)) }, rowIndex)),
12111
12225
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
@@ -12127,7 +12241,7 @@ function BlockEditor({
12127
12241
  ] });
12128
12242
  }
12129
12243
  if (block.kind === "image") {
12130
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12244
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12131
12245
  header,
12132
12246
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
12133
12247
  ImageAssetEditor,
@@ -12164,7 +12278,7 @@ function BlockEditor({
12164
12278
  ] });
12165
12279
  }
12166
12280
  if (block.kind === "bibliography") {
12167
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12281
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12168
12282
  header,
12169
12283
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ol", { className: "butex-document2-widget__bibliography-editor", dir: documentDirection, children: referenceList.map((reference, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { children: [
12170
12284
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("strong", { children: [
@@ -12180,7 +12294,7 @@ function BlockEditor({
12180
12294
  onManageReferences ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", onClick: onManageReferences, children: messages.manageReferences }) : null
12181
12295
  ] });
12182
12296
  }
12183
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, children: [
12297
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: chromeClass, "data-butex-block-source": block.metadata?.source, children: [
12184
12298
  header,
12185
12299
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("pre", { className: "butex-document2-widget__raw", children: block.value })
12186
12300
  ] });
@@ -12669,6 +12783,7 @@ function PreviewBlock({
12669
12783
  }) {
12670
12784
  const messages = document2Messages(uiLocale);
12671
12785
  const floatCaptionSeparator = uiLocale === "ar" ? ": " : ". ";
12786
+ const source = "metadata" in block ? block.metadata?.source : void 0;
12672
12787
  function FloatCaption({ numberLabel, caption }) {
12673
12788
  if (!numberLabel && !caption) {
12674
12789
  return null;
@@ -12708,14 +12823,14 @@ function PreviewBlock({
12708
12823
  }
12709
12824
  if (block.kind === "heading") {
12710
12825
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
12711
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Tag, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
12826
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Tag, { "data-butex-block-source": source, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
12712
12827
  }
12713
12828
  if (block.kind === "paragraph") {
12714
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: block.centered ? "butex-document2-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
12829
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { "data-butex-block-source": source, className: block.centered ? "butex-document2-widget__preview-paragraph--centered" : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
12715
12830
  }
12716
12831
  if (block.kind === "list") {
12717
12832
  const Tag = block.ordered ? "ol" : "ul";
12718
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Tag, { children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("li", { children: [
12833
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Tag, { "data-butex-block-source": source, children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("li", { children: [
12719
12834
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewInlines, { inlines: item.inlines, output }),
12720
12835
  item.blocks.map((child) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
12721
12836
  PreviewBlock,
@@ -12735,20 +12850,20 @@ function PreviewBlock({
12735
12850
  return null;
12736
12851
  }
12737
12852
  if (block.kind === "table") {
12738
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("figure", { className: "butex-document2-widget__preview-float", children: [
12853
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("figure", { className: "butex-document2-widget__preview-float", "data-butex-block-source": source, children: [
12739
12854
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("table", { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("tr", { children: row.map((cell, columnIndex) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PreviewInlines, { inlines: cell, output }) }, columnIndex)) }, rowIndex)) }) }),
12740
12855
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption })
12741
12856
  ] });
12742
12857
  }
12743
12858
  if (block.kind === "image") {
12744
12859
  const src = resolveImageUrl ? resolveImageUrl({ assetId: block.assetId, value: block.src }) : block.src;
12745
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("figure", { className: "butex-document2-widget__preview-float", children: [
12860
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("figure", { className: "butex-document2-widget__preview-float", "data-butex-block-source": source, children: [
12746
12861
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("img", { src, alt: block.caption ?? "" }),
12747
12862
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(FloatCaption, { numberLabel: block.numberLabel, caption: block.caption })
12748
12863
  ] });
12749
12864
  }
12750
12865
  if (block.kind === "bibliography") {
12751
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("ol", { className: "butex-document2-widget__preview-bibliography", children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("li", { children: [
12866
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("ol", { className: "butex-document2-widget__preview-bibliography", "data-butex-block-source": source, children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("li", { children: [
12752
12867
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: "butex-document2-widget__preview-bib-number", children: [
12753
12868
  item.numberLabel,
12754
12869
  "."