@superdoc/mcp 1.7.0-next.12 → 1.7.0-next.13

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.
Files changed (2) hide show
  1. package/dist/index.js +186 -46
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31600,7 +31600,7 @@ var init_host = __esm(() => {
31600
31600
  });
31601
31601
 
31602
31602
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31603
- var SDK_VERSION = "2.20.0-next.12";
31603
+ var SDK_VERSION = "2.20.0-next.13";
31604
31604
 
31605
31605
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31606
31606
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -312476,6 +312476,7 @@ function convertHtmlToFragment(html, options = {}) {
312476
312476
  range: { startOffset: 0, endOffset: html.length }
312477
312477
  }), limits.maxDiagnostics);
312478
312478
  }
312479
+ attachSiblingListsToPreviousItems(tree);
312479
312480
  const treeViolation = inspectTreeLimits(tree, limits);
312480
312481
  if (treeViolation) {
312481
312482
  appendBoundedConversionDiagnostic(diagnostics, htmlDiagnostic({
@@ -312537,6 +312538,34 @@ function convertHtmlToFragment(html, options = {}) {
312537
312538
  diagnostics
312538
312539
  };
312539
312540
  }
312541
+ function attachSiblingListsToPreviousItems(parent) {
312542
+ const pending = [parent];
312543
+ while (pending.length > 0) {
312544
+ const current = pending.pop();
312545
+ if ("tagName" in current && (current.tagName === "ul" || current.tagName === "ol")) {
312546
+ let previousItem = null;
312547
+ const retained = [];
312548
+ for (const child of current.childNodes) {
312549
+ if (isElement(child) && child.tagName === "li") {
312550
+ previousItem = child;
312551
+ retained.push(child);
312552
+ } else if (previousItem && isElement(child) && (child.tagName === "ul" || child.tagName === "ol")) {
312553
+ previousItem.childNodes.push(child);
312554
+ child.parentNode = previousItem;
312555
+ } else {
312556
+ if (!isText(child) || child.value.trim() !== "")
312557
+ previousItem = null;
312558
+ retained.push(child);
312559
+ }
312560
+ }
312561
+ current.childNodes = retained;
312562
+ }
312563
+ for (const child of current.childNodes) {
312564
+ if (isElement(child))
312565
+ pending.push(child);
312566
+ }
312567
+ }
312568
+ }
312540
312569
  function parseErrorDiagnostic(error48) {
312541
312570
  return htmlDiagnostic({
312542
312571
  code: "conversion-malformed-input",
@@ -312914,9 +312943,9 @@ function convertSemanticList(root, context, inherited, path6) {
312914
312943
  level,
312915
312944
  path: canonicalPath,
312916
312945
  ...itemValue !== undefined && itemValue !== null ? { marker: `${itemValue}${definition.text?.endsWith(")") ? ")" : "."}` } : {},
312917
- content: content.length > 0 ? content : [
312946
+ content: applyListItemParagraphMarkRunProps(content.length > 0 ? content : [
312918
312947
  paragraph2(context, [], undefined, itemPath, context.droppedContentCount === droppedContentStart)
312919
- ]
312948
+ ], itemContext.runProps)
312920
312949
  });
312921
312950
  for (let nestedIndex = 0;nestedIndex < child.childNodes.length; nestedIndex += 1) {
312922
312951
  const nested = child.childNodes[nestedIndex];
@@ -312984,7 +313013,7 @@ function convertSemanticList(root, context, inherited, path6) {
312984
313013
  level,
312985
313014
  path: canonicalPath,
312986
313015
  ...itemValue !== undefined && itemValue !== null ? { marker: `${itemValue}${definition.text?.endsWith(")") ? ")" : "."}` } : {},
312987
- content: nestedContent
313016
+ content: applyListItemParagraphMarkRunProps(nestedContent, itemContext.runProps)
312988
313017
  });
312989
313018
  }
312990
313019
  if (nestedItems.length === 0)
@@ -313098,7 +313127,7 @@ function convertWordListGroup(group, context, inherited) {
313098
313127
  level: descriptor.level,
313099
313128
  path: canonicalPath,
313100
313129
  ...exceptionalMarker ? { marker: exceptionalMarker } : {},
313101
- content: applyWordListParagraphMarkRunProps(itemContent, itemContext.runProps)
313130
+ content: applyListItemParagraphMarkRunProps(itemContent, itemContext.runProps)
313102
313131
  });
313103
313132
  previousLevel = descriptor.level;
313104
313133
  }
@@ -313110,7 +313139,7 @@ function convertWordListGroup(group, context, inherited) {
313110
313139
  list: { levels: [...levels.values()].sort((a, b) => a.level - b.level), items }
313111
313140
  };
313112
313141
  }
313113
- function applyWordListParagraphMarkRunProps(content, runProps) {
313142
+ function applyListItemParagraphMarkRunProps(content, runProps) {
313114
313143
  if (Object.keys(runProps).length === 0)
313115
313144
  return content;
313116
313145
  let applied = false;
@@ -326322,22 +326351,50 @@ function comparablePlainTokenVariants(plan, plain) {
326322
326351
  return variants;
326323
326352
  }
326324
326353
  function normalizeRepresentedListMarkers(plan, lines) {
326325
- const listTexts = plan.blocks.flatMap((block) => block.kind === "paragraph" && block.listIntent ? [comparableText(blockText(block))] : []);
326326
- if (listTexts.length === 0)
326354
+ const representedTokens = [];
326355
+ const listStarts = new Set;
326356
+ for (const block of plan.blocks) {
326357
+ const tokens = comparableTokens(blockText(block));
326358
+ if (tokens.length > 0 && block.kind === "paragraph" && block.listIntent) {
326359
+ listStarts.add(representedTokens.length);
326360
+ }
326361
+ for (const token of tokens)
326362
+ representedTokens.push(token);
326363
+ }
326364
+ if (listStarts.size === 0)
326327
326365
  return null;
326328
- let listIndex = 0;
326366
+ let tokenIndex = 0;
326367
+ const matchesNext = (tokens) => tokens.length > 0 && tokens.every((token, index2) => token === representedTokens[tokenIndex + index2]);
326329
326368
  let changed = false;
326330
326369
  const normalized = lines.map((line) => {
326331
- if (!hasPlainListMarker(line) || listIndex >= listTexts.length)
326370
+ const tokens = comparableTokens(line);
326371
+ if (matchesNext(tokens)) {
326372
+ tokenIndex += tokens.length;
326373
+ return line;
326374
+ }
326375
+ if (!listStarts.has(tokenIndex))
326332
326376
  return line;
326333
- const withoutMarker = stripPlainListMarker(line);
326334
- if (comparableText(withoutMarker) !== listTexts[listIndex])
326377
+ const withoutMarker = stripRepresentedListMarker(line);
326378
+ if (withoutMarker === null)
326335
326379
  return line;
326336
- listIndex += 1;
326380
+ const withoutMarkerTokens = comparableTokens(withoutMarker);
326381
+ if (!matchesNext(withoutMarkerTokens))
326382
+ return line;
326383
+ tokenIndex += withoutMarkerTokens.length;
326337
326384
  changed = true;
326338
326385
  return withoutMarker;
326339
326386
  });
326340
- return changed && listIndex === listTexts.length ? normalized : null;
326387
+ return changed && tokenIndex === representedTokens.length ? normalized : null;
326388
+ }
326389
+ function stripRepresentedListMarker(line) {
326390
+ if (hasPlainListMarker(line))
326391
+ return stripPlainListMarker(line);
326392
+ const separator = line.indexOf("\t");
326393
+ if (separator < 1)
326394
+ return null;
326395
+ if (!/^(?:o|[\uE000-\uF8FF])$/u.test(line.slice(0, separator).trim()))
326396
+ return null;
326397
+ return line.slice(separator).replace(/^\t+/u, "");
326341
326398
  }
326342
326399
  function hasPlainListMarker(value2) {
326343
326400
  return PLAIN_LIST_MARKER_PATTERN.test(value2);
@@ -326373,7 +326430,7 @@ function isSubsequence(needles, haystack) {
326373
326430
  var PLAIN_LIST_MARKER_PATTERN;
326374
326431
  var init_html_plain_reconciliation = __esm(() => {
326375
326432
  init_contracts();
326376
- PLAIN_LIST_MARKER_PATTERN = /^(?:[•◦▪‣⁃●○■*+-]|\d{1,9}[.)]|[A-Za-z][.)]|[ivxlcdmIVXLCDM]{1,8}[.)])(?:[\t ]+)/u;
326433
+ PLAIN_LIST_MARKER_PATTERN = /^(?:[•◦▪‣⁃●○■□▫◻◽*+-]|\d{1,9}[.)]|[A-Za-z][.)]|[ivxlcdmIVXLCDM]{1,8}[.)])(?:[\t ]+)/u;
326377
326434
  });
326378
326435
 
326379
326436
  // ../../../v2/document-api-v2-adapter/dist/clipboard/parse-v1-slice.js
@@ -328508,15 +328565,14 @@ function* serializeSelectionRangeSteps(context, target, includeHtml, options) {
328508
328565
  let numbering = properties.numbering;
328509
328566
  const listState = readListStateForSession(context.session, resolved.storyId, entry.blockId);
328510
328567
  let listKind = listState?.isListItem ? listState.numFmt === "bullet" ? "bullet" : listState.numFmt ? "ordered" : undefined : undefined;
328568
+ const marker = fullyCovered || listKind ? resolveNumberingLevelForMarker({
328569
+ resolverParams: styleModel.resolverParams,
328570
+ numId: listState?.isListItem && listState.numId != null ? Number(listState.numId) : properties.numbering ? Number(properties.numbering.numId) : undefined,
328571
+ ilvl: listState?.isListItem ? listState.ilvl : properties.numbering ? Number(properties.numbering.ilvl) : undefined,
328572
+ paragraphStyleId: properties.styleRef
328573
+ }) : null;
328511
328574
  if (fullyCovered) {
328512
- const model = copyStyleModel ?? (copyStyleModel = compileCopyStyleModel(context));
328513
- const marker = resolveNumberingLevelForMarker({
328514
- resolverParams: model.resolverParams,
328515
- numId: properties.numbering ? Number(properties.numbering.numId) : undefined,
328516
- ilvl: properties.numbering ? Number(properties.numbering.ilvl) : undefined,
328517
- paragraphStyleId: properties.styleRef
328518
- });
328519
- if (marker.definition && !marker.definition.suppressed) {
328575
+ if (marker?.definition && !marker.definition.suppressed) {
328520
328576
  numbering = {
328521
328577
  numId: String(marker.definition.numId),
328522
328578
  ilvl: String(marker.definition.ilvl)
@@ -328564,7 +328620,8 @@ function* serializeSelectionRangeSteps(context, target, includeHtml, options) {
328564
328620
  ...cellFormatting
328565
328621
  }
328566
328622
  } : {},
328567
- ...listKind ? { listKind } : {},
328623
+ ...listKind ? { listKind, listLevel: listState?.isListItem ? listState.ilvl : listLevel ?? 0 } : {},
328624
+ ...listKind && marker?.definition ? { listMarkerStyle: portableListMarkerStyle(marker.definition, styleModel, paragraphXml) } : {},
328568
328625
  ...semanticHeadingLevel != null && semanticHeadingLevel >= 1 && semanticHeadingLevel <= 6 ? { headingLevel: semanticHeadingLevel } : {},
328569
328626
  parts
328570
328627
  });
@@ -329774,14 +329831,14 @@ function paragraphPaintedLength(xml) {
329774
329831
  const map3 = parseParagraphInlineMap(xml);
329775
329832
  return map3.visibleLength + map3.leaves().filter(isVisibleZeroWidthObjectPiece).length;
329776
329833
  }
329777
- function blockInlineHtml(block, assets) {
329778
- return block.parts.map((part) => renderHtmlPart(part, assets)).join("");
329834
+ function blockInlineHtml(block, assets, defaultTextColor) {
329835
+ return block.parts.map((part) => renderHtmlPart(part, assets, defaultTextColor)).join("");
329779
329836
  }
329780
- function renderHtmlPart(part, assets) {
329837
+ function renderHtmlPart(part, assets, defaultTextColor) {
329781
329838
  if (part.kind === "break")
329782
329839
  return "<br/>";
329783
329840
  if (part.kind === "run")
329784
- return renderHtmlRun(part.run);
329841
+ return renderHtmlRun(part.run, defaultTextColor);
329785
329842
  if (part.kind === "image") {
329786
329843
  const asset = assets.get(part.image.assetId);
329787
329844
  if (!asset)
@@ -329790,18 +329847,17 @@ function renderHtmlPart(part, assets) {
329790
329847
  return `<img src="data:${asset.mimeType};base64,${asset.data}" width="${widthPx}" height="${heightPx}"` + (alt ? ` alt="${escapeHtmlAttribute(alt)}"` : "") + (title2 ? ` title="${escapeHtmlAttribute(title2)}"` : "") + "/>";
329791
329848
  }
329792
329849
  if (part.kind === "sdt")
329793
- return part.parts.map((child) => renderHtmlPart(child, assets)).join("");
329850
+ return part.parts.map((child) => renderHtmlPart(child, assets, defaultTextColor)).join("");
329794
329851
  const href = part.target.kind === "external" ? part.target.url : `#${part.target.anchor}`;
329795
329852
  const title = part.tooltip ? ` title="${escapeHtmlAttribute(part.tooltip)}"` : "";
329796
- return `<a href="${escapeHtmlAttribute(href)}"${title}>${part.parts.map((child) => renderHtmlPart(child, assets)).join("")}</a>`;
329853
+ return `<a href="${escapeHtmlAttribute(href)}"${title}>${part.parts.map((child) => renderHtmlPart(child, assets, defaultTextColor)).join("")}</a>`;
329797
329854
  }
329798
329855
  function buildHtmlFlavor(grouped, assets) {
329799
329856
  const out = [];
329800
- let openList = null;
329857
+ const openLists = [];
329801
329858
  const closeList = () => {
329802
- if (openList) {
329803
- out.push(`</${openList}>`);
329804
- openList = null;
329859
+ while (openLists.length > 0) {
329860
+ out.push(`</li></${openLists.pop().tag}>`);
329805
329861
  }
329806
329862
  };
329807
329863
  for (const entry of grouped) {
@@ -329811,15 +329867,41 @@ function buildHtmlFlavor(grouped, assets) {
329811
329867
  continue;
329812
329868
  }
329813
329869
  const block = entry.block;
329814
- const inline = blockInlineHtml(block, assets);
329870
+ const inline = blockInlineHtml(block, assets, block.listMarkerStyle?.color && block.listMarkerStyle.color !== "000000" ? "000000" : undefined);
329815
329871
  if (block.listKind) {
329816
329872
  const tag = block.listKind === "bullet" ? "ul" : "ol";
329817
- if (openList !== tag) {
329818
- closeList();
329819
- out.push(`<${tag}>`);
329820
- openList = tag;
329821
- }
329822
- out.push(`<li>${inline}</li>`);
329873
+ const styleType = block.listMarkerStyle?.type;
329874
+ const level = block.listLevel ?? 0;
329875
+ if (openLists.length > 0)
329876
+ openLists[0].sourceLevel = Math.min(openLists[0].sourceLevel, level);
329877
+ while (openLists.length > 1 && openLists[openLists.length - 1].sourceLevel > level) {
329878
+ out.push(`</li></${openLists.pop().tag}>`);
329879
+ }
329880
+ const depth = openLists.length === 0 ? 0 : level > openLists[openLists.length - 1].sourceLevel ? openLists.length : openLists.length - 1;
329881
+ if (openLists.length === depth + 1) {
329882
+ out.push("</li>");
329883
+ if (openLists[depth].tag !== tag || openLists[depth].styleType !== styleType) {
329884
+ out.push(`</${openLists.pop().tag}>`);
329885
+ }
329886
+ }
329887
+ if (openLists.length === depth) {
329888
+ const listStyles = [
329889
+ ...styleType ? [`list-style-type: ${styleType}`] : [],
329890
+ ...openLists[depth - 1]?.currentItemHasMarkerColor ? ["color: #000000"] : []
329891
+ ];
329892
+ const orderedType = tag === "ol" ? orderedListTypeAttribute(styleType) : undefined;
329893
+ out.push(`<${tag}${orderedType ? ` type="${orderedType}"` : ""}` + `${listStyles.length > 0 ? ` style="${listStyles.join("; ")}"` : ""}>`);
329894
+ openLists.push({ tag, sourceLevel: level, ...styleType ? { styleType } : {}, currentItemHasMarkerColor: false });
329895
+ }
329896
+ const markerColor = block.listMarkerStyle?.color;
329897
+ const previousItemHadColoredMarker = openLists[openLists.length - 1].currentItemHasMarkerColor;
329898
+ const itemColor = markerColor && markerColor !== "000000" ? markerColor : previousItemHadColoredMarker ? "000000" : undefined;
329899
+ const itemStyles = [
329900
+ ...styleType ? [`list-style-type: ${styleType}`] : [],
329901
+ ...itemColor ? [`color: #${itemColor}`] : []
329902
+ ];
329903
+ out.push(`<li${itemStyles.length > 0 ? ` style="${itemStyles.join("; ")}"` : ""}>${inline}`);
329904
+ openLists[openLists.length - 1].currentItemHasMarkerColor = Boolean(markerColor && markerColor !== "000000");
329823
329905
  continue;
329824
329906
  }
329825
329907
  closeList();
@@ -329831,6 +329913,63 @@ function buildHtmlFlavor(grouped, assets) {
329831
329913
  closeList();
329832
329914
  return out.join("");
329833
329915
  }
329916
+ function portableListMarkerStyle(definition2, model, paragraphXml) {
329917
+ const glyph = definition2.lvlText?.trim();
329918
+ const type = definition2.numFmt === "bullet" ? glyph === "•" || glyph === "●" || glyph === "" ? "disc" : glyph === "◦" || glyph === "○" ? "circle" : glyph === "▪" || glyph === "■" || glyph === "◼" ? "square" : undefined : portableOrderedListStyleType(definition2.numFmt);
329919
+ const runContext = {
329920
+ themeColors: model.themeColors,
329921
+ themeFontScheme: model.themeFontScheme
329922
+ };
329923
+ const directParagraphProperties = parseWordParagraphPropertiesXml(paragraphXml);
329924
+ const resolvedParagraphProperties = model.resolveParagraph({ inlineProps: directParagraphProperties });
329925
+ const markerRun = model.resolveRun({
329926
+ inlineRpr: parseWordRunPropertiesXml(extractParagraphMarkRPrXml(paragraphXml)),
329927
+ resolvedParagraphProperties,
329928
+ isListNumber: true,
329929
+ numberingDefinedInline: directParagraphProperties.numberingProperties != null
329930
+ });
329931
+ const markerColor = normalizeRunAttrsFromOoxml(markerRun, runContext).color;
329932
+ const color2 = markerColor && /^#[0-9a-f]{6}$/i.test(markerColor) ? markerColor.slice(1).toUpperCase() : undefined;
329933
+ return {
329934
+ ...type ? { type } : {},
329935
+ ...color2 ? { color: color2 } : {}
329936
+ };
329937
+ }
329938
+ function portableOrderedListStyleType(numFmt) {
329939
+ switch (numFmt) {
329940
+ case "decimal":
329941
+ return "decimal";
329942
+ case "decimalZero":
329943
+ return "decimal-leading-zero";
329944
+ case "lowerLetter":
329945
+ return "lower-alpha";
329946
+ case "upperLetter":
329947
+ return "upper-alpha";
329948
+ case "lowerRoman":
329949
+ return "lower-roman";
329950
+ case "upperRoman":
329951
+ return "upper-roman";
329952
+ default:
329953
+ return;
329954
+ }
329955
+ }
329956
+ function orderedListTypeAttribute(styleType) {
329957
+ switch (styleType) {
329958
+ case "decimal":
329959
+ case "decimal-leading-zero":
329960
+ return "1";
329961
+ case "lower-alpha":
329962
+ return "a";
329963
+ case "upper-alpha":
329964
+ return "A";
329965
+ case "lower-roman":
329966
+ return "i";
329967
+ case "upper-roman":
329968
+ return "I";
329969
+ default:
329970
+ return;
329971
+ }
329972
+ }
329834
329973
  function tableCellHtmlStyle(cell) {
329835
329974
  const styles = [];
329836
329975
  if (cell.shadingColor)
@@ -329861,14 +330000,15 @@ function tableCellHtmlStyle(cell) {
329861
330000
  }
329862
330001
  return styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
329863
330002
  }
329864
- function renderHtmlRun(run) {
330003
+ function renderHtmlRun(run, defaultTextColor) {
329865
330004
  let html = escapeHtmlText(run.text);
329866
- const marks = run.marks;
329867
- if (!marks)
330005
+ if (!run.marks && !defaultTextColor)
329868
330006
  return html;
330007
+ const marks = run.marks ?? {};
329869
330008
  const styles = [];
329870
- if (marks.color)
329871
- styles.push(`color: #${marks.color}`);
330009
+ const color2 = marks.color ?? defaultTextColor;
330010
+ if (color2)
330011
+ styles.push(`color: #${color2}`);
329872
330012
  if (marks.fontSizePt)
329873
330013
  styles.push(`font-size: ${marks.fontSizePt}pt`);
329874
330014
  if (marks.fontFamily)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.7.0-next.12",
3
+ "version": "1.7.0-next.13",
4
4
  "description": "Model Context Protocol server for SuperDoc, giving an AI agent tools to read and edit .docx files.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0",
@@ -24,13 +24,13 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@modelcontextprotocol/sdk": "^1.26.0",
27
- "@superdoc/sdk": "2.20.0-next.12",
27
+ "@superdoc/sdk": "2.20.0-next.13",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.23.0-next.12",
33
- "@superdoc/docx-engine": "0.22.0-next.12",
32
+ "superdoc": "2.23.0-next.13",
33
+ "@superdoc/docx-engine": "0.22.0-next.13",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",