roosterjs 8.11.3 → 8.13.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.
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 8.11.3)
1
+ // Type definitions for roosterjs (Version 8.13.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -56,6 +56,10 @@ export interface BrowserInfo {
56
56
  * Whether current browser is IE/Edge
57
57
  */
58
58
  readonly isIEOrEdge?: boolean;
59
+ /**
60
+ * Whether current OS is Android
61
+ */
62
+ readonly isAndroid?: boolean;
59
63
  }
60
64
 
61
65
  /**
@@ -766,7 +770,13 @@ export const enum GetContentMode {
766
770
  /**
767
771
  * Get plain text content only, all format will be ignored
768
772
  */
769
- PlainText = 3
773
+ PlainText = 3,
774
+ /**
775
+ * A fast way to get plain text content, the line-end positions may not be exactly same with HTML content,
776
+ * but the text content should be the same. This is used for quickly retrieve text content and check
777
+ * text only
778
+ */
779
+ PlainTextFast = 4
770
780
  }
771
781
 
772
782
  /**
@@ -2256,6 +2266,7 @@ export interface HtmlSanitizerOptions {
2256
2266
  }
2257
2267
 
2258
2268
  /**
2269
+ * @deprecated
2259
2270
  * Options for sanitizeHtml function
2260
2271
  */
2261
2272
  export interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
@@ -2272,86 +2283,12 @@ export interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
2272
2283
 
2273
2284
  /**
2274
2285
  * Define DOM types of window, used by safeInstanceOf() to check if a given object is of the specified type of its own window
2275
- *
2276
- * !!!Note: This file is generated from /tools/generateTargetWindow.js. Do NOT modify this file directly!!!
2277
2286
  */
2278
2287
  export interface TargetWindowBase {
2279
2288
  Range: Range;
2280
2289
  Node: Node;
2281
2290
  ParentNode: ParentNode;
2282
2291
  Element: Element;
2283
- SVGElement: SVGElement;
2284
- SVGViewElement: SVGViewElement;
2285
- SVGTitleElement: SVGTitleElement;
2286
- SVGSymbolElement: SVGSymbolElement;
2287
- SVGStyleElement: SVGStyleElement;
2288
- SVGStopElement: SVGStopElement;
2289
- SVGScriptElement: SVGScriptElement;
2290
- SVGPatternElement: SVGPatternElement;
2291
- SVGMetadataElement: SVGMetadataElement;
2292
- SVGMaskElement: SVGMaskElement;
2293
- SVGMarkerElement: SVGMarkerElement;
2294
- SVGMPathElement: SVGMPathElement;
2295
- SVGGraphicsElement: SVGGraphicsElement;
2296
- SVGUseElement: SVGUseElement;
2297
- SVGTextContentElement: SVGTextContentElement;
2298
- SVGTextPositioningElement: SVGTextPositioningElement;
2299
- SVGTextElement: SVGTextElement;
2300
- SVGTSpanElement: SVGTSpanElement;
2301
- SVGTextPathElement: SVGTextPathElement;
2302
- SVGSwitchElement: SVGSwitchElement;
2303
- SVGSVGElement: SVGSVGElement;
2304
- SVGImageElement: SVGImageElement;
2305
- SVGGeometryElement: SVGGeometryElement;
2306
- SVGRectElement: SVGRectElement;
2307
- SVGPolylineElement: SVGPolylineElement;
2308
- SVGPolygonElement: SVGPolygonElement;
2309
- SVGPathElement: SVGPathElement;
2310
- SVGLineElement: SVGLineElement;
2311
- SVGEllipseElement: SVGEllipseElement;
2312
- SVGCircleElement: SVGCircleElement;
2313
- SVGGElement: SVGGElement;
2314
- SVGForeignObjectElement: SVGForeignObjectElement;
2315
- SVGDefsElement: SVGDefsElement;
2316
- SVGAElement: SVGAElement;
2317
- SVGGradientElement: SVGGradientElement;
2318
- SVGRadialGradientElement: SVGRadialGradientElement;
2319
- SVGLinearGradientElement: SVGLinearGradientElement;
2320
- SVGFilterElement: SVGFilterElement;
2321
- SVGFETurbulenceElement: SVGFETurbulenceElement;
2322
- SVGFETileElement: SVGFETileElement;
2323
- SVGFESpotLightElement: SVGFESpotLightElement;
2324
- SVGFESpecularLightingElement: SVGFESpecularLightingElement;
2325
- SVGFEPointLightElement: SVGFEPointLightElement;
2326
- SVGFEOffsetElement: SVGFEOffsetElement;
2327
- SVGFEMorphologyElement: SVGFEMorphologyElement;
2328
- SVGFEMergeNodeElement: SVGFEMergeNodeElement;
2329
- SVGFEMergeElement: SVGFEMergeElement;
2330
- SVGFEImageElement: SVGFEImageElement;
2331
- SVGFEGaussianBlurElement: SVGFEGaussianBlurElement;
2332
- SVGFEFloodElement: SVGFEFloodElement;
2333
- SVGFEDropShadowElement: SVGFEDropShadowElement;
2334
- SVGFEDistantLightElement: SVGFEDistantLightElement;
2335
- SVGFEDisplacementMapElement: SVGFEDisplacementMapElement;
2336
- SVGFEDiffuseLightingElement: SVGFEDiffuseLightingElement;
2337
- SVGFEConvolveMatrixElement: SVGFEConvolveMatrixElement;
2338
- SVGFECompositeElement: SVGFECompositeElement;
2339
- SVGFEComponentTransferElement: SVGFEComponentTransferElement;
2340
- SVGFEColorMatrixElement: SVGFEColorMatrixElement;
2341
- SVGFEBlendElement: SVGFEBlendElement;
2342
- SVGDescElement: SVGDescElement;
2343
- SVGComponentTransferFunctionElement: SVGComponentTransferFunctionElement;
2344
- SVGFEFuncRElement: SVGFEFuncRElement;
2345
- SVGFEFuncGElement: SVGFEFuncGElement;
2346
- SVGFEFuncBElement: SVGFEFuncBElement;
2347
- SVGFEFuncAElement: SVGFEFuncAElement;
2348
- SVGClipPathElement: SVGClipPathElement;
2349
- SVGAnimationElement: SVGAnimationElement;
2350
- SVGSetElement: SVGSetElement;
2351
- SVGAnimateTransformElement: SVGAnimateTransformElement;
2352
- SVGAnimateMotionElement: SVGAnimateMotionElement;
2353
- SVGAnimateElement: SVGAnimateElement;
2354
- MathMLElement: MathMLElement;
2355
2292
  HTMLElement: HTMLElement;
2356
2293
  HTMLUnknownElement: HTMLUnknownElement;
2357
2294
  HTMLUListElement: HTMLUListElement;
@@ -2881,6 +2818,10 @@ export interface IEditor {
2881
2818
  * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
2882
2819
  */
2883
2820
  getTrustedHTMLHandler(): TrustedHTMLHandler;
2821
+ /**
2822
+ * Get a transformer function. It transform the size changes according to current situation.
2823
+ */
2824
+ getSizeTransformer(): SizeTransformer;
2884
2825
  }
2885
2826
 
2886
2827
  /**
@@ -3081,6 +3022,12 @@ export interface EditorCore extends PluginState {
3081
3022
  * To override, pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler
3082
3023
  */
3083
3024
  readonly trustedHTMLHandler: TrustedHTMLHandler;
3025
+ /**
3026
+ * A transformer function. It transform the size changes according to current situation.
3027
+ * A typical scenario to use this function is when editor is located under a scaled container, so we need to
3028
+ * calculate the scaled size change according to current zoom rate.
3029
+ */
3030
+ sizeTransformer: SizeTransformer;
3084
3031
  }
3085
3032
 
3086
3033
  /**
@@ -3436,6 +3383,12 @@ export interface EditorOptions {
3436
3383
  * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
3437
3384
  */
3438
3385
  trustedHTMLHandler?: TrustedHTMLHandler;
3386
+ /**
3387
+ * A transformer function. It transform the size changes according to current situation.
3388
+ * A typical scenario to use this function is when editor is located under a scaled container, so we need to
3389
+ * calculate the scaled size change according to current zoom rate.
3390
+ */
3391
+ sizeTransformer?: SizeTransformer;
3439
3392
  }
3440
3393
 
3441
3394
  /**
@@ -4127,6 +4080,15 @@ export type DOMEventHandler = PluginEventType | DOMEventHandlerFunction | DOMEve
4127
4080
  */
4128
4081
  export type TrustedHTMLHandler = (html: string) => string;
4129
4082
 
4083
+ /**
4084
+ * A transformer function. It transform the size changes according to current situation.
4085
+ * A typical scenario to use this function is when editor is located under a scaled container, so we need to
4086
+ * calculate the scaled size change according to current zoom rate.
4087
+ * @param size Original delta size from mouse event
4088
+ * @returns Calculated delta size. By default it should just return original value
4089
+ */
4090
+ export type SizeTransformer = (size: number) => number;
4091
+
4130
4092
  /**
4131
4093
  * This produces a block element from a a node
4132
4094
  * It needs to account for various HTML structure. Examples:
@@ -4819,7 +4781,7 @@ export function toArray<T>(array: readonly T[]): T[];
4819
4781
  * @param obj Object to check
4820
4782
  * @param typeName Target type name
4821
4783
  */
4822
- export function safeInstanceOf<T extends keyof TargetWindow>(obj: any, typeName: T): obj is TargetWindow[T];
4784
+ export function safeInstanceOf<T extends keyof W, W extends TargetWindow = TargetWindow>(obj: any, typeName: T): obj is W[T];
4823
4785
 
4824
4786
  /**
4825
4787
  * Read a file object and invoke a callback function with the data url of this file
@@ -5521,12 +5483,14 @@ export function canUndoAutoComplete(snapshots: Snapshots): boolean;
5521
5483
  */
5522
5484
  export class HtmlSanitizer {
5523
5485
  /**
5486
+ * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
5524
5487
  * Convert global CSS to inline CSS if any
5525
5488
  * @param html HTML source
5526
5489
  * @param additionalStyleNodes (Optional) additional HTML STYLE elements used as global CSS
5527
5490
  */
5528
5491
  static convertInlineCss(html: string, additionalStyleNodes?: HTMLStyleElement[]): string;
5529
5492
  /**
5493
+ * @deprecated Use new HtmlSanitizer().sanitize() instead
5530
5494
  * Sanitize HTML string, remove any unused HTML node/attribute/CSS.
5531
5495
  * @param html HTML source string
5532
5496
  * @param options Options used for this sanitizing process
@@ -5549,6 +5513,7 @@ export class HtmlSanitizer {
5549
5513
  */
5550
5514
  constructor(options?: HtmlSanitizerOptions);
5551
5515
  /**
5516
+ * @deprecated Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead
5552
5517
  * Sanitize HTML string
5553
5518
  * This function will do the following work:
5554
5519
  * 1. Convert global CSS into inline CSS
@@ -6003,6 +5968,10 @@ export class Editor implements IEditor {
6003
5968
  * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types
6004
5969
  */
6005
5970
  getTrustedHTMLHandler(): TrustedHTMLHandler;
5971
+ /**
5972
+ * Get a transformer function. It transform the size changes according to current situation.
5973
+ */
5974
+ getSizeTransformer(): SizeTransformer;
6006
5975
  }
6007
5976
 
6008
5977
  /**
@@ -1336,12 +1336,13 @@ module.exports = {
1336
1336
  /* MIT license */
1337
1337
  var colorNames = __webpack_require__(/*! color-name */ "./node_modules/color-name/index.js");
1338
1338
  var swizzle = __webpack_require__(/*! simple-swizzle */ "./node_modules/simple-swizzle/index.js");
1339
+ var hasOwnProperty = Object.hasOwnProperty;
1339
1340
 
1340
1341
  var reverseNames = {};
1341
1342
 
1342
1343
  // create a list of reverse color names
1343
1344
  for (var name in colorNames) {
1344
- if (colorNames.hasOwnProperty(name)) {
1345
+ if (hasOwnProperty.call(colorNames, name)) {
1345
1346
  reverseNames[colorNames[name]] = name;
1346
1347
  }
1347
1348
  }
@@ -1384,9 +1385,9 @@ cs.get.rgb = function (string) {
1384
1385
 
1385
1386
  var abbr = /^#([a-f0-9]{3,4})$/i;
1386
1387
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
1387
- var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1388
- var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1389
- var keyword = /(\D+)/;
1388
+ var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
1389
+ var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
1390
+ var keyword = /^(\w+)$/;
1390
1391
 
1391
1392
  var rgb = [0, 0, 0, 1];
1392
1393
  var match;
@@ -1423,7 +1424,11 @@ cs.get.rgb = function (string) {
1423
1424
  }
1424
1425
 
1425
1426
  if (match[4]) {
1426
- rgb[3] = parseFloat(match[4]);
1427
+ if (match[5]) {
1428
+ rgb[3] = parseFloat(match[4]) * 0.01;
1429
+ } else {
1430
+ rgb[3] = parseFloat(match[4]);
1431
+ }
1427
1432
  }
1428
1433
  } else if (match = string.match(per)) {
1429
1434
  for (i = 0; i < 3; i++) {
@@ -1431,19 +1436,22 @@ cs.get.rgb = function (string) {
1431
1436
  }
1432
1437
 
1433
1438
  if (match[4]) {
1434
- rgb[3] = parseFloat(match[4]);
1439
+ if (match[5]) {
1440
+ rgb[3] = parseFloat(match[4]) * 0.01;
1441
+ } else {
1442
+ rgb[3] = parseFloat(match[4]);
1443
+ }
1435
1444
  }
1436
1445
  } else if (match = string.match(keyword)) {
1437
1446
  if (match[1] === 'transparent') {
1438
1447
  return [0, 0, 0, 0];
1439
1448
  }
1440
1449
 
1441
- rgb = colorNames[match[1]];
1442
-
1443
- if (!rgb) {
1450
+ if (!hasOwnProperty.call(colorNames, match[1])) {
1444
1451
  return null;
1445
1452
  }
1446
1453
 
1454
+ rgb = colorNames[match[1]];
1447
1455
  rgb[3] = 1;
1448
1456
 
1449
1457
  return rgb;
@@ -1464,12 +1472,12 @@ cs.get.hsl = function (string) {
1464
1472
  return null;
1465
1473
  }
1466
1474
 
1467
- var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d\.]+)\s*)?\)$/;
1475
+ var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
1468
1476
  var match = string.match(hsl);
1469
1477
 
1470
1478
  if (match) {
1471
1479
  var alpha = parseFloat(match[4]);
1472
- var h = (parseFloat(match[1]) + 360) % 360;
1480
+ var h = ((parseFloat(match[1]) % 360) + 360) % 360;
1473
1481
  var s = clamp(parseFloat(match[2]), 0, 100);
1474
1482
  var l = clamp(parseFloat(match[3]), 0, 100);
1475
1483
  var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
@@ -1485,7 +1493,7 @@ cs.get.hwb = function (string) {
1485
1493
  return null;
1486
1494
  }
1487
1495
 
1488
- var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1496
+ var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
1489
1497
  var match = string.match(hwb);
1490
1498
 
1491
1499
  if (match) {
@@ -1564,7 +1572,7 @@ function clamp(num, min, max) {
1564
1572
  }
1565
1573
 
1566
1574
  function hexDouble(num) {
1567
- var str = num.toString(16).toUpperCase();
1575
+ var str = Math.round(num).toString(16).toUpperCase();
1568
1576
  return (str.length < 2) ? '0' + str : str;
1569
1577
  }
1570
1578
 
@@ -4759,7 +4767,10 @@ var getContent = function (core, mode) {
4759
4767
  // When there is fragment for shadow edit, always use the cached fragment as document since HTML node in editor
4760
4768
  // has been changed by uncommitted shadow edit which should be ignored.
4761
4769
  var root = core.lifecycle.shadowEditFragment || core.contentDiv;
4762
- if (mode == 3 /* PlainText */) {
4770
+ if (mode == 4 /* PlainTextFast */) {
4771
+ content = root.textContent;
4772
+ }
4773
+ else if (mode == 3 /* PlainText */) {
4763
4774
  content = (0, roosterjs_editor_dom_1.getTextContent)(root);
4764
4775
  }
4765
4776
  else if (triggerExtractContentEvent || core.lifecycle.isDarkMode) {
@@ -5448,7 +5459,9 @@ function transformToDarkMode(element, getDarkColor) {
5448
5459
  var attrColor = element.getAttribute(names[1 /* HtmlColor */]);
5449
5460
  if (!element.dataset[names[2 /* CssDataSet */]] &&
5450
5461
  !element.dataset[names[3 /* HtmlDataSet */]] &&
5451
- (styleColor || attrColor)) {
5462
+ (styleColor || attrColor) &&
5463
+ styleColor != 'inherit' // For inherit style, no need to change it and let it keep inherit from parent element
5464
+ ) {
5452
5465
  var newColor = getDarkColor(computedValues[index] || styleColor || attrColor);
5453
5466
  element.style.setProperty(names[0 /* CssColor */], newColor, 'important');
5454
5467
  element.dataset[names[2 /* CssDataSet */]] = styleColor || '';
@@ -5500,7 +5513,8 @@ exports.triggerEvent = void 0;
5500
5513
  * @param broadcast Set to true to skip the shouldHandleEventExclusively check
5501
5514
  */
5502
5515
  var triggerEvent = function (core, pluginEvent, broadcast) {
5503
- if (!core.lifecycle.shadowEditFragment &&
5516
+ if ((!core.lifecycle.shadowEditFragment ||
5517
+ pluginEvent.eventType == 12 /* BeforeDispose */) &&
5504
5518
  (broadcast || !core.plugins.some(function (plugin) { return handledExclusively(pluginEvent, plugin); }))) {
5505
5519
  core.plugins.forEach(function (plugin) {
5506
5520
  if (plugin.onPluginEvent) {
@@ -5641,6 +5655,9 @@ var CopyPastePlugin = /** @class */ (function () {
5641
5655
  return div;
5642
5656
  };
5643
5657
  CopyPastePlugin.prototype.cleanUpAndRestoreSelection = function (tempDiv, range) {
5658
+ if (roosterjs_editor_dom_1.Browser.isAndroid) {
5659
+ range.collapse();
5660
+ }
5644
5661
  this.editor.select(range);
5645
5662
  tempDiv.style.backgroundColor = '';
5646
5663
  tempDiv.style.color = '';
@@ -6974,11 +6991,11 @@ function createCorePlugins(contentDiv, options) {
6974
6991
  return {
6975
6992
  typeInContainer: map.typeInContainer || new TypeInContainerPlugin_1.default(),
6976
6993
  edit: map.edit || new EditPlugin_1.default(),
6994
+ pendingFormatState: map.pendingFormatState || new PendingFormatStatePlugin_1.default(),
6977
6995
  _placeholder: null,
6978
6996
  typeAfterLink: null,
6979
6997
  undo: map.undo || new UndoPlugin_1.default(options),
6980
6998
  domEvent: map.domEvent || new DOMEventPlugin_1.default(options, contentDiv),
6981
- pendingFormatState: map.pendingFormatState || new PendingFormatStatePlugin_1.default(),
6982
6999
  mouseUp: map.mouseUp || new MouseUpPlugin_1.default(),
6983
7000
  copyPaste: map.copyPaste || new CopyPastePlugin_1.default(options),
6984
7001
  entity: map.entity || new EntityPlugin_1.default(),
@@ -7059,7 +7076,7 @@ var Editor = /** @class */ (function () {
7059
7076
  plugins.push(corePlugins[name]);
7060
7077
  }
7061
7078
  });
7062
- this.core = __assign(__assign({ contentDiv: contentDiv, api: __assign(__assign({}, coreApiMap_1.coreApiMap), (options.coreApiOverride || {})), plugins: plugins.filter(function (x) { return !!x; }) }, (0, createCorePlugins_1.getPluginState)(corePlugins)), { trustedHTMLHandler: options.trustedHTMLHandler || (function (html) { return html; }) });
7079
+ this.core = __assign(__assign({ contentDiv: contentDiv, api: __assign(__assign({}, coreApiMap_1.coreApiMap), (options.coreApiOverride || {})), plugins: plugins.filter(function (x) { return !!x; }) }, (0, createCorePlugins_1.getPluginState)(corePlugins)), { trustedHTMLHandler: options.trustedHTMLHandler || (function (html) { return html; }), sizeTransformer: options.sizeTransformer });
7063
7080
  // 3. Initialize plugins
7064
7081
  this.core.plugins.forEach(function (plugin) { return plugin.initialize(_this); });
7065
7082
  // 4. Ensure user will type in a container node, not the editor content DIV
@@ -7069,7 +7086,9 @@ var Editor = /** @class */ (function () {
7069
7086
  * Dispose this editor, dispose all plugins and custom data
7070
7087
  */
7071
7088
  Editor.prototype.dispose = function () {
7072
- this.core.plugins.reverse().forEach(function (plugin) { return plugin.dispose(); });
7089
+ for (var i = this.core.plugins.length - 1; i >= 0; i--) {
7090
+ this.core.plugins[i].dispose();
7091
+ }
7073
7092
  this.core = null;
7074
7093
  };
7075
7094
  /**
@@ -7652,6 +7671,12 @@ var Editor = /** @class */ (function () {
7652
7671
  Editor.prototype.getTrustedHTMLHandler = function () {
7653
7672
  return this.core.trustedHTMLHandler;
7654
7673
  };
7674
+ /**
7675
+ * Get a transformer function. It transform the size changes according to current situation.
7676
+ */
7677
+ Editor.prototype.getSizeTransformer = function () {
7678
+ return this.core.sizeTransformer;
7679
+ };
7655
7680
  return Editor;
7656
7681
  }());
7657
7682
  exports.default = Editor;
@@ -9236,6 +9261,7 @@ var HtmlSanitizer = /** @class */ (function () {
9236
9261
  this.unknownTagReplacement = options.unknownTagReplacement;
9237
9262
  }
9238
9263
  /**
9264
+ * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
9239
9265
  * Convert global CSS to inline CSS if any
9240
9266
  * @param html HTML source
9241
9267
  * @param additionalStyleNodes (Optional) additional HTML STYLE elements used as global CSS
@@ -9247,6 +9273,7 @@ var HtmlSanitizer = /** @class */ (function () {
9247
9273
  return sanitizer.exec(html, true /*convertCssOnly*/);
9248
9274
  };
9249
9275
  /**
9276
+ * @deprecated Use new HtmlSanitizer().sanitize() instead
9250
9277
  * Sanitize HTML string, remove any unused HTML node/attribute/CSS.
9251
9278
  * @param html HTML source string
9252
9279
  * @param options Options used for this sanitizing process
@@ -9260,6 +9287,7 @@ var HtmlSanitizer = /** @class */ (function () {
9260
9287
  return sanitizer.exec(html, options.convertCssOnly, currentStyles);
9261
9288
  };
9262
9289
  /**
9290
+ * @deprecated Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead
9263
9291
  * Sanitize HTML string
9264
9292
  * This function will do the following work:
9265
9293
  * 1. Convert global CSS into inline CSS
@@ -9271,7 +9299,7 @@ var HtmlSanitizer = /** @class */ (function () {
9271
9299
  */
9272
9300
  HtmlSanitizer.prototype.exec = function (html, convertCssOnly, currentStyles) {
9273
9301
  var parser = new DOMParser();
9274
- var doc = parser.parseFromString(unsafeConvertToTrustedHTML(html) || '', 'text/html');
9302
+ var doc = parser.parseFromString(html || '', 'text/html');
9275
9303
  if (doc && doc.body && doc.body.firstChild) {
9276
9304
  this.convertGlobalCssToInlineCss(doc);
9277
9305
  if (!convertCssOnly) {
@@ -9477,15 +9505,6 @@ var HtmlSanitizer = /** @class */ (function () {
9477
9505
  return HtmlSanitizer;
9478
9506
  }());
9479
9507
  exports.default = HtmlSanitizer;
9480
- var trustedTypes = window.trustedTypes;
9481
- var policy = trustedTypes === null || trustedTypes === void 0 ? void 0 : trustedTypes.createPolicy('roosterjsUnsafeConvertHTML', {
9482
- // This is unsafe. However, we only use this function for HtmlSanitizer which we will
9483
- // sanitize HTML tree by our own code. So we just directly return the HTML string here.
9484
- createHTML: function (html) { return html; },
9485
- });
9486
- var unsafeConvertToTrustedHTML = policy
9487
- ? function (html) { return policy.createHTML(html || ''); }
9488
- : function (html) { return html; };
9489
9508
 
9490
9509
 
9491
9510
  /***/ }),
@@ -13630,6 +13649,7 @@ function cloneNode(node) {
13630
13649
 
13631
13650
  Object.defineProperty(exports, "__esModule", { value: true });
13632
13651
  exports.Browser = exports.getBrowserInfo = void 0;
13652
+ var isAndroidRegex = /android/i;
13633
13653
  /**
13634
13654
  * Get current browser information from user agent string
13635
13655
  * @param userAgent The userAgent string of a browser
@@ -13665,6 +13685,7 @@ function getBrowserInfo(userAgent, appVersion) {
13665
13685
  }
13666
13686
  var isMac = appVersion.indexOf('Mac') != -1;
13667
13687
  var isWin = appVersion.indexOf('Win') != -1 || appVersion.indexOf('NT') != -1;
13688
+ var isAndroid = isAndroidRegex.test(userAgent);
13668
13689
  return {
13669
13690
  isMac: isMac,
13670
13691
  isWin: isWin,
@@ -13676,6 +13697,7 @@ function getBrowserInfo(userAgent, appVersion) {
13676
13697
  isFirefox: isFirefox,
13677
13698
  isEdge: isEdge,
13678
13699
  isIEOrEdge: isIE || isEdge,
13700
+ isAndroid: isAndroid,
13679
13701
  };
13680
13702
  }
13681
13703
  exports.getBrowserInfo = getBrowserInfo;
@@ -15873,6 +15895,9 @@ __exportStar(__webpack_require__(/*! ./Watermark */ "./packages/roosterjs-editor
15873
15895
  "use strict";
15874
15896
 
15875
15897
  Object.defineProperty(exports, "__esModule", { value: true });
15898
+ function defaultTransformer(size) {
15899
+ return size;
15900
+ }
15876
15901
  /**
15877
15902
  * @internal
15878
15903
  * A helper class to help manage drag and drop to an HTML element
@@ -15887,12 +15912,13 @@ var DragAndDropHelper = /** @class */ (function () {
15887
15912
  * @param onSubmit A callback that will be invoked when event handler in handler object returns true
15888
15913
  * @param handler The event handler object, see DragAndDropHandler interface for more information
15889
15914
  */
15890
- function DragAndDropHelper(trigger, context, onSubmit, handler) {
15915
+ function DragAndDropHelper(trigger, context, onSubmit, handler, sizeTransformer) {
15891
15916
  var _this = this;
15892
15917
  this.trigger = trigger;
15893
15918
  this.context = context;
15894
15919
  this.onSubmit = onSubmit;
15895
15920
  this.handler = handler;
15921
+ this.sizeTransformer = sizeTransformer;
15896
15922
  this.onMouseDown = function (e) {
15897
15923
  var _a, _b;
15898
15924
  e.preventDefault();
@@ -15905,8 +15931,9 @@ var DragAndDropHelper = /** @class */ (function () {
15905
15931
  this.onMouseMove = function (e) {
15906
15932
  var _a, _b, _c;
15907
15933
  e.preventDefault();
15908
- var deltaX = e.pageX - _this.initX;
15909
- var deltaY = e.pageY - _this.initY;
15934
+ var sizeTransformer = _this.sizeTransformer || defaultTransformer;
15935
+ var deltaX = sizeTransformer(e.pageX - _this.initX);
15936
+ var deltaY = sizeTransformer(e.pageY - _this.initY);
15910
15937
  if ((_b = (_a = _this.handler).onDragging) === null || _b === void 0 ? void 0 : _b.call(_a, _this.context, e, _this.initValue, deltaX, deltaY)) {
15911
15938
  (_c = _this.onSubmit) === null || _c === void 0 ? void 0 : _c.call(_this, _this.context);
15912
15939
  }
@@ -16534,7 +16561,7 @@ function getCacheNextSibling(event, editor) {
16534
16561
  function prepareAutoBullet(editor, range) {
16535
16562
  var block = editor.getBlockElementAtNode(range.startContainer);
16536
16563
  var endNode = block === null || block === void 0 ? void 0 : block.getEndNode();
16537
- if (endNode && (0, roosterjs_editor_dom_1.getTagOfNode)(endNode) != 'BR' && (block === null || block === void 0 ? void 0 : block.getTextContent().trim()) === '') {
16564
+ if (endNode && (0, roosterjs_editor_dom_1.getTagOfNode)(endNode) != 'BR') {
16538
16565
  var br = editor.getDocument().createElement('BR');
16539
16566
  if ((0, roosterjs_editor_dom_1.isBlockElement)(endNode)) {
16540
16567
  endNode.appendChild(br);
@@ -17193,9 +17220,7 @@ var ContextMenu = /** @class */ (function () {
17193
17220
  ContextMenu.prototype.initContainer = function (x, y) {
17194
17221
  if (!this.container) {
17195
17222
  this.container = (0, roosterjs_editor_dom_1.createElement)(5 /* ContextMenuWrapper */, this.editor.getDocument());
17196
- this.editor.insertNode(this.container, {
17197
- position: 4 /* Outside */,
17198
- });
17223
+ this.editor.getDocument().body.appendChild(this.container);
17199
17224
  }
17200
17225
  this.container.style.left = x + 'px';
17201
17226
  this.container.style.top = y + 'px';
@@ -17294,7 +17319,7 @@ var CustomReplacePlugin = /** @class */ (function () {
17294
17319
  */
17295
17320
  CustomReplacePlugin.prototype.onPluginEvent = function (event) {
17296
17321
  var _this = this;
17297
- if (this.editor.isInIME() || event.eventType != 3 /* Input */) {
17322
+ if (event.eventType != 3 /* Input */ || this.editor.isInIME()) {
17298
17323
  return;
17299
17324
  }
17300
17325
  // Exit early on input events that do not insert a replacement's final character.
@@ -18033,7 +18058,7 @@ var ImageEdit = /** @class */ (function () {
18033
18058
  wrapper.style.verticalAlign = 'bottom';
18034
18059
  wrapper.style.display = roosterjs_editor_dom_1.Browser.isSafari ? 'inline-block' : 'inline-flex';
18035
18060
  // Cache current src so that we can compare it after edit see if src is changed
18036
- this.lastSrc = this.image.src;
18061
+ this.lastSrc = this.image.getAttribute('src');
18037
18062
  // Set image src to original src to help show editing UI, also it will be used when regenerate image dataURL after editing
18038
18063
  this.image.src = this.editInfo.src;
18039
18064
  this.image.style.position = 'absolute';
@@ -18086,7 +18111,7 @@ var ImageEdit = /** @class */ (function () {
18086
18111
  var wrapper = this.getImageWrapper(this.image);
18087
18112
  return wrapper
18088
18113
  ? getEditElements(wrapper, elementClass).map(function (element) {
18089
- return new DragAndDropHelper_1.default(element, __assign(__assign({}, commonContext), { x: element.dataset.x, y: element.dataset.y }), _this.updateWrapper, dragAndDrop);
18114
+ return new DragAndDropHelper_1.default(element, __assign(__assign({}, commonContext), { x: element.dataset.x, y: element.dataset.y }), _this.updateWrapper, dragAndDrop, _this.editor.getSizeTransformer());
18090
18115
  })
18091
18116
  : [];
18092
18117
  };
@@ -18293,7 +18318,7 @@ function resizeByPercentage(editor, image, percentage, minWidth, minHeight) {
18293
18318
  if (!(0, isResizedTo_1.default)(image, percentage)) {
18294
18319
  loadImage(image, editInfo.src, function () {
18295
18320
  if (!editor.isDisposed() && editor.contains(image)) {
18296
- var lastSrc_1 = image.src;
18321
+ var lastSrc_1 = image.getAttribute('src');
18297
18322
  var _a = (0, getTargetSizeByPercentage_1.default)(editInfo, percentage), width = _a.width, height = _a.height;
18298
18323
  editInfo.widthPx = Math.max(width, minWidth);
18299
18324
  editInfo.heightPx = Math.max(height, minHeight);
@@ -18537,7 +18562,7 @@ function getEditInfoFromImage(image) {
18537
18562
  exports.getEditInfoFromImage = getEditInfoFromImage;
18538
18563
  function getInitialEditInfo(image) {
18539
18564
  return {
18540
- src: image.src,
18565
+ src: image.getAttribute('src') || '',
18541
18566
  widthPx: image.clientWidth,
18542
18567
  heightPx: image.clientHeight,
18543
18568
  naturalWidth: image.naturalWidth,