@yltrcc/vditor 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Vditor v0.1.1 - A markdown editor written in TypeScript.
2
+ * Vditor v0.3.0 - A markdown editor written in TypeScript.
3
3
  *
4
4
  * MIT License
5
5
  *
@@ -169,7 +169,7 @@ var codeRender = __webpack_require__(663);
169
169
  // EXTERNAL MODULE: ./src/ts/markdown/flowchartRender.ts
170
170
  var flowchartRender = __webpack_require__(600);
171
171
  // EXTERNAL MODULE: ./src/ts/markdown/graphvizRender.ts
172
- var graphvizRender = __webpack_require__(407);
172
+ var graphvizRender = __webpack_require__(788);
173
173
  // EXTERNAL MODULE: ./src/ts/markdown/highlightRender.ts
174
174
  var highlightRender = __webpack_require__(376);
175
175
  ;// ./src/ts/markdown/lazyLoadImageRender.ts
@@ -1267,7 +1267,7 @@ var looseJsonParse = function (text) {
1267
1267
  /* harmony export */ Y: () => (/* binding */ Constants),
1268
1268
  /* harmony export */ g: () => (/* binding */ _VDITOR_VERSION)
1269
1269
  /* harmony export */ });
1270
- var _VDITOR_VERSION = "0.1.1";
1270
+ var _VDITOR_VERSION = "0.3.0";
1271
1271
 
1272
1272
  var Constants = /** @class */ (function () {
1273
1273
  function Constants() {
@@ -1315,7 +1315,7 @@ var Constants = /** @class */ (function () {
1315
1315
  // 别名
1316
1316
  "js", "ts", "html", "toml", "c#", "bat"
1317
1317
  ];
1318
- Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.1.1");
1318
+ Constants.CDN = "https://unpkg.com/@yltrcc/vditor@".concat("0.3.0");
1319
1319
  Constants.MARKDOWN_OPTIONS = {
1320
1320
  autoSpace: false,
1321
1321
  gfmAutoLink: true,
@@ -1456,59 +1456,6 @@ var highlightRender = function (hljsOption, element, cdn) {
1456
1456
  };
1457
1457
 
1458
1458
 
1459
- /***/ },
1460
-
1461
- /***/ 407
1462
- (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1463
-
1464
- "use strict";
1465
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1466
- /* harmony export */ m: () => (/* binding */ graphvizRender)
1467
- /* harmony export */ });
1468
- /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(357);
1469
- /* harmony import */ var _util_addScript__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(901);
1470
- /* harmony import */ var _adapterRender__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(687);
1471
-
1472
-
1473
-
1474
- var graphvizRender = function (element, cdn) {
1475
- if (cdn === void 0) { cdn = _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants */ .Y.CDN; }
1476
- var graphvizElements = _adapterRender__WEBPACK_IMPORTED_MODULE_2__.graphvizRenderAdapter.getElements(element);
1477
- if (graphvizElements.length === 0) {
1478
- return;
1479
- }
1480
- (0,_util_addScript__WEBPACK_IMPORTED_MODULE_1__/* .addScript */ .Z)("".concat(cdn, "/dist/js/graphviz/viz.js"), "vditorGraphVizScript").then(function () {
1481
- graphvizElements.forEach(function (e) {
1482
- var code = _adapterRender__WEBPACK_IMPORTED_MODULE_2__.graphvizRenderAdapter.getCode(e);
1483
- if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
1484
- e.parentElement.classList.contains("vditor-ir__marker--pre")) {
1485
- return;
1486
- }
1487
- if (e.getAttribute("data-processed") === "true" || code.trim() === "") {
1488
- return;
1489
- }
1490
- try {
1491
- var blob = new Blob(["importScripts('".concat(document.getElementById("vditorGraphVizScript").src.replace("viz.js", "full.render.js"), "');")], { type: "application/javascript" });
1492
- var url = window.URL || window.webkitURL;
1493
- var blobUrl = url.createObjectURL(blob);
1494
- var worker = new Worker(blobUrl);
1495
- new Viz({ worker: worker })
1496
- .renderSVGElement(code).then(function (result) {
1497
- e.innerHTML = result.outerHTML;
1498
- }).catch(function (error) {
1499
- e.innerHTML = "graphviz render error: <br>".concat(error);
1500
- e.className = "vditor-reset--error";
1501
- });
1502
- }
1503
- catch (e) {
1504
- console.error("graphviz error", e);
1505
- }
1506
- e.setAttribute("data-processed", "true");
1507
- });
1508
- });
1509
- };
1510
-
1511
-
1512
1459
  /***/ },
1513
1460
 
1514
1461
  /***/ 417
@@ -2426,6 +2373,59 @@ var markmapRender = function (element, cdn) {
2426
2373
  };
2427
2374
 
2428
2375
 
2376
+ /***/ },
2377
+
2378
+ /***/ 788
2379
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
2380
+
2381
+ "use strict";
2382
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2383
+ /* harmony export */ m: () => (/* binding */ graphvizRender)
2384
+ /* harmony export */ });
2385
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(357);
2386
+ /* harmony import */ var _util_addScript__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(901);
2387
+ /* harmony import */ var _adapterRender__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(687);
2388
+
2389
+
2390
+
2391
+ var graphvizRender = function (element, cdn) {
2392
+ if (cdn === void 0) { cdn = _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants */ .Y.CDN; }
2393
+ var graphvizElements = _adapterRender__WEBPACK_IMPORTED_MODULE_2__.graphvizRenderAdapter.getElements(element);
2394
+ if (graphvizElements.length === 0) {
2395
+ return;
2396
+ }
2397
+ (0,_util_addScript__WEBPACK_IMPORTED_MODULE_1__/* .addScript */ .Z)("".concat(cdn, "/dist/js/graphviz/viz.js"), "vditorGraphVizScript").then(function () {
2398
+ graphvizElements.forEach(function (e) {
2399
+ var code = _adapterRender__WEBPACK_IMPORTED_MODULE_2__.graphvizRenderAdapter.getCode(e);
2400
+ if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
2401
+ e.parentElement.classList.contains("vditor-ir__marker--pre")) {
2402
+ return;
2403
+ }
2404
+ if (e.getAttribute("data-processed") === "true" || code.trim() === "") {
2405
+ return;
2406
+ }
2407
+ try {
2408
+ var blob = new Blob(["importScripts('".concat(document.getElementById("vditorGraphVizScript").src.replace("viz.js", "full.render.js"), "');")], { type: "application/javascript" });
2409
+ var url = window.URL || window.webkitURL;
2410
+ var blobUrl = url.createObjectURL(blob);
2411
+ var worker = new Worker(blobUrl);
2412
+ new Viz({ worker: worker })
2413
+ .renderSVGElement(code).then(function (result) {
2414
+ e.innerHTML = result.outerHTML;
2415
+ }).catch(function (error) {
2416
+ e.innerHTML = "graphviz render error: <br>".concat(error);
2417
+ e.className = "vditor-reset--error";
2418
+ });
2419
+ }
2420
+ catch (e) {
2421
+ console.error("graphviz error", e);
2422
+ }
2423
+ e.setAttribute("data-processed", "true");
2424
+ });
2425
+ });
2426
+ };
2427
+
2428
+
2429
2429
  /***/ },
2430
2430
 
2431
2431
  /***/ 849
@@ -5108,18 +5108,61 @@ var processDocLinksInHTML = function (html) {
5108
5108
  });
5109
5109
  return tempDiv.innerHTML;
5110
5110
  };
5111
+ /**
5112
+ * 处理图片尺寸,将带 width/height 属性的图片转换为 Markdown 语法
5113
+ * 支持: ![alt](url =300x200)
5114
+ */
5115
+ var processImageSizeInHTML = function (html) {
5116
+ var tempDiv = document.createElement("div");
5117
+ tempDiv.innerHTML = html;
5118
+ // 查找所有带有 data-resizable="true" 标记的图片元素
5119
+ var images = tempDiv.querySelectorAll('img[data-resizable="true"]');
5120
+ images.forEach(function (imgElement) {
5121
+ var img = imgElement;
5122
+ var src = img.getAttribute("src") || "";
5123
+ var alt = img.getAttribute("alt") || "";
5124
+ // 获取尺寸 - 优先从 attribute 获取
5125
+ var width = img.getAttribute("width") || "";
5126
+ var height = img.getAttribute("height") || "";
5127
+ // 如果 attribute 没有或为空,尝试从 style 获取
5128
+ if (!width && img.style.width) {
5129
+ width = img.style.width.replace("px", "").replace("%", "");
5130
+ }
5131
+ if (!height && img.style.height) {
5132
+ height = img.style.height.replace("px", "").replace("%", "");
5133
+ }
5134
+ // 构建带尺寸的 Markdown 语法: ![alt](url =300x200)
5135
+ if (width && height) {
5136
+ var md = "![".concat(alt, "](").concat(src, " =").concat(width, "x").concat(height, ")");
5137
+ // 用 Markdown 文本替换图片元素
5138
+ img.replaceWith(document.createTextNode(md));
5139
+ }
5140
+ else if (width) {
5141
+ var md = "![".concat(alt, "](").concat(src, " =").concat(width, "x)");
5142
+ img.replaceWith(document.createTextNode(md));
5143
+ }
5144
+ else if (height) {
5145
+ var md = "![".concat(alt, "](").concat(src, " =x").concat(height, ")");
5146
+ img.replaceWith(document.createTextNode(md));
5147
+ }
5148
+ });
5149
+ return tempDiv.innerHTML;
5150
+ };
5111
5151
  var getMarkdown = function (vditor) {
5112
5152
  if (vditor.currentMode === "sv") {
5113
5153
  return (0,code160to32/* code160to32 */.p)("".concat(vditor.sv.element.textContent, "\n").replace(/\n\n$/, "\n"));
5114
5154
  }
5115
5155
  else if (vditor.currentMode === "wysiwyg") {
5116
- // 先处理 doclink 元素,将其转换回 Markdown 语法
5117
- var processedHTML = processDocLinksInHTML(vditor.wysiwyg.element.innerHTML);
5156
+ // 先处理图片尺寸 - 必须在处理 doclink 之前
5157
+ var processedHTML = processImageSizeInHTML(vditor.wysiwyg.element.innerHTML);
5158
+ // 再处理 doclink 元素
5159
+ processedHTML = processDocLinksInHTML(processedHTML);
5118
5160
  return vditor.lute.VditorDOM2Md(processedHTML);
5119
5161
  }
5120
5162
  else if (vditor.currentMode === "ir") {
5121
5163
  // 同样处理 IR 模式
5122
- var processedHTML = processDocLinksInHTML(vditor.ir.element.innerHTML);
5164
+ var processedHTML = processImageSizeInHTML(vditor.ir.element.innerHTML);
5165
+ processedHTML = processDocLinksInHTML(processedHTML);
5123
5166
  return vditor.lute.VditorIRDOM2Md(processedHTML);
5124
5167
  }
5125
5168
  return "";
@@ -5345,7 +5388,7 @@ var codeRender = __webpack_require__(663);
5345
5388
  // EXTERNAL MODULE: ./src/ts/markdown/flowchartRender.ts
5346
5389
  var flowchartRender = __webpack_require__(600);
5347
5390
  // EXTERNAL MODULE: ./src/ts/markdown/graphvizRender.ts
5348
- var graphvizRender = __webpack_require__(407);
5391
+ var graphvizRender = __webpack_require__(788);
5349
5392
  // EXTERNAL MODULE: ./src/ts/markdown/highlightRender.ts
5350
5393
  var highlightRender = __webpack_require__(376);
5351
5394
  // EXTERNAL MODULE: ./src/ts/markdown/mathRender.ts
@@ -7017,6 +7060,13 @@ var showCode = function (previewElement, vditor, first) {
7017
7060
  // 移除内联样式,让 CSS 类控制显示
7018
7061
  codeElement.style.removeProperty("display");
7019
7062
  previewElement.style.removeProperty("display");
7063
+ // 将语言信息传递给编辑区域
7064
+ var language = previewElement.getAttribute("data-language") || "";
7065
+ codeElement.setAttribute("data-language", language);
7066
+ // 隐藏编辑时的多余工具栏
7067
+ if (vditor.wysiwyg.popover) {
7068
+ vditor.wysiwyg.popover.style.display = "none";
7069
+ }
7020
7070
  var range = codeElement.ownerDocument.createRange();
7021
7071
  if (codeElement.tagName === "CODE") {
7022
7072
  // 行内代码
@@ -7954,6 +8004,12 @@ var highlightToolbarWYSIWYG = function (vditor) {
7954
8004
  }
7955
8005
  });
7956
8006
  if (blockRenderElement && isBlock) {
8007
+ // 如果代码块处于编辑状态,则不显示工具栏
8008
+ var isCodeBlockEditing = blockRenderElement.classList.contains("vditor-wysiwyg__block--editing");
8009
+ if (isCodeBlockEditing) {
8010
+ vditor.wysiwyg.popover.style.display = "none";
8011
+ return;
8012
+ }
7957
8013
  vditor.wysiwyg.popover.innerHTML = "";
7958
8014
  genUp(range, blockRenderElement, vditor);
7959
8015
  genDown(range, blockRenderElement, vditor);
@@ -8464,6 +8520,83 @@ var highlightToolbar = function (vditor) {
8464
8520
  ;// ./src/ts/wysiwyg/renderDomByMd.ts
8465
8521
 
8466
8522
 
8523
+ /**
8524
+ * 后处理 DOM,处理图片尺寸
8525
+ * 1. 将文本节点中的 ![alt](url =300x200) 转换为带尺寸的 <img>
8526
+ * 2. 给没有 width/height 的 <img> 添加默认尺寸 300x200
8527
+ */
8528
+ var processImageSizeInDOM = function (element) {
8529
+ console.log('processImageSizeInDOM called');
8530
+ // 第一步:处理文本节点中的带尺寸图片语法 ![alt](url =300x200)
8531
+ var walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null);
8532
+ var textNodes = [];
8533
+ var node;
8534
+ while (node = walker.nextNode()) {
8535
+ textNodes.push(node);
8536
+ }
8537
+ textNodes.forEach(function (textNode) {
8538
+ var text = textNode.textContent || '';
8539
+ // 匹配带尺寸的图片: ![alt](url =300x200)
8540
+ var imageWithSizeRegex = /!\[([^\]]*)\]\(([^)]+?)\s*=(\d+)x(\d+)\)/g;
8541
+ if (imageWithSizeRegex.test(text)) {
8542
+ console.log('Found image with size in text:', text);
8543
+ var parent_1 = textNode.parentNode;
8544
+ if (parent_1) {
8545
+ var tempDiv = document.createElement('div');
8546
+ var processedText = text.replace(imageWithSizeRegex, function (match, alt, url, width, height) {
8547
+ console.log('Match found:', { match: match, alt: alt, url: url, width: width, height: height });
8548
+ var imgHtml = "<img src=\"".concat(url.trim(), "\" alt=\"").concat(alt, "\" data-resizable=\"true\"");
8549
+ if (width)
8550
+ imgHtml += " width=\"".concat(width, "\"");
8551
+ if (height)
8552
+ imgHtml += " height=\"".concat(height, "\"");
8553
+ imgHtml += " />";
8554
+ console.log('Generated imgHtml:', imgHtml);
8555
+ return imgHtml;
8556
+ });
8557
+ tempDiv.innerHTML = processedText;
8558
+ // 替换文本节点
8559
+ while (tempDiv.firstChild) {
8560
+ parent_1.insertBefore(tempDiv.firstChild, textNode);
8561
+ }
8562
+ parent_1.removeChild(textNode);
8563
+ }
8564
+ }
8565
+ });
8566
+ // 第二步:给没有 width/height 的 <img> 添加默认尺寸
8567
+ var images = element.querySelectorAll('img:not([data-resizable="true"])');
8568
+ images.forEach(function (img) {
8569
+ var imgElement = img;
8570
+ var width = imgElement.getAttribute('width');
8571
+ var height = imgElement.getAttribute('height');
8572
+ var styleWidth = imgElement.style.width;
8573
+ var styleHeight = imgElement.style.height;
8574
+ // 如果没有设置尺寸,添加默认尺寸
8575
+ if (!width && !height && !styleWidth && !styleHeight) {
8576
+ console.log('Adding default size to img:', imgElement.src);
8577
+ imgElement.setAttribute('width', '300');
8578
+ imgElement.setAttribute('height', '200');
8579
+ imgElement.setAttribute('data-resizable', 'true');
8580
+ }
8581
+ });
8582
+ };
8583
+ /**
8584
+ * 预处理 Markdown,为没有尺寸的图片添加默认尺寸
8585
+ * 将 ![alt](url) 转换为 ![alt](url =300x200)
8586
+ */
8587
+ var preprocessImageSize = function (md) {
8588
+ // 匹配普通图片语法 ![alt](url),但排除已经有 =widthxheight 的
8589
+ // 使用负向前瞻来排除已包含 = 的图片
8590
+ var imageRegex = /!\[([^\]]*)\]\(([^)=\]]+)\)(?![\s\w]*=)/g;
8591
+ return md.replace(imageRegex, function (match, alt, url) {
8592
+ // 检查 URL 是否已经包含尺寸参数
8593
+ if (url.includes('=')) {
8594
+ return match;
8595
+ }
8596
+ console.log('Preprocess: Adding default size to image:', match);
8597
+ return "![".concat(alt, "](").concat(url.trim(), " =300x200)");
8598
+ });
8599
+ };
8467
8600
  var renderDomByMd = function (vditor, md, options) {
8468
8601
  if (options === void 0) { options = {
8469
8602
  enableAddUndoStack: true,
@@ -8471,7 +8604,15 @@ var renderDomByMd = function (vditor, md, options) {
8471
8604
  enableInput: true,
8472
8605
  }; }
8473
8606
  var editorElement = vditor.wysiwyg.element;
8474
- editorElement.innerHTML = vditor.lute.Md2VditorDOM(md);
8607
+ console.log('renderDomByMd input:', md);
8608
+ // 预处理:为普通图片添加默认尺寸
8609
+ var processedMd = preprocessImageSize(md);
8610
+ console.log('After preprocess:', processedMd);
8611
+ editorElement.innerHTML = vditor.lute.Md2VditorDOM(processedMd);
8612
+ console.log('After Lute render:', editorElement.innerHTML);
8613
+ // 后处理图片尺寸(处理带 =widthxheight 的)
8614
+ processImageSizeInDOM(editorElement);
8615
+ console.log('After processImageSizeInDOM:', editorElement.innerHTML);
8475
8616
  editorElement.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach(function (item) {
8476
8617
  processCodeRender(item, vditor);
8477
8618
  item.previousElementSibling.setAttribute("style", "display:none");
@@ -9880,6 +10021,7 @@ var uploadFiles = function (vditor, files, element) { return __awaiter(void 0, v
9880
10021
 
9881
10022
 
9882
10023
 
10024
+
9883
10025
  var input_input = function (vditor, range, event) {
9884
10026
  var _a;
9885
10027
  // 检查是否在代码块编辑模式中
@@ -10020,14 +10162,16 @@ var input_input = function (vditor, range, event) {
10020
10162
  }
10021
10163
  else {
10022
10164
  blockElement.outerHTML = html_1;
10023
- if (footnoteElement) {
10024
- // 更新正文中的 tip
10025
- var footnoteItemElement = (0,hasClosest/* hasTopClosestByTag */.Ab)(vditor.wysiwyg.element.querySelector("wbr"), "LI");
10026
- if (footnoteItemElement) {
10027
- var footnoteRefElement = vditor.wysiwyg.element.querySelector("sup[data-type=\"footnotes-ref\"][data-footnotes-label=\"".concat(footnoteItemElement.getAttribute("data-marker"), "\"]"));
10028
- if (footnoteRefElement) {
10029
- footnoteRefElement.setAttribute("aria-label", footnoteItemElement.textContent.trim().substr(0, 24));
10030
- }
10165
+ }
10166
+ // 处理图片尺寸
10167
+ processImageSizeInDOM(vditor.wysiwyg.element);
10168
+ if (footnoteElement) {
10169
+ // 更新正文中的 tip
10170
+ var footnoteItemElement = (0,hasClosest/* hasTopClosestByTag */.Ab)(vditor.wysiwyg.element.querySelector("wbr"), "LI");
10171
+ if (footnoteItemElement) {
10172
+ var footnoteRefElement = vditor.wysiwyg.element.querySelector("sup[data-type=\"footnotes-ref\"][data-footnotes-label=\"".concat(footnoteItemElement.getAttribute("data-marker"), "\"]"));
10173
+ if (footnoteRefElement) {
10174
+ footnoteRefElement.setAttribute("aria-label", footnoteItemElement.textContent.trim().substr(0, 24));
10031
10175
  }
10032
10176
  }
10033
10177
  }
@@ -11323,7 +11467,7 @@ var fixFirefoxArrowUpTable = function (event, blockElement, range) {
11323
11467
  return false;
11324
11468
  };
11325
11469
  var paste = function (vditor, event, callback) { return fixBrowserBehavior_awaiter(void 0, void 0, void 0, function () {
11326
- var textHTML, textPlain, files, renderers, renderLinkDest, doc, height, code, codeElement, position, tempElement, fileReader_1, file_1, range, blockElement, range;
11470
+ var textHTML, textPlain, files, renderers, renderLinkDest, doc, height, code, codeElement, position, nextSibling, tempElement, fileReader_1, file_1, range, blockElement, range;
11327
11471
  var _a;
11328
11472
  return fixBrowserBehavior_generator(this, function (_b) {
11329
11473
  switch (_b.label) {
@@ -11449,9 +11593,11 @@ var paste = function (vditor, event, callback) { return fixBrowserBehavior_await
11449
11593
  codeElement.textContent = codeElement.textContent.substring(0, position.start)
11450
11594
  + textPlain + codeElement.textContent.substring(position.end);
11451
11595
  (0,selection/* setSelectionByPosition */.Fm)(position.start + textPlain.length, position.start + textPlain.length, codeElement.parentElement);
11452
- if ((_a = codeElement.parentElement) === null || _a === void 0 ? void 0 : _a.nextElementSibling.classList.contains("vditor-".concat(vditor.currentMode, "__preview"))) {
11453
- codeElement.parentElement.nextElementSibling.innerHTML = codeElement.outerHTML;
11454
- processCodeRender(codeElement.parentElement.nextElementSibling, vditor);
11596
+ nextSibling = (_a = codeElement.parentElement) === null || _a === void 0 ? void 0 : _a.nextElementSibling;
11597
+ if (nextSibling && nextSibling.classList
11598
+ .contains("vditor-".concat(vditor.currentMode, "__preview"))) {
11599
+ nextSibling.innerHTML = codeElement.outerHTML;
11600
+ processCodeRender(nextSibling, vditor);
11455
11601
  }
11456
11602
  }
11457
11603
  return [3 /*break*/, 10];
@@ -15474,8 +15620,36 @@ var WYSIWYG = /** @class */ (function () {
15474
15620
  el.replaceWith(document.createTextNode(markdown));
15475
15621
  }
15476
15622
  });
15623
+ // 处理带尺寸的图片 - 将 <img> 标签替换为自定义 Markdown 语法
15624
+ var images = tempElement.querySelectorAll('img[data-resizable="true"]');
15625
+ images.forEach(function (imgElement) {
15626
+ var img = imgElement;
15627
+ var src = img.getAttribute("src") || "";
15628
+ var alt = img.getAttribute("alt") || "";
15629
+ var width = img.getAttribute("width") || "";
15630
+ var height = img.getAttribute("height") || "";
15631
+ if (!width && img.style.width) {
15632
+ width = img.style.width.replace("px", "").replace("%", "");
15633
+ }
15634
+ if (!height && img.style.height) {
15635
+ height = img.style.height.replace("px", "").replace("%", "");
15636
+ }
15637
+ if (width && height) {
15638
+ var md = "![".concat(alt, "](").concat(src, " =").concat(width, "x").concat(height, ")");
15639
+ imgElement.replaceWith(document.createTextNode(md));
15640
+ }
15641
+ else if (width) {
15642
+ var md = "![".concat(alt, "](").concat(src, " =").concat(width, "x)");
15643
+ imgElement.replaceWith(document.createTextNode(md));
15644
+ }
15645
+ else if (height) {
15646
+ var md = "![".concat(alt, "](").concat(src, " =x").concat(height, ")");
15647
+ imgElement.replaceWith(document.createTextNode(md));
15648
+ }
15649
+ });
15477
15650
  event.clipboardData.setData("text/plain", vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim());
15478
15651
  event.clipboardData.setData("text/html", "");
15652
+ console.log('Copy completed, data set to clipboard');
15479
15653
  };
15480
15654
  WYSIWYG.prototype.bindEvent = function (vditor) {
15481
15655
  var _this = this;
@@ -15814,6 +15988,141 @@ var WYSIWYG = /** @class */ (function () {
15814
15988
  }());
15815
15989
 
15816
15990
 
15991
+ ;// ./src/ts/util/imageResize.ts
15992
+
15993
+
15994
+ var initImageResize = function (vditor) {
15995
+ var editorElement = vditor.wysiwyg.element;
15996
+ var currentResizeState = null;
15997
+ // 检测鼠标是否在图片的四个角附近
15998
+ var getResizeCorner = function (imgElement, mouseX, mouseY) {
15999
+ var rect = imgElement.getBoundingClientRect();
16000
+ var cornerSize = 20; // 角落检测区域大小
16001
+ // 左上角
16002
+ if (mouseX >= rect.left && mouseX <= rect.left + cornerSize &&
16003
+ mouseY >= rect.top && mouseY <= rect.top + cornerSize) {
16004
+ return 'nw';
16005
+ }
16006
+ // 右上角
16007
+ if (mouseX >= rect.right - cornerSize && mouseX <= rect.right &&
16008
+ mouseY >= rect.top && mouseY <= rect.top + cornerSize) {
16009
+ return 'ne';
16010
+ }
16011
+ // 左下角
16012
+ if (mouseX >= rect.left && mouseX <= rect.left + cornerSize &&
16013
+ mouseY >= rect.bottom - cornerSize && mouseY <= rect.bottom) {
16014
+ return 'sw';
16015
+ }
16016
+ // 右下角
16017
+ if (mouseX >= rect.right - cornerSize && mouseX <= rect.right &&
16018
+ mouseY >= rect.bottom - cornerSize && mouseY <= rect.bottom) {
16019
+ return 'se';
16020
+ }
16021
+ return null;
16022
+ };
16023
+ // 根据角落设置鼠标样式
16024
+ var getCursorStyle = function (corner) {
16025
+ switch (corner) {
16026
+ case 'nw':
16027
+ case 'se':
16028
+ return 'nwse-resize';
16029
+ case 'ne':
16030
+ case 'sw':
16031
+ return 'nesw-resize';
16032
+ default:
16033
+ return 'default';
16034
+ }
16035
+ };
16036
+ // 鼠标移动处理
16037
+ var handleMouseMove = function (e) {
16038
+ if (currentResizeState && currentResizeState.isResizing) {
16039
+ // 正在调整大小
16040
+ var imgElement = currentResizeState.imgElement, startX = currentResizeState.startX, startY = currentResizeState.startY, startWidth = currentResizeState.startWidth, startHeight = currentResizeState.startHeight, corner = currentResizeState.corner;
16041
+ var deltaX = e.clientX - startX;
16042
+ var deltaY = e.clientY - startY;
16043
+ var newWidth = startWidth;
16044
+ var newHeight = startHeight;
16045
+ switch (corner) {
16046
+ case "se": // 右下角
16047
+ newWidth = Math.max(50, startWidth + deltaX);
16048
+ newHeight = Math.max(50, startHeight + deltaY);
16049
+ break;
16050
+ case "sw": // 左下角
16051
+ newWidth = Math.max(50, startWidth - deltaX);
16052
+ newHeight = Math.max(50, startHeight + deltaY);
16053
+ break;
16054
+ case "ne": // 右上角
16055
+ newWidth = Math.max(50, startWidth + deltaX);
16056
+ newHeight = Math.max(50, startHeight - deltaY);
16057
+ break;
16058
+ case "nw": // 左上角
16059
+ newWidth = Math.max(50, startWidth - deltaX);
16060
+ newHeight = Math.max(50, startHeight - deltaY);
16061
+ break;
16062
+ }
16063
+ imgElement.style.width = newWidth + "px";
16064
+ imgElement.style.height = newHeight + "px";
16065
+ e.preventDefault();
16066
+ e.stopPropagation();
16067
+ }
16068
+ else {
16069
+ // 检测鼠标是否在角落,改变鼠标样式
16070
+ var target = e.target;
16071
+ var imgElement = (0,hasClosest/* hasClosestByMatchTag */._Y)(target, "IMG");
16072
+ if (imgElement && imgElement.getAttribute("data-resizable")) {
16073
+ var corner = getResizeCorner(imgElement, e.clientX, e.clientY);
16074
+ imgElement.style.cursor = getCursorStyle(corner);
16075
+ }
16076
+ }
16077
+ };
16078
+ // 鼠标按下处理
16079
+ var handleMouseDown = function (e) {
16080
+ var target = e.target;
16081
+ var imgElement = (0,hasClosest/* hasClosestByMatchTag */._Y)(target, "IMG");
16082
+ if (imgElement && imgElement.getAttribute("data-resizable")) {
16083
+ var corner = getResizeCorner(imgElement, e.clientX, e.clientY);
16084
+ if (corner) {
16085
+ console.log('Start resizing from corner:', corner);
16086
+ e.preventDefault();
16087
+ e.stopPropagation();
16088
+ currentResizeState = {
16089
+ isResizing: true,
16090
+ imgElement: imgElement,
16091
+ startX: e.clientX,
16092
+ startY: e.clientY,
16093
+ startWidth: imgElement.offsetWidth,
16094
+ startHeight: imgElement.offsetHeight,
16095
+ corner: corner
16096
+ };
16097
+ imgElement.classList.add("resizing");
16098
+ }
16099
+ }
16100
+ };
16101
+ // 鼠标释放处理
16102
+ var handleMouseUp = function () {
16103
+ if (currentResizeState && currentResizeState.isResizing) {
16104
+ console.log('Stop resizing');
16105
+ var imgElement = currentResizeState.imgElement;
16106
+ currentResizeState.isResizing = false;
16107
+ imgElement.classList.remove("resizing");
16108
+ var finalWidth = parseInt(imgElement.style.width) || imgElement.offsetWidth;
16109
+ var finalHeight = parseInt(imgElement.style.height) || imgElement.offsetHeight;
16110
+ imgElement.setAttribute("width", finalWidth.toString());
16111
+ imgElement.setAttribute("height", finalHeight.toString());
16112
+ if (typeof vditor.options.input === "function") {
16113
+ setTimeout(function () {
16114
+ vditor.options.input(getMarkdown(vditor));
16115
+ }, 0);
16116
+ }
16117
+ currentResizeState = null;
16118
+ }
16119
+ };
16120
+ // 添加事件监听器
16121
+ editorElement.addEventListener("mousemove", handleMouseMove);
16122
+ editorElement.addEventListener("mousedown", handleMouseDown);
16123
+ document.addEventListener("mouseup", handleMouseUp);
16124
+ };
16125
+
15817
16126
  ;// ./src/index.ts
15818
16127
  var src_extends = (undefined && undefined.__extends) || (function () {
15819
16128
  var extendStatics = function (d, b) {
@@ -15867,6 +16176,7 @@ var src_extends = (undefined && undefined.__extends) || (function () {
15867
16176
 
15868
16177
 
15869
16178
 
16179
+
15870
16180
 
15871
16181
 
15872
16182
  var Vditor = /** @class */ (function (_super) {
@@ -16334,6 +16644,7 @@ var Vditor = /** @class */ (function (_super) {
16334
16644
  });
16335
16645
  _this.vditor.preview = new Preview(_this.vditor);
16336
16646
  initUI(_this.vditor);
16647
+ initImageResize(_this.vditor);
16337
16648
  if (mergedOptions.after) {
16338
16649
  mergedOptions.after();
16339
16650
  }