roosterjs 9.60.0 → 9.62.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/rooster.js CHANGED
@@ -6470,7 +6470,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6470
6470
  exports.insertLink = void 0;
6471
6471
  var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
6472
6472
  var adjustTrailingSpaceSelection_1 = __webpack_require__(/*! ../../modelApi/selection/adjustTrailingSpaceSelection */ "./packages/roosterjs-content-model-api/lib/modelApi/selection/adjustTrailingSpaceSelection.ts");
6473
- var checkXss_1 = __webpack_require__(/*! ../utils/checkXss */ "./packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts");
6474
6473
  var matchLink_1 = __webpack_require__(/*! ../../modelApi/link/matchLink */ "./packages/roosterjs-content-model-api/lib/modelApi/link/matchLink.ts");
6475
6474
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
6476
6475
  // Regex matching Uri scheme
@@ -6494,7 +6493,7 @@ var FTP_REGEX = /^ftp\./i;
6494
6493
  */
6495
6494
  function insertLink(editor, link, anchorTitle, displayText, target) {
6496
6495
  editor.focus();
6497
- var url = ((0, checkXss_1.checkXss)(link) || '').trim();
6496
+ var url = ((0, roosterjs_content_model_dom_1.isUnsafeUrl)(link) ? '' : link || '').trim();
6498
6497
  if (url) {
6499
6498
  var linkData_1 = (0, matchLink_1.matchLink)(url);
6500
6499
  var linkUrl_1 = linkData_1 ? linkData_1.normalizedUrl : applyLinkPrefix(url);
@@ -8050,31 +8049,6 @@ function setTableCellShade(editor, color) {
8050
8049
  exports.setTableCellShade = setTableCellShade;
8051
8050
 
8052
8051
 
8053
- /***/ },
8054
-
8055
- /***/ "./packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"
8056
- /*!******************************************************************************!*\
8057
- !*** ./packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts ***!
8058
- \******************************************************************************/
8059
- (__unused_webpack_module, exports) {
8060
-
8061
- "use strict";
8062
-
8063
- Object.defineProperty(exports, "__esModule", ({ value: true }));
8064
- exports.checkXss = void 0;
8065
- /**
8066
- * @internal Check if there is XSS attack in the link
8067
- * @param link The link to be checked
8068
- * @returns The safe link, or empty string if there is XSS attack
8069
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
8070
- * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
8071
- */
8072
- function checkXss(link) {
8073
- return link.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
8074
- }
8075
- exports.checkXss = checkXss;
8076
-
8077
-
8078
8052
  /***/ },
8079
8053
 
8080
8054
  /***/ "./packages/roosterjs-content-model-api/lib/publicApi/utils/createEditorContextForEntity.ts"
@@ -8857,7 +8831,6 @@ exports.AllowedTags = [
8857
8831
  'ul',
8858
8832
  'var',
8859
8833
  'wbr',
8860
- 'xmp',
8861
8834
  ];
8862
8835
  /**
8863
8836
  * @internal
@@ -9042,7 +9015,7 @@ function createSanitizedElement(doc, tag, attributes, styleSanitizers, attribute
9042
9015
  var attribute = attributes[i];
9043
9016
  var name_1 = attribute.name.toLowerCase().trim();
9044
9017
  var value = attribute.value;
9045
- var sanitizer = attributeSanitizers === null || attributeSanitizers === void 0 ? void 0 : attributeSanitizers[name_1];
9018
+ var sanitizer = getOwnValue(attributeSanitizers, name_1);
9046
9019
  var newValue = name_1 == 'style'
9047
9020
  ? processStyles(tag, value, styleSanitizers)
9048
9021
  : typeof sanitizer == 'function'
@@ -9054,10 +9027,7 @@ function createSanitizedElement(doc, tag, attributes, styleSanitizers, attribute
9054
9027
  : AllowedAttributes.indexOf(name_1) >= 0 || name_1.indexOf('data-') == 0
9055
9028
  ? value
9056
9029
  : null;
9057
- if (newValue !== null &&
9058
- newValue !== undefined &&
9059
- !newValue.match(/s\n*c\n*r\n*i\n*p\n*t\n*:/i) // match script: with any NewLine inside. Browser will ignore those NewLine char and still treat it as script prefix
9060
- ) {
9030
+ if (newValue !== null && newValue !== undefined && !(0, roosterjs_content_model_dom_1.isUnsafeUrl)(newValue)) {
9061
9031
  element.setAttribute(name_1, newValue);
9062
9032
  }
9063
9033
  }
@@ -9075,7 +9045,7 @@ function processStyles(tagName, value, styleSanitizers) {
9075
9045
  if (isCssVariable(value)) {
9076
9046
  value = processCssVariable(value);
9077
9047
  }
9078
- var sanitizer = styleSanitizers === null || styleSanitizers === void 0 ? void 0 : styleSanitizers[name];
9048
+ var sanitizer = getOwnValue(styleSanitizers, name);
9079
9049
  var sanitizedValue = typeof sanitizer == 'function'
9080
9050
  ? sanitizer(value, tagName)
9081
9051
  : sanitizer === false
@@ -9086,7 +9056,7 @@ function processStyles(tagName, value, styleSanitizers) {
9086
9056
  sanitizedValue != 'initial' &&
9087
9057
  sanitizedValue.indexOf('expression') < 0 &&
9088
9058
  !name.startsWith('-') &&
9089
- DefaultStyleValue[name] != sanitizedValue) {
9059
+ getOwnValue(DefaultStyleValue, name) != sanitizedValue) {
9090
9060
  result.push(name + ":" + sanitizedValue);
9091
9061
  }
9092
9062
  }
@@ -9097,6 +9067,12 @@ function processCssVariable(value) {
9097
9067
  var match = VARIABLE_REGEX.exec(value);
9098
9068
  return (match === null || match === void 0 ? void 0 : match[2]) || ''; // Without fallback value, we don't know what does the original value mean, so ignore it
9099
9069
  }
9070
+ // Attribute and style names come from the pasted content, so a name such as "valueOf" or
9071
+ // "hasOwnProperty" would otherwise resolve to the inherited member of Object.prototype and be
9072
+ // invoked as if it were a sanitizer, which throws and fails the whole conversion.
9073
+ function getOwnValue(map, name) {
9074
+ return map && Object.prototype.hasOwnProperty.call(map, name) ? map[name] : undefined;
9075
+ }
9100
9076
  function isCssVariable(value) {
9101
9077
  return value.indexOf(VARIABLE_PREFIX) == 0;
9102
9078
  }
@@ -11056,6 +11032,33 @@ function findTableCellElement(parsedTable, coordinate) {
11056
11032
  exports.findTableCellElement = findTableCellElement;
11057
11033
 
11058
11034
 
11035
+ /***/ },
11036
+
11037
+ /***/ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts"
11038
+ /*!****************************************************************************************************!*\
11039
+ !*** ./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts ***!
11040
+ \****************************************************************************************************/
11041
+ (__unused_webpack_module, exports) {
11042
+
11043
+ "use strict";
11044
+
11045
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
11046
+ exports.getTextSelectionStyle = exports.RANGE_SELECTION_CSS_KEY = void 0;
11047
+ /**
11048
+ * @internal
11049
+ */
11050
+ exports.RANGE_SELECTION_CSS_KEY = '_RangeSelection';
11051
+ /**
11052
+ * @internal
11053
+ * Get the text selection style for the current color mode, or null to use browser defaults.
11054
+ */
11055
+ function getTextSelectionStyle(state, isDarkMode) {
11056
+ var color = isDarkMode ? state.textSelectionColorDark : state.textSelectionColor;
11057
+ return color ? "background-color: " + color + " !important; color: currentColor !important;" : null;
11058
+ }
11059
+ exports.getTextSelectionStyle = getTextSelectionStyle;
11060
+
11061
+
11059
11062
  /***/ },
11060
11063
 
11061
11064
  /***/ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setDOMSelection.ts"
@@ -11073,6 +11076,7 @@ var ensureUniqueId_1 = __webpack_require__(/*! ../setEditorStyle/ensureUniqueId
11073
11076
  var findLastedCoInMergedCell_1 = __webpack_require__(/*! ./findLastedCoInMergedCell */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/findLastedCoInMergedCell.ts");
11074
11077
  var findTableCellElement_1 = __webpack_require__(/*! ./findTableCellElement */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/findTableCellElement.ts");
11075
11078
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
11079
+ var getTextSelectionStyle_1 = __webpack_require__(/*! ./getTextSelectionStyle */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts");
11076
11080
  var setTableCellsStyle_1 = __webpack_require__(/*! ./setTableCellsStyle */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setTableCellsStyle.ts");
11077
11081
  var toggleCaret_1 = __webpack_require__(/*! ./toggleCaret */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleCaret.ts");
11078
11082
  var DOM_SELECTION_CSS_KEY = '_DOMSelection';
@@ -11097,6 +11101,7 @@ var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
11097
11101
  core.selection.skipReselectOnFocus = true;
11098
11102
  core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, null /*cssRule*/);
11099
11103
  core.api.setEditorStyle(core, HIDE_SELECTION_CSS_KEY, null /*cssRule*/);
11104
+ core.api.setEditorStyle(core, getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, null /*cssRule*/);
11100
11105
  (0, toggleCaret_1.toggleCaret)(core, false /* hide */);
11101
11106
  try {
11102
11107
  switch (selection === null || selection === void 0 ? void 0 : selection.type) {
@@ -11149,6 +11154,14 @@ var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
11149
11154
  }
11150
11155
  break;
11151
11156
  case 'range':
11157
+ var textSelectionStyle = !selection.range.collapsed
11158
+ ? (0, getTextSelectionStyle_1.getTextSelectionStyle)(core.selection, isDarkMode)
11159
+ : null;
11160
+ if (textSelectionStyle) {
11161
+ core.api.setEditorStyle(core, getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, textSelectionStyle, [
11162
+ SELECTION_SELECTOR,
11163
+ ]);
11164
+ }
11152
11165
  core.domHelper.setSelectionRange(selection.range, selection.isReverted);
11153
11166
  core.selection.selection = core.domHelper.hasFocus() ? null : selection;
11154
11167
  break;
@@ -14545,6 +14558,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
14545
14558
  exports.createSelectionPlugin = exports.DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR = exports.DEFAULT_SELECTION_BORDER_COLOR = void 0;
14546
14559
  var findCoordinate_1 = __webpack_require__(/*! ./findCoordinate */ "./packages/roosterjs-content-model-core/lib/corePlugin/selection/findCoordinate.ts");
14547
14560
  var findTableCellElement_1 = __webpack_require__(/*! ../../coreApi/setDOMSelection/findTableCellElement */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/findTableCellElement.ts");
14561
+ var getTextSelectionStyle_1 = __webpack_require__(/*! ../../coreApi/setDOMSelection/getTextSelectionStyle */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts");
14548
14562
  var isSingleImageInSelection_1 = __webpack_require__(/*! ./isSingleImageInSelection */ "./packages/roosterjs-content-model-core/lib/corePlugin/selection/isSingleImageInSelection.ts");
14549
14563
  var normalizePos_1 = __webpack_require__(/*! ./normalizePos */ "./packages/roosterjs-content-model-core/lib/corePlugin/selection/normalizePos.ts");
14550
14564
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
@@ -14664,6 +14678,7 @@ var SelectionPlugin = /** @class */ (function () {
14664
14678
  this.onSelectionChange = function () {
14665
14679
  var _a, _b;
14666
14680
  if (((_a = _this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) && !_this.editor.isInShadowEdit()) {
14681
+ _this.editor.setEditorStyle(getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, null /* cssRule */);
14667
14682
  var newSelection = _this.editor.getDOMSelection();
14668
14683
  var domHelper = _this.editor.getDOMHelper();
14669
14684
  // If an image selection changed to a wider range due to a keyboard event, we should update the selection
@@ -14675,22 +14690,31 @@ var SelectionPlugin = /** @class */ (function () {
14675
14690
  var isReverted = sel
14676
14691
  ? sel.focusNode != range.endContainer || sel.focusOffset != range.endOffset
14677
14692
  : false;
14678
- _this.editor.setDOMSelection({
14693
+ newSelection = {
14679
14694
  type: 'range',
14680
14695
  range: range,
14681
14696
  isReverted: isReverted,
14682
- });
14697
+ };
14698
+ _this.editor.setDOMSelection(newSelection);
14683
14699
  }
14684
14700
  else if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) !== 'image' && image) {
14685
- _this.editor.setDOMSelection({
14701
+ newSelection = {
14686
14702
  type: 'image',
14687
14703
  image: image,
14688
- });
14704
+ };
14705
+ _this.editor.setDOMSelection(newSelection);
14689
14706
  }
14690
14707
  }
14691
- // Safari has problem to handle onBlur event. When blur, we cannot get the original selection from editor.
14692
- // So we always save a selection whenever editor has focus. Then after blur, we can still use this cached selection.
14693
14708
  if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) == 'range') {
14709
+ if (!newSelection.range.collapsed) {
14710
+ var textSelectionStyle = (0, getTextSelectionStyle_1.getTextSelectionStyle)(_this.state, _this.editor.isDarkMode());
14711
+ if (textSelectionStyle) {
14712
+ _this.editor.setEditorStyle(getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, textSelectionStyle, [
14713
+ '*::selection',
14714
+ ]);
14715
+ }
14716
+ }
14717
+ // Safari cannot retrieve the original selection on blur, so cache it while focused.
14694
14718
  if (_this.isSafari) {
14695
14719
  _this.state.selection = newSelection;
14696
14720
  }
@@ -14709,12 +14733,20 @@ var SelectionPlugin = /** @class */ (function () {
14709
14733
  ? undefined
14710
14734
  : exports.DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
14711
14735
  };
14736
+ if (options.textSelectionColor) {
14737
+ this.state.textSelectionColor = options.textSelectionColor;
14738
+ }
14712
14739
  }
14713
14740
  SelectionPlugin.prototype.getName = function () {
14714
14741
  return 'Selection';
14715
14742
  };
14716
14743
  SelectionPlugin.prototype.initialize = function (editor) {
14717
14744
  this.editor = editor;
14745
+ if (!this.state.textSelectionColorDark && this.state.textSelectionColor) {
14746
+ this.state.textSelectionColorDark = editor
14747
+ .getColorManager()
14748
+ .getDarkColor(this.state.textSelectionColor, undefined, 'background');
14749
+ }
14718
14750
  if (!this.state.imageSelectionBorderColorDark && this.state.imageSelectionBorderColor) {
14719
14751
  this.state.imageSelectionBorderColorDark = editor
14720
14752
  .getColorManager()
@@ -17512,6 +17544,7 @@ exports.EmptySegmentFormat = {
17512
17544
  letterSpacing: '',
17513
17545
  lineHeight: '',
17514
17546
  strikethrough: false,
17547
+ superOrSubScriptFontSize: '',
17515
17548
  superOrSubScriptSequence: '',
17516
17549
  textColor: '',
17517
17550
  underline: false,
@@ -20631,6 +20664,48 @@ function isNodeOfType(node, expectedType) {
20631
20664
  exports.isNodeOfType = isNodeOfType;
20632
20665
 
20633
20666
 
20667
+ /***/ },
20668
+
20669
+ /***/ "./packages/roosterjs-content-model-dom/lib/domUtils/isUnsafeUrl.ts"
20670
+ /*!**************************************************************************!*\
20671
+ !*** ./packages/roosterjs-content-model-dom/lib/domUtils/isUnsafeUrl.ts ***!
20672
+ \**************************************************************************/
20673
+ (__unused_webpack_module, exports) {
20674
+
20675
+ "use strict";
20676
+
20677
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
20678
+ exports.isUnsafeUrl = void 0;
20679
+ var UnsafeProtocols = ['javascript', 'vbscript', 'livescript', 'jscript', 'mocha', 'script'];
20680
+ var IgnoredCharacters = /[\t\n\r]/g;
20681
+ var MaxControlCharCode = 0x20;
20682
+ /**
20683
+ * Check whether the given URL uses a protocol that can execute script, such as "javascript:"
20684
+ * @param url The URL to check
20685
+ * @returns True if the URL can execute script when navigated to, otherwise false
20686
+ * @remarks Browsers remove every TAB, LF and CR character from a URL and ignore any leading control
20687
+ * character or space before they resolve its protocol. Those characters must be removed before the
20688
+ * protocol is checked here, otherwise a value such as "java&#9;script:" or "javascr&#13;ipt:" would
20689
+ * be treated as safe but still executed by the browser.
20690
+ */
20691
+ function isUnsafeUrl(url) {
20692
+ if (!url) {
20693
+ return false;
20694
+ }
20695
+ var normalizedUrl = trimControlCharacters(url.replace(IgnoredCharacters, '')).toLowerCase();
20696
+ var colonIndex = normalizedUrl.indexOf(':');
20697
+ return colonIndex >= 0 && UnsafeProtocols.indexOf(normalizedUrl.substring(0, colonIndex)) >= 0;
20698
+ }
20699
+ exports.isUnsafeUrl = isUnsafeUrl;
20700
+ function trimControlCharacters(url) {
20701
+ var start = 0;
20702
+ while (start < url.length && url.charCodeAt(start) <= MaxControlCharCode) {
20703
+ start++;
20704
+ }
20705
+ return url.substring(start);
20706
+ }
20707
+
20708
+
20634
20709
  /***/ },
20635
20710
 
20636
20711
  /***/ "./packages/roosterjs-content-model-dom/lib/domUtils/isWhiteSpacePreserved.ts"
@@ -23099,6 +23174,7 @@ exports.listStyleFormatHandler = {
23099
23174
 
23100
23175
  Object.defineProperty(exports, "__esModule", ({ value: true }));
23101
23176
  exports.boldFormatHandler = void 0;
23177
+ var isBlockElement_1 = __webpack_require__(/*! ../../domToModel/utils/isBlockElement */ "./packages/roosterjs-content-model-dom/lib/domToModel/utils/isBlockElement.ts");
23102
23178
  var shouldSetValue_1 = __webpack_require__(/*! ../utils/shouldSetValue */ "./packages/roosterjs-content-model-dom/lib/formatHandlers/utils/shouldSetValue.ts");
23103
23179
  var moveChildNodes_1 = __webpack_require__(/*! ../../domUtils/moveChildNodes */ "./packages/roosterjs-content-model-dom/lib/domUtils/moveChildNodes.ts");
23104
23180
  /**
@@ -23118,7 +23194,7 @@ exports.boldFormatHandler = {
23118
23194
  var blockFontWeight = context.implicitFormat.fontWeight;
23119
23195
  if ((blockFontWeight && blockFontWeight != format.fontWeight) ||
23120
23196
  (!blockFontWeight && format.fontWeight && format.fontWeight != 'normal')) {
23121
- if (format.fontWeight == 'bold') {
23197
+ if (format.fontWeight == 'bold' && !(0, isBlockElement_1.isBlockElement)(element)) {
23122
23198
  (0, moveChildNodes_1.wrapAllChildNodes)(element, 'b');
23123
23199
  }
23124
23200
  else {
@@ -23396,6 +23472,7 @@ exports.letterSpacingFormatHandler = {
23396
23472
  Object.defineProperty(exports, "__esModule", ({ value: true }));
23397
23473
  exports.linkFormatHandler = void 0;
23398
23474
  var isElementOfType_1 = __webpack_require__(/*! ../../domUtils/isElementOfType */ "./packages/roosterjs-content-model-dom/lib/domUtils/isElementOfType.ts");
23475
+ var isUnsafeUrl_1 = __webpack_require__(/*! ../../domUtils/isUnsafeUrl */ "./packages/roosterjs-content-model-dom/lib/domUtils/isUnsafeUrl.ts");
23399
23476
  /**
23400
23477
  * @internal
23401
23478
  */
@@ -23412,7 +23489,7 @@ exports.linkFormatHandler = {
23412
23489
  if (name_1) {
23413
23490
  format.name = name_1;
23414
23491
  }
23415
- if (href) {
23492
+ if (href && !(0, isUnsafeUrl_1.isUnsafeUrl)(href)) {
23416
23493
  format.href = href;
23417
23494
  }
23418
23495
  if (target) {
@@ -23434,7 +23511,7 @@ exports.linkFormatHandler = {
23434
23511
  },
23435
23512
  apply: function (format, element) {
23436
23513
  if ((0, isElementOfType_1.isElementOfType)(element, 'a') && (format.href || format.name)) {
23437
- if (format.href) {
23514
+ if (format.href && !(0, isUnsafeUrl_1.isUnsafeUrl)(format.href)) {
23438
23515
  element.href = format.href;
23439
23516
  }
23440
23517
  if (format.name) {
@@ -23511,12 +23588,17 @@ exports.superOrSubScriptFormatHandler = {
23511
23588
  parse: function (format, element, context, defaultStyle) {
23512
23589
  var verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;
23513
23590
  var fontSize = element.style.fontSize || defaultStyle.fontSize;
23514
- if (isSuperOrSubScript(fontSize, verticalAlign)) {
23591
+ var inheritFontSize = (element.tagName == 'SUP' || element.tagName == 'SUB') && fontSize == 'inherit';
23592
+ if (isSuperOrSubScript(fontSize, verticalAlign) ||
23593
+ (inheritFontSize && (verticalAlign == 'super' || verticalAlign == 'sub'))) {
23515
23594
  format.superOrSubScriptSequence = (format.superOrSubScriptSequence || '')
23516
23595
  .split(' ')
23517
23596
  .concat(verticalAlign)
23518
23597
  .join(' ')
23519
23598
  .trim();
23599
+ if (inheritFontSize) {
23600
+ format.superOrSubScriptFontSize = 'inherit';
23601
+ }
23520
23602
  }
23521
23603
  },
23522
23604
  apply: function (format, element) {
@@ -23527,7 +23609,10 @@ exports.superOrSubScriptFormatHandler = {
23527
23609
  .forEach(function (value) {
23528
23610
  var tagName = value == 'super' ? 'sup' : value == 'sub' ? 'sub' : null;
23529
23611
  if (tagName) {
23530
- (0, moveChildNodes_1.wrapAllChildNodes)(element, tagName);
23612
+ var wrapper = (0, moveChildNodes_1.wrapAllChildNodes)(element, tagName);
23613
+ if (format.superOrSubScriptFontSize) {
23614
+ wrapper.style.fontSize = format.superOrSubScriptFontSize;
23615
+ }
23531
23616
  }
23532
23617
  });
23533
23618
  }
@@ -24199,10 +24284,10 @@ exports.shouldSetValue = shouldSetValue;
24199
24284
  "use strict";
24200
24285
 
24201
24286
  Object.defineProperty(exports, "__esModule", ({ value: true }));
24202
- exports.createImage = exports.createText = exports.createTableCell = exports.createTable = exports.createSelectionMarker = exports.createParagraph = exports.createFormatContainer = exports.createListItem = exports.createBr = exports.isLinkUndeletable = exports.setLinkUndeletable = exports.scrollRectIntoView = exports.normalizeRect = exports.isWhiteSpacePreserved = exports.reuseCachedElement = exports.findClosestBlockEntityContainer = exports.isBlockEntityContainer = exports.isEntityDelimiter = exports.addDelimiters = exports.generateEntityClassNames = exports.parseEntityFormat = exports.getAllEntityWrappers = exports.findClosestEntityWrapper = exports.isEntityElement = exports.unwrap = exports.wrap = exports.wrapAllChildNodes = exports.moveChildNodes = exports.toArray = exports.getSafeIdSelector = exports.getObjectKeys = exports.isElementOfType = exports.isNodeOfType = exports.hasMetadata = exports.getMetadata = exports.updateMetadata = exports.buildSelectionMarker = exports.isBlockElement = exports.areSameFormats = exports.parseFormat = exports.getRegularSelectionOffsets = exports.formatContainerProcessor = exports.tableProcessor = exports.entityProcessor = exports.processChildNode = exports.handleRegularSelection = exports.childProcessor = exports.contentModelToText = exports.contentModelToDom = exports.domToContentModel = void 0;
24203
- exports.getDOMInsertPointRect = exports.getSelectionRootNode = exports.isBold = exports.createModelToDomConfig = exports.createModelToDomContextWithConfig = exports.createModelToDomContext = exports.createDomToModelConfig = exports.createDomToModelContextWithConfig = exports.createDomToModelContext = exports.defaultGenerateColorKey = exports.parseColor = exports.setColor = exports.getColor = exports.DeprecatedColors = exports.BorderKeys = exports.parseValueWithUnit = exports.getAutoListStyleType = exports.getOrderedListNumberStr = exports.ParagraphFormats = exports.ListFormatsToMove = exports.ListFormatsToKeep = exports.ListFormats = exports.copyFormat = exports.setParagraphNotImplicit = exports.normalizeSegmentFormat = exports.mergeTextSegments = exports.normalizeSingleSegment = exports.isEmpty = exports.addSegment = exports.unwrapBlock = exports.isGeneralSegment = exports.normalizeContentModel = exports.normalizeParagraph = exports.addTextSegment = exports.addLink = exports.addData = exports.addCode = exports.addBlock = exports.mutateSegment = exports.mutateSegments = exports.mutateBlock = exports.createTableRow = exports.createEmptyModel = exports.createListLevel = exports.createDivider = exports.createEntity = exports.createGeneralBlock = exports.createGeneralSegment = exports.createParagraphDecorator = exports.createContentModelDocument = void 0;
24204
- exports.retrieveModelFormatState = exports.setTableCellBackgroundColor = exports.MIN_ALLOWED_TABLE_CELL_HEIGHT = exports.MIN_ALLOWED_TABLE_CELL_WIDTH = exports.normalizeTable = exports.setFirstColumnFormatBorders = exports.applyTableFormat = exports.deleteBlock = exports.deleteSegment = exports.deleteSelection = exports.mergeModel = exports.canMergeCells = exports.cloneModelForPaste = exports.cloneModel = exports.setSelection = exports.hasSelectionInBlockGroup = exports.hasSelectionInSegment = exports.hasSelectionInBlock = exports.getSelectedCells = exports.getSelectedSegmentsAndParagraphs = exports.getSelectedSegments = exports.getSelectedParagraphs = exports.getOperationalBlocks = exports.getFirstSelectedTable = exports.getFirstSelectedListItem = exports.iterateSelections = exports.isBlockGroupOfType = exports.getRangesByText = exports.getImageState = exports.setImageState = exports.getParagraphMarker = exports.setParagraphMarker = exports.cacheGetEventData = exports.createPasteFragment = exports.extractClipboardItems = exports.normalizeFontFamily = exports.transformColor = exports.retrieveDocumentMetadata = exports.readFile = exports.parseTableCells = exports.normalizeText = exports.isSpace = exports.isPunctuation = exports.extractBorderValues = exports.combineBorderValue = exports.getNodePositionFromEvent = exports.isCursorMovingKey = exports.isModifierKey = exports.isCharacterValue = exports.trimModelForSelection = void 0;
24205
- exports.EmptySegmentFormat = exports.UnorderedListStyleMap = exports.OrderedListStyleMap = exports.TableBorderFormat = exports.NumberingListType = exports.BulletListType = exports.ChangeSource = exports.ListMetadataDefinition = exports.getListMetadata = exports.updateListMetadata = exports.getTableMetadata = exports.updateTableMetadata = exports.getTableCellMetadata = exports.updateTableCellMetadata = exports.getImageMetadata = exports.updateImageMetadata = exports.runEditSteps = exports.getClosestAncestorBlockGroupIndex = exports.getSegmentTextFormat = exports.getListStyleTypeFromString = void 0;
24287
+ exports.createText = exports.createTableCell = exports.createTable = exports.createSelectionMarker = exports.createParagraph = exports.createFormatContainer = exports.createListItem = exports.createBr = exports.isLinkUndeletable = exports.setLinkUndeletable = exports.scrollRectIntoView = exports.normalizeRect = exports.isWhiteSpacePreserved = exports.reuseCachedElement = exports.findClosestBlockEntityContainer = exports.isBlockEntityContainer = exports.isEntityDelimiter = exports.addDelimiters = exports.generateEntityClassNames = exports.parseEntityFormat = exports.getAllEntityWrappers = exports.findClosestEntityWrapper = exports.isEntityElement = exports.unwrap = exports.wrap = exports.wrapAllChildNodes = exports.moveChildNodes = exports.toArray = exports.getSafeIdSelector = exports.getObjectKeys = exports.isUnsafeUrl = exports.isElementOfType = exports.isNodeOfType = exports.hasMetadata = exports.getMetadata = exports.updateMetadata = exports.buildSelectionMarker = exports.isBlockElement = exports.areSameFormats = exports.parseFormat = exports.getRegularSelectionOffsets = exports.formatContainerProcessor = exports.tableProcessor = exports.entityProcessor = exports.processChildNode = exports.handleRegularSelection = exports.childProcessor = exports.contentModelToText = exports.contentModelToDom = exports.domToContentModel = void 0;
24288
+ exports.getSelectionRootNode = exports.isBold = exports.createModelToDomConfig = exports.createModelToDomContextWithConfig = exports.createModelToDomContext = exports.createDomToModelConfig = exports.createDomToModelContextWithConfig = exports.createDomToModelContext = exports.defaultGenerateColorKey = exports.parseColor = exports.setColor = exports.getColor = exports.DeprecatedColors = exports.BorderKeys = exports.parseValueWithUnit = exports.getAutoListStyleType = exports.getOrderedListNumberStr = exports.ParagraphFormats = exports.ListFormatsToMove = exports.ListFormatsToKeep = exports.ListFormats = exports.copyFormat = exports.setParagraphNotImplicit = exports.normalizeSegmentFormat = exports.mergeTextSegments = exports.normalizeSingleSegment = exports.isEmpty = exports.addSegment = exports.unwrapBlock = exports.isGeneralSegment = exports.normalizeContentModel = exports.normalizeParagraph = exports.addTextSegment = exports.addLink = exports.addData = exports.addCode = exports.addBlock = exports.mutateSegment = exports.mutateSegments = exports.mutateBlock = exports.createTableRow = exports.createEmptyModel = exports.createListLevel = exports.createDivider = exports.createEntity = exports.createGeneralBlock = exports.createGeneralSegment = exports.createParagraphDecorator = exports.createContentModelDocument = exports.createImage = void 0;
24289
+ exports.setTableCellBackgroundColor = exports.MIN_ALLOWED_TABLE_CELL_HEIGHT = exports.MIN_ALLOWED_TABLE_CELL_WIDTH = exports.normalizeTable = exports.setFirstColumnFormatBorders = exports.applyTableFormat = exports.deleteBlock = exports.deleteSegment = exports.deleteSelection = exports.mergeModel = exports.canMergeCells = exports.cloneModelForPaste = exports.cloneModel = exports.setSelection = exports.hasSelectionInBlockGroup = exports.hasSelectionInSegment = exports.hasSelectionInBlock = exports.getSelectedCells = exports.getSelectedSegmentsAndParagraphs = exports.getSelectedSegments = exports.getSelectedParagraphs = exports.getOperationalBlocks = exports.getFirstSelectedTable = exports.getFirstSelectedListItem = exports.iterateSelections = exports.isBlockGroupOfType = exports.getRangesByText = exports.getImageState = exports.setImageState = exports.getParagraphMarker = exports.setParagraphMarker = exports.cacheGetEventData = exports.createPasteFragment = exports.extractClipboardItems = exports.normalizeFontFamily = exports.transformColor = exports.retrieveDocumentMetadata = exports.readFile = exports.parseTableCells = exports.normalizeText = exports.isSpace = exports.isPunctuation = exports.extractBorderValues = exports.combineBorderValue = exports.getNodePositionFromEvent = exports.isCursorMovingKey = exports.isModifierKey = exports.isCharacterValue = exports.trimModelForSelection = exports.getDOMInsertPointRect = void 0;
24290
+ exports.EmptySegmentFormat = exports.UnorderedListStyleMap = exports.OrderedListStyleMap = exports.TableBorderFormat = exports.NumberingListType = exports.BulletListType = exports.ChangeSource = exports.ListMetadataDefinition = exports.getListMetadata = exports.updateListMetadata = exports.getTableMetadata = exports.updateTableMetadata = exports.getTableCellMetadata = exports.updateTableCellMetadata = exports.getImageMetadata = exports.updateImageMetadata = exports.runEditSteps = exports.getClosestAncestorBlockGroupIndex = exports.getSegmentTextFormat = exports.getListStyleTypeFromString = exports.retrieveModelFormatState = void 0;
24206
24291
  var domToContentModel_1 = __webpack_require__(/*! ./domToModel/domToContentModel */ "./packages/roosterjs-content-model-dom/lib/domToModel/domToContentModel.ts");
24207
24292
  Object.defineProperty(exports, "domToContentModel", ({ enumerable: true, get: function () { return domToContentModel_1.domToContentModel; } }));
24208
24293
  var contentModelToDom_1 = __webpack_require__(/*! ./modelToDom/contentModelToDom */ "./packages/roosterjs-content-model-dom/lib/modelToDom/contentModelToDom.ts");
@@ -24237,6 +24322,8 @@ var isNodeOfType_1 = __webpack_require__(/*! ./domUtils/isNodeOfType */ "./packa
24237
24322
  Object.defineProperty(exports, "isNodeOfType", ({ enumerable: true, get: function () { return isNodeOfType_1.isNodeOfType; } }));
24238
24323
  var isElementOfType_1 = __webpack_require__(/*! ./domUtils/isElementOfType */ "./packages/roosterjs-content-model-dom/lib/domUtils/isElementOfType.ts");
24239
24324
  Object.defineProperty(exports, "isElementOfType", ({ enumerable: true, get: function () { return isElementOfType_1.isElementOfType; } }));
24325
+ var isUnsafeUrl_1 = __webpack_require__(/*! ./domUtils/isUnsafeUrl */ "./packages/roosterjs-content-model-dom/lib/domUtils/isUnsafeUrl.ts");
24326
+ Object.defineProperty(exports, "isUnsafeUrl", ({ enumerable: true, get: function () { return isUnsafeUrl_1.isUnsafeUrl; } }));
24240
24327
  var getObjectKeys_1 = __webpack_require__(/*! ./domUtils/getObjectKeys */ "./packages/roosterjs-content-model-dom/lib/domUtils/getObjectKeys.ts");
24241
24328
  Object.defineProperty(exports, "getObjectKeys", ({ enumerable: true, get: function () { return getObjectKeys_1.getObjectKeys; } }));
24242
24329
  var getSafeIdSelector_1 = __webpack_require__(/*! ./domUtils/getSafeIdSelector */ "./packages/roosterjs-content-model-dom/lib/domUtils/getSafeIdSelector.ts");
@@ -25461,9 +25548,9 @@ exports.normalizeSegmentFormat = normalizeSegmentFormat;
25461
25548
  Object.defineProperty(exports, "__esModule", ({ value: true }));
25462
25549
  exports.stripInvisibleUnicode = void 0;
25463
25550
  // According to https://embracethered.com/blog/posts/2024/hiding-and-finding-text-with-unicode-tags/
25464
- // there are some invisible unicode characters in the range of U+E0000 to U+EFFFF, which are used for hiding text in HTML.
25551
+ // there are some invisible unicode characters in the range of U+E0000 to U+E007F, which are used for hiding text in HTML.
25465
25552
  // We need to strip them out before processing the pasted content, otherwise they will be treated as normal text and cause unexpected behavior.
25466
- var INVISIBLE_UNICODE_REGEX = /[\u{E0000}-\u{EFFFF}]/gu;
25553
+ var INVISIBLE_UNICODE_REGEX = /[\u{E0000}-\u{E007F}]/gu;
25467
25554
  /**
25468
25555
  * @internal
25469
25556
  * Strip invisible unicode characters from the given string
@@ -27444,21 +27531,22 @@ var KeysOfSegmentFormat = (0, getObjectKeys_1.getObjectKeys)(EmptySegmentFormat_
27444
27531
  * @returns Insert point after merge, or null if there is no insert point
27445
27532
  */
27446
27533
  function mergeModel(target, source, context, options) {
27447
- var _a, _b;
27534
+ var _a, _b, _c;
27448
27535
  var insertPosition = (_a = options === null || options === void 0 ? void 0 : options.insertPosition) !== null && _a !== void 0 ? _a : (0, deleteSelection_1.deleteSelection)(target, [], context).insertPoint;
27449
- var _c = options || {}, addParagraphAfterMergedContent = _c.addParagraphAfterMergedContent, mergeFormat = _c.mergeFormat, mergeParagraphAfterList = _c.mergeParagraphAfterList, mergeTable = _c.mergeTable;
27536
+ var _d = options || {}, addParagraphAfterMergedContent = _d.addParagraphAfterMergedContent, mergeFormat = _d.mergeFormat, mergeParagraphAfterList = _d.mergeParagraphAfterList, mergeTable = _d.mergeTable;
27450
27537
  if (mergeParagraphAfterList && insertPosition && ((_b = source.blocks[0]) === null || _b === void 0 ? void 0 : _b.blockType) == 'Paragraph') {
27451
27538
  moveParagraphAfterListIntoList(insertPosition);
27452
27539
  }
27453
27540
  if (addParagraphAfterMergedContent && !mergeTable) {
27454
- var _d = insertPosition || {}, paragraph = _d.paragraph, marker = _d.marker;
27541
+ var _e = insertPosition || {}, paragraph = _e.paragraph, marker = _e.marker;
27455
27542
  var newPara = (0, createParagraph_1.createParagraph)(false /* isImplicit */, paragraph === null || paragraph === void 0 ? void 0 : paragraph.format, marker === null || marker === void 0 ? void 0 : marker.format);
27456
27543
  (0, addBlock_1.addBlock)(source, newPara);
27457
27544
  }
27458
27545
  if (insertPosition) {
27459
27546
  if (mergeFormat && mergeFormat != 'none') {
27460
- var newFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (target.format || {})), insertPosition.marker.format);
27461
- applyDefaultFormat(source, newFormat, mergeFormat);
27547
+ var newFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (target.format || {})), ((options === null || options === void 0 ? void 0 : options.preserveParagraphDecorator)
27548
+ ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (_c = insertPosition.paragraph.decorator) === null || _c === void 0 ? void 0 : _c.format), insertPosition.paragraph.segmentFormat) : undefined)), insertPosition.marker.format);
27549
+ applyDefaultFormat(source, newFormat, mergeFormat, options === null || options === void 0 ? void 0 : options.preserveParagraphDecorator);
27462
27550
  }
27463
27551
  for (var i = 0; i < source.blocks.length; i++) {
27464
27552
  var block = source.blocks[i];
@@ -27736,7 +27824,7 @@ function insertBlock(markerPosition, block) {
27736
27824
  (0, mutate_1.mutateBlock)(path[0]).blocks.splice(blockIndex, 0, block);
27737
27825
  }
27738
27826
  }
27739
- function applyDefaultFormat(group, format, applyDefaultFormatOption) {
27827
+ function applyDefaultFormat(group, format, applyDefaultFormatOption, preserveParagraphDecorator) {
27740
27828
  group.blocks.forEach(function (block) {
27741
27829
  var _a;
27742
27830
  mergeBlockFormat(applyDefaultFormatOption, block);
@@ -27745,28 +27833,32 @@ function applyDefaultFormat(group, format, applyDefaultFormatOption) {
27745
27833
  if (block.blockGroupType == 'ListItem') {
27746
27834
  (0, mutate_1.mutateBlock)(block).formatHolder.format = mergeSegmentFormat(applyDefaultFormatOption, format, block.formatHolder.format);
27747
27835
  }
27748
- applyDefaultFormat(block, format, applyDefaultFormatOption);
27836
+ applyDefaultFormat(block, format, applyDefaultFormatOption, preserveParagraphDecorator);
27749
27837
  break;
27750
27838
  case 'Table':
27751
27839
  block.rows.forEach(function (row) {
27752
27840
  return row.cells.forEach(function (cell) {
27753
- applyDefaultFormat(cell, format, applyDefaultFormatOption);
27841
+ applyDefaultFormat(cell, format, applyDefaultFormatOption, preserveParagraphDecorator);
27754
27842
  });
27755
27843
  });
27756
27844
  break;
27757
27845
  case 'Paragraph':
27758
27846
  var paragraphFormat_1 = ((_a = block.decorator) === null || _a === void 0 ? void 0 : _a.format) || {};
27759
27847
  var paragraph = (0, mutate_1.mutateBlock)(block);
27848
+ var paragraphTargetFormat_1 = applyDefaultFormatOption === 'keepSourceEmphasisFormat' &&
27849
+ preserveParagraphDecorator
27850
+ ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, format), paragraphFormat_1) : format;
27760
27851
  paragraph.segments.forEach(function (segment) {
27761
27852
  if (segment.segmentType == 'General') {
27762
- applyDefaultFormat(segment, format, applyDefaultFormatOption);
27853
+ applyDefaultFormat(segment, format, applyDefaultFormatOption, preserveParagraphDecorator);
27763
27854
  }
27764
- segment.format = mergeSegmentFormat(applyDefaultFormatOption, format, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, paragraphFormat_1), segment.format));
27855
+ segment.format = mergeSegmentFormat(applyDefaultFormatOption, paragraphTargetFormat_1, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, paragraphFormat_1), segment.format));
27765
27856
  if (segment.link) {
27766
27857
  segment.link.format = mergeLinkFormat(applyDefaultFormatOption, format, segment.link.format);
27767
27858
  }
27768
27859
  });
27769
- if (applyDefaultFormatOption === 'keepSourceEmphasisFormat') {
27860
+ if (applyDefaultFormatOption === 'keepSourceEmphasisFormat' &&
27861
+ !preserveParagraphDecorator) {
27770
27862
  delete paragraph.decorator;
27771
27863
  }
27772
27864
  break;
@@ -27816,7 +27908,7 @@ function mergeSegmentFormat(applyDefaultFormatOption, targetFormat, sourceFormat
27816
27908
  }
27817
27909
  function getSemanticFormat(segmentFormat) {
27818
27910
  var result = {};
27819
- var fontWeight = segmentFormat.fontWeight, italic = segmentFormat.italic, underline = segmentFormat.underline;
27911
+ var fontWeight = segmentFormat.fontWeight, italic = segmentFormat.italic, underline = segmentFormat.underline, strikethrough = segmentFormat.strikethrough;
27820
27912
  if (fontWeight && fontWeight != 'normal') {
27821
27913
  result.fontWeight = fontWeight;
27822
27914
  }
@@ -27826,6 +27918,9 @@ function getSemanticFormat(segmentFormat) {
27826
27918
  if (underline) {
27827
27919
  result.underline = underline;
27828
27920
  }
27921
+ if (strikethrough) {
27922
+ result.strikethrough = strikethrough;
27923
+ }
27829
27924
  return result;
27830
27925
  }
27831
27926
  /**
@@ -31817,11 +31912,27 @@ exports.createTableFromMarkdown = void 0;
31817
31912
  var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
31818
31913
  var createParagraphFromMarkdown_1 = __webpack_require__(/*! ./createParagraphFromMarkdown */ "./packages/roosterjs-content-model-markdown/lib/markdownToModel/creators/createParagraphFromMarkdown.ts");
31819
31914
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
31915
+ var DefaultMarkdownTable = {
31916
+ headerRowColor: null,
31917
+ topBorderColor: '#000',
31918
+ bottomBorderColor: '#000',
31919
+ verticalBorderColor: '#000',
31920
+ tableBorderFormat: roosterjs_content_model_dom_1.TableBorderFormat.Default,
31921
+ headerRowCustomStyles: {
31922
+ fontWeight: 'normal',
31923
+ italic: false,
31924
+ },
31925
+ firstColumnCustomStyles: {
31926
+ fontWeight: 'normal',
31927
+ italic: false,
31928
+ },
31929
+ };
31820
31930
  /**
31821
31931
  * @internal
31822
31932
  */
31823
31933
  function createTableFromMarkdown(tableLines, options) {
31824
31934
  var e_1, _a;
31935
+ var _b;
31825
31936
  var tableDivider = tableLines[1].split('|').filter(function (content) { return content.trim() !== ''; });
31826
31937
  tableLines.splice(1, 1);
31827
31938
  var table = (0, roosterjs_content_model_dom_1.createTable)(0, options.direction
@@ -31840,9 +31951,7 @@ function createTableFromMarkdown(tableLines, options) {
31840
31951
  }
31841
31952
  finally { if (e_1) throw e_1.error; }
31842
31953
  }
31843
- (0, roosterjs_content_model_dom_1.applyTableFormat)(table, {
31844
- hasHeaderRow: true,
31845
- });
31954
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, (_b = options.tableStyles) !== null && _b !== void 0 ? _b : DefaultMarkdownTable);
31846
31955
  return table;
31847
31956
  }
31848
31957
  exports.createTableFromMarkdown = createTableFromMarkdown;
@@ -32822,12 +32931,16 @@ exports.modelProcessor = modelProcessor;
32822
32931
 
32823
32932
  Object.defineProperty(exports, "__esModule", ({ value: true }));
32824
32933
  exports.MarkdownPastePlugin = void 0;
32934
+ var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
32825
32935
  var convertMarkdownToContentModel_1 = __webpack_require__(/*! ../markdownToModel/convertMarkdownToContentModel */ "./packages/roosterjs-content-model-markdown/lib/markdownToModel/convertMarkdownToContentModel.ts");
32826
32936
  var isPastedContentMarkdown_1 = __webpack_require__(/*! ../publicApi/isPastedContentMarkdown */ "./packages/roosterjs-content-model-markdown/lib/publicApi/isPastedContentMarkdown.ts");
32827
32937
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
32828
32938
  var DefaultOptions = {
32829
32939
  autoConversion: false,
32830
32940
  undoConversion: false,
32941
+ markdownToModelOptions: {
32942
+ emptyLine: 'merge',
32943
+ },
32831
32944
  };
32832
32945
  /**
32833
32946
  * Markdown paste plugin. Handles the BeforePaste event and, when the pasted content
@@ -32840,8 +32953,9 @@ var MarkdownPastePlugin = /** @class */ (function () {
32840
32953
  * @param options Options to control the markdown paste behavior
32841
32954
  */
32842
32955
  function MarkdownPastePlugin(options) {
32956
+ var _a, _b;
32843
32957
  this.editor = null;
32844
- this.options = options !== null && options !== void 0 ? options : DefaultOptions;
32958
+ this.options = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultOptions), options), { markdownToModelOptions: (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultOptions.markdownToModelOptions), options === null || options === void 0 ? void 0 : options.markdownToModelOptions), { emptyLine: (_b = (_a = options === null || options === void 0 ? void 0 : options.markdownToModelOptions) === null || _a === void 0 ? void 0 : _a.emptyLine) !== null && _b !== void 0 ? _b : 'merge' }) });
32845
32959
  }
32846
32960
  /**
32847
32961
  * Get name of this plugin
@@ -32886,10 +33000,9 @@ var MarkdownPastePlugin = /** @class */ (function () {
32886
33000
  (0, isPastedContentMarkdown_1.isPastedContentMarkdown)(this.editor, clipboardData) &&
32887
33001
  clipboardData.modelBeforePaste) {
32888
33002
  var modelBeforePaste_1 = (0, roosterjs_content_model_dom_1.cloneModelForPaste)(clipboardData.modelBeforePaste);
32889
- (0, roosterjs_content_model_dom_1.mergeModel)(modelBeforePaste_1, (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(clipboardData.text, {
32890
- emptyLine: 'merge',
32891
- }), undefined /*context*/, {
32892
- mergeFormat: 'preferTarget',
33003
+ (0, roosterjs_content_model_dom_1.mergeModel)(modelBeforePaste_1, (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(clipboardData.text, this.options.markdownToModelOptions), undefined /*context*/, {
33004
+ mergeFormat: 'keepSourceEmphasisFormat',
33005
+ preserveParagraphDecorator: true,
32893
33006
  });
32894
33007
  if (this.options.undoConversion) {
32895
33008
  this.editor.takeSnapshot();
@@ -32907,17 +33020,15 @@ var MarkdownPastePlugin = /** @class */ (function () {
32907
33020
  else if (event.eventType === 'beforePaste' && !event.clipboardData.pasteNativeEvent) {
32908
33021
  var shouldConvert = event.pasteType === 'asMarkdown';
32909
33022
  if (shouldConvert && (0, isPastedContentMarkdown_1.isPastedContentMarkdown)(this.editor, event.clipboardData)) {
32910
- convertPastedTextToMarkdown(this.editor, event.fragment, event.clipboardData.text);
33023
+ convertPastedTextToMarkdown(this.editor, event.fragment, event.clipboardData.text, this.options.markdownToModelOptions);
32911
33024
  }
32912
33025
  }
32913
33026
  };
32914
33027
  return MarkdownPastePlugin;
32915
33028
  }());
32916
33029
  exports.MarkdownPastePlugin = MarkdownPastePlugin;
32917
- function convertPastedTextToMarkdown(editor, fragment, text) {
32918
- var model = (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(text, {
32919
- emptyLine: 'merge',
32920
- });
33030
+ function convertPastedTextToMarkdown(editor, fragment, text, markdownToModelOptions) {
33031
+ var model = (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(text, markdownToModelOptions);
32921
33032
  while (fragment.firstChild) {
32922
33033
  fragment.removeChild(fragment.firstChild);
32923
33034
  }
@@ -36408,6 +36519,9 @@ function handleTabOnParagraph(model, paragraph, rawEvent, context) {
36408
36519
  return false;
36409
36520
  }
36410
36521
  }
36522
+ else {
36523
+ return false;
36524
+ }
36411
36525
  }
36412
36526
  }
36413
36527
  }
@@ -37567,6 +37681,211 @@ var HyperlinkPlugin = /** @class */ (function () {
37567
37681
  exports.HyperlinkPlugin = HyperlinkPlugin;
37568
37682
 
37569
37683
 
37684
+ /***/ },
37685
+
37686
+ /***/ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/ImageCropKeyboardHelper.ts"
37687
+ /*!***************************************************************************************************!*\
37688
+ !*** ./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/ImageCropKeyboardHelper.ts ***!
37689
+ \***************************************************************************************************/
37690
+ (__unused_webpack_module, exports, __webpack_require__) {
37691
+
37692
+ "use strict";
37693
+
37694
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
37695
+ exports.ImageCropKeyboardHelper = void 0;
37696
+ var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
37697
+ var cropperContext_1 = __webpack_require__(/*! ./cropperContext */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/cropperContext.ts");
37698
+ var ImageEditElementClass_1 = __webpack_require__(/*! ../types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
37699
+ var DefaultTopLeftLabel = 'Top left';
37700
+ var DefaultBottomRightLabel = 'Bottom right';
37701
+ var DefaultMoveCropLabel = 'Move Crop';
37702
+ var FocusTargetAttributes = [
37703
+ 'tabindex',
37704
+ 'contenteditable',
37705
+ 'role',
37706
+ 'aria-label',
37707
+ 'aria-describedby',
37708
+ 'part',
37709
+ ];
37710
+ /**
37711
+ * @internal
37712
+ * Keyboard cropping shares the pointer handler's geometry and constraints.
37713
+ */
37714
+ var ImageCropKeyboardHelper = /** @class */ (function () {
37715
+ function ImageCropKeyboardHelper(wrapper, imageId, editInfo, options, onCrop, onFinish) {
37716
+ var _this = this;
37717
+ this.wrapper = wrapper;
37718
+ this.editInfo = editInfo;
37719
+ this.options = options;
37720
+ this.onCrop = onCrop;
37721
+ this.onFinish = onFinish;
37722
+ this.cropFocusTargets = [];
37723
+ this.disposed = false;
37724
+ this.stopPropagation = function (event) {
37725
+ if (_this.contains(event.target)) {
37726
+ event.stopPropagation();
37727
+ }
37728
+ };
37729
+ this.onFocusOut = function (event) {
37730
+ if (!_this.disposed && _this.contains(event.target) && !_this.contains(event.relatedTarget)) {
37731
+ _this.onFinish(true, false);
37732
+ }
37733
+ };
37734
+ this.onKeyDown = function (event) {
37735
+ if (!_this.contains(event.target)) {
37736
+ return;
37737
+ }
37738
+ event.stopPropagation();
37739
+ if (event.key == 'Tab') {
37740
+ var index = _this.cropFocusTargets.findIndex(function (target) { return target === event.target; });
37741
+ var next = _this.cropFocusTargets[index + (event.shiftKey ? -1 : 1)];
37742
+ if (next) {
37743
+ event.preventDefault();
37744
+ next.focus();
37745
+ }
37746
+ }
37747
+ else if (event.key == 'Enter' || event.key == 'Escape') {
37748
+ event.preventDefault();
37749
+ _this.onFinish(event.key == 'Enter', true);
37750
+ }
37751
+ else if (event.key == 'ArrowLeft' ||
37752
+ event.key == 'ArrowRight' ||
37753
+ event.key == 'ArrowUp' ||
37754
+ event.key == 'ArrowDown') {
37755
+ event.preventDefault();
37756
+ if (!event.ctrlKey && !event.metaKey && !event.altKey) {
37757
+ _this.crop(event);
37758
+ }
37759
+ }
37760
+ else if (event.key == ' ' || event.key == 'Delete' || event.key == 'Backspace') {
37761
+ event.preventDefault();
37762
+ }
37763
+ };
37764
+ var cropLabels = options.cropLabels;
37765
+ if (cropLabels === null || cropLabels === void 0 ? void 0 : cropLabels.instructions) {
37766
+ this.instructions = this.createInstructions(imageId, cropLabels.instructions);
37767
+ wrapper.appendChild(this.instructions);
37768
+ }
37769
+ ['nw', 'se'].forEach(function (direction) {
37770
+ var _a;
37771
+ var handle = wrapper.querySelector("." + ImageEditElementClass_1.ImageEditElementClass.CropHandle + "[data-y=\"" + direction[0] + "\"][data-x=\"" + direction[1] + "\"]");
37772
+ if (handle) {
37773
+ _this.prepareTarget(handle, ((_a = cropLabels === null || cropLabels === void 0 ? void 0 : cropLabels.handleLabel) === null || _a === void 0 ? void 0 : _a.call(cropLabels, direction)) ||
37774
+ (direction == 'nw' ? DefaultTopLeftLabel : DefaultBottomRightLabel));
37775
+ }
37776
+ });
37777
+ this.cropMoveTarget = wrapper.querySelector("." + ImageEditElementClass_1.ImageEditElementClass.ImageBorder);
37778
+ if (this.cropMoveTarget) {
37779
+ wrapper.appendChild(this.cropMoveTarget);
37780
+ this.prepareTarget(this.cropMoveTarget, (cropLabels === null || cropLabels === void 0 ? void 0 : cropLabels.moveCropLabel) || DefaultMoveCropLabel);
37781
+ }
37782
+ // Make native tab entry start at the top-left corner as well.
37783
+ var first = this.cropFocusTargets[0];
37784
+ if (first === null || first === void 0 ? void 0 : first.parentElement) {
37785
+ first.parentElement.insertBefore(first, first.parentElement.firstChild);
37786
+ }
37787
+ wrapper.addEventListener('keydown', this.onKeyDown);
37788
+ wrapper.addEventListener('keyup', this.stopPropagation);
37789
+ wrapper.addEventListener('keypress', this.stopPropagation);
37790
+ wrapper.addEventListener('focusout', this.onFocusOut);
37791
+ }
37792
+ ImageCropKeyboardHelper.prototype.focus = function () {
37793
+ var _a;
37794
+ (_a = this.cropFocusTargets[0]) === null || _a === void 0 ? void 0 : _a.focus();
37795
+ };
37796
+ ImageCropKeyboardHelper.prototype.contains = function (target) {
37797
+ return this.cropFocusTargets.some(function (element) { return element === target; });
37798
+ };
37799
+ ImageCropKeyboardHelper.prototype.dispose = function () {
37800
+ var e_1, _a, e_2, _b;
37801
+ var _c;
37802
+ this.disposed = true;
37803
+ this.wrapper.removeEventListener('keydown', this.onKeyDown);
37804
+ this.wrapper.removeEventListener('keyup', this.stopPropagation);
37805
+ this.wrapper.removeEventListener('keypress', this.stopPropagation);
37806
+ this.wrapper.removeEventListener('focusout', this.onFocusOut);
37807
+ try {
37808
+ for (var _d = (0, tslib_1.__values)(this.cropFocusTargets), _e = _d.next(); !_e.done; _e = _d.next()) {
37809
+ var target = _e.value;
37810
+ try {
37811
+ for (var FocusTargetAttributes_1 = (e_2 = void 0, (0, tslib_1.__values)(FocusTargetAttributes)), FocusTargetAttributes_1_1 = FocusTargetAttributes_1.next(); !FocusTargetAttributes_1_1.done; FocusTargetAttributes_1_1 = FocusTargetAttributes_1.next()) {
37812
+ var attribute = FocusTargetAttributes_1_1.value;
37813
+ target.removeAttribute(attribute);
37814
+ }
37815
+ }
37816
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
37817
+ finally {
37818
+ try {
37819
+ if (FocusTargetAttributes_1_1 && !FocusTargetAttributes_1_1.done && (_b = FocusTargetAttributes_1.return)) _b.call(FocusTargetAttributes_1);
37820
+ }
37821
+ finally { if (e_2) throw e_2.error; }
37822
+ }
37823
+ target.classList.remove(ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget);
37824
+ }
37825
+ }
37826
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
37827
+ finally {
37828
+ try {
37829
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
37830
+ }
37831
+ finally { if (e_1) throw e_1.error; }
37832
+ }
37833
+ (_c = this.instructions) === null || _c === void 0 ? void 0 : _c.remove();
37834
+ };
37835
+ ImageCropKeyboardHelper.prototype.createInstructions = function (imageId, text) {
37836
+ var instructions = this.wrapper.ownerDocument.createElement('span');
37837
+ instructions.id = 'imageCropInstructions' + imageId;
37838
+ instructions.textContent = text;
37839
+ instructions.style.cssText =
37840
+ 'position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;';
37841
+ return instructions;
37842
+ };
37843
+ ImageCropKeyboardHelper.prototype.prepareTarget = function (target, label) {
37844
+ target.tabIndex = 0;
37845
+ target.contentEditable = 'false';
37846
+ target.setAttribute('role', 'application');
37847
+ if (label) {
37848
+ target.setAttribute('aria-label', label);
37849
+ }
37850
+ if (this.instructions) {
37851
+ target.setAttribute('aria-describedby', this.instructions.id);
37852
+ }
37853
+ target.classList.add(ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget);
37854
+ target.setAttribute('part', ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget);
37855
+ this.cropFocusTargets.push(target);
37856
+ };
37857
+ ImageCropKeyboardHelper.prototype.crop = function (event) {
37858
+ var _a, _b;
37859
+ var target = this.cropFocusTargets.find(function (element) { return element === event.target; });
37860
+ var context = {
37861
+ editInfo: this.editInfo,
37862
+ options: this.options,
37863
+ elementClass: target === this.cropMoveTarget
37864
+ ? ImageEditElementClass_1.ImageEditElementClass.CropContainer
37865
+ : ImageEditElementClass_1.ImageEditElementClass.CropHandle,
37866
+ x: (target === null || target === void 0 ? void 0 : target.dataset.x) == 'e' ? 'e' : (target === null || target === void 0 ? void 0 : target.dataset.x) == 'w' ? 'w' : '',
37867
+ y: (target === null || target === void 0 ? void 0 : target.dataset.y) == 'n' ? 'n' : (target === null || target === void 0 ? void 0 : target.dataset.y) == 's' ? 's' : '',
37868
+ };
37869
+ var dragEvent = {
37870
+ clientX: 0,
37871
+ clientY: 0,
37872
+ pageX: 0,
37873
+ pageY: 0,
37874
+ target: event.target,
37875
+ shiftKey: event.shiftKey,
37876
+ altKey: event.altKey,
37877
+ };
37878
+ var base = (_a = cropperContext_1.Cropper.onDragStart) === null || _a === void 0 ? void 0 : _a.call(cropperContext_1.Cropper, context, dragEvent);
37879
+ if (base &&
37880
+ ((_b = cropperContext_1.Cropper.onDragging) === null || _b === void 0 ? void 0 : _b.call(cropperContext_1.Cropper, context, dragEvent, base, event.key == 'ArrowLeft' ? -1 : event.key == 'ArrowRight' ? 1 : 0, event.key == 'ArrowUp' ? -1 : event.key == 'ArrowDown' ? 1 : 0))) {
37881
+ this.onCrop();
37882
+ }
37883
+ };
37884
+ return ImageCropKeyboardHelper;
37885
+ }());
37886
+ exports.ImageCropKeyboardHelper = ImageCropKeyboardHelper;
37887
+
37888
+
37570
37889
  /***/ },
37571
37890
 
37572
37891
  /***/ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/createImageCropper.ts"
@@ -37671,6 +37990,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
37671
37990
  exports.Cropper = void 0;
37672
37991
  var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
37673
37992
  var imageEditUtils_1 = __webpack_require__(/*! ../utils/imageEditUtils */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/imageEditUtils.ts");
37993
+ var ImageEditElementClass_1 = __webpack_require__(/*! ../types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
37674
37994
  /**
37675
37995
  * @internal
37676
37996
  * Crop handle for DragAndDropHelper
@@ -37683,7 +38003,7 @@ exports.Cropper = {
37683
38003
  onDragging: function (_a, e, base, dx, dy) {
37684
38004
  var _b;
37685
38005
  var _c;
37686
- var editInfo = _a.editInfo, x = _a.x, y = _a.y, options = _a.options;
38006
+ var editInfo = _a.editInfo, x = _a.x, y = _a.y, options = _a.options, elementClass = _a.elementClass;
37687
38007
  _b = (0, tslib_1.__read)((0, imageEditUtils_1.rotateCoordinate)(dx, dy, (_c = editInfo.angleRad) !== null && _c !== void 0 ? _c : 0), 2), dx = _b[0], dy = _b[1];
37688
38008
  var widthPx = editInfo.widthPx, heightPx = editInfo.heightPx, leftPercent = editInfo.leftPercent, rightPercent = editInfo.rightPercent, topPercent = editInfo.topPercent, bottomPercent = editInfo.bottomPercent;
37689
38009
  if (leftPercent === undefined ||
@@ -37707,6 +38027,15 @@ exports.Cropper = {
37707
38027
  minHeight !== undefined) {
37708
38028
  var fullWidth = widthPx / widthPercent;
37709
38029
  var fullHeight = heightPx / heightPercent;
38030
+ if (elementClass == ImageEditElementClass_1.ImageEditElementClass.CropContainer) {
38031
+ var deltaX = Math.max(-base.leftPercent, Math.min(dx / fullWidth, base.rightPercent));
38032
+ var deltaY = Math.max(-base.topPercent, Math.min(dy / fullHeight, base.bottomPercent));
38033
+ editInfo.leftPercent = base.leftPercent + deltaX;
38034
+ editInfo.rightPercent = base.rightPercent - deltaX;
38035
+ editInfo.topPercent = base.topPercent + deltaY;
38036
+ editInfo.bottomPercent = base.bottomPercent - deltaY;
38037
+ return true;
38038
+ }
37710
38039
  var newLeft = x != 'e'
37711
38040
  ? crop(base.leftPercent, dx, fullWidth, rightPercent, minWidth)
37712
38041
  : leftPercent;
@@ -37765,6 +38094,7 @@ var getHTMLImageOptions_1 = __webpack_require__(/*! ./utils/getHTMLImageOptions
37765
38094
  var getSelectedImage_1 = __webpack_require__(/*! ./utils/getSelectedImage */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/getSelectedImage.ts");
37766
38095
  var updateImageEditInfo_1 = __webpack_require__(/*! ./utils/updateImageEditInfo */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/updateImageEditInfo.ts");
37767
38096
  var ImageEditElementClass_1 = __webpack_require__(/*! ./types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
38097
+ var ImageCropKeyboardHelper_1 = __webpack_require__(/*! ./Cropper/ImageCropKeyboardHelper */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/ImageCropKeyboardHelper.ts");
37768
38098
  var normalizeImageSelection_1 = __webpack_require__(/*! ./utils/normalizeImageSelection */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/normalizeImageSelection.ts");
37769
38099
  var resizerContext_1 = __webpack_require__(/*! ./Resizer/resizerContext */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Resizer/resizerContext.ts");
37770
38100
  var rotatorContext_1 = __webpack_require__(/*! ./Rotator/rotatorContext */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Rotator/rotatorContext.ts");
@@ -37785,6 +38115,7 @@ var MouseRightButton = 2;
37785
38115
  var DRAG_ID = '_dragging';
37786
38116
  var IMAGE_EDIT_CLASS = 'imageEdit';
37787
38117
  var IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor';
38118
+ var IMAGE_EDIT_CLASS_CROP_KEYBOARD = 'imageEditCropKeyboard';
37788
38119
  var IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';
37789
38120
  /**
37790
38121
  * ImageEdit plugin handles the following image editing features:
@@ -37792,6 +38123,10 @@ var IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';
37792
38123
  * - Crop image
37793
38124
  * - Rotate image
37794
38125
  * - Flip image
38126
+ *
38127
+ * In crop mode, Tab focuses the top-left corner, bottom-right corner, then the
38128
+ * whole image. Arrow keys crop at corners or move the fixed-size crop viewport
38129
+ * by one pixel. Enter applies the crop; Escape cancels it.
37795
38130
  */
37796
38131
  var ImageEditPlugin = /** @class */ (function () {
37797
38132
  function ImageEditPlugin(options) {
@@ -37811,6 +38146,7 @@ var ImageEditPlugin = /** @class */ (function () {
37811
38146
  this.croppers = [];
37812
38147
  this.zoomScale = 1;
37813
38148
  this.disposer = null;
38149
+ this.cropKeyboardHelper = null;
37814
38150
  this.isEditing = false;
37815
38151
  this.options = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultOptions), options);
37816
38152
  }
@@ -37830,8 +38166,19 @@ var ImageEditPlugin = /** @class */ (function () {
37830
38166
  var _this = this;
37831
38167
  this.editor = editor;
37832
38168
  this.disposer = editor.attachDomEvent({
38169
+ keydown: {
38170
+ capture: true,
38171
+ beforeDispatch: function (ev) {
38172
+ _this.focusCropHandle(ev);
38173
+ },
38174
+ },
37833
38175
  blur: {
37834
- beforeDispatch: function () {
38176
+ beforeDispatch: function (ev) {
38177
+ if (_this.cropKeyboardHelper &&
38178
+ (ev.relatedTarget === _this.shadowSpan ||
38179
+ _this.cropKeyboardHelper.contains(ev.relatedTarget))) {
38180
+ return;
38181
+ }
37835
38182
  if (_this.isEditing && _this.editor && !_this.editor.isDisposed()) {
37836
38183
  _this.applyFormatWithContentModel(_this.editor, _this.isCropMode, true /* shouldSelectImage */);
37837
38184
  }
@@ -37966,6 +38313,11 @@ var ImageEditPlugin = /** @class */ (function () {
37966
38313
  };
37967
38314
  ImageEditPlugin.prototype.keyDownHandler = function (editor, event) {
37968
38315
  if (this.isEditing) {
38316
+ if (this.cropKeyboardHelper &&
38317
+ (this.cropKeyboardHelper.contains(event.rawEvent.composedPath()[0]) ||
38318
+ this.focusCropHandle(event.rawEvent))) {
38319
+ return;
38320
+ }
37969
38321
  if (event.rawEvent.key === 'Escape' ||
37970
38322
  event.rawEvent.key === 'Delete' ||
37971
38323
  event.rawEvent.key === 'Backspace') {
@@ -37982,6 +38334,19 @@ var ImageEditPlugin = /** @class */ (function () {
37982
38334
  }
37983
38335
  }
37984
38336
  };
38337
+ ImageEditPlugin.prototype.focusCropHandle = function (event) {
38338
+ if (this.cropKeyboardHelper &&
38339
+ event.key == 'Tab' &&
38340
+ !event.shiftKey &&
38341
+ !this.cropKeyboardHelper.contains(event.composedPath()[0])) {
38342
+ // Enter crop controls before editing plugins can indent or rerender the image.
38343
+ event.preventDefault();
38344
+ event.stopPropagation();
38345
+ this.cropKeyboardHelper.focus();
38346
+ return true;
38347
+ }
38348
+ return false;
38349
+ };
37985
38350
  ImageEditPlugin.prototype.setContentHandler = function () {
37986
38351
  if (this.selectedImage) {
37987
38352
  this.cleanInfo();
@@ -38222,7 +38587,7 @@ var ImageEditPlugin = /** @class */ (function () {
38222
38587
  if (this.imageEditInfo) {
38223
38588
  this.startEditing(editor, image, ['crop']);
38224
38589
  if (this.imageEditInfo && this.selectedImage && this.wrapper && this.clonedImage) {
38225
- this.dndHelpers = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.CropHandle, cropperContext_1.Cropper, function () {
38590
+ var onCrop = function () {
38226
38591
  if (_this.imageEditInfo &&
38227
38592
  _this.selectedImage &&
38228
38593
  _this.wrapper &&
@@ -38230,11 +38595,46 @@ var ImageEditPlugin = /** @class */ (function () {
38230
38595
  (0, updateWrapper_1.updateWrapper)(_this.imageEditInfo, _this.options, _this.selectedImage, _this.clonedImage, _this.wrapper, undefined /* resizers */, _this.croppers, isRTL);
38231
38596
  _this.isCropMode = true;
38232
38597
  }
38233
- }, this.zoomScale, !!editor.getEnvironment().isMobileOrTablet, !!editor.getEnvironment().isTouchSupported)), false);
38598
+ };
38599
+ this.dndHelpers = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.CropHandle, cropperContext_1.Cropper, onCrop, this.zoomScale, !!editor.getEnvironment().isMobileOrTablet, !!editor.getEnvironment().isTouchSupported)), false);
38234
38600
  (0, updateWrapper_1.updateWrapper)(this.imageEditInfo, this.options, this.selectedImage, this.clonedImage, this.wrapper, undefined /* resizers */, this.croppers, isRTL);
38601
+ this.startCropWithKeyboard(editor, onCrop);
38235
38602
  }
38236
38603
  }
38237
38604
  };
38605
+ ImageEditPlugin.prototype.startCropWithKeyboard = function (editor, onCrop) {
38606
+ var _this = this;
38607
+ var _a;
38608
+ if (this.wrapper && this.selectedImage && this.imageEditInfo) {
38609
+ (_a = this.cropKeyboardHelper) === null || _a === void 0 ? void 0 : _a.dispose();
38610
+ this.cropKeyboardHelper = new ImageCropKeyboardHelper_1.ImageCropKeyboardHelper(this.wrapper, this.selectedImage.id, this.imageEditInfo, this.options, onCrop, function (apply, restoreFocus) { return _this.finishKeyboardCrop(editor, apply, restoreFocus); });
38611
+ editor.setEditorStyle(IMAGE_EDIT_CLASS_CROP_KEYBOARD, 'outline:2px solid Highlight;outline-offset:-2px;', ["span::part(" + ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget + "):focus"]);
38612
+ }
38613
+ };
38614
+ ImageEditPlugin.prototype.finishKeyboardCrop = function (editor, apply, restoreFocus) {
38615
+ var _a;
38616
+ (_a = this.cropKeyboardHelper) === null || _a === void 0 ? void 0 : _a.dispose();
38617
+ this.cropKeyboardHelper = null;
38618
+ editor.setEditorStyle(IMAGE_EDIT_CLASS_CROP_KEYBOARD, null);
38619
+ if (apply) {
38620
+ this.applyFormatWithContentModel(editor, true, true);
38621
+ }
38622
+ else {
38623
+ this.isEditing = false;
38624
+ var image = this.removeImageWrapper();
38625
+ if (image) {
38626
+ (0, roosterjs_content_model_dom_1.setImageState)(image, '');
38627
+ }
38628
+ this.cleanInfo();
38629
+ if (restoreFocus && image) {
38630
+ editor.focus();
38631
+ editor.setDOMSelection({ type: 'image', image: image });
38632
+ }
38633
+ }
38634
+ if (restoreFocus) {
38635
+ editor.focus();
38636
+ }
38637
+ };
38238
38638
  ImageEditPlugin.prototype.cropImage = function () {
38239
38639
  if (!this.editor) {
38240
38640
  return;
@@ -38260,9 +38660,12 @@ var ImageEditPlugin = /** @class */ (function () {
38260
38660
  * Exported for testing purpose only
38261
38661
  */
38262
38662
  ImageEditPlugin.prototype.cleanInfo = function () {
38263
- var _a, _b;
38264
- (_a = this.editor) === null || _a === void 0 ? void 0 : _a.setEditorStyle(IMAGE_EDIT_CLASS, null);
38265
- (_b = this.editor) === null || _b === void 0 ? void 0 : _b.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
38663
+ var _a, _b, _c, _d;
38664
+ (_a = this.cropKeyboardHelper) === null || _a === void 0 ? void 0 : _a.dispose();
38665
+ this.cropKeyboardHelper = null;
38666
+ (_b = this.editor) === null || _b === void 0 ? void 0 : _b.setEditorStyle(IMAGE_EDIT_CLASS, null);
38667
+ (_c = this.editor) === null || _c === void 0 ? void 0 : _c.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
38668
+ (_d = this.editor) === null || _d === void 0 ? void 0 : _d.setEditorStyle(IMAGE_EDIT_CLASS_CROP_KEYBOARD, null);
38266
38669
  this.selectedImage = null;
38267
38670
  this.shadowSpan = null;
38268
38671
  this.wrapper = null;
@@ -38849,6 +39252,14 @@ exports.ImageEditElementClass = void 0;
38849
39252
  */
38850
39253
  var ImageEditElementClass;
38851
39254
  (function (ImageEditElementClass) {
39255
+ /**
39256
+ * CSS class name for the image border
39257
+ */
39258
+ ImageEditElementClass["ImageBorder"] = "r_imageB";
39259
+ /**
39260
+ * CSS class and part name for keyboard crop focus targets
39261
+ */
39262
+ ImageEditElementClass["CropKeyboardTarget"] = "r_cropK";
38852
39263
  /**
38853
39264
  * CSS class name for resize handle
38854
39265
  */
@@ -39088,6 +39499,7 @@ exports.createImageWrapper = void 0;
39088
39499
  var createImageCropper_1 = __webpack_require__(/*! ../Cropper/createImageCropper */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/createImageCropper.ts");
39089
39500
  var createImageResizer_1 = __webpack_require__(/*! ../Resizer/createImageResizer */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Resizer/createImageResizer.ts");
39090
39501
  var createImageRotator_1 = __webpack_require__(/*! ../Rotator/createImageRotator */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Rotator/createImageRotator.ts");
39502
+ var ImageEditElementClass_1 = __webpack_require__(/*! ../types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
39091
39503
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
39092
39504
  /**
39093
39505
  * @internal
@@ -39164,6 +39576,7 @@ var createWrapper = function (editor, image, options, editInfo, resizers, rotato
39164
39576
  var createBorder = function (editor, borderColor) {
39165
39577
  var doc = editor.getDocument();
39166
39578
  var resizeBorder = doc.createElement('div');
39579
+ resizeBorder.className = ImageEditElementClass_1.ImageEditElementClass.ImageBorder;
39167
39580
  resizeBorder.setAttribute("style", "position:absolute;left:0;right:0;top:0;bottom:0;border:solid 2px " + borderColor + ";pointer-events:none;");
39168
39581
  return resizeBorder;
39169
39582
  };
@@ -40861,12 +41274,16 @@ var wacSubSuperParser = function (format, element) {
40861
41274
  if (verticalAlign === 'sub') {
40862
41275
  format.superOrSubScriptSequence = 'sub';
40863
41276
  }
41277
+ if ((verticalAlign === 'super' || verticalAlign === 'sub') &&
41278
+ element.style.fontSize !== 'smaller') {
41279
+ format.superOrSubScriptFontSize = 'inherit';
41280
+ }
40864
41281
  };
40865
41282
  /**
40866
41283
  * This processor does:
40867
41284
  * 1) Remove the display and margin of the element.
40868
41285
  * 2) When an element should be ignored but should handle the child elements call the default child processor.
40869
- * 3) Removes the End of Paragraph element to avoid empty lines, we should only remove this if the previous element of the EOP is an EmptyTextRun
41286
+ * 3) Removes selected End of Paragraph markers unless they are the paragraph's only content.
40870
41287
  * 4) Finally call the default processor.
40871
41288
  * @returns
40872
41289
  */
@@ -40880,12 +41297,19 @@ var wacElementProcessor = function (group, element, context) {
40880
41297
  context.elementProcessors.child(group, element, context);
40881
41298
  return;
40882
41299
  }
40883
- if (constants_1.TEMP_ELEMENTS_CLASSES.some(function (className) { return element.classList.contains(className); }) ||
40884
- // This is needed to remove some temporary End of paragraph elements that WAC sometimes preserves
40885
- (element.classList.contains(SELECTED_CLASS) && element.classList.contains(END_OF_PARAGRAPH))) {
41300
+ if (constants_1.TEMP_ELEMENTS_CLASSES.some(function (className) { return element.classList.contains(className); })) {
40886
41301
  return;
40887
41302
  }
40888
- else if (shouldClearListContext(elementTag, element, context)) {
41303
+ if (element.classList.contains(SELECTED_CLASS) &&
41304
+ element.classList.contains(END_OF_PARAGRAPH)) {
41305
+ var lastBlock = group.blocks[group.blocks.length - 1];
41306
+ if ((lastBlock === null || lastBlock === void 0 ? void 0 : lastBlock.blockType) != 'Paragraph' || lastBlock.segments.length > 0) {
41307
+ return;
41308
+ }
41309
+ element.style.removeProperty('background-color');
41310
+ element.style.removeProperty('border-color');
41311
+ }
41312
+ if (shouldClearListContext(elementTag, element, context)) {
40889
41313
  var listFormat = context.listFormat;
40890
41314
  listFormat.levels = [];
40891
41315
  listFormat.listParent = undefined;
@@ -40923,6 +41347,7 @@ var wacLiElementProcessor = function (group, element, context) {
40923
41347
  if (lastblock.blockType == 'BlockGroup' && lastblock.blockGroupType == 'ListItem') {
40924
41348
  var currentLevel = lastblock.levels[lastblock.levels.length - 1];
40925
41349
  updateStartOverride(currentLevel, element, context);
41350
+ updateHeading(lastblock, element, context);
40926
41351
  }
40927
41352
  }
40928
41353
  var newLevels = [];
@@ -40954,6 +41379,19 @@ var wacListLevelParser = function (format) {
40954
41379
  format.marginLeft = undefined;
40955
41380
  format.paddingLeft = BASE_PADDING_WAC_LISTS;
40956
41381
  };
41382
+ var wacTableCellPaddingParser = function (format, element) {
41383
+ var keys = [
41384
+ 'paddingTop',
41385
+ 'paddingRight',
41386
+ 'paddingBottom',
41387
+ 'paddingLeft',
41388
+ ];
41389
+ keys.forEach(function (key) {
41390
+ if (element.style[key]) {
41391
+ format[key] = element.style[key];
41392
+ }
41393
+ });
41394
+ };
40957
41395
  /**
40958
41396
  * This function returns whether we need to clear the list format.
40959
41397
  * Word Online wraps lists inside divs to have this structure:
@@ -40997,6 +41435,7 @@ function processPastedContentWacComponents(ev) {
40997
41435
  (0, addParser_1.addParser)(ev.domToModelOption, 'listLevel', wacListLevelParser);
40998
41436
  (0, addParser_1.addParser)(ev.domToModelOption, 'container', wacContainerParser);
40999
41437
  (0, addParser_1.addParser)(ev.domToModelOption, 'table', wacContainerParser);
41438
+ (0, addParser_1.addParser)(ev.domToModelOption, 'tableCell', wacTableCellPaddingParser);
41000
41439
  (0, addParser_1.addParser)(ev.domToModelOption, 'segment', wacCommentParser);
41001
41440
  (0, setProcessor_1.setProcessor)(ev.domToModelOption, 'element', wacElementProcessor);
41002
41441
  (0, setProcessor_1.setProcessor)(ev.domToModelOption, 'li', wacLiElementProcessor);
@@ -41007,6 +41446,58 @@ var wacContainerParser = function (format, element) {
41007
41446
  delete format.marginLeft;
41008
41447
  }
41009
41448
  };
41449
+ function updateHeading(listItem, element, context) {
41450
+ var _a;
41451
+ var paragraph = element.querySelector('p');
41452
+ var styleName = (_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.querySelector('[data-ccp-parastyle]')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-ccp-parastyle');
41453
+ var list = element.closest('ol');
41454
+ if (!paragraph || !list || !/^heading [1-6]$/i.test(styleName || '')) {
41455
+ return;
41456
+ }
41457
+ var headingParagraph = listItem.blocks.find(function (block) { var _a; return block.blockType == 'Paragraph' && ((_a = block.decorator) === null || _a === void 0 ? void 0 : _a.tagName) == 'p'; });
41458
+ if ((headingParagraph === null || headingParagraph === void 0 ? void 0 : headingParagraph.blockType) == 'Paragraph') {
41459
+ // An inside marker and a block paragraph would occupy separate lines.
41460
+ Object.assign(listItem.format, headingParagraph.format);
41461
+ headingParagraph.isImplicit = true;
41462
+ headingParagraph.format = {};
41463
+ delete headingParagraph.decorator;
41464
+ }
41465
+ listItem.levels.forEach(function (level) {
41466
+ level.format.paddingLeft = '0px';
41467
+ level.format.paddingRight = '0px';
41468
+ level.format.marginTop = '0px';
41469
+ level.format.marginBottom = '0px';
41470
+ });
41471
+ listItem.format.marginLeft = '0px';
41472
+ listItem.format.marginRight = '0px';
41473
+ listItem.format.listStylePosition = 'inside';
41474
+ (0, roosterjs_content_model_dom_1.parseFormat)(paragraph, context.formatParsers.segmentOnBlock, listItem.formatHolder.format, context);
41475
+ var listId = element.getAttribute('data-listid');
41476
+ var template = element.getAttribute('data-leveltext');
41477
+ var _b = (0, tslib_1.__read)(extractWordListMetadata(list, element), 2), start = _b[0], level = _b[1];
41478
+ if (!listId ||
41479
+ !template ||
41480
+ !/^%[1-9](?:\.%[1-9])*[.)]?$/.test(template) ||
41481
+ !(level > 0 && level <= 9) ||
41482
+ !Number.isFinite(start)) {
41483
+ return;
41484
+ }
41485
+ var listFormat = context.listFormat;
41486
+ var headings = (listFormat.headingNumbers = listFormat.headingNumbers || new Map());
41487
+ var numbers = headings.get(listId) || [];
41488
+ numbers[level - 1] = start;
41489
+ numbers.length = level;
41490
+ headings.set(listId, numbers);
41491
+ var complete = true;
41492
+ var label = template.replace(/%([1-9])/g, function (_match, index) {
41493
+ var number = numbers[parseInt(index) - 1];
41494
+ complete = complete && number !== undefined;
41495
+ return number === undefined ? '' : number.toString();
41496
+ });
41497
+ if (complete) {
41498
+ listItem.format.listStyleType = '"' + label + ' "';
41499
+ }
41500
+ }
41010
41501
  function updateStartOverride(currentLevel, element, ctx) {
41011
41502
  if (!currentLevel || currentLevel.listType == 'UL') {
41012
41503
  return;
@@ -41177,6 +41668,7 @@ var setProcessor_1 = __webpack_require__(/*! ../utils/setProcessor */ "./package
41177
41668
  var wordContainerParser_1 = __webpack_require__(/*! ../parsers/wordContainerParser */ "./packages/roosterjs-content-model-plugins/lib/paste/parsers/wordContainerParser.ts");
41178
41669
  var wordTableParser_1 = __webpack_require__(/*! ../parsers/wordTableParser */ "./packages/roosterjs-content-model-plugins/lib/paste/parsers/wordTableParser.ts");
41179
41670
  var removeListParagraphMargins_1 = __webpack_require__(/*! ./removeListParagraphMargins */ "./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/removeListParagraphMargins.ts");
41671
+ var wordBorderParser_1 = __webpack_require__(/*! ./wordBorderParser */ "./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/wordBorderParser.ts");
41180
41672
  /**
41181
41673
  * @internal
41182
41674
  * Handles pasted content when the source is Word Desktop.
@@ -41196,6 +41688,7 @@ function processPastedContentFromWordDesktop(domToModelOption, htmlString, globa
41196
41688
  (0, addParser_1.addParser)(domToModelOption, 'listLevel', listLevelParser_1.listLevelParser);
41197
41689
  (0, addParser_1.addParser)(domToModelOption, 'container', wordContainerParser_1.wordContainerParser);
41198
41690
  (0, addParser_1.addParser)(domToModelOption, 'table', wordTableParser_1.wordTableParser);
41691
+ (0, addParser_1.addParser)(domToModelOption, 'tableBorder', wordBorderParser_1.wordBorderParser);
41199
41692
  }
41200
41693
  exports.processPastedContentFromWordDesktop = processPastedContentFromWordDesktop;
41201
41694
  var wordDesktopElementProcessor = function (metadataKey) {
@@ -41294,30 +41787,66 @@ function processWordList(styles, group, element, context, metadata) {
41294
41787
  (listFormat.wordList && listFormat.wordKnownLevels.get(listFormat.wordList)) || [];
41295
41788
  }
41296
41789
  if (wordListStyle && group && typeof listFormat.wordLevel === 'number') {
41297
- var wordLevel = listFormat.wordLevel, wordList = listFormat.wordList;
41790
+ var wordLevel_1 = listFormat.wordLevel, wordList = listFormat.wordList;
41791
+ var isHeading_1 = /^H[1-6]$/.test(element.tagName);
41298
41792
  // Retrieve the Fake bullet on the element and also the list type
41299
41793
  var listMetadata_1 = metadata.get(lNumber + ":" + level);
41300
41794
  var listType_1 = ((_a = listMetadata_1 === null || listMetadata_1 === void 0 ? void 0 : listMetadata_1['mso-level-number-format']) === null || _a === void 0 ? void 0 : _a.toLowerCase()) != BULLET_METADATA
41301
41795
  ? 'OL'
41302
41796
  : 'UL';
41303
41797
  // Create the new level of the list item and parse the format
41304
- (0, customListUtils_1.setupListFormat)(listType_1, element, context, wordLevel, listFormat, group, [
41798
+ (0, customListUtils_1.setupListFormat)(listType_1, element, context, wordLevel_1, listFormat, group, [
41305
41799
  wordListPaddingParser,
41306
41800
  ]);
41307
- listFormat.levels[listFormat.levels.length - 1]
41308
- .format.wordList = wordList;
41309
- var bullet = getBulletFromMetadata(listMetadata_1, listType_1);
41310
- var listFormatMetadata = bullet
41801
+ var currentLevelFormat = listFormat.levels[listFormat.levels.length - 1]
41802
+ .format;
41803
+ currentLevelFormat.wordList = wordList;
41804
+ if (isHeading_1) {
41805
+ // Keep Word's heading spacing on the item, not on synthesized list wrappers.
41806
+ currentLevelFormat.paddingLeft = '0px';
41807
+ currentLevelFormat.paddingRight = '0px';
41808
+ currentLevelFormat.marginTop = '0px';
41809
+ currentLevelFormat.marginBottom = '0px';
41810
+ }
41811
+ else if (wordLevel_1 > 1) {
41812
+ delete currentLevelFormat.paddingLeft;
41813
+ delete currentLevelFormat.paddingRight;
41814
+ }
41815
+ var bullet_1 = getBulletFromMetadata(listMetadata_1, listType_1);
41816
+ var bulletElement_1 = getBulletElement(element);
41817
+ var listFormatMetadata = bullet_1
41311
41818
  ? {
41312
- unorderedStyleType: listType_1 == 'UL' ? bullet : undefined,
41313
- orderedStyleType: listType_1 == 'OL' ? bullet : undefined,
41819
+ unorderedStyleType: listType_1 == 'UL' ? bullet_1 : undefined,
41820
+ orderedStyleType: listType_1 == 'OL' ? bullet_1 : undefined,
41314
41821
  }
41315
41822
  : undefined;
41316
- (0, customListUtils_1.processAsListItem)(context, element, group, listFormatMetadata, getBulletElement(element), function (listItem) {
41317
- if (listType_1 == 'OL') {
41318
- setStartNumber(listItem, context, listMetadata_1, element);
41319
- }
41320
- });
41823
+ var originalSegmentFormat = context.segmentFormat;
41824
+ try {
41825
+ context.segmentFormat = (0, tslib_1.__assign)({}, originalSegmentFormat);
41826
+ (0, customListUtils_1.processAsListItem)(context, element, group, listFormatMetadata, bulletElement_1, function (listItem) {
41827
+ var _a;
41828
+ if (isHeading_1 && listType_1 == 'OL') {
41829
+ listItem.format.marginLeft = '0px';
41830
+ listItem.format.marginRight = '0px';
41831
+ listItem.format.listStylePosition = 'inside';
41832
+ // Preserve Word's rendered number when its outline template is unsupported.
41833
+ var number = (_a = bulletElement_1 === null || bulletElement_1 === void 0 ? void 0 : bulletElement_1.textContent) === null || _a === void 0 ? void 0 : _a.trim();
41834
+ if (bullet_1 === undefined && number && /^\d+(?:\.\d+)*[.)]?$/.test(number)) {
41835
+ listItem.format.listStyleType = '"' + number + ' "';
41836
+ }
41837
+ }
41838
+ else if (wordLevel_1 > 1 && !isHeading_1) {
41839
+ delete listItem.format.marginLeft;
41840
+ delete listItem.format.marginRight;
41841
+ }
41842
+ if (listType_1 == 'OL') {
41843
+ setStartNumber(listItem, context, listMetadata_1, element);
41844
+ }
41845
+ });
41846
+ }
41847
+ finally {
41848
+ context.segmentFormat = originalSegmentFormat;
41849
+ }
41321
41850
  if (listFormat.levels.length > 0 &&
41322
41851
  listFormat.wordKnownLevels.get(wordList) != listFormat.levels) {
41323
41852
  listFormat.wordKnownLevels.set(wordList, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(listFormat.levels), false));
@@ -41438,8 +41967,13 @@ function wordListPaddingParser(format, element) {
41438
41967
  * @returns
41439
41968
  */
41440
41969
  function getBulletElement(element) {
41970
+ var _a;
41441
41971
  var firstChild = element.firstElementChild;
41442
41972
  var isBulletElement = false;
41973
+ if ((0, roosterjs_content_model_dom_1.isNodeOfType)(firstChild, 'ELEMENT_NODE') &&
41974
+ ((_a = (0, getStyles_1.getStyles)(firstChild)[MSO_LIST]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === MSO_LIST_IGNORE) {
41975
+ return firstChild;
41976
+ }
41443
41977
  if (firstChild) {
41444
41978
  for (var i = 0; i < firstChild.childNodes.length; i++) {
41445
41979
  var child = firstChild.childNodes[i];
@@ -41486,35 +42020,108 @@ var WORD_LIST_PARAGRAPH_SELECTORS = new Set([
41486
42020
  ]);
41487
42021
  /**
41488
42022
  * @internal
41489
- * Strips all margin-* properties from a CSS property string.
42023
+ * Strips horizontal margin properties from a CSS property string while preserving
42024
+ * vertical values from the margin shorthand.
41490
42025
  * Empty tokens produced by a trailing semicolon are preserved so that the
41491
42026
  * resulting string still ends with ";" and remains safe to concatenate.
41492
- * For example, "margin-top: 0pt; color: red;" becomes " color: red;".
41493
- */
41494
- function removeMarginProperties(cssText) {
41495
- return cssText
41496
- .split(';')
41497
- .filter(function (prop) {
41498
- var name = prop.split(':')[0].trim().toLowerCase();
41499
- // Keep empty tokens (the trailing ';' produces one) and any non-margin property.
41500
- return !name || !/^margin/.test(name);
41501
- })
41502
- .join(';');
42027
+ * For example, "margin: 1pt 2pt 3pt 4pt; color: red;" becomes
42028
+ * "margin-top: 1pt; margin-bottom: 3pt; color: red;".
42029
+ */
42030
+ function removeHorizontalMarginProperties(cssText) {
42031
+ var result = [];
42032
+ cssText.split(';').forEach(function (prop) {
42033
+ var _a, _b;
42034
+ var separatorIndex = prop.indexOf(':');
42035
+ var name = prop
42036
+ .substring(0, separatorIndex < 0 ? prop.length : separatorIndex)
42037
+ .trim()
42038
+ .toLowerCase();
42039
+ if (name == 'margin-left' ||
42040
+ name == 'margin-right' ||
42041
+ name == 'margin-inline' ||
42042
+ name == 'margin-inline-start' ||
42043
+ name == 'margin-inline-end') {
42044
+ return;
42045
+ }
42046
+ if (name == 'margin' && separatorIndex >= 0) {
42047
+ var value = prop.substring(separatorIndex + 1).trim();
42048
+ var importantMatch = value.match(/\s*!important\s*$/i);
42049
+ var important = importantMatch ? ' !important' : '';
42050
+ var values = splitCssValue(value.substring(0, (_a = importantMatch === null || importantMatch === void 0 ? void 0 : importantMatch.index) !== null && _a !== void 0 ? _a : value.length));
42051
+ if (values.length >= 1 && values.length <= 4) {
42052
+ var leadingWhitespace = ((_b = prop.match(/^\s*/)) === null || _b === void 0 ? void 0 : _b[0]) || '';
42053
+ var top_1 = values[0];
42054
+ var bottom = values.length >= 3 ? values[2] : values[0];
42055
+ result.push(leadingWhitespace + "margin-top: " + top_1 + important);
42056
+ result.push(" margin-bottom: " + bottom + important);
42057
+ return;
42058
+ }
42059
+ }
42060
+ result.push(prop);
42061
+ });
42062
+ return result.join(';');
42063
+ }
42064
+ function splitCssValue(value) {
42065
+ var result = [];
42066
+ var current = '';
42067
+ var quote = null;
42068
+ var parenthesisDepth = 0;
42069
+ for (var i = 0; i < value.length; i++) {
42070
+ var char = value[i];
42071
+ if (quote) {
42072
+ current += char;
42073
+ if (char == '\\') {
42074
+ i++;
42075
+ current += value[i] || '';
42076
+ }
42077
+ else if (char == quote) {
42078
+ quote = null;
42079
+ }
42080
+ }
42081
+ else if (char == '"' || char == "'") {
42082
+ current += char;
42083
+ quote = char;
42084
+ }
42085
+ else if (char == '(') {
42086
+ current += char;
42087
+ parenthesisDepth++;
42088
+ }
42089
+ else if (char == ')') {
42090
+ current += char;
42091
+ parenthesisDepth = Math.max(0, parenthesisDepth - 1);
42092
+ }
42093
+ else if (parenthesisDepth == 0 && /\s/.test(char)) {
42094
+ if (current) {
42095
+ result.push(current);
42096
+ current = '';
42097
+ }
42098
+ }
42099
+ else {
42100
+ current += char;
42101
+ }
42102
+ }
42103
+ if (current) {
42104
+ result.push(current);
42105
+ }
42106
+ return result;
41503
42107
  }
41504
42108
  /**
41505
42109
  * @internal
41506
- * Removes margin properties from global CSS rules that target Word list paragraph
41507
- * classes (p.MsoListParagraph, p.MsoListParagraphCxSpFirst, etc.).
42110
+ * Removes horizontal margin properties from global CSS rules that target Word list
42111
+ * paragraph classes (p.MsoListParagraph, p.MsoListParagraphCxSpFirst, etc.).
41508
42112
  *
41509
42113
  * Word Desktop pastes a global stylesheet that typically includes rules like:
41510
42114
  * p.MsoListParagraph { margin: 0in; margin-bottom: .0001pt; ... }
41511
- * These margins conflict with RoosterJS's own list indentation, causing double
41512
- * indentation when the CSS is converted to inline styles via convertInlineCss.
42115
+ * Horizontal margins conflict with RoosterJS's own list indentation, causing double
42116
+ * indentation when the CSS is converted to inline styles via convertInlineCss. The
42117
+ * vertical margins are preserved so Word's margin-top: 0 is not replaced by the
42118
+ * browser's default paragraph margin when the list level is created.
41513
42119
  *
41514
- * When a rule's selectors are exclusively list paragraph classes the margins are
41515
- * removed in place. When a rule groups list paragraph classes with other selectors
41516
- * the rule is split: the non-list selectors keep the original text, and a new rule
41517
- * is inserted for the list paragraph selectors with margins stripped.
42120
+ * When a rule's selectors are exclusively list paragraph classes the horizontal
42121
+ * margins are removed in place. When a rule groups list paragraph classes with other
42122
+ * selectors the rule is split: the non-list selectors keep the original text, and a
42123
+ * new rule is inserted for the list paragraph selectors with horizontal margins
42124
+ * stripped.
41518
42125
  *
41519
42126
  * The array is mutated in place so the changes are reflected when convertInlineCss
41520
42127
  * subsequently processes the same array reference.
@@ -41529,17 +42136,16 @@ function removeListParagraphMargins(globalCssRules) {
41529
42136
  }
41530
42137
  var nonMatchingSelectors = rule.selectors.filter(function (s) { return !WORD_LIST_PARAGRAPH_SELECTORS.has(s); });
41531
42138
  if (nonMatchingSelectors.length === 0) {
41532
- // All selectors target list paragraphs — strip margins directly.
41533
- rule.text = removeMarginProperties(rule.text);
42139
+ // All selectors target list paragraphs — strip horizontal margins directly.
42140
+ rule.text = removeHorizontalMarginProperties(rule.text);
41534
42141
  }
41535
42142
  else {
41536
42143
  // Mixed rule: keep the non-list selectors on the original entry, then
41537
- // insert a new entry immediately after for the list paragraph selectors
41538
- // with margins removed.
42144
+ // insert a new entry immediately after for the list paragraph selectors.
41539
42145
  rule.selectors = nonMatchingSelectors;
41540
42146
  globalCssRules.splice(i + 1, 0, {
41541
42147
  selectors: matchingSelectors,
41542
- text: removeMarginProperties(rule.text),
42148
+ text: removeHorizontalMarginProperties(rule.text),
41543
42149
  });
41544
42150
  }
41545
42151
  }
@@ -41547,6 +42153,63 @@ function removeListParagraphMargins(globalCssRules) {
41547
42153
  exports.removeListParagraphMargins = removeListParagraphMargins;
41548
42154
 
41549
42155
 
42156
+ /***/ },
42157
+
42158
+ /***/ "./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/wordBorderParser.ts"
42159
+ /*!********************************************************************************************!*\
42160
+ !*** ./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/wordBorderParser.ts ***!
42161
+ \********************************************************************************************/
42162
+ (__unused_webpack_module, exports, __webpack_require__) {
42163
+
42164
+ "use strict";
42165
+
42166
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
42167
+ exports.wordBorderParser = void 0;
42168
+ var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
42169
+ var BorderStyleNames = new Map([
42170
+ ['border-top', 'borderTop'],
42171
+ ['border-right', 'borderRight'],
42172
+ ['border-bottom', 'borderBottom'],
42173
+ ['border-left', 'borderLeft'],
42174
+ ]);
42175
+ /**
42176
+ * @internal
42177
+ */
42178
+ var wordBorderParser = function (format, element) {
42179
+ var style = element.getAttribute('style');
42180
+ if (style) {
42181
+ var noBorder_1 = new Map();
42182
+ style.split(';').forEach(function (declaration) {
42183
+ var separatorIndex = declaration.indexOf(':');
42184
+ if (separatorIndex < 0) {
42185
+ return;
42186
+ }
42187
+ var name = declaration.substring(0, separatorIndex).trim().toLowerCase();
42188
+ var value = declaration
42189
+ .substring(separatorIndex + 1)
42190
+ .trim()
42191
+ .toLowerCase();
42192
+ var isNone = /^none(?:\s|$|!important)/.test(value);
42193
+ if (name == 'border') {
42194
+ roosterjs_content_model_dom_1.BorderKeys.forEach(function (key) { return noBorder_1.set(key, isNone); });
42195
+ }
42196
+ else {
42197
+ var key = BorderStyleNames.get(name);
42198
+ if (key) {
42199
+ noBorder_1.set(key, isNone);
42200
+ }
42201
+ }
42202
+ });
42203
+ noBorder_1.forEach(function (isNone, key) {
42204
+ if (isNone) {
42205
+ format[key] = 'none';
42206
+ }
42207
+ });
42208
+ }
42209
+ };
42210
+ exports.wordBorderParser = wordBorderParser;
42211
+
42212
+
41550
42213
  /***/ },
41551
42214
 
41552
42215
  /***/ "./packages/roosterjs-content-model-plugins/lib/paste/oneNote/processPastedContentFromOneNote.ts"
@@ -41851,18 +42514,23 @@ var INVALID_LINKS_REGEX = /^file:\/\/\/[a-zA-Z\/]/i;
41851
42514
  * @internal
41852
42515
  */
41853
42516
  var parseLink = function (format, element) {
42517
+ var _a;
41854
42518
  if (!(0, roosterjs_content_model_dom_1.isElementOfType)(element, 'a')) {
41855
42519
  return;
41856
42520
  }
42521
+ // On an SVG anchor "href" is an SVGAnimatedString instead of a resolved URL string. Passing it
42522
+ // to the URL constructor always throws, which used to skip the protocol check altogether.
42523
+ var href = typeof element.href == 'string' ? element.href : (_a = element.getAttribute('href')) !== null && _a !== void 0 ? _a : '';
41857
42524
  var url;
41858
42525
  try {
41859
- url = new URL(element.href);
42526
+ url = new URL(href);
41860
42527
  }
41861
- catch (_a) {
42528
+ catch (_b) {
41862
42529
  url = undefined;
41863
42530
  }
41864
- if ((url && SUPPORTED_PROTOCOLS.indexOf(url.protocol) === -1) ||
41865
- INVALID_LINKS_REGEX.test(element.href)) {
42531
+ if ((0, roosterjs_content_model_dom_1.isUnsafeUrl)(href) ||
42532
+ (url && SUPPORTED_PROTOCOLS.indexOf(url.protocol) === -1) ||
42533
+ INVALID_LINKS_REGEX.test(href)) {
41866
42534
  element.removeAttribute('href');
41867
42535
  format.href = '';
41868
42536
  }
@@ -42524,8 +43192,12 @@ function processAsListItem(context, element, group, listFormatMetadata, bulletEl
42524
43192
  if (listFormatMetadata && lastLevel) {
42525
43193
  (0, roosterjs_content_model_dom_1.updateListMetadata)(lastLevel, function (metadata) { return Object.assign({}, metadata, listFormatMetadata); });
42526
43194
  }
42527
- var listItem = (0, roosterjs_content_model_dom_1.createListItem)(listFormat.levels, context.segmentFormat);
43195
+ // Parse the list item element's own segment format (e.g. font family/size) into
43196
+ // context.segmentFormat *before* creating the list item, so the format holder
43197
+ // (used to render the list bullet/number) reflects this list item's own font instead
43198
+ // of whatever was left over from the previously processed element.
42528
43199
  (0, roosterjs_content_model_dom_1.parseFormat)(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);
43200
+ var listItem = (0, roosterjs_content_model_dom_1.createListItem)(listFormat.levels, context.segmentFormat);
42529
43201
  (0, roosterjs_content_model_dom_1.parseFormat)(element, context.formatParsers.listItemElement, listItem.format, context);
42530
43202
  (0, roosterjs_content_model_dom_1.parseFormat)(element, [removeNegativeTextIndentParser_1.removeNegativeTextIndentParser, nonListElementParser], listItem.format, context);
42531
43203
  if (bulletElement) {