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.
@@ -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
 
@@ -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
  /**
@@ -2256,6 +2260,7 @@ export interface HtmlSanitizerOptions {
2256
2260
  }
2257
2261
 
2258
2262
  /**
2263
+ * @deprecated
2259
2264
  * Options for sanitizeHtml function
2260
2265
  */
2261
2266
  export interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
@@ -2272,86 +2277,12 @@ export interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
2272
2277
 
2273
2278
  /**
2274
2279
  * 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
2280
  */
2278
2281
  export interface TargetWindowBase {
2279
2282
  Range: Range;
2280
2283
  Node: Node;
2281
2284
  ParentNode: ParentNode;
2282
2285
  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
2286
  HTMLElement: HTMLElement;
2356
2287
  HTMLUnknownElement: HTMLUnknownElement;
2357
2288
  HTMLUListElement: HTMLUListElement;
@@ -4819,7 +4750,7 @@ export function toArray<T>(array: readonly T[]): T[];
4819
4750
  * @param obj Object to check
4820
4751
  * @param typeName Target type name
4821
4752
  */
4822
- export function safeInstanceOf<T extends keyof TargetWindow>(obj: any, typeName: T): obj is TargetWindow[T];
4753
+ export function safeInstanceOf<T extends keyof W, W extends TargetWindow = TargetWindow>(obj: any, typeName: T): obj is W[T];
4823
4754
 
4824
4755
  /**
4825
4756
  * Read a file object and invoke a callback function with the data url of this file
@@ -5521,12 +5452,14 @@ export function canUndoAutoComplete(snapshots: Snapshots): boolean;
5521
5452
  */
5522
5453
  export class HtmlSanitizer {
5523
5454
  /**
5455
+ * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
5524
5456
  * Convert global CSS to inline CSS if any
5525
5457
  * @param html HTML source
5526
5458
  * @param additionalStyleNodes (Optional) additional HTML STYLE elements used as global CSS
5527
5459
  */
5528
5460
  static convertInlineCss(html: string, additionalStyleNodes?: HTMLStyleElement[]): string;
5529
5461
  /**
5462
+ * @deprecated Use new HtmlSanitizer().sanitize() instead
5530
5463
  * Sanitize HTML string, remove any unused HTML node/attribute/CSS.
5531
5464
  * @param html HTML source string
5532
5465
  * @param options Options used for this sanitizing process
@@ -5549,6 +5482,7 @@ export class HtmlSanitizer {
5549
5482
  */
5550
5483
  constructor(options?: HtmlSanitizerOptions);
5551
5484
  /**
5485
+ * @deprecated Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead
5552
5486
  * Sanitize HTML string
5553
5487
  * This function will do the following work:
5554
5488
  * 1. Convert global CSS into inline CSS
@@ -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
 
@@ -5448,7 +5456,9 @@ function transformToDarkMode(element, getDarkColor) {
5448
5456
  var attrColor = element.getAttribute(names[1 /* HtmlColor */]);
5449
5457
  if (!element.dataset[names[2 /* CssDataSet */]] &&
5450
5458
  !element.dataset[names[3 /* HtmlDataSet */]] &&
5451
- (styleColor || attrColor)) {
5459
+ (styleColor || attrColor) &&
5460
+ styleColor != 'inherit' // For inherit style, no need to change it and let it keep inherit from parent element
5461
+ ) {
5452
5462
  var newColor = getDarkColor(computedValues[index] || styleColor || attrColor);
5453
5463
  element.style.setProperty(names[0 /* CssColor */], newColor, 'important');
5454
5464
  element.dataset[names[2 /* CssDataSet */]] = styleColor || '';
@@ -5641,6 +5651,9 @@ var CopyPastePlugin = /** @class */ (function () {
5641
5651
  return div;
5642
5652
  };
5643
5653
  CopyPastePlugin.prototype.cleanUpAndRestoreSelection = function (tempDiv, range) {
5654
+ if (roosterjs_editor_dom_1.Browser.isAndroid) {
5655
+ range.collapse();
5656
+ }
5644
5657
  this.editor.select(range);
5645
5658
  tempDiv.style.backgroundColor = '';
5646
5659
  tempDiv.style.color = '';
@@ -8132,7 +8145,7 @@ function extractClipboardItems(items, options) {
8132
8145
  }
8133
8146
  return Promise.all((items || []).map(function (item) {
8134
8147
  var type = item.type;
8135
- if (type.indexOf("image/" /* Image */) == 0 && !data.image) {
8148
+ if (type.indexOf("image/" /* Image */) == 0 && !data.image && item.kind == 'file') {
8136
8149
  data.types.push(type);
8137
8150
  data.image = item.getAsFile();
8138
8151
  return new Promise(function (resolve) {
@@ -9236,6 +9249,7 @@ var HtmlSanitizer = /** @class */ (function () {
9236
9249
  this.unknownTagReplacement = options.unknownTagReplacement;
9237
9250
  }
9238
9251
  /**
9252
+ * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
9239
9253
  * Convert global CSS to inline CSS if any
9240
9254
  * @param html HTML source
9241
9255
  * @param additionalStyleNodes (Optional) additional HTML STYLE elements used as global CSS
@@ -9247,6 +9261,7 @@ var HtmlSanitizer = /** @class */ (function () {
9247
9261
  return sanitizer.exec(html, true /*convertCssOnly*/);
9248
9262
  };
9249
9263
  /**
9264
+ * @deprecated Use new HtmlSanitizer().sanitize() instead
9250
9265
  * Sanitize HTML string, remove any unused HTML node/attribute/CSS.
9251
9266
  * @param html HTML source string
9252
9267
  * @param options Options used for this sanitizing process
@@ -9260,6 +9275,7 @@ var HtmlSanitizer = /** @class */ (function () {
9260
9275
  return sanitizer.exec(html, options.convertCssOnly, currentStyles);
9261
9276
  };
9262
9277
  /**
9278
+ * @deprecated Use HtmlSanitizer.convertGlobalCssToInlineCss() and HtmlSanitizer.sanitize() instead
9263
9279
  * Sanitize HTML string
9264
9280
  * This function will do the following work:
9265
9281
  * 1. Convert global CSS into inline CSS
@@ -9271,7 +9287,7 @@ var HtmlSanitizer = /** @class */ (function () {
9271
9287
  */
9272
9288
  HtmlSanitizer.prototype.exec = function (html, convertCssOnly, currentStyles) {
9273
9289
  var parser = new DOMParser();
9274
- var doc = parser.parseFromString(unsafeConvertToTrustedHTML(html) || '', 'text/html');
9290
+ var doc = parser.parseFromString(html || '', 'text/html');
9275
9291
  if (doc && doc.body && doc.body.firstChild) {
9276
9292
  this.convertGlobalCssToInlineCss(doc);
9277
9293
  if (!convertCssOnly) {
@@ -9477,15 +9493,6 @@ var HtmlSanitizer = /** @class */ (function () {
9477
9493
  return HtmlSanitizer;
9478
9494
  }());
9479
9495
  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
9496
 
9490
9497
 
9491
9498
  /***/ }),
@@ -13630,6 +13637,7 @@ function cloneNode(node) {
13630
13637
 
13631
13638
  Object.defineProperty(exports, "__esModule", { value: true });
13632
13639
  exports.Browser = exports.getBrowserInfo = void 0;
13640
+ var isAndroidRegex = /android/i;
13633
13641
  /**
13634
13642
  * Get current browser information from user agent string
13635
13643
  * @param userAgent The userAgent string of a browser
@@ -13665,6 +13673,7 @@ function getBrowserInfo(userAgent, appVersion) {
13665
13673
  }
13666
13674
  var isMac = appVersion.indexOf('Mac') != -1;
13667
13675
  var isWin = appVersion.indexOf('Win') != -1 || appVersion.indexOf('NT') != -1;
13676
+ var isAndroid = isAndroidRegex.test(userAgent);
13668
13677
  return {
13669
13678
  isMac: isMac,
13670
13679
  isWin: isWin,
@@ -13676,6 +13685,7 @@ function getBrowserInfo(userAgent, appVersion) {
13676
13685
  isFirefox: isFirefox,
13677
13686
  isEdge: isEdge,
13678
13687
  isIEOrEdge: isIE || isEdge,
13688
+ isAndroid: isAndroid,
13679
13689
  };
13680
13690
  }
13681
13691
  exports.getBrowserInfo = getBrowserInfo;
@@ -16534,7 +16544,7 @@ function getCacheNextSibling(event, editor) {
16534
16544
  function prepareAutoBullet(editor, range) {
16535
16545
  var block = editor.getBlockElementAtNode(range.startContainer);
16536
16546
  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()) === '') {
16547
+ if (endNode && (0, roosterjs_editor_dom_1.getTagOfNode)(endNode) != 'BR') {
16538
16548
  var br = editor.getDocument().createElement('BR');
16539
16549
  if ((0, roosterjs_editor_dom_1.isBlockElement)(endNode)) {
16540
16550
  endNode.appendChild(br);