roosterjs 8.11.2 → 8.12.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 8.11.2)
1
+ // Type definitions for roosterjs (Version 8.12.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -57,6 +57,10 @@ interface BrowserInfo {
57
57
  * Whether current browser is IE/Edge
58
58
  */
59
59
  readonly isIEOrEdge?: boolean;
60
+ /**
61
+ * Whether current OS is Android
62
+ */
63
+ readonly isAndroid?: boolean;
60
64
  }
61
65
 
62
66
  /**
@@ -2257,6 +2261,7 @@ interface HtmlSanitizerOptions {
2257
2261
  }
2258
2262
 
2259
2263
  /**
2264
+ * @deprecated
2260
2265
  * Options for sanitizeHtml function
2261
2266
  */
2262
2267
  interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
@@ -2273,86 +2278,12 @@ interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
2273
2278
 
2274
2279
  /**
2275
2280
  * Define DOM types of window, used by safeInstanceOf() to check if a given object is of the specified type of its own window
2276
- *
2277
- * !!!Note: This file is generated from /tools/generateTargetWindow.js. Do NOT modify this file directly!!!
2278
2281
  */
2279
2282
  interface TargetWindowBase {
2280
2283
  Range: Range;
2281
2284
  Node: Node;
2282
2285
  ParentNode: ParentNode;
2283
2286
  Element: Element;
2284
- SVGElement: SVGElement;
2285
- SVGViewElement: SVGViewElement;
2286
- SVGTitleElement: SVGTitleElement;
2287
- SVGSymbolElement: SVGSymbolElement;
2288
- SVGStyleElement: SVGStyleElement;
2289
- SVGStopElement: SVGStopElement;
2290
- SVGScriptElement: SVGScriptElement;
2291
- SVGPatternElement: SVGPatternElement;
2292
- SVGMetadataElement: SVGMetadataElement;
2293
- SVGMaskElement: SVGMaskElement;
2294
- SVGMarkerElement: SVGMarkerElement;
2295
- SVGMPathElement: SVGMPathElement;
2296
- SVGGraphicsElement: SVGGraphicsElement;
2297
- SVGUseElement: SVGUseElement;
2298
- SVGTextContentElement: SVGTextContentElement;
2299
- SVGTextPositioningElement: SVGTextPositioningElement;
2300
- SVGTextElement: SVGTextElement;
2301
- SVGTSpanElement: SVGTSpanElement;
2302
- SVGTextPathElement: SVGTextPathElement;
2303
- SVGSwitchElement: SVGSwitchElement;
2304
- SVGSVGElement: SVGSVGElement;
2305
- SVGImageElement: SVGImageElement;
2306
- SVGGeometryElement: SVGGeometryElement;
2307
- SVGRectElement: SVGRectElement;
2308
- SVGPolylineElement: SVGPolylineElement;
2309
- SVGPolygonElement: SVGPolygonElement;
2310
- SVGPathElement: SVGPathElement;
2311
- SVGLineElement: SVGLineElement;
2312
- SVGEllipseElement: SVGEllipseElement;
2313
- SVGCircleElement: SVGCircleElement;
2314
- SVGGElement: SVGGElement;
2315
- SVGForeignObjectElement: SVGForeignObjectElement;
2316
- SVGDefsElement: SVGDefsElement;
2317
- SVGAElement: SVGAElement;
2318
- SVGGradientElement: SVGGradientElement;
2319
- SVGRadialGradientElement: SVGRadialGradientElement;
2320
- SVGLinearGradientElement: SVGLinearGradientElement;
2321
- SVGFilterElement: SVGFilterElement;
2322
- SVGFETurbulenceElement: SVGFETurbulenceElement;
2323
- SVGFETileElement: SVGFETileElement;
2324
- SVGFESpotLightElement: SVGFESpotLightElement;
2325
- SVGFESpecularLightingElement: SVGFESpecularLightingElement;
2326
- SVGFEPointLightElement: SVGFEPointLightElement;
2327
- SVGFEOffsetElement: SVGFEOffsetElement;
2328
- SVGFEMorphologyElement: SVGFEMorphologyElement;
2329
- SVGFEMergeNodeElement: SVGFEMergeNodeElement;
2330
- SVGFEMergeElement: SVGFEMergeElement;
2331
- SVGFEImageElement: SVGFEImageElement;
2332
- SVGFEGaussianBlurElement: SVGFEGaussianBlurElement;
2333
- SVGFEFloodElement: SVGFEFloodElement;
2334
- SVGFEDropShadowElement: SVGFEDropShadowElement;
2335
- SVGFEDistantLightElement: SVGFEDistantLightElement;
2336
- SVGFEDisplacementMapElement: SVGFEDisplacementMapElement;
2337
- SVGFEDiffuseLightingElement: SVGFEDiffuseLightingElement;
2338
- SVGFEConvolveMatrixElement: SVGFEConvolveMatrixElement;
2339
- SVGFECompositeElement: SVGFECompositeElement;
2340
- SVGFEComponentTransferElement: SVGFEComponentTransferElement;
2341
- SVGFEColorMatrixElement: SVGFEColorMatrixElement;
2342
- SVGFEBlendElement: SVGFEBlendElement;
2343
- SVGDescElement: SVGDescElement;
2344
- SVGComponentTransferFunctionElement: SVGComponentTransferFunctionElement;
2345
- SVGFEFuncRElement: SVGFEFuncRElement;
2346
- SVGFEFuncGElement: SVGFEFuncGElement;
2347
- SVGFEFuncBElement: SVGFEFuncBElement;
2348
- SVGFEFuncAElement: SVGFEFuncAElement;
2349
- SVGClipPathElement: SVGClipPathElement;
2350
- SVGAnimationElement: SVGAnimationElement;
2351
- SVGSetElement: SVGSetElement;
2352
- SVGAnimateTransformElement: SVGAnimateTransformElement;
2353
- SVGAnimateMotionElement: SVGAnimateMotionElement;
2354
- SVGAnimateElement: SVGAnimateElement;
2355
- MathMLElement: MathMLElement;
2356
2287
  HTMLElement: HTMLElement;
2357
2288
  HTMLUnknownElement: HTMLUnknownElement;
2358
2289
  HTMLUListElement: HTMLUListElement;
@@ -4820,7 +4751,7 @@ function toArray<T>(array: readonly T[]): T[];
4820
4751
  * @param obj Object to check
4821
4752
  * @param typeName Target type name
4822
4753
  */
4823
- function safeInstanceOf<T extends keyof TargetWindow>(obj: any, typeName: T): obj is TargetWindow[T];
4754
+ function safeInstanceOf<T extends keyof W, W extends TargetWindow = TargetWindow>(obj: any, typeName: T): obj is W[T];
4824
4755
 
4825
4756
  /**
4826
4757
  * Read a file object and invoke a callback function with the data url of this file
@@ -5522,12 +5453,14 @@ function canUndoAutoComplete(snapshots: Snapshots): boolean;
5522
5453
  */
5523
5454
  class HtmlSanitizer {
5524
5455
  /**
5456
+ * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
5525
5457
  * Convert global CSS to inline CSS if any
5526
5458
  * @param html HTML source
5527
5459
  * @param additionalStyleNodes (Optional) additional HTML STYLE elements used as global CSS
5528
5460
  */
5529
5461
  static convertInlineCss(html: string, additionalStyleNodes?: HTMLStyleElement[]): string;
5530
5462
  /**
5463
+ * @deprecated Use new HtmlSanitizer().sanitize() instead
5531
5464
  * Sanitize HTML string, remove any unused HTML node/attribute/CSS.
5532
5465
  * @param html HTML source string
5533
5466
  * @param options Options used for this sanitizing process
@@ -5550,6 +5483,7 @@ class HtmlSanitizer {
5550
5483
  */
5551
5484
  constructor(options?: HtmlSanitizerOptions);
5552
5485
  /**
5486
+ * @deprecated Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead
5553
5487
  * Sanitize HTML string
5554
5488
  * This function will do the following work:
5555
5489
  * 1. Convert global CSS into inline CSS
package/dist/rooster.js CHANGED
@@ -1337,12 +1337,13 @@ module.exports = {
1337
1337
  /* MIT license */
1338
1338
  var colorNames = __webpack_require__(/*! color-name */ "./node_modules/color-name/index.js");
1339
1339
  var swizzle = __webpack_require__(/*! simple-swizzle */ "./node_modules/simple-swizzle/index.js");
1340
+ var hasOwnProperty = Object.hasOwnProperty;
1340
1341
 
1341
1342
  var reverseNames = {};
1342
1343
 
1343
1344
  // create a list of reverse color names
1344
1345
  for (var name in colorNames) {
1345
- if (colorNames.hasOwnProperty(name)) {
1346
+ if (hasOwnProperty.call(colorNames, name)) {
1346
1347
  reverseNames[colorNames[name]] = name;
1347
1348
  }
1348
1349
  }
@@ -1385,9 +1386,9 @@ cs.get.rgb = function (string) {
1385
1386
 
1386
1387
  var abbr = /^#([a-f0-9]{3,4})$/i;
1387
1388
  var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
1388
- var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\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 = /(\D+)/;
1389
+ var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
1390
+ var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
1391
+ var keyword = /^(\w+)$/;
1391
1392
 
1392
1393
  var rgb = [0, 0, 0, 1];
1393
1394
  var match;
@@ -1424,7 +1425,11 @@ cs.get.rgb = function (string) {
1424
1425
  }
1425
1426
 
1426
1427
  if (match[4]) {
1427
- rgb[3] = parseFloat(match[4]);
1428
+ if (match[5]) {
1429
+ rgb[3] = parseFloat(match[4]) * 0.01;
1430
+ } else {
1431
+ rgb[3] = parseFloat(match[4]);
1432
+ }
1428
1433
  }
1429
1434
  } else if (match = string.match(per)) {
1430
1435
  for (i = 0; i < 3; i++) {
@@ -1432,19 +1437,22 @@ cs.get.rgb = function (string) {
1432
1437
  }
1433
1438
 
1434
1439
  if (match[4]) {
1435
- rgb[3] = parseFloat(match[4]);
1440
+ if (match[5]) {
1441
+ rgb[3] = parseFloat(match[4]) * 0.01;
1442
+ } else {
1443
+ rgb[3] = parseFloat(match[4]);
1444
+ }
1436
1445
  }
1437
1446
  } else if (match = string.match(keyword)) {
1438
1447
  if (match[1] === 'transparent') {
1439
1448
  return [0, 0, 0, 0];
1440
1449
  }
1441
1450
 
1442
- rgb = colorNames[match[1]];
1443
-
1444
- if (!rgb) {
1451
+ if (!hasOwnProperty.call(colorNames, match[1])) {
1445
1452
  return null;
1446
1453
  }
1447
1454
 
1455
+ rgb = colorNames[match[1]];
1448
1456
  rgb[3] = 1;
1449
1457
 
1450
1458
  return rgb;
@@ -1465,12 +1473,12 @@ cs.get.hsl = function (string) {
1465
1473
  return null;
1466
1474
  }
1467
1475
 
1468
- var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d\.]+)\s*)?\)$/;
1476
+ 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*)?\)$/;
1469
1477
  var match = string.match(hsl);
1470
1478
 
1471
1479
  if (match) {
1472
1480
  var alpha = parseFloat(match[4]);
1473
- var h = (parseFloat(match[1]) + 360) % 360;
1481
+ var h = ((parseFloat(match[1]) % 360) + 360) % 360;
1474
1482
  var s = clamp(parseFloat(match[2]), 0, 100);
1475
1483
  var l = clamp(parseFloat(match[3]), 0, 100);
1476
1484
  var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
@@ -1486,7 +1494,7 @@ cs.get.hwb = function (string) {
1486
1494
  return null;
1487
1495
  }
1488
1496
 
1489
- var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
1497
+ 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*)?\)$/;
1490
1498
  var match = string.match(hwb);
1491
1499
 
1492
1500
  if (match) {
@@ -1565,7 +1573,7 @@ function clamp(num, min, max) {
1565
1573
  }
1566
1574
 
1567
1575
  function hexDouble(num) {
1568
- var str = num.toString(16).toUpperCase();
1576
+ var str = Math.round(num).toString(16).toUpperCase();
1569
1577
  return (str.length < 2) ? '0' + str : str;
1570
1578
  }
1571
1579
 
@@ -5449,7 +5457,9 @@ function transformToDarkMode(element, getDarkColor) {
5449
5457
  var attrColor = element.getAttribute(names[1 /* HtmlColor */]);
5450
5458
  if (!element.dataset[names[2 /* CssDataSet */]] &&
5451
5459
  !element.dataset[names[3 /* HtmlDataSet */]] &&
5452
- (styleColor || attrColor)) {
5460
+ (styleColor || attrColor) &&
5461
+ styleColor != 'inherit' // For inherit style, no need to change it and let it keep inherit from parent element
5462
+ ) {
5453
5463
  var newColor = getDarkColor(computedValues[index] || styleColor || attrColor);
5454
5464
  element.style.setProperty(names[0 /* CssColor */], newColor, 'important');
5455
5465
  element.dataset[names[2 /* CssDataSet */]] = styleColor || '';
@@ -5642,6 +5652,9 @@ var CopyPastePlugin = /** @class */ (function () {
5642
5652
  return div;
5643
5653
  };
5644
5654
  CopyPastePlugin.prototype.cleanUpAndRestoreSelection = function (tempDiv, range) {
5655
+ if (roosterjs_editor_dom_1.Browser.isAndroid) {
5656
+ range.collapse();
5657
+ }
5645
5658
  this.editor.select(range);
5646
5659
  tempDiv.style.backgroundColor = '';
5647
5660
  tempDiv.style.color = '';
@@ -8133,7 +8146,7 @@ function extractClipboardItems(items, options) {
8133
8146
  }
8134
8147
  return Promise.all((items || []).map(function (item) {
8135
8148
  var type = item.type;
8136
- if (type.indexOf("image/" /* Image */) == 0 && !data.image) {
8149
+ if (type.indexOf("image/" /* Image */) == 0 && !data.image && item.kind == 'file') {
8137
8150
  data.types.push(type);
8138
8151
  data.image = item.getAsFile();
8139
8152
  return new Promise(function (resolve) {
@@ -9237,6 +9250,7 @@ var HtmlSanitizer = /** @class */ (function () {
9237
9250
  this.unknownTagReplacement = options.unknownTagReplacement;
9238
9251
  }
9239
9252
  /**
9253
+ * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
9240
9254
  * Convert global CSS to inline CSS if any
9241
9255
  * @param html HTML source
9242
9256
  * @param additionalStyleNodes (Optional) additional HTML STYLE elements used as global CSS
@@ -9248,6 +9262,7 @@ var HtmlSanitizer = /** @class */ (function () {
9248
9262
  return sanitizer.exec(html, true /*convertCssOnly*/);
9249
9263
  };
9250
9264
  /**
9265
+ * @deprecated Use new HtmlSanitizer().sanitize() instead
9251
9266
  * Sanitize HTML string, remove any unused HTML node/attribute/CSS.
9252
9267
  * @param html HTML source string
9253
9268
  * @param options Options used for this sanitizing process
@@ -9261,6 +9276,7 @@ var HtmlSanitizer = /** @class */ (function () {
9261
9276
  return sanitizer.exec(html, options.convertCssOnly, currentStyles);
9262
9277
  };
9263
9278
  /**
9279
+ * @deprecated Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead
9264
9280
  * Sanitize HTML string
9265
9281
  * This function will do the following work:
9266
9282
  * 1. Convert global CSS into inline CSS
@@ -9272,7 +9288,7 @@ var HtmlSanitizer = /** @class */ (function () {
9272
9288
  */
9273
9289
  HtmlSanitizer.prototype.exec = function (html, convertCssOnly, currentStyles) {
9274
9290
  var parser = new DOMParser();
9275
- var doc = parser.parseFromString(unsafeConvertToTrustedHTML(html) || '', 'text/html');
9291
+ var doc = parser.parseFromString(html || '', 'text/html');
9276
9292
  if (doc && doc.body && doc.body.firstChild) {
9277
9293
  this.convertGlobalCssToInlineCss(doc);
9278
9294
  if (!convertCssOnly) {
@@ -9478,15 +9494,6 @@ var HtmlSanitizer = /** @class */ (function () {
9478
9494
  return HtmlSanitizer;
9479
9495
  }());
9480
9496
  exports.default = HtmlSanitizer;
9481
- var trustedTypes = window.trustedTypes;
9482
- var policy = trustedTypes === null || trustedTypes === void 0 ? void 0 : trustedTypes.createPolicy('roosterjsUnsafeConvertHTML', {
9483
- // This is unsafe. However, we only use this function for HtmlSanitizer which we will
9484
- // sanitize HTML tree by our own code. So we just directly return the HTML string here.
9485
- createHTML: function (html) { return html; },
9486
- });
9487
- var unsafeConvertToTrustedHTML = policy
9488
- ? function (html) { return policy.createHTML(html || ''); }
9489
- : function (html) { return html; };
9490
9497
 
9491
9498
 
9492
9499
  /***/ }),
@@ -13631,6 +13638,7 @@ function cloneNode(node) {
13631
13638
 
13632
13639
  Object.defineProperty(exports, "__esModule", { value: true });
13633
13640
  exports.Browser = exports.getBrowserInfo = void 0;
13641
+ var isAndroidRegex = /android/i;
13634
13642
  /**
13635
13643
  * Get current browser information from user agent string
13636
13644
  * @param userAgent The userAgent string of a browser
@@ -13666,6 +13674,7 @@ function getBrowserInfo(userAgent, appVersion) {
13666
13674
  }
13667
13675
  var isMac = appVersion.indexOf('Mac') != -1;
13668
13676
  var isWin = appVersion.indexOf('Win') != -1 || appVersion.indexOf('NT') != -1;
13677
+ var isAndroid = isAndroidRegex.test(userAgent);
13669
13678
  return {
13670
13679
  isMac: isMac,
13671
13680
  isWin: isWin,
@@ -13677,6 +13686,7 @@ function getBrowserInfo(userAgent, appVersion) {
13677
13686
  isFirefox: isFirefox,
13678
13687
  isEdge: isEdge,
13679
13688
  isIEOrEdge: isIE || isEdge,
13689
+ isAndroid: isAndroid,
13680
13690
  };
13681
13691
  }
13682
13692
  exports.getBrowserInfo = getBrowserInfo;
@@ -16535,7 +16545,7 @@ function getCacheNextSibling(event, editor) {
16535
16545
  function prepareAutoBullet(editor, range) {
16536
16546
  var block = editor.getBlockElementAtNode(range.startContainer);
16537
16547
  var endNode = block === null || block === void 0 ? void 0 : block.getEndNode();
16538
- if (endNode && (0, roosterjs_editor_dom_1.getTagOfNode)(endNode) != 'BR' && (block === null || block === void 0 ? void 0 : block.getTextContent().trim()) === '') {
16548
+ if (endNode && (0, roosterjs_editor_dom_1.getTagOfNode)(endNode) != 'BR') {
16539
16549
  var br = editor.getDocument().createElement('BR');
16540
16550
  if ((0, roosterjs_editor_dom_1.isBlockElement)(endNode)) {
16541
16551
  endNode.appendChild(br);