@superdoc-dev/mcp 0.3.0-next.79 → 0.3.0-next.80

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 +494 -22
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -51891,7 +51891,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
51891
51891
  emptyOptions2 = {};
51892
51892
  });
51893
51893
 
51894
- // ../../packages/superdoc/dist/chunks/SuperConverter-BInxZk0I.es.js
51894
+ // ../../packages/superdoc/dist/chunks/SuperConverter-VRDgcp1i.es.js
51895
51895
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
51896
51896
  const fieldValue = extension$1.config[field];
51897
51897
  if (typeof fieldValue === "function")
@@ -64122,6 +64122,239 @@ function uint8ToBase64(bytes) {
64122
64122
  }
64123
64123
  return btoa(binary);
64124
64124
  }
64125
+ function detectCompressedImageFormat(bytes) {
64126
+ if (!bytes || bytes.length < 4)
64127
+ return null;
64128
+ if (bytes.length >= 8 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10)
64129
+ return {
64130
+ mime: "image/png",
64131
+ format: "png"
64132
+ };
64133
+ if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255)
64134
+ return {
64135
+ mime: "image/jpeg",
64136
+ format: "jpeg"
64137
+ };
64138
+ if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 56)
64139
+ return {
64140
+ mime: "image/gif",
64141
+ format: "gif"
64142
+ };
64143
+ return null;
64144
+ }
64145
+ function concatBytes(parts) {
64146
+ let totalLength = 0;
64147
+ for (const part of parts)
64148
+ totalLength += part.byteLength;
64149
+ const result = new Uint8Array(totalLength);
64150
+ let offset = 0;
64151
+ for (const part of parts) {
64152
+ result.set(part, offset);
64153
+ offset += part.byteLength;
64154
+ }
64155
+ return result;
64156
+ }
64157
+ function createCanvasFromEnv() {
64158
+ const env = domEnvironment$1 || {};
64159
+ const doc$2 = env.document || env.mockDocument || env.window?.document || env.mockWindow?.document || null;
64160
+ if (doc$2)
64161
+ return doc$2.createElement("canvas");
64162
+ if (typeof document !== "undefined")
64163
+ return document.createElement("canvas");
64164
+ return null;
64165
+ }
64166
+ function convertEmfPlusPixelRow(src, srcOffset, dst, dstOffset, width, pixelFormat) {
64167
+ if (srcOffset + width * (pixelFormat === EMF_PLUS_PIXEL_FORMAT_24BPP_RGB ? 3 : 4) > src.byteLength)
64168
+ return false;
64169
+ let s = srcOffset;
64170
+ let d = dstOffset;
64171
+ for (let x = 0;x < width; x++) {
64172
+ const b = src[s];
64173
+ const g = src[s + 1];
64174
+ const r = src[s + 2];
64175
+ if (pixelFormat === EMF_PLUS_PIXEL_FORMAT_24BPP_RGB) {
64176
+ dst[d] = r;
64177
+ dst[d + 1] = g;
64178
+ dst[d + 2] = b;
64179
+ dst[d + 3] = 255;
64180
+ s += 3;
64181
+ } else if (pixelFormat === EMF_PLUS_PIXEL_FORMAT_32BPP_PARGB) {
64182
+ const a = src[s + 3];
64183
+ if (a === 0) {
64184
+ dst[d] = 0;
64185
+ dst[d + 1] = 0;
64186
+ dst[d + 2] = 0;
64187
+ dst[d + 3] = 0;
64188
+ } else {
64189
+ const scale = 255 / a;
64190
+ dst[d] = r * scale;
64191
+ dst[d + 1] = g * scale;
64192
+ dst[d + 2] = b * scale;
64193
+ dst[d + 3] = a;
64194
+ }
64195
+ s += 4;
64196
+ } else {
64197
+ dst[d] = r;
64198
+ dst[d + 1] = g;
64199
+ dst[d + 2] = b;
64200
+ dst[d + 3] = pixelFormat === EMF_PLUS_PIXEL_FORMAT_32BPP_ARGB ? src[s + 3] : 255;
64201
+ s += 4;
64202
+ }
64203
+ d += 4;
64204
+ }
64205
+ return true;
64206
+ }
64207
+ function renderEmfPlusPixelBitmap({ width, height, stride, pixelFormat, pixels }) {
64208
+ if (width <= 0 || height === 0)
64209
+ return null;
64210
+ const absHeight = Math.abs(height);
64211
+ const absStride = Math.abs(stride);
64212
+ if (absStride === 0)
64213
+ return null;
64214
+ if (width * absHeight > MAX_PIXEL_BITMAP_PIXELS)
64215
+ return null;
64216
+ if ((pixelFormat & EMF_PLUS_PIXEL_FORMAT_INDEXED_FLAG) !== 0)
64217
+ return null;
64218
+ if (pixelFormat !== EMF_PLUS_PIXEL_FORMAT_24BPP_RGB && pixelFormat !== EMF_PLUS_PIXEL_FORMAT_32BPP_RGB && pixelFormat !== EMF_PLUS_PIXEL_FORMAT_32BPP_ARGB && pixelFormat !== EMF_PLUS_PIXEL_FORMAT_32BPP_PARGB)
64219
+ return null;
64220
+ if (absStride * absHeight > pixels.byteLength)
64221
+ return null;
64222
+ const rgba = new Uint8ClampedArray(width * absHeight * 4);
64223
+ for (let y = 0;y < absHeight; y++)
64224
+ if (!convertEmfPlusPixelRow(pixels, y * absStride, rgba, y * width * 4, width, pixelFormat))
64225
+ return null;
64226
+ const canvas = createCanvasFromEnv();
64227
+ if (!canvas)
64228
+ return null;
64229
+ canvas.width = width;
64230
+ canvas.height = absHeight;
64231
+ const ctx = canvas.getContext("2d");
64232
+ if (!ctx)
64233
+ return null;
64234
+ const imageData = ctx.createImageData(width, absHeight);
64235
+ imageData.data.set(rgba);
64236
+ ctx.putImageData(imageData, 0, 0);
64237
+ const dataUri = canvas.toDataURL("image/png");
64238
+ if (!dataUri || dataUri === "data:,")
64239
+ return null;
64240
+ return {
64241
+ dataUri,
64242
+ format: "png"
64243
+ };
64244
+ }
64245
+ function parseEmfPlusImageObject(bytes) {
64246
+ if (!bytes || bytes.byteLength < 28)
64247
+ return null;
64248
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
64249
+ if (view.getUint32(4, true) !== EMF_PLUS_IMAGE_TYPE_BITMAP)
64250
+ return null;
64251
+ const bitmapType = view.getUint32(24, true);
64252
+ if (bitmapType === EMF_PLUS_BITMAP_TYPE_COMPRESSED) {
64253
+ const compressed = bytes.subarray(28);
64254
+ const formatInfo = detectCompressedImageFormat(compressed);
64255
+ if (!formatInfo)
64256
+ return null;
64257
+ return {
64258
+ dataUri: `data:${formatInfo.mime};base64,${uint8ToBase64(compressed)}`,
64259
+ format: formatInfo.format
64260
+ };
64261
+ }
64262
+ if (bitmapType === EMF_PLUS_BITMAP_TYPE_PIXEL)
64263
+ return renderEmfPlusPixelBitmap({
64264
+ width: view.getInt32(8, true),
64265
+ height: view.getInt32(12, true),
64266
+ stride: view.getInt32(16, true),
64267
+ pixelFormat: view.getUint32(20, true),
64268
+ pixels: bytes.subarray(28)
64269
+ });
64270
+ return null;
64271
+ }
64272
+ function extractBitmapFromEmfPlus(buffer3) {
64273
+ const view = new DataView(buffer3);
64274
+ if (view.byteLength < 108)
64275
+ return null;
64276
+ const type = view.getUint32(0, true);
64277
+ const headerSize = view.getUint32(4, true);
64278
+ const signature = view.getUint32(40, true);
64279
+ if (type !== 1 || signature !== EMF_SIGNATURE)
64280
+ return null;
64281
+ if (headerSize <= 0 || headerSize >= view.byteLength)
64282
+ return null;
64283
+ const pendingByObjectId = /* @__PURE__ */ new Map;
64284
+ let offset = headerSize;
64285
+ while (offset + 8 <= view.byteLength) {
64286
+ const recordType2 = view.getUint32(offset, true);
64287
+ const recordSize = view.getUint32(offset + 4, true);
64288
+ if (recordSize < 8 || offset + recordSize > view.byteLength)
64289
+ break;
64290
+ if (recordType2 === EMR_COMMENT && recordSize >= 20) {
64291
+ const dataSize = view.getUint32(offset + 8, true);
64292
+ if (dataSize >= 4 && dataSize <= recordSize - 12) {
64293
+ if (view.getUint32(offset + 12, true) === EMF_PLUS_SIGNATURE) {
64294
+ const emfPlusStart = offset + 16;
64295
+ const emfPlusEnd = offset + 12 + dataSize;
64296
+ let pos = emfPlusStart;
64297
+ while (pos + 12 <= emfPlusEnd) {
64298
+ const epType = view.getUint16(pos, true);
64299
+ const epFlags = view.getUint16(pos + 2, true);
64300
+ const epSize = view.getUint32(pos + 4, true);
64301
+ if (epSize < 12 || pos + epSize > emfPlusEnd)
64302
+ break;
64303
+ if (epType === EMF_PLUS_OBJECT) {
64304
+ const objectId = epFlags & 255;
64305
+ const objectType2 = epFlags >> 8 & 127;
64306
+ const continueBit = (epFlags & 32768) !== 0;
64307
+ const headerBytes = continueBit ? 16 : 12;
64308
+ if (epSize < headerBytes)
64309
+ break;
64310
+ const totalObjectSize = continueBit ? view.getUint32(pos + 8, true) : 0;
64311
+ const dataSize$1 = view.getUint32(pos + (continueBit ? 12 : 8), true);
64312
+ const dataStart = pos + headerBytes;
64313
+ if (dataSize$1 > epSize - headerBytes || dataStart + dataSize$1 > emfPlusEnd)
64314
+ break;
64315
+ if (objectType2 === EMF_PLUS_OBJECT_TYPE_IMAGE) {
64316
+ let result = null;
64317
+ if (continueBit) {
64318
+ let entry = pendingByObjectId.get(objectId);
64319
+ if (!entry) {
64320
+ entry = {
64321
+ totalSize: totalObjectSize,
64322
+ parts: [],
64323
+ collected: 0
64324
+ };
64325
+ pendingByObjectId.set(objectId, entry);
64326
+ } else if (entry.totalSize === 0 && totalObjectSize > 0)
64327
+ entry.totalSize = totalObjectSize;
64328
+ const chunk = new Uint8Array(buffer3, dataStart, dataSize$1);
64329
+ entry.parts.push(chunk);
64330
+ entry.collected += chunk.byteLength;
64331
+ if (entry.totalSize > 0 && entry.collected >= entry.totalSize) {
64332
+ result = parseEmfPlusImageObject(concatBytes(entry.parts).subarray(0, entry.totalSize));
64333
+ pendingByObjectId.delete(objectId);
64334
+ }
64335
+ } else {
64336
+ const pending = pendingByObjectId.get(objectId);
64337
+ if (pending) {
64338
+ pending.parts.push(new Uint8Array(buffer3, dataStart, dataSize$1));
64339
+ const combined = concatBytes(pending.parts);
64340
+ result = parseEmfPlusImageObject(pending.totalSize > 0 ? combined.subarray(0, pending.totalSize) : combined);
64341
+ pendingByObjectId.delete(objectId);
64342
+ } else
64343
+ result = parseEmfPlusImageObject(new Uint8Array(buffer3, dataStart, dataSize$1));
64344
+ }
64345
+ if (result)
64346
+ return result;
64347
+ }
64348
+ }
64349
+ pos += epSize;
64350
+ }
64351
+ }
64352
+ }
64353
+ }
64354
+ offset += recordSize;
64355
+ }
64356
+ return null;
64357
+ }
64125
64358
  function extractBitmapFromEmf(buffer3) {
64126
64359
  const view = new DataView(buffer3);
64127
64360
  if (view.byteLength < 120)
@@ -64202,7 +64435,7 @@ function isEmfPlus(buffer3) {
64202
64435
  const recordSize = view.getUint32(offset + 4, true);
64203
64436
  if (recordSize < 8 || offset + recordSize > view.byteLength)
64204
64437
  break;
64205
- if (recordType2 === 70 && recordSize >= 20) {
64438
+ if (recordType2 === EMR_COMMENT && recordSize >= 20) {
64206
64439
  if (view.getUint32(offset + 12, true) === EMF_PLUS_SIGNATURE)
64207
64440
  return true;
64208
64441
  }
@@ -64265,12 +64498,16 @@ function convertEmfToSvg(data, size = {}) {
64265
64498
  if (bitmapResult)
64266
64499
  return bitmapResult;
64267
64500
  const dimensions = getEmfDimensions(buffer3);
64268
- if (isEmfPlus(buffer3))
64501
+ if (isEmfPlus(buffer3)) {
64502
+ const embedded = extractBitmapFromEmfPlus(buffer3);
64503
+ if (embedded)
64504
+ return embedded;
64269
64505
  return createPlaceholder({
64270
64506
  width: size.width || dimensions.width,
64271
64507
  height: size.height || dimensions.height,
64272
64508
  label: "Unable to render EMF+ image"
64273
64509
  });
64510
+ }
64274
64511
  const renderer = new Renderer$1(buffer3);
64275
64512
  const renderSettings = {
64276
64513
  width: String(size.width || dimensions.width) + "px",
@@ -96149,7 +96386,7 @@ var isRegExp = (value) => {
96149
96386
  }
96150
96387
  }, domEnvironment$1 = null, setMetafileDomEnvironment = (env) => {
96151
96388
  domEnvironment$1 = env || null;
96152
- }, MM_ANISOTROPIC = 8, EMF_SIGNATURE = 1179469088, EMF_PLUS_SIGNATURE = 726027589, base64ToArrayBuffer, require_common, require_trees, require_adler32, require_crc32, require_messages, require_deflate$1, require_strings, require_zstream, require_deflate, require_inffast, require_inftrees, require_inflate$1, require_constants, require_gzheader, require_inflate, require_pako, import_UTIF, domEnvironment = null, MAX_PIXEL_COUNT = 1e8, setTiffDomEnvironment = (env) => {
96389
+ }, MM_ANISOTROPIC = 8, EMF_SIGNATURE = 1179469088, EMF_PLUS_SIGNATURE = 726027589, EMR_COMMENT = 70, EMF_PLUS_OBJECT = 16392, EMF_PLUS_OBJECT_TYPE_IMAGE = 5, EMF_PLUS_IMAGE_TYPE_BITMAP = 1, EMF_PLUS_BITMAP_TYPE_PIXEL = 0, EMF_PLUS_BITMAP_TYPE_COMPRESSED = 1, EMF_PLUS_PIXEL_FORMAT_INDEXED_FLAG = 65536, EMF_PLUS_PIXEL_FORMAT_24BPP_RGB = 137224, EMF_PLUS_PIXEL_FORMAT_32BPP_RGB = 139273, EMF_PLUS_PIXEL_FORMAT_32BPP_ARGB = 2498570, EMF_PLUS_PIXEL_FORMAT_32BPP_PARGB = 925707, MAX_PIXEL_BITMAP_PIXELS = 1e8, base64ToArrayBuffer, require_common, require_trees, require_adler32, require_crc32, require_messages, require_deflate$1, require_strings, require_zstream, require_deflate, require_inffast, require_inftrees, require_inflate$1, require_constants, require_gzheader, require_inflate, require_pako, import_UTIF, domEnvironment = null, MAX_PIXEL_COUNT = 1e8, setTiffDomEnvironment = (env) => {
96153
96390
  domEnvironment = env || null;
96154
96391
  }, getInstructionPreProcessor = (instruction) => {
96155
96392
  switch (instruction.split(" ")[0]) {
@@ -105086,7 +105323,7 @@ var isRegExp = (value) => {
105086
105323
  state.kern = kernNode.attributes["w:val"];
105087
105324
  }
105088
105325
  }, SuperConverter;
105089
- var init_SuperConverter_BInxZk0I_es = __esm(() => {
105326
+ var init_SuperConverter_VRDgcp1i_es = __esm(() => {
105090
105327
  init_rolldown_runtime_Bg48TavK_es();
105091
105328
  init_jszip_C49i9kUs_es();
105092
105329
  init_xml_js_CqGKpaft_es();
@@ -142955,7 +143192,7 @@ var init_SuperConverter_BInxZk0I_es = __esm(() => {
142955
143192
  };
142956
143193
  });
142957
143194
 
142958
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-rUh3xIsa.es.js
143195
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-DDhCzATq.es.js
142959
143196
  function parseSizeUnit(val = "0") {
142960
143197
  const length = val.toString() || "0";
142961
143198
  const value = Number.parseFloat(length);
@@ -145622,8 +145859,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
145622
145859
  }
145623
145860
  };
145624
145861
  };
145625
- var init_create_headless_toolbar_rUh3xIsa_es = __esm(() => {
145626
- init_SuperConverter_BInxZk0I_es();
145862
+ var init_create_headless_toolbar_DDhCzATq_es = __esm(() => {
145863
+ init_SuperConverter_VRDgcp1i_es();
145627
145864
  init_constants_DrU4EASo_es();
145628
145865
  init_dist_B8HfvhaK_es();
145629
145866
  CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
@@ -199842,7 +200079,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
199842
200079
  init_remark_gfm_BhnWr3yf_es();
199843
200080
  });
199844
200081
 
199845
- // ../../packages/superdoc/dist/chunks/src-DnSeNxAx.es.js
200082
+ // ../../packages/superdoc/dist/chunks/src-DhjNaQR7.es.js
199846
200083
  function deleteProps(obj, propOrProps) {
199847
200084
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
199848
200085
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -293451,12 +293688,12 @@ menclose::after {
293451
293688
  return;
293452
293689
  console.log(...args$1);
293453
293690
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
293454
- var init_src_DnSeNxAx_es = __esm(() => {
293691
+ var init_src_DhjNaQR7_es = __esm(() => {
293455
293692
  init_rolldown_runtime_Bg48TavK_es();
293456
- init_SuperConverter_BInxZk0I_es();
293693
+ init_SuperConverter_VRDgcp1i_es();
293457
293694
  init_jszip_C49i9kUs_es();
293458
293695
  init_uuid_qzgm05fK_es();
293459
- init_create_headless_toolbar_rUh3xIsa_es();
293696
+ init_create_headless_toolbar_DDhCzATq_es();
293460
293697
  init_constants_DrU4EASo_es();
293461
293698
  init_dist_B8HfvhaK_es();
293462
293699
  init_unified_Dsuw2be5_es();
@@ -331474,11 +331711,11 @@ function print() { __p += __j.call(arguments, '') }
331474
331711
  ];
331475
331712
  });
331476
331713
 
331477
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-DzAnOuIL.es.js
331714
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-C_pZyj7a.es.js
331478
331715
  var MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
331479
- var init_create_super_doc_ui_DzAnOuIL_es = __esm(() => {
331480
- init_SuperConverter_BInxZk0I_es();
331481
- init_create_headless_toolbar_rUh3xIsa_es();
331716
+ var init_create_super_doc_ui_C_pZyj7a_es = __esm(() => {
331717
+ init_SuperConverter_VRDgcp1i_es();
331718
+ init_create_headless_toolbar_DDhCzATq_es();
331482
331719
  MOD_ALIASES = new Set([
331483
331720
  "Mod",
331484
331721
  "Meta",
@@ -331520,16 +331757,16 @@ var init_zipper_BxRAi0_5_es = __esm(() => {
331520
331757
 
331521
331758
  // ../../packages/superdoc/dist/super-editor.es.js
331522
331759
  var init_super_editor_es = __esm(() => {
331523
- init_src_DnSeNxAx_es();
331524
- init_SuperConverter_BInxZk0I_es();
331760
+ init_src_DhjNaQR7_es();
331761
+ init_SuperConverter_VRDgcp1i_es();
331525
331762
  init_jszip_C49i9kUs_es();
331526
331763
  init_xml_js_CqGKpaft_es();
331527
- init_create_headless_toolbar_rUh3xIsa_es();
331764
+ init_create_headless_toolbar_DDhCzATq_es();
331528
331765
  init_constants_DrU4EASo_es();
331529
331766
  init_dist_B8HfvhaK_es();
331530
331767
  init_unified_Dsuw2be5_es();
331531
331768
  init_DocxZipper_Dh4RtvcE_es();
331532
- init_create_super_doc_ui_DzAnOuIL_es();
331769
+ init_create_super_doc_ui_C_pZyj7a_es();
331533
331770
  init_ui_CGB3qmy3_es();
331534
331771
  init_eventemitter3_UwU_CLPU_es();
331535
331772
  init_errors_C_DoKMoN_es();
@@ -402259,6 +402496,238 @@ function uint8ToBase642(bytes) {
402259
402496
  }
402260
402497
  return btoa(binary);
402261
402498
  }
402499
+ function detectCompressedImageFormat2(bytes) {
402500
+ if (!bytes || bytes.length < 4)
402501
+ return null;
402502
+ if (bytes.length >= 8 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71 && bytes[4] === 13 && bytes[5] === 10 && bytes[6] === 26 && bytes[7] === 10) {
402503
+ return { mime: "image/png", format: "png" };
402504
+ }
402505
+ if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) {
402506
+ return { mime: "image/jpeg", format: "jpeg" };
402507
+ }
402508
+ if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 56) {
402509
+ return { mime: "image/gif", format: "gif" };
402510
+ }
402511
+ return null;
402512
+ }
402513
+ function concatBytes2(parts) {
402514
+ let totalLength = 0;
402515
+ for (const part of parts)
402516
+ totalLength += part.byteLength;
402517
+ const result = new Uint8Array(totalLength);
402518
+ let offset2 = 0;
402519
+ for (const part of parts) {
402520
+ result.set(part, offset2);
402521
+ offset2 += part.byteLength;
402522
+ }
402523
+ return result;
402524
+ }
402525
+ function createCanvasFromEnv2() {
402526
+ const env2 = domEnvironment2 || {};
402527
+ const doc6 = env2.document || env2.mockDocument || env2.window?.document || env2.mockWindow?.document || null;
402528
+ if (doc6) {
402529
+ return doc6.createElement("canvas");
402530
+ }
402531
+ if (typeof document !== "undefined") {
402532
+ return document.createElement("canvas");
402533
+ }
402534
+ return null;
402535
+ }
402536
+ function convertEmfPlusPixelRow2(src, srcOffset, dst, dstOffset, width, pixelFormat) {
402537
+ const bytesPerPixel = pixelFormat === EMF_PLUS_PIXEL_FORMAT_24BPP_RGB2 ? 3 : 4;
402538
+ if (srcOffset + width * bytesPerPixel > src.byteLength)
402539
+ return false;
402540
+ let s2 = srcOffset;
402541
+ let d = dstOffset;
402542
+ for (let x = 0;x < width; x++) {
402543
+ const b2 = src[s2];
402544
+ const g2 = src[s2 + 1];
402545
+ const r2 = src[s2 + 2];
402546
+ if (pixelFormat === EMF_PLUS_PIXEL_FORMAT_24BPP_RGB2) {
402547
+ dst[d] = r2;
402548
+ dst[d + 1] = g2;
402549
+ dst[d + 2] = b2;
402550
+ dst[d + 3] = 255;
402551
+ s2 += 3;
402552
+ } else if (pixelFormat === EMF_PLUS_PIXEL_FORMAT_32BPP_PARGB2) {
402553
+ const a2 = src[s2 + 3];
402554
+ if (a2 === 0) {
402555
+ dst[d] = 0;
402556
+ dst[d + 1] = 0;
402557
+ dst[d + 2] = 0;
402558
+ dst[d + 3] = 0;
402559
+ } else {
402560
+ const scale = 255 / a2;
402561
+ dst[d] = r2 * scale;
402562
+ dst[d + 1] = g2 * scale;
402563
+ dst[d + 2] = b2 * scale;
402564
+ dst[d + 3] = a2;
402565
+ }
402566
+ s2 += 4;
402567
+ } else {
402568
+ dst[d] = r2;
402569
+ dst[d + 1] = g2;
402570
+ dst[d + 2] = b2;
402571
+ dst[d + 3] = pixelFormat === EMF_PLUS_PIXEL_FORMAT_32BPP_ARGB2 ? src[s2 + 3] : 255;
402572
+ s2 += 4;
402573
+ }
402574
+ d += 4;
402575
+ }
402576
+ return true;
402577
+ }
402578
+ function renderEmfPlusPixelBitmap2({ width, height, stride, pixelFormat, pixels }) {
402579
+ if (width <= 0 || height === 0)
402580
+ return null;
402581
+ const absHeight = Math.abs(height);
402582
+ const absStride = Math.abs(stride);
402583
+ if (absStride === 0)
402584
+ return null;
402585
+ if (width * absHeight > MAX_PIXEL_BITMAP_PIXELS2)
402586
+ return null;
402587
+ if ((pixelFormat & EMF_PLUS_PIXEL_FORMAT_INDEXED_FLAG2) !== 0)
402588
+ return null;
402589
+ if (pixelFormat !== EMF_PLUS_PIXEL_FORMAT_24BPP_RGB2 && pixelFormat !== EMF_PLUS_PIXEL_FORMAT_32BPP_RGB2 && pixelFormat !== EMF_PLUS_PIXEL_FORMAT_32BPP_ARGB2 && pixelFormat !== EMF_PLUS_PIXEL_FORMAT_32BPP_PARGB2) {
402590
+ return null;
402591
+ }
402592
+ if (absStride * absHeight > pixels.byteLength)
402593
+ return null;
402594
+ const rgba = new Uint8ClampedArray(width * absHeight * 4);
402595
+ for (let y2 = 0;y2 < absHeight; y2++) {
402596
+ if (!convertEmfPlusPixelRow2(pixels, y2 * absStride, rgba, y2 * width * 4, width, pixelFormat)) {
402597
+ return null;
402598
+ }
402599
+ }
402600
+ const canvas2 = createCanvasFromEnv2();
402601
+ if (!canvas2)
402602
+ return null;
402603
+ canvas2.width = width;
402604
+ canvas2.height = absHeight;
402605
+ const ctx2 = canvas2.getContext("2d");
402606
+ if (!ctx2)
402607
+ return null;
402608
+ const imageData = ctx2.createImageData(width, absHeight);
402609
+ imageData.data.set(rgba);
402610
+ ctx2.putImageData(imageData, 0, 0);
402611
+ const dataUri = canvas2.toDataURL("image/png");
402612
+ if (!dataUri || dataUri === "data:,")
402613
+ return null;
402614
+ return { dataUri, format: "png" };
402615
+ }
402616
+ function parseEmfPlusImageObject2(bytes) {
402617
+ if (!bytes || bytes.byteLength < 28)
402618
+ return null;
402619
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
402620
+ const imageType = view.getUint32(4, true);
402621
+ if (imageType !== EMF_PLUS_IMAGE_TYPE_BITMAP2)
402622
+ return null;
402623
+ const bitmapType = view.getUint32(24, true);
402624
+ if (bitmapType === EMF_PLUS_BITMAP_TYPE_COMPRESSED2) {
402625
+ const compressed = bytes.subarray(28);
402626
+ const formatInfo = detectCompressedImageFormat2(compressed);
402627
+ if (!formatInfo)
402628
+ return null;
402629
+ return {
402630
+ dataUri: `data:${formatInfo.mime};base64,${uint8ToBase642(compressed)}`,
402631
+ format: formatInfo.format
402632
+ };
402633
+ }
402634
+ if (bitmapType === EMF_PLUS_BITMAP_TYPE_PIXEL2) {
402635
+ return renderEmfPlusPixelBitmap2({
402636
+ width: view.getInt32(8, true),
402637
+ height: view.getInt32(12, true),
402638
+ stride: view.getInt32(16, true),
402639
+ pixelFormat: view.getUint32(20, true),
402640
+ pixels: bytes.subarray(28)
402641
+ });
402642
+ }
402643
+ return null;
402644
+ }
402645
+ function extractBitmapFromEmfPlus2(buffer3) {
402646
+ const view = new DataView(buffer3);
402647
+ if (view.byteLength < 108)
402648
+ return null;
402649
+ const type = view.getUint32(0, true);
402650
+ const headerSize = view.getUint32(4, true);
402651
+ const signature = view.getUint32(40, true);
402652
+ if (type !== 1 || signature !== EMF_SIGNATURE2)
402653
+ return null;
402654
+ if (headerSize <= 0 || headerSize >= view.byteLength)
402655
+ return null;
402656
+ const pendingByObjectId = new Map;
402657
+ let offset2 = headerSize;
402658
+ while (offset2 + 8 <= view.byteLength) {
402659
+ const recordType2 = view.getUint32(offset2, true);
402660
+ const recordSize = view.getUint32(offset2 + 4, true);
402661
+ if (recordSize < 8 || offset2 + recordSize > view.byteLength)
402662
+ break;
402663
+ if (recordType2 === EMR_COMMENT2 && recordSize >= 20) {
402664
+ const dataSize = view.getUint32(offset2 + 8, true);
402665
+ if (dataSize >= 4 && dataSize <= recordSize - 12) {
402666
+ const identifier = view.getUint32(offset2 + 12, true);
402667
+ if (identifier === EMF_PLUS_SIGNATURE2) {
402668
+ const emfPlusStart = offset2 + 16;
402669
+ const emfPlusEnd = offset2 + 12 + dataSize;
402670
+ let pos = emfPlusStart;
402671
+ while (pos + 12 <= emfPlusEnd) {
402672
+ const epType = view.getUint16(pos, true);
402673
+ const epFlags = view.getUint16(pos + 2, true);
402674
+ const epSize = view.getUint32(pos + 4, true);
402675
+ if (epSize < 12 || pos + epSize > emfPlusEnd)
402676
+ break;
402677
+ if (epType === EMF_PLUS_OBJECT2) {
402678
+ const objectId = epFlags & 255;
402679
+ const objectType2 = epFlags >> 8 & 127;
402680
+ const continueBit = (epFlags & 32768) !== 0;
402681
+ const headerBytes = continueBit ? 16 : 12;
402682
+ if (epSize < headerBytes)
402683
+ break;
402684
+ const totalObjectSize = continueBit ? view.getUint32(pos + 8, true) : 0;
402685
+ const dataSize2 = view.getUint32(pos + (continueBit ? 12 : 8), true);
402686
+ const dataStart = pos + headerBytes;
402687
+ if (dataSize2 > epSize - headerBytes || dataStart + dataSize2 > emfPlusEnd)
402688
+ break;
402689
+ if (objectType2 === EMF_PLUS_OBJECT_TYPE_IMAGE2) {
402690
+ let result = null;
402691
+ if (continueBit) {
402692
+ let entry = pendingByObjectId.get(objectId);
402693
+ if (!entry) {
402694
+ entry = { totalSize: totalObjectSize, parts: [], collected: 0 };
402695
+ pendingByObjectId.set(objectId, entry);
402696
+ } else if (entry.totalSize === 0 && totalObjectSize > 0) {
402697
+ entry.totalSize = totalObjectSize;
402698
+ }
402699
+ const chunk = new Uint8Array(buffer3, dataStart, dataSize2);
402700
+ entry.parts.push(chunk);
402701
+ entry.collected += chunk.byteLength;
402702
+ if (entry.totalSize > 0 && entry.collected >= entry.totalSize) {
402703
+ result = parseEmfPlusImageObject2(concatBytes2(entry.parts).subarray(0, entry.totalSize));
402704
+ pendingByObjectId.delete(objectId);
402705
+ }
402706
+ } else {
402707
+ const pending = pendingByObjectId.get(objectId);
402708
+ if (pending) {
402709
+ pending.parts.push(new Uint8Array(buffer3, dataStart, dataSize2));
402710
+ const combined = concatBytes2(pending.parts);
402711
+ const trimmed = pending.totalSize > 0 ? combined.subarray(0, pending.totalSize) : combined;
402712
+ result = parseEmfPlusImageObject2(trimmed);
402713
+ pendingByObjectId.delete(objectId);
402714
+ } else {
402715
+ result = parseEmfPlusImageObject2(new Uint8Array(buffer3, dataStart, dataSize2));
402716
+ }
402717
+ }
402718
+ if (result)
402719
+ return result;
402720
+ }
402721
+ }
402722
+ pos += epSize;
402723
+ }
402724
+ }
402725
+ }
402726
+ }
402727
+ offset2 += recordSize;
402728
+ }
402729
+ return null;
402730
+ }
402262
402731
  function extractBitmapFromEmf2(buffer3) {
402263
402732
  const view = new DataView(buffer3);
402264
402733
  if (view.byteLength < 120)
@@ -402340,7 +402809,7 @@ function isEmfPlus2(buffer3) {
402340
402809
  const recordSize = view.getUint32(offset2 + 4, true);
402341
402810
  if (recordSize < 8 || offset2 + recordSize > view.byteLength)
402342
402811
  break;
402343
- if (recordType2 === 70 && recordSize >= 20) {
402812
+ if (recordType2 === EMR_COMMENT2 && recordSize >= 20) {
402344
402813
  const identifier = view.getUint32(offset2 + 12, true);
402345
402814
  if (identifier === EMF_PLUS_SIGNATURE2)
402346
402815
  return true;
@@ -402405,6 +402874,9 @@ function convertEmfToSvg2(data, size3 = {}) {
402405
402874
  }
402406
402875
  const dimensions = getEmfDimensions2(buffer3);
402407
402876
  if (isEmfPlus2(buffer3)) {
402877
+ const embedded2 = extractBitmapFromEmfPlus2(buffer3);
402878
+ if (embedded2)
402879
+ return embedded2;
402408
402880
  return createPlaceholder2({
402409
402881
  width: size3.width || dimensions.width,
402410
402882
  height: size3.height || dimensions.height,
@@ -402476,7 +402948,7 @@ function isMetafileExtension2(extension2) {
402476
402948
  }
402477
402949
  var domEnvironment2 = null, setMetafileDomEnvironment2 = (env2) => {
402478
402950
  domEnvironment2 = env2 || null;
402479
- }, MM_ANISOTROPIC2 = 8, EMF_SIGNATURE2 = 1179469088, EMF_PLUS_SIGNATURE2 = 726027589, base64ToArrayBuffer2;
402951
+ }, MM_ANISOTROPIC2 = 8, EMF_SIGNATURE2 = 1179469088, EMF_PLUS_SIGNATURE2 = 726027589, EMR_COMMENT2 = 70, EMF_PLUS_OBJECT2 = 16392, EMF_PLUS_OBJECT_TYPE_IMAGE2 = 5, EMF_PLUS_IMAGE_TYPE_BITMAP2 = 1, EMF_PLUS_BITMAP_TYPE_PIXEL2 = 0, EMF_PLUS_BITMAP_TYPE_COMPRESSED2 = 1, EMF_PLUS_PIXEL_FORMAT_INDEXED_FLAG2 = 65536, EMF_PLUS_PIXEL_FORMAT_24BPP_RGB2 = 137224, EMF_PLUS_PIXEL_FORMAT_32BPP_RGB2 = 139273, EMF_PLUS_PIXEL_FORMAT_32BPP_ARGB2 = 2498570, EMF_PLUS_PIXEL_FORMAT_32BPP_PARGB2 = 925707, MAX_PIXEL_BITMAP_PIXELS2 = 1e8, base64ToArrayBuffer2;
402480
402952
  var init_metafile_converter = __esm(() => {
402481
402953
  init_rtfjs();
402482
402954
  init_helpers();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/mcp",
3
- "version": "0.3.0-next.79",
3
+ "version": "0.3.0-next.80",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20"
@@ -20,8 +20,8 @@
20
20
  "@types/node": "22.19.2",
21
21
  "typescript": "^5.9.2",
22
22
  "@superdoc/document-api": "0.0.1",
23
- "superdoc": "1.32.0",
24
- "@superdoc/super-editor": "0.0.1"
23
+ "@superdoc/super-editor": "0.0.1",
24
+ "superdoc": "1.32.0"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"