roosterjs-content-model-core 0.21.0 → 0.21.1

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.
@@ -4,9 +4,9 @@ import type { ColorKeyAndValue, DarkColorHandler, ModeIndependentColor } from 'r
4
4
  */
5
5
  export declare class DarkColorHandlerImpl implements DarkColorHandler {
6
6
  private contentDiv;
7
+ private getDarkColor;
7
8
  private knownColors;
8
- readonly baseLightness: number;
9
- constructor(contentDiv: HTMLElement, baseDarkColor?: string);
9
+ constructor(contentDiv: HTMLElement, getDarkColor: (color: string) => string);
10
10
  /**
11
11
  * Get a copy of known colors
12
12
  * @returns
@@ -2,9 +2,7 @@
2
2
  var _a, _b;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.DarkColorHandlerImpl = void 0;
5
- var Color = require("color");
6
5
  var roosterjs_editor_dom_1 = require("roosterjs-editor-dom");
7
- var DefaultLightness = 21.25; // Lightness for #333333
8
6
  var VARIABLE_REGEX = /^\s*var\(\s*(\-\-[a-zA-Z0-9\-_]+)\s*(?:,\s*(.*))?\)\s*$/;
9
7
  var VARIABLE_PREFIX = 'var(';
10
8
  var COLOR_VAR_PREFIX = 'darkColor';
@@ -27,10 +25,10 @@ var ColorAttributeName = [
27
25
  * @internal
28
26
  */
29
27
  var DarkColorHandlerImpl = /** @class */ (function () {
30
- function DarkColorHandlerImpl(contentDiv, baseDarkColor) {
28
+ function DarkColorHandlerImpl(contentDiv, getDarkColor) {
31
29
  this.contentDiv = contentDiv;
30
+ this.getDarkColor = getDarkColor;
32
31
  this.knownColors = {};
33
- this.baseLightness = getLightness(baseDarkColor);
34
32
  }
35
33
  /**
36
34
  * Get a copy of known colors
@@ -58,7 +56,7 @@ var DarkColorHandlerImpl = /** @class */ (function () {
58
56
  colorKey =
59
57
  colorKey || "--" + COLOR_VAR_PREFIX + "_" + lightModeColor.replace(/[^\d\w]/g, '_');
60
58
  if (!this.knownColors[colorKey]) {
61
- darkModeColor = darkModeColor || getDarkColor(lightModeColor, this.baseLightness);
59
+ darkModeColor = darkModeColor || this.getDarkColor(lightModeColor);
62
60
  this.knownColors[colorKey] = { lightModeColor: lightModeColor, darkModeColor: darkModeColor };
63
61
  this.contentDiv.style.setProperty(colorKey, darkModeColor);
64
62
  }
@@ -157,28 +155,4 @@ var DarkColorHandlerImpl = /** @class */ (function () {
157
155
  return DarkColorHandlerImpl;
158
156
  }());
159
157
  exports.DarkColorHandlerImpl = DarkColorHandlerImpl;
160
- function getDarkColor(color, baseLightness) {
161
- try {
162
- var computedColor = Color(color || undefined);
163
- var colorLab = computedColor.lab().array();
164
- var newLValue = (100 - colorLab[0]) * ((100 - baseLightness) / 100) + baseLightness;
165
- color = Color.lab(newLValue, colorLab[1], colorLab[2])
166
- .rgb()
167
- .alpha(computedColor.alpha())
168
- .toString();
169
- }
170
- catch (_a) { }
171
- return color;
172
- }
173
- function getLightness(color) {
174
- var result = DefaultLightness;
175
- if (color) {
176
- try {
177
- var computedColor = Color(color || undefined);
178
- result = computedColor.lab().array()[0];
179
- }
180
- catch (_a) { }
181
- }
182
- return result;
183
- }
184
158
  //# sourceMappingURL=DarkColorHandlerImpl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DarkColorHandlerImpl.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/DarkColorHandlerImpl.ts"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,6DAA2E;AAO3E,IAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,wBAAwB;AACxD,IAAM,cAAc,GAAG,yDAAyD,CAAC;AACjF,IAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,IAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,IAAW,kBAGV;AAHD,WAAW,kBAAkB;IACzB,mEAAY,CAAA;IACZ,qEAAa,CAAA;AACjB,CAAC,EAHU,kBAAkB,KAAlB,kBAAkB,QAG5B;AACD,IAAM,kBAAkB,GAA8C;;Q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CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;SAC3C;QAAC,WAAM,GAAE;KACb;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import * as Color from 'color';\nimport { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';\nimport type {\n ColorKeyAndValue,\n DarkColorHandler,\n ModeIndependentColor,\n} from 'roosterjs-editor-types';\n\nconst DefaultLightness = 21.25; // Lightness for #333333\nconst VARIABLE_REGEX = /^\\s*var\\(\\s*(\\-\\-[a-zA-Z0-9\\-_]+)\\s*(?:,\\s*(.*))?\\)\\s*$/;\nconst VARIABLE_PREFIX = 'var(';\nconst COLOR_VAR_PREFIX = 'darkColor';\nconst enum ColorAttributeEnum {\n CssColor = 0,\n HtmlColor = 1,\n}\nconst ColorAttributeName: { [key in ColorAttributeEnum]: string }[] = [\n {\n [ColorAttributeEnum.CssColor]: 'color',\n [ColorAttributeEnum.HtmlColor]: 'color',\n },\n {\n [ColorAttributeEnum.CssColor]: 'background-color',\n [ColorAttributeEnum.HtmlColor]: 'bgcolor',\n },\n];\n\n/**\n * @internal\n */\nexport class DarkColorHandlerImpl implements DarkColorHandler {\n private knownColors: Record<string, Readonly<ModeIndependentColor>> = {};\n readonly baseLightness: number;\n\n constructor(private contentDiv: HTMLElement, baseDarkColor?: string) {\n this.baseLightness = getLightness(baseDarkColor);\n }\n\n /**\n * Get a copy of known colors\n * @returns\n */\n getKnownColorsCopy() {\n return Object.values(this.knownColors);\n }\n\n /**\n * Given a light mode color value and an optional dark mode color value, register this color\n * so that editor can handle it, then return the CSS color value for current color mode.\n * @param lightModeColor Light mode color value\n * @param isDarkMode Whether current color mode is dark mode\n * @param darkModeColor Optional dark mode color value. If not passed, we will calculate one.\n */\n registerColor(lightModeColor: string, isDarkMode: boolean, darkModeColor?: string): string {\n const parsedColor = this.parseColorValue(lightModeColor);\n let colorKey: string | undefined;\n\n if (parsedColor) {\n lightModeColor = parsedColor.lightModeColor;\n darkModeColor = parsedColor.darkModeColor || darkModeColor;\n colorKey = parsedColor.key;\n }\n\n if (isDarkMode && lightModeColor) {\n colorKey =\n colorKey || `--${COLOR_VAR_PREFIX}_${lightModeColor.replace(/[^\\d\\w]/g, '_')}`;\n\n if (!this.knownColors[colorKey]) {\n darkModeColor = darkModeColor || getDarkColor(lightModeColor, this.baseLightness);\n\n this.knownColors[colorKey] = { lightModeColor, darkModeColor };\n this.contentDiv.style.setProperty(colorKey, darkModeColor);\n }\n\n return `var(${colorKey}, ${lightModeColor})`;\n } else {\n return lightModeColor;\n }\n }\n\n /**\n * Reset known color record, clean up registered color variables.\n */\n reset(): void {\n getObjectKeys(this.knownColors).forEach(key => this.contentDiv.style.removeProperty(key));\n this.knownColors = {};\n }\n\n /**\n * Parse an existing color value, if it is in variable-based color format, extract color key,\n * light color and query related dark color if any\n * @param color The color string to parse\n * @param isInDarkMode Whether current content is in dark mode. When set to true, if the color value is not in dark var format,\n * we will treat is as a dark mode color and try to find a matched dark mode color.\n */\n parseColorValue(color: string | undefined | null, isInDarkMode?: boolean): ColorKeyAndValue {\n let key: string | undefined;\n let lightModeColor = '';\n let darkModeColor: string | undefined;\n\n if (color) {\n const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null;\n\n if (match) {\n if (match[2]) {\n key = match[1];\n lightModeColor = match[2];\n darkModeColor = this.knownColors[key]?.darkModeColor;\n } else {\n lightModeColor = '';\n }\n } else if (isInDarkMode) {\n // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code\n // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related\n // light color as light mode color. Otherwise we need to drop this color to avoid show \"white on white\" content.\n lightModeColor = this.findLightColorFromDarkColor(color) || '';\n\n if (lightModeColor) {\n darkModeColor = color;\n }\n } else {\n lightModeColor = color;\n }\n }\n\n return { key, lightModeColor, darkModeColor };\n }\n\n /**\n * Find related light mode color from dark mode color.\n * @param darkColor The existing dark color\n */\n findLightColorFromDarkColor(darkColor: string): string | null {\n const rgbSearch = parseColor(darkColor);\n\n if (rgbSearch) {\n const key = getObjectKeys(this.knownColors).find(key => {\n const rgbCurrent = parseColor(this.knownColors[key].darkModeColor);\n\n return (\n rgbCurrent &&\n rgbCurrent[0] == rgbSearch[0] &&\n rgbCurrent[1] == rgbSearch[1] &&\n rgbCurrent[2] == rgbSearch[2]\n );\n });\n\n if (key) {\n return this.knownColors[key].lightModeColor;\n }\n }\n\n return null;\n }\n\n /**\n * Transform element color, from dark to light or from light to dark\n * @param element The element to transform color\n * @param fromDarkMode Whether this is transforming color from dark mode\n * @param toDarkMode Whether this is transforming color to dark mode\n */\n transformElementColor(element: HTMLElement, fromDarkMode: boolean, toDarkMode: boolean): void {\n ColorAttributeName.forEach((names, i) => {\n const color = this.parseColorValue(\n element.style.getPropertyValue(names[ColorAttributeEnum.CssColor]) ||\n element.getAttribute(names[ColorAttributeEnum.HtmlColor]),\n !!fromDarkMode\n ).lightModeColor;\n\n element.style.setProperty(names[ColorAttributeEnum.CssColor], null);\n element.removeAttribute(names[ColorAttributeEnum.HtmlColor]);\n\n if (color && color != 'inherit') {\n setColor(element, color, i != 0, toDarkMode, false /*shouldAdaptFontColor*/, this);\n }\n });\n }\n}\n\nfunction getDarkColor(color: string, baseLightness: number): string {\n try {\n const computedColor = Color(color || undefined);\n const colorLab = computedColor.lab().array();\n const newLValue = (100 - colorLab[0]) * ((100 - baseLightness) / 100) + baseLightness;\n color = Color.lab(newLValue, colorLab[1], colorLab[2])\n .rgb()\n .alpha(computedColor.alpha())\n .toString();\n } catch {}\n\n return color;\n}\n\nfunction getLightness(color?: string): number {\n let result = DefaultLightness;\n\n if (color) {\n try {\n const computedColor = Color(color || undefined);\n result = computedColor.lab().array()[0];\n } catch {}\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"DarkColorHandlerImpl.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/DarkColorHandlerImpl.ts"],"names":[],"mappings":";;;;AAAA,6DAA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C,KAAK,EAAE,CAAC;YAChC,IAAM,KAAK,GAAG,KAAI,CAAC,eAAe,CAC9B,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,kBAA6B,CAAC;gBAC9D,OAAO,CAAC,YAAY,CAAC,KAAK,mBAA8B,CAAC,EAC7D,CAAC,CAAC,YAAY,CACjB,CAAC,cAAc,CAAC;YAEjB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,kBAA6B,EAAE,IAAI,CAAC,CAAC;YACpE,OAAO,CAAC,eAAe,CAAC,KAAK,mBAA8B,CAAC,CAAC;YAE7D,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,EAAE;gBAC7B,IAAA,+BAAQ,EAAC,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,wBAAwB,EAAE,KAAI,CAAC,CAAC;aACtF;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,2BAAC;AAAD,CAAC,AAhJD,IAgJC;AAhJY,oDAAoB","sourcesContent":["import { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';\nimport type {\n ColorKeyAndValue,\n DarkColorHandler,\n ModeIndependentColor,\n} from 'roosterjs-editor-types';\n\nconst VARIABLE_REGEX = /^\\s*var\\(\\s*(\\-\\-[a-zA-Z0-9\\-_]+)\\s*(?:,\\s*(.*))?\\)\\s*$/;\nconst VARIABLE_PREFIX = 'var(';\nconst COLOR_VAR_PREFIX = 'darkColor';\nconst enum ColorAttributeEnum {\n CssColor = 0,\n HtmlColor = 1,\n}\nconst ColorAttributeName: { [key in ColorAttributeEnum]: string }[] = [\n {\n [ColorAttributeEnum.CssColor]: 'color',\n [ColorAttributeEnum.HtmlColor]: 'color',\n },\n {\n [ColorAttributeEnum.CssColor]: 'background-color',\n [ColorAttributeEnum.HtmlColor]: 'bgcolor',\n },\n];\n\n/**\n * @internal\n */\nexport class DarkColorHandlerImpl implements DarkColorHandler {\n private knownColors: Record<string, Readonly<ModeIndependentColor>> = {};\n\n constructor(private contentDiv: HTMLElement, private getDarkColor: (color: string) => string) {}\n\n /**\n * Get a copy of known colors\n * @returns\n */\n getKnownColorsCopy() {\n return Object.values(this.knownColors);\n }\n\n /**\n * Given a light mode color value and an optional dark mode color value, register this color\n * so that editor can handle it, then return the CSS color value for current color mode.\n * @param lightModeColor Light mode color value\n * @param isDarkMode Whether current color mode is dark mode\n * @param darkModeColor Optional dark mode color value. If not passed, we will calculate one.\n */\n registerColor(lightModeColor: string, isDarkMode: boolean, darkModeColor?: string): string {\n const parsedColor = this.parseColorValue(lightModeColor);\n let colorKey: string | undefined;\n\n if (parsedColor) {\n lightModeColor = parsedColor.lightModeColor;\n darkModeColor = parsedColor.darkModeColor || darkModeColor;\n colorKey = parsedColor.key;\n }\n\n if (isDarkMode && lightModeColor) {\n colorKey =\n colorKey || `--${COLOR_VAR_PREFIX}_${lightModeColor.replace(/[^\\d\\w]/g, '_')}`;\n\n if (!this.knownColors[colorKey]) {\n darkModeColor = darkModeColor || this.getDarkColor(lightModeColor);\n\n this.knownColors[colorKey] = { lightModeColor, darkModeColor };\n this.contentDiv.style.setProperty(colorKey, darkModeColor);\n }\n\n return `var(${colorKey}, ${lightModeColor})`;\n } else {\n return lightModeColor;\n }\n }\n\n /**\n * Reset known color record, clean up registered color variables.\n */\n reset(): void {\n getObjectKeys(this.knownColors).forEach(key => this.contentDiv.style.removeProperty(key));\n this.knownColors = {};\n }\n\n /**\n * Parse an existing color value, if it is in variable-based color format, extract color key,\n * light color and query related dark color if any\n * @param color The color string to parse\n * @param isInDarkMode Whether current content is in dark mode. When set to true, if the color value is not in dark var format,\n * we will treat is as a dark mode color and try to find a matched dark mode color.\n */\n parseColorValue(color: string | undefined | null, isInDarkMode?: boolean): ColorKeyAndValue {\n let key: string | undefined;\n let lightModeColor = '';\n let darkModeColor: string | undefined;\n\n if (color) {\n const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null;\n\n if (match) {\n if (match[2]) {\n key = match[1];\n lightModeColor = match[2];\n darkModeColor = this.knownColors[key]?.darkModeColor;\n } else {\n lightModeColor = '';\n }\n } else if (isInDarkMode) {\n // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code\n // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related\n // light color as light mode color. Otherwise we need to drop this color to avoid show \"white on white\" content.\n lightModeColor = this.findLightColorFromDarkColor(color) || '';\n\n if (lightModeColor) {\n darkModeColor = color;\n }\n } else {\n lightModeColor = color;\n }\n }\n\n return { key, lightModeColor, darkModeColor };\n }\n\n /**\n * Find related light mode color from dark mode color.\n * @param darkColor The existing dark color\n */\n findLightColorFromDarkColor(darkColor: string): string | null {\n const rgbSearch = parseColor(darkColor);\n\n if (rgbSearch) {\n const key = getObjectKeys(this.knownColors).find(key => {\n const rgbCurrent = parseColor(this.knownColors[key].darkModeColor);\n\n return (\n rgbCurrent &&\n rgbCurrent[0] == rgbSearch[0] &&\n rgbCurrent[1] == rgbSearch[1] &&\n rgbCurrent[2] == rgbSearch[2]\n );\n });\n\n if (key) {\n return this.knownColors[key].lightModeColor;\n }\n }\n\n return null;\n }\n\n /**\n * Transform element color, from dark to light or from light to dark\n * @param element The element to transform color\n * @param fromDarkMode Whether this is transforming color from dark mode\n * @param toDarkMode Whether this is transforming color to dark mode\n */\n transformElementColor(element: HTMLElement, fromDarkMode: boolean, toDarkMode: boolean): void {\n ColorAttributeName.forEach((names, i) => {\n const color = this.parseColorValue(\n element.style.getPropertyValue(names[ColorAttributeEnum.CssColor]) ||\n element.getAttribute(names[ColorAttributeEnum.HtmlColor]),\n !!fromDarkMode\n ).lightModeColor;\n\n element.style.setProperty(names[ColorAttributeEnum.CssColor], null);\n element.removeAttribute(names[ColorAttributeEnum.HtmlColor]);\n\n if (color && color != 'inherit') {\n setColor(element, color, i != 0, toDarkMode, false /*shouldAdaptFontColor*/, this);\n }\n });\n }\n}\n"]}
@@ -12,6 +12,7 @@ var standaloneCoreApiMap_1 = require("./standaloneCoreApiMap");
12
12
  * @param options Editor options
13
13
  */
14
14
  function createStandaloneEditorCore(contentDiv, options, unportedCoreApiMap, unportedCorePluginState, tempPlugins) {
15
+ var _a;
15
16
  var corePlugins = (0, createStandaloneEditorCorePlugins_1.createStandaloneEditorCorePlugins)(options, contentDiv);
16
17
  return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({ contentDiv: contentDiv, api: (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, standaloneCoreApiMap_1.standaloneCoreApiMap), unportedCoreApiMap), options.coreApiOverride), originalApi: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, standaloneCoreApiMap_1.standaloneCoreApiMap), unportedCoreApiMap), plugins: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([
17
18
  corePlugins.cache,
@@ -22,7 +23,7 @@ function createStandaloneEditorCore(contentDiv, options, unportedCoreApiMap, unp
22
23
  corePlugins.entity
23
24
  ], (0, tslib_1.__read)(tempPlugins), false), [
24
25
  corePlugins.lifecycle,
25
- ], false), environment: createEditorEnvironment(), darkColorHandler: new DarkColorHandlerImpl_1.DarkColorHandlerImpl(contentDiv, options.baseDarkColor), trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler }, (0, createStandaloneEditorDefaultSettings_1.createStandaloneEditorDefaultSettings)(options)), getPluginState(corePlugins)), unportedCorePluginState);
26
+ ], false), environment: createEditorEnvironment(), darkColorHandler: new DarkColorHandlerImpl_1.DarkColorHandlerImpl(contentDiv, (_a = options.getDarkColor) !== null && _a !== void 0 ? _a : getDarkColorFallback), trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler }, (0, createStandaloneEditorDefaultSettings_1.createStandaloneEditorDefaultSettings)(options)), getPluginState(corePlugins)), unportedCorePluginState);
26
27
  }
27
28
  exports.createStandaloneEditorCore = createStandaloneEditorCore;
28
29
  function createEditorEnvironment() {
@@ -54,4 +55,8 @@ function getPluginState(corePlugins) {
54
55
  selection: corePlugins.selection.getState(),
55
56
  };
56
57
  }
58
+ // A fallback function, always return original color
59
+ function getDarkColorFallback(color) {
60
+ return color;
61
+ }
57
62
  //# sourceMappingURL=createStandaloneEditorCore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createStandaloneEditorCore.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/createStandaloneEditorCore.ts"],"names":[],"mappings":";;;;AAAA,qGAAoG;AACpG,iGAAgG;AAChG,+DAA8D;AAC9D,+DAA8D;AAY9D;;;;GAIG;AACH,SAAgB,0BAA0B,CACtC,UAA0B,EAC1B,OAAgC,EAChC,kBAAsC,EACtC,uBAAgD,EAChD,WAA2B;IAE3B,IAAM,WAAW,GAAG,IAAA,qEAAiC,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAE3E,2EACI,UAAU,YAAA,EACV,GAAG,wEAAO,2CAAoB,GAAK,kBAAkB,GAAK,OAAO,CAAC,eAAe,GACjF,WAAW,kDAAO,2CAAoB,GAAK,kBAAkB,GAC7D,OAAO;YACH,WAAW,CAAC,KAAK;YACjB,WAAW,CAAC,MAAM;YAClB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,QAAQ;YACpB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,MAAM;+BACf,WAAW;YACd,WAAW,CAAC,SAAS;mBAEzB,WAAW,EAAE,uBAAuB,EAAE,EACtC,gBAAgB,EAAE,IAAI,2CAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,EAC7E,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,uBAAuB,IACtE,IAAA,6EAAqC,EAAC,OAAO,CAAC,GAC9C,cAAc,CAAC,WAAW,CAAC,GAC3B,uBAAuB,EAC5B;AACN,CAAC;AA9BD,gEA8BC;AAED,SAAS,uBAAuB;IAC5B,oHAAoH;IACpH,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;IAE7C,OAAO;QACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;QACrC,QAAQ,EACJ,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC/B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;KACvC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,IAAY;IAChD,OAAO,IAAI,CAAC;AAChB,CAAC;AAFD,0DAEC;AAED,SAAS,cAAc,CAAC,WAAwC;IAC5D,OAAO;QACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;KAC9C,CAAC;AACN,CAAC","sourcesContent":["import { createStandaloneEditorCorePlugins } from '../corePlugin/createStandaloneEditorCorePlugins';\nimport { createStandaloneEditorDefaultSettings } from './createStandaloneEditorDefaultSettings';\nimport { DarkColorHandlerImpl } from './DarkColorHandlerImpl';\nimport { standaloneCoreApiMap } from './standaloneCoreApiMap';\nimport type { EditorPlugin } from 'roosterjs-editor-types';\nimport type {\n EditorEnvironment,\n StandaloneEditorCore,\n StandaloneEditorCorePluginState,\n StandaloneEditorCorePlugins,\n StandaloneEditorOptions,\n UnportedCoreApiMap,\n UnportedCorePluginState,\n} from 'roosterjs-content-model-types';\n\n/**\n * A temporary function to create Standalone Editor core\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createStandaloneEditorCore(\n contentDiv: HTMLDivElement,\n options: StandaloneEditorOptions,\n unportedCoreApiMap: UnportedCoreApiMap,\n unportedCorePluginState: UnportedCorePluginState,\n tempPlugins: EditorPlugin[]\n): StandaloneEditorCore {\n const corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);\n\n return {\n contentDiv,\n api: { ...standaloneCoreApiMap, ...unportedCoreApiMap, ...options.coreApiOverride },\n originalApi: { ...standaloneCoreApiMap, ...unportedCoreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...tempPlugins,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(),\n darkColorHandler: new DarkColorHandlerImpl(contentDiv, options.baseDarkColor),\n trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,\n ...createStandaloneEditorDefaultSettings(options),\n ...getPluginState(corePlugins),\n ...unportedCorePluginState,\n };\n}\n\nfunction createEditorEnvironment(): EditorEnvironment {\n // It is ok to use global window here since the environment should always be the same for all windows in one session\n const userAgent = window.navigator.userAgent;\n\n return {\n isMac: window.navigator.appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isSafari:\n userAgent.indexOf('Safari') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n };\n}\n\n/**\n * @internal export for test only\n */\nexport function defaultTrustHtmlHandler(html: string) {\n return html;\n}\n\nfunction getPluginState(corePlugins: StandaloneEditorCorePlugins): StandaloneEditorCorePluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n };\n}\n"]}
1
+ {"version":3,"file":"createStandaloneEditorCore.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/createStandaloneEditorCore.ts"],"names":[],"mappings":";;;;AAAA,qGAAoG;AACpG,iGAAgG;AAChG,+DAA8D;AAC9D,+DAA8D;AAY9D;;;;GAIG;AACH,SAAgB,0BAA0B,CACtC,UAA0B,EAC1B,OAAgC,EAChC,kBAAsC,EACtC,uBAAgD,EAChD,WAA2B;;IAE3B,IAAM,WAAW,GAAG,IAAA,qEAAiC,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAE3E,2EACI,UAAU,YAAA,EACV,GAAG,wEAAO,2CAAoB,GAAK,kBAAkB,GAAK,OAAO,CAAC,eAAe,GACjF,WAAW,kDAAO,2CAAoB,GAAK,kBAAkB,GAC7D,OAAO;YACH,WAAW,CAAC,KAAK;YACjB,WAAW,CAAC,MAAM;YAClB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,QAAQ;YACpB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,MAAM;+BACf,WAAW;YACd,WAAW,CAAC,SAAS;mBAEzB,WAAW,EAAE,uBAAuB,EAAE,EACtC,gBAAgB,EAAE,IAAI,2CAAoB,CACtC,UAAU,EACV,MAAA,OAAO,CAAC,YAAY,mCAAI,oBAAoB,CAC/C,EACD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,uBAAuB,IACtE,IAAA,6EAAqC,EAAC,OAAO,CAAC,GAC9C,cAAc,CAAC,WAAW,CAAC,GAC3B,uBAAuB,EAC5B;AACN,CAAC;AAjCD,gEAiCC;AAED,SAAS,uBAAuB;IAC5B,oHAAoH;IACpH,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;IAE7C,OAAO;QACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;QACrC,QAAQ,EACJ,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC/B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;KACvC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,IAAY;IAChD,OAAO,IAAI,CAAC;AAChB,CAAC;AAFD,0DAEC;AAED,SAAS,cAAc,CAAC,WAAwC;IAC5D,OAAO;QACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;KAC9C,CAAC;AACN,CAAC;AAED,oDAAoD;AACpD,SAAS,oBAAoB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { createStandaloneEditorCorePlugins } from '../corePlugin/createStandaloneEditorCorePlugins';\nimport { createStandaloneEditorDefaultSettings } from './createStandaloneEditorDefaultSettings';\nimport { DarkColorHandlerImpl } from './DarkColorHandlerImpl';\nimport { standaloneCoreApiMap } from './standaloneCoreApiMap';\nimport type { EditorPlugin } from 'roosterjs-editor-types';\nimport type {\n EditorEnvironment,\n StandaloneEditorCore,\n StandaloneEditorCorePluginState,\n StandaloneEditorCorePlugins,\n StandaloneEditorOptions,\n UnportedCoreApiMap,\n UnportedCorePluginState,\n} from 'roosterjs-content-model-types';\n\n/**\n * A temporary function to create Standalone Editor core\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createStandaloneEditorCore(\n contentDiv: HTMLDivElement,\n options: StandaloneEditorOptions,\n unportedCoreApiMap: UnportedCoreApiMap,\n unportedCorePluginState: UnportedCorePluginState,\n tempPlugins: EditorPlugin[]\n): StandaloneEditorCore {\n const corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);\n\n return {\n contentDiv,\n api: { ...standaloneCoreApiMap, ...unportedCoreApiMap, ...options.coreApiOverride },\n originalApi: { ...standaloneCoreApiMap, ...unportedCoreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...tempPlugins,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(),\n darkColorHandler: new DarkColorHandlerImpl(\n contentDiv,\n options.getDarkColor ?? getDarkColorFallback\n ),\n trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,\n ...createStandaloneEditorDefaultSettings(options),\n ...getPluginState(corePlugins),\n ...unportedCorePluginState,\n };\n}\n\nfunction createEditorEnvironment(): EditorEnvironment {\n // It is ok to use global window here since the environment should always be the same for all windows in one session\n const userAgent = window.navigator.userAgent;\n\n return {\n isMac: window.navigator.appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isSafari:\n userAgent.indexOf('Safari') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n };\n}\n\n/**\n * @internal export for test only\n */\nexport function defaultTrustHtmlHandler(html: string) {\n return html;\n}\n\nfunction getPluginState(corePlugins: StandaloneEditorCorePlugins): StandaloneEditorCorePluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n };\n}\n\n// A fallback function, always return original color\nfunction getDarkColorFallback(color: string) {\n return color;\n}\n"]}
@@ -4,9 +4,9 @@ import type { ColorKeyAndValue, DarkColorHandler, ModeIndependentColor } from 'r
4
4
  */
5
5
  export declare class DarkColorHandlerImpl implements DarkColorHandler {
6
6
  private contentDiv;
7
+ private getDarkColor;
7
8
  private knownColors;
8
- readonly baseLightness: number;
9
- constructor(contentDiv: HTMLElement, baseDarkColor?: string);
9
+ constructor(contentDiv: HTMLElement, getDarkColor: (color: string) => string);
10
10
  /**
11
11
  * Get a copy of known colors
12
12
  * @returns
@@ -1,9 +1,8 @@
1
- define(["require", "exports", "color", "roosterjs-editor-dom"], function (require, exports, Color, roosterjs_editor_dom_1) {
1
+ define(["require", "exports", "roosterjs-editor-dom"], function (require, exports, roosterjs_editor_dom_1) {
2
2
  "use strict";
3
3
  var _a, _b;
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.DarkColorHandlerImpl = void 0;
6
- var DefaultLightness = 21.25; // Lightness for #333333
7
6
  var VARIABLE_REGEX = /^\s*var\(\s*(\-\-[a-zA-Z0-9\-_]+)\s*(?:,\s*(.*))?\)\s*$/;
8
7
  var VARIABLE_PREFIX = 'var(';
9
8
  var COLOR_VAR_PREFIX = 'darkColor';
@@ -26,10 +25,10 @@ define(["require", "exports", "color", "roosterjs-editor-dom"], function (requir
26
25
  * @internal
27
26
  */
28
27
  var DarkColorHandlerImpl = /** @class */ (function () {
29
- function DarkColorHandlerImpl(contentDiv, baseDarkColor) {
28
+ function DarkColorHandlerImpl(contentDiv, getDarkColor) {
30
29
  this.contentDiv = contentDiv;
30
+ this.getDarkColor = getDarkColor;
31
31
  this.knownColors = {};
32
- this.baseLightness = getLightness(baseDarkColor);
33
32
  }
34
33
  /**
35
34
  * Get a copy of known colors
@@ -57,7 +56,7 @@ define(["require", "exports", "color", "roosterjs-editor-dom"], function (requir
57
56
  colorKey =
58
57
  colorKey || "--" + COLOR_VAR_PREFIX + "_" + lightModeColor.replace(/[^\d\w]/g, '_');
59
58
  if (!this.knownColors[colorKey]) {
60
- darkModeColor = darkModeColor || getDarkColor(lightModeColor, this.baseLightness);
59
+ darkModeColor = darkModeColor || this.getDarkColor(lightModeColor);
61
60
  this.knownColors[colorKey] = { lightModeColor: lightModeColor, darkModeColor: darkModeColor };
62
61
  this.contentDiv.style.setProperty(colorKey, darkModeColor);
63
62
  }
@@ -156,29 +155,5 @@ define(["require", "exports", "color", "roosterjs-editor-dom"], function (requir
156
155
  return DarkColorHandlerImpl;
157
156
  }());
158
157
  exports.DarkColorHandlerImpl = DarkColorHandlerImpl;
159
- function getDarkColor(color, baseLightness) {
160
- try {
161
- var computedColor = Color(color || undefined);
162
- var colorLab = computedColor.lab().array();
163
- var newLValue = (100 - colorLab[0]) * ((100 - baseLightness) / 100) + baseLightness;
164
- color = Color.lab(newLValue, colorLab[1], colorLab[2])
165
- .rgb()
166
- .alpha(computedColor.alpha())
167
- .toString();
168
- }
169
- catch (_a) { }
170
- return color;
171
- }
172
- function getLightness(color) {
173
- var result = DefaultLightness;
174
- if (color) {
175
- try {
176
- var computedColor = Color(color || undefined);
177
- result = computedColor.lab().array()[0];
178
- }
179
- catch (_a) { }
180
- }
181
- return result;
182
- }
183
158
  });
184
159
  //# sourceMappingURL=DarkColorHandlerImpl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DarkColorHandlerImpl.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/DarkColorHandlerImpl.ts"],"names":[],"mappings":";;;;;IAQA,IAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,wBAAwB;IACxD,IAAM,cAAc,GAAG,yDAAyD,CAAC;IACjF,IAAM,eAAe,GAAG,MAAM,CAAC;IAC/B,IAAM,gBAAgB,GAAG,WAAW,CAAC;IACrC,IAAW,kBAGV;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AAM,GAAG,gBAAgB,CAAC;QAE9B,IAAI,KAAK,EAAE;YACP,IAAI;gBACA,IAAM,aAAa,GAAG,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC;gBAChD,MAAM,GAAG,aAAa,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;aAC3C;YAAC,WAAM,GAAE;SACb;QAED,OAAO,MAAM,CAAC;IAClB,CAAC","sourcesContent":["import * as Color from 'color';\nimport { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';\nimport type {\n ColorKeyAndValue,\n DarkColorHandler,\n ModeIndependentColor,\n} from 'roosterjs-editor-types';\n\nconst DefaultLightness = 21.25; // Lightness for #333333\nconst VARIABLE_REGEX = /^\\s*var\\(\\s*(\\-\\-[a-zA-Z0-9\\-_]+)\\s*(?:,\\s*(.*))?\\)\\s*$/;\nconst VARIABLE_PREFIX = 'var(';\nconst COLOR_VAR_PREFIX = 'darkColor';\nconst enum ColorAttributeEnum {\n CssColor = 0,\n HtmlColor = 1,\n}\nconst ColorAttributeName: { [key in ColorAttributeEnum]: string }[] = [\n {\n [ColorAttributeEnum.CssColor]: 'color',\n [ColorAttributeEnum.HtmlColor]: 'color',\n },\n {\n [ColorAttributeEnum.CssColor]: 'background-color',\n [ColorAttributeEnum.HtmlColor]: 'bgcolor',\n },\n];\n\n/**\n * @internal\n */\nexport class DarkColorHandlerImpl implements DarkColorHandler {\n private knownColors: Record<string, Readonly<ModeIndependentColor>> = {};\n readonly baseLightness: number;\n\n constructor(private contentDiv: HTMLElement, baseDarkColor?: string) {\n this.baseLightness = getLightness(baseDarkColor);\n }\n\n /**\n * Get a copy of known colors\n * @returns\n */\n getKnownColorsCopy() {\n return Object.values(this.knownColors);\n }\n\n /**\n * Given a light mode color value and an optional dark mode color value, register this color\n * so that editor can handle it, then return the CSS color value for current color mode.\n * @param lightModeColor Light mode color value\n * @param isDarkMode Whether current color mode is dark mode\n * @param darkModeColor Optional dark mode color value. If not passed, we will calculate one.\n */\n registerColor(lightModeColor: string, isDarkMode: boolean, darkModeColor?: string): string {\n const parsedColor = this.parseColorValue(lightModeColor);\n let colorKey: string | undefined;\n\n if (parsedColor) {\n lightModeColor = parsedColor.lightModeColor;\n darkModeColor = parsedColor.darkModeColor || darkModeColor;\n colorKey = parsedColor.key;\n }\n\n if (isDarkMode && lightModeColor) {\n colorKey =\n colorKey || `--${COLOR_VAR_PREFIX}_${lightModeColor.replace(/[^\\d\\w]/g, '_')}`;\n\n if (!this.knownColors[colorKey]) {\n darkModeColor = darkModeColor || getDarkColor(lightModeColor, this.baseLightness);\n\n this.knownColors[colorKey] = { lightModeColor, darkModeColor };\n this.contentDiv.style.setProperty(colorKey, darkModeColor);\n }\n\n return `var(${colorKey}, ${lightModeColor})`;\n } else {\n return lightModeColor;\n }\n }\n\n /**\n * Reset known color record, clean up registered color variables.\n */\n reset(): void {\n getObjectKeys(this.knownColors).forEach(key => this.contentDiv.style.removeProperty(key));\n this.knownColors = {};\n }\n\n /**\n * Parse an existing color value, if it is in variable-based color format, extract color key,\n * light color and query related dark color if any\n * @param color The color string to parse\n * @param isInDarkMode Whether current content is in dark mode. When set to true, if the color value is not in dark var format,\n * we will treat is as a dark mode color and try to find a matched dark mode color.\n */\n parseColorValue(color: string | undefined | null, isInDarkMode?: boolean): ColorKeyAndValue {\n let key: string | undefined;\n let lightModeColor = '';\n let darkModeColor: string | undefined;\n\n if (color) {\n const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null;\n\n if (match) {\n if (match[2]) {\n key = match[1];\n lightModeColor = match[2];\n darkModeColor = this.knownColors[key]?.darkModeColor;\n } else {\n lightModeColor = '';\n }\n } else if (isInDarkMode) {\n // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code\n // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related\n // light color as light mode color. Otherwise we need to drop this color to avoid show \"white on white\" content.\n lightModeColor = this.findLightColorFromDarkColor(color) || '';\n\n if (lightModeColor) {\n darkModeColor = color;\n }\n } else {\n lightModeColor = color;\n }\n }\n\n return { key, lightModeColor, darkModeColor };\n }\n\n /**\n * Find related light mode color from dark mode color.\n * @param darkColor The existing dark color\n */\n findLightColorFromDarkColor(darkColor: string): string | null {\n const rgbSearch = parseColor(darkColor);\n\n if (rgbSearch) {\n const key = getObjectKeys(this.knownColors).find(key => {\n const rgbCurrent = parseColor(this.knownColors[key].darkModeColor);\n\n return (\n rgbCurrent &&\n rgbCurrent[0] == rgbSearch[0] &&\n rgbCurrent[1] == rgbSearch[1] &&\n rgbCurrent[2] == rgbSearch[2]\n );\n });\n\n if (key) {\n return this.knownColors[key].lightModeColor;\n }\n }\n\n return null;\n }\n\n /**\n * Transform element color, from dark to light or from light to dark\n * @param element The element to transform color\n * @param fromDarkMode Whether this is transforming color from dark mode\n * @param toDarkMode Whether this is transforming color to dark mode\n */\n transformElementColor(element: HTMLElement, fromDarkMode: boolean, toDarkMode: boolean): void {\n ColorAttributeName.forEach((names, i) => {\n const color = this.parseColorValue(\n element.style.getPropertyValue(names[ColorAttributeEnum.CssColor]) ||\n element.getAttribute(names[ColorAttributeEnum.HtmlColor]),\n !!fromDarkMode\n ).lightModeColor;\n\n element.style.setProperty(names[ColorAttributeEnum.CssColor], null);\n element.removeAttribute(names[ColorAttributeEnum.HtmlColor]);\n\n if (color && color != 'inherit') {\n setColor(element, color, i != 0, toDarkMode, false /*shouldAdaptFontColor*/, this);\n }\n });\n }\n}\n\nfunction getDarkColor(color: string, baseLightness: number): string {\n try {\n const computedColor = Color(color || undefined);\n const colorLab = computedColor.lab().array();\n const newLValue = (100 - colorLab[0]) * ((100 - baseLightness) / 100) + baseLightness;\n color = Color.lab(newLValue, colorLab[1], colorLab[2])\n .rgb()\n .alpha(computedColor.alpha())\n .toString();\n } catch {}\n\n return color;\n}\n\nfunction getLightness(color?: string): number {\n let result = DefaultLightness;\n\n if (color) {\n try {\n const computedColor = Color(color || undefined);\n result = computedColor.lab().array()[0];\n } catch {}\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"DarkColorHandlerImpl.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/DarkColorHandlerImpl.ts"],"names":[],"mappings":";;;;;IAOA,IAAM,cAAc,GAAG,yDAAyD,CAAC;IACjF,IAAM,eAAe,GAAG,MAAM,CAAC;IAC/B,IAAM,gBAAgB,GAAG,WAAW,CAAC;IACrC,IAAW,kBAGV;IAHD,WAAW,kBAAkB;QACzB,mEAAY,CAAA;QACZ,qEAAa,CAAA;IACjB,CAAC,EAHU,kBAAkB,KAAlB,kBAAkB,QAG5B;IACD,IAAM,kBAAkB,GAA8C;;YAE9D,uBAA+B,OAAO;YACtC,wBAAgC,OAAO;;;YAGvC,uBAA+B,kBAAkB;YACjD,wBAAgC,SAAS;;KAEhD,CAAC;IAEF;;OAEG;IACH;QAGI,8BAAoB,UAAuB,EAAU,YAAuC;YAAxE,eAAU,GAAV,UAAU,CAAa;YAAU,iBAAY,GAAZ,YAAY,CAA2B;YAFpF,gBAAW,GAAmD,EAAE,CAAC;QAEsB,CAAC;QAEhG;;;WAGG;QACH,iDAAkB,GAAlB;YACI,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3C,CAAC;QAED;;;;;;WAMG;QACH,4CAAa,GAAb,UAAc,cAAsB,EAAE,UAAmB,EAAE,aAAsB;YAC7E,IAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;YACzD,IAAI,QAA4B,CAAC;YAEjC,IAAI,WAAW,EAAE;gBACb,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC;gBAC5C,aAAa,GAAG,WAAW,CAAC,aAAa,IAAI,aAAa,CAAC;gBAC3D,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC;aAC9B;YAED,IAAI,UAAU,IAAI,cAAc,EAAE;gBAC9B,QAAQ;oBACJ,QAAQ,IAAI,OAA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C;iBAC/C;aACJ;YAED,OAAO,IAAI,CAAC;QAChB,CAAC;QAED;;;;;WAKG;QACH,oDAAqB,GAArB,UAAsB,OAAoB,EAAE,YAAqB,EAAE,UAAmB;YAAtF,iBAeC;YAdG,kBAAkB,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,CAAC;gBAChC,IAAM,KAAK,GAAG,KAAI,CAAC,eAAe,CAC9B,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,kBAA6B,CAAC;oBAC9D,OAAO,CAAC,YAAY,CAAC,KAAK,mBAA8B,CAAC,EAC7D,CAAC,CAAC,YAAY,CACjB,CAAC,cAAc,CAAC;gBAEjB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,kBAA6B,EAAE,IAAI,CAAC,CAAC;gBACpE,OAAO,CAAC,eAAe,CAAC,KAAK,mBAA8B,CAAC,CAAC;gBAE7D,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,EAAE;oBAC7B,IAAA,+BAAQ,EAAC,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,wBAAwB,EAAE,KAAI,CAAC,CAAC;iBACtF;YACL,CAAC,CAAC,CAAC;QACP,CAAC;QACL,2BAAC;IAAD,CAAC,AAhJD,IAgJC;IAhJY,oDAAoB","sourcesContent":["import { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';\nimport type {\n ColorKeyAndValue,\n DarkColorHandler,\n ModeIndependentColor,\n} from 'roosterjs-editor-types';\n\nconst VARIABLE_REGEX = /^\\s*var\\(\\s*(\\-\\-[a-zA-Z0-9\\-_]+)\\s*(?:,\\s*(.*))?\\)\\s*$/;\nconst VARIABLE_PREFIX = 'var(';\nconst COLOR_VAR_PREFIX = 'darkColor';\nconst enum ColorAttributeEnum {\n CssColor = 0,\n HtmlColor = 1,\n}\nconst ColorAttributeName: { [key in ColorAttributeEnum]: string }[] = [\n {\n [ColorAttributeEnum.CssColor]: 'color',\n [ColorAttributeEnum.HtmlColor]: 'color',\n },\n {\n [ColorAttributeEnum.CssColor]: 'background-color',\n [ColorAttributeEnum.HtmlColor]: 'bgcolor',\n },\n];\n\n/**\n * @internal\n */\nexport class DarkColorHandlerImpl implements DarkColorHandler {\n private knownColors: Record<string, Readonly<ModeIndependentColor>> = {};\n\n constructor(private contentDiv: HTMLElement, private getDarkColor: (color: string) => string) {}\n\n /**\n * Get a copy of known colors\n * @returns\n */\n getKnownColorsCopy() {\n return Object.values(this.knownColors);\n }\n\n /**\n * Given a light mode color value and an optional dark mode color value, register this color\n * so that editor can handle it, then return the CSS color value for current color mode.\n * @param lightModeColor Light mode color value\n * @param isDarkMode Whether current color mode is dark mode\n * @param darkModeColor Optional dark mode color value. If not passed, we will calculate one.\n */\n registerColor(lightModeColor: string, isDarkMode: boolean, darkModeColor?: string): string {\n const parsedColor = this.parseColorValue(lightModeColor);\n let colorKey: string | undefined;\n\n if (parsedColor) {\n lightModeColor = parsedColor.lightModeColor;\n darkModeColor = parsedColor.darkModeColor || darkModeColor;\n colorKey = parsedColor.key;\n }\n\n if (isDarkMode && lightModeColor) {\n colorKey =\n colorKey || `--${COLOR_VAR_PREFIX}_${lightModeColor.replace(/[^\\d\\w]/g, '_')}`;\n\n if (!this.knownColors[colorKey]) {\n darkModeColor = darkModeColor || this.getDarkColor(lightModeColor);\n\n this.knownColors[colorKey] = { lightModeColor, darkModeColor };\n this.contentDiv.style.setProperty(colorKey, darkModeColor);\n }\n\n return `var(${colorKey}, ${lightModeColor})`;\n } else {\n return lightModeColor;\n }\n }\n\n /**\n * Reset known color record, clean up registered color variables.\n */\n reset(): void {\n getObjectKeys(this.knownColors).forEach(key => this.contentDiv.style.removeProperty(key));\n this.knownColors = {};\n }\n\n /**\n * Parse an existing color value, if it is in variable-based color format, extract color key,\n * light color and query related dark color if any\n * @param color The color string to parse\n * @param isInDarkMode Whether current content is in dark mode. When set to true, if the color value is not in dark var format,\n * we will treat is as a dark mode color and try to find a matched dark mode color.\n */\n parseColorValue(color: string | undefined | null, isInDarkMode?: boolean): ColorKeyAndValue {\n let key: string | undefined;\n let lightModeColor = '';\n let darkModeColor: string | undefined;\n\n if (color) {\n const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null;\n\n if (match) {\n if (match[2]) {\n key = match[1];\n lightModeColor = match[2];\n darkModeColor = this.knownColors[key]?.darkModeColor;\n } else {\n lightModeColor = '';\n }\n } else if (isInDarkMode) {\n // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code\n // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related\n // light color as light mode color. Otherwise we need to drop this color to avoid show \"white on white\" content.\n lightModeColor = this.findLightColorFromDarkColor(color) || '';\n\n if (lightModeColor) {\n darkModeColor = color;\n }\n } else {\n lightModeColor = color;\n }\n }\n\n return { key, lightModeColor, darkModeColor };\n }\n\n /**\n * Find related light mode color from dark mode color.\n * @param darkColor The existing dark color\n */\n findLightColorFromDarkColor(darkColor: string): string | null {\n const rgbSearch = parseColor(darkColor);\n\n if (rgbSearch) {\n const key = getObjectKeys(this.knownColors).find(key => {\n const rgbCurrent = parseColor(this.knownColors[key].darkModeColor);\n\n return (\n rgbCurrent &&\n rgbCurrent[0] == rgbSearch[0] &&\n rgbCurrent[1] == rgbSearch[1] &&\n rgbCurrent[2] == rgbSearch[2]\n );\n });\n\n if (key) {\n return this.knownColors[key].lightModeColor;\n }\n }\n\n return null;\n }\n\n /**\n * Transform element color, from dark to light or from light to dark\n * @param element The element to transform color\n * @param fromDarkMode Whether this is transforming color from dark mode\n * @param toDarkMode Whether this is transforming color to dark mode\n */\n transformElementColor(element: HTMLElement, fromDarkMode: boolean, toDarkMode: boolean): void {\n ColorAttributeName.forEach((names, i) => {\n const color = this.parseColorValue(\n element.style.getPropertyValue(names[ColorAttributeEnum.CssColor]) ||\n element.getAttribute(names[ColorAttributeEnum.HtmlColor]),\n !!fromDarkMode\n ).lightModeColor;\n\n element.style.setProperty(names[ColorAttributeEnum.CssColor], null);\n element.removeAttribute(names[ColorAttributeEnum.HtmlColor]);\n\n if (color && color != 'inherit') {\n setColor(element, color, i != 0, toDarkMode, false /*shouldAdaptFontColor*/, this);\n }\n });\n }\n}\n"]}
@@ -8,6 +8,7 @@ define(["require", "exports", "tslib", "../corePlugin/createStandaloneEditorCore
8
8
  * @param options Editor options
9
9
  */
10
10
  function createStandaloneEditorCore(contentDiv, options, unportedCoreApiMap, unportedCorePluginState, tempPlugins) {
11
+ var _a;
11
12
  var corePlugins = (0, createStandaloneEditorCorePlugins_1.createStandaloneEditorCorePlugins)(options, contentDiv);
12
13
  return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({ contentDiv: contentDiv, api: (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, standaloneCoreApiMap_1.standaloneCoreApiMap), unportedCoreApiMap), options.coreApiOverride), originalApi: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, standaloneCoreApiMap_1.standaloneCoreApiMap), unportedCoreApiMap), plugins: (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([
13
14
  corePlugins.cache,
@@ -18,7 +19,7 @@ define(["require", "exports", "tslib", "../corePlugin/createStandaloneEditorCore
18
19
  corePlugins.entity
19
20
  ], (0, tslib_1.__read)(tempPlugins), false), [
20
21
  corePlugins.lifecycle,
21
- ], false), environment: createEditorEnvironment(), darkColorHandler: new DarkColorHandlerImpl_1.DarkColorHandlerImpl(contentDiv, options.baseDarkColor), trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler }, (0, createStandaloneEditorDefaultSettings_1.createStandaloneEditorDefaultSettings)(options)), getPluginState(corePlugins)), unportedCorePluginState);
22
+ ], false), environment: createEditorEnvironment(), darkColorHandler: new DarkColorHandlerImpl_1.DarkColorHandlerImpl(contentDiv, (_a = options.getDarkColor) !== null && _a !== void 0 ? _a : getDarkColorFallback), trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler }, (0, createStandaloneEditorDefaultSettings_1.createStandaloneEditorDefaultSettings)(options)), getPluginState(corePlugins)), unportedCorePluginState);
22
23
  }
23
24
  exports.createStandaloneEditorCore = createStandaloneEditorCore;
24
25
  function createEditorEnvironment() {
@@ -50,5 +51,9 @@ define(["require", "exports", "tslib", "../corePlugin/createStandaloneEditorCore
50
51
  selection: corePlugins.selection.getState(),
51
52
  };
52
53
  }
54
+ // A fallback function, always return original color
55
+ function getDarkColorFallback(color) {
56
+ return color;
57
+ }
53
58
  });
54
59
  //# sourceMappingURL=createStandaloneEditorCore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createStandaloneEditorCore.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/createStandaloneEditorCore.ts"],"names":[],"mappings":";;;;IAeA;;;;OAIG;IACH,SAAgB,0BAA0B,CACtC,UAA0B,EAC1B,OAAgC,EAChC,kBAAsC,EACtC,uBAAgD,EAChD,WAA2B;QAE3B,IAAM,WAAW,GAAG,IAAA,qEAAiC,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAE3E,2EACI,UAAU,YAAA,EACV,GAAG,wEAAO,2CAAoB,GAAK,kBAAkB,GAAK,OAAO,CAAC,eAAe,GACjF,WAAW,kDAAO,2CAAoB,GAAK,kBAAkB,GAC7D,OAAO;gBACH,WAAW,CAAC,KAAK;gBACjB,WAAW,CAAC,MAAM;gBAClB,WAAW,CAAC,SAAS;gBACrB,WAAW,CAAC,QAAQ;gBACpB,WAAW,CAAC,SAAS;gBACrB,WAAW,CAAC,MAAM;mCACf,WAAW;gBACd,WAAW,CAAC,SAAS;uBAEzB,WAAW,EAAE,uBAAuB,EAAE,EACtC,gBAAgB,EAAE,IAAI,2CAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,EAC7E,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,uBAAuB,IACtE,IAAA,6EAAqC,EAAC,OAAO,CAAC,GAC9C,cAAc,CAAC,WAAW,CAAC,GAC3B,uBAAuB,EAC5B;IACN,CAAC;IA9BD,gEA8BC;IAED,SAAS,uBAAuB;QAC5B,oHAAoH;QACpH,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;QAE7C,OAAO;YACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;YACrC,QAAQ,EACJ,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAChC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAC/B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;SACvC,CAAC;IACN,CAAC;IAED;;OAEG;IACH,SAAgB,uBAAuB,CAAC,IAAY;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;IAFD,0DAEC;IAED,SAAS,cAAc,CAAC,WAAwC;QAC5D,OAAO;YACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;YACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;SAC9C,CAAC;IACN,CAAC","sourcesContent":["import { createStandaloneEditorCorePlugins } from '../corePlugin/createStandaloneEditorCorePlugins';\nimport { createStandaloneEditorDefaultSettings } from './createStandaloneEditorDefaultSettings';\nimport { DarkColorHandlerImpl } from './DarkColorHandlerImpl';\nimport { standaloneCoreApiMap } from './standaloneCoreApiMap';\nimport type { EditorPlugin } from 'roosterjs-editor-types';\nimport type {\n EditorEnvironment,\n StandaloneEditorCore,\n StandaloneEditorCorePluginState,\n StandaloneEditorCorePlugins,\n StandaloneEditorOptions,\n UnportedCoreApiMap,\n UnportedCorePluginState,\n} from 'roosterjs-content-model-types';\n\n/**\n * A temporary function to create Standalone Editor core\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createStandaloneEditorCore(\n contentDiv: HTMLDivElement,\n options: StandaloneEditorOptions,\n unportedCoreApiMap: UnportedCoreApiMap,\n unportedCorePluginState: UnportedCorePluginState,\n tempPlugins: EditorPlugin[]\n): StandaloneEditorCore {\n const corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);\n\n return {\n contentDiv,\n api: { ...standaloneCoreApiMap, ...unportedCoreApiMap, ...options.coreApiOverride },\n originalApi: { ...standaloneCoreApiMap, ...unportedCoreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...tempPlugins,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(),\n darkColorHandler: new DarkColorHandlerImpl(contentDiv, options.baseDarkColor),\n trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,\n ...createStandaloneEditorDefaultSettings(options),\n ...getPluginState(corePlugins),\n ...unportedCorePluginState,\n };\n}\n\nfunction createEditorEnvironment(): EditorEnvironment {\n // It is ok to use global window here since the environment should always be the same for all windows in one session\n const userAgent = window.navigator.userAgent;\n\n return {\n isMac: window.navigator.appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isSafari:\n userAgent.indexOf('Safari') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n };\n}\n\n/**\n * @internal export for test only\n */\nexport function defaultTrustHtmlHandler(html: string) {\n return html;\n}\n\nfunction getPluginState(corePlugins: StandaloneEditorCorePlugins): StandaloneEditorCorePluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n };\n}\n"]}
1
+ {"version":3,"file":"createStandaloneEditorCore.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/createStandaloneEditorCore.ts"],"names":[],"mappings":";;;;IAeA;;;;OAIG;IACH,SAAgB,0BAA0B,CACtC,UAA0B,EAC1B,OAAgC,EAChC,kBAAsC,EACtC,uBAAgD,EAChD,WAA2B;;QAE3B,IAAM,WAAW,GAAG,IAAA,qEAAiC,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAE3E,2EACI,UAAU,YAAA,EACV,GAAG,wEAAO,2CAAoB,GAAK,kBAAkB,GAAK,OAAO,CAAC,eAAe,GACjF,WAAW,kDAAO,2CAAoB,GAAK,kBAAkB,GAC7D,OAAO;gBACH,WAAW,CAAC,KAAK;gBACjB,WAAW,CAAC,MAAM;gBAClB,WAAW,CAAC,SAAS;gBACrB,WAAW,CAAC,QAAQ;gBACpB,WAAW,CAAC,SAAS;gBACrB,WAAW,CAAC,MAAM;mCACf,WAAW;gBACd,WAAW,CAAC,SAAS;uBAEzB,WAAW,EAAE,uBAAuB,EAAE,EACtC,gBAAgB,EAAE,IAAI,2CAAoB,CACtC,UAAU,EACV,MAAA,OAAO,CAAC,YAAY,mCAAI,oBAAoB,CAC/C,EACD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,uBAAuB,IACtE,IAAA,6EAAqC,EAAC,OAAO,CAAC,GAC9C,cAAc,CAAC,WAAW,CAAC,GAC3B,uBAAuB,EAC5B;IACN,CAAC;IAjCD,gEAiCC;IAED,SAAS,uBAAuB;QAC5B,oHAAoH;QACpH,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;QAE7C,OAAO;YACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACvD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;YACrC,QAAQ,EACJ,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAChC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAC/B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;SACvC,CAAC;IACN,CAAC;IAED;;OAEG;IACH,SAAgB,uBAAuB,CAAC,IAAY;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;IAFD,0DAEC;IAED,SAAS,cAAc,CAAC,WAAwC;QAC5D,OAAO;YACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;YACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;SAC9C,CAAC;IACN,CAAC;IAED,oDAAoD;IACpD,SAAS,oBAAoB,CAAC,KAAa;QACvC,OAAO,KAAK,CAAC;IACjB,CAAC","sourcesContent":["import { createStandaloneEditorCorePlugins } from '../corePlugin/createStandaloneEditorCorePlugins';\nimport { createStandaloneEditorDefaultSettings } from './createStandaloneEditorDefaultSettings';\nimport { DarkColorHandlerImpl } from './DarkColorHandlerImpl';\nimport { standaloneCoreApiMap } from './standaloneCoreApiMap';\nimport type { EditorPlugin } from 'roosterjs-editor-types';\nimport type {\n EditorEnvironment,\n StandaloneEditorCore,\n StandaloneEditorCorePluginState,\n StandaloneEditorCorePlugins,\n StandaloneEditorOptions,\n UnportedCoreApiMap,\n UnportedCorePluginState,\n} from 'roosterjs-content-model-types';\n\n/**\n * A temporary function to create Standalone Editor core\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createStandaloneEditorCore(\n contentDiv: HTMLDivElement,\n options: StandaloneEditorOptions,\n unportedCoreApiMap: UnportedCoreApiMap,\n unportedCorePluginState: UnportedCorePluginState,\n tempPlugins: EditorPlugin[]\n): StandaloneEditorCore {\n const corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);\n\n return {\n contentDiv,\n api: { ...standaloneCoreApiMap, ...unportedCoreApiMap, ...options.coreApiOverride },\n originalApi: { ...standaloneCoreApiMap, ...unportedCoreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...tempPlugins,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(),\n darkColorHandler: new DarkColorHandlerImpl(\n contentDiv,\n options.getDarkColor ?? getDarkColorFallback\n ),\n trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,\n ...createStandaloneEditorDefaultSettings(options),\n ...getPluginState(corePlugins),\n ...unportedCorePluginState,\n };\n}\n\nfunction createEditorEnvironment(): EditorEnvironment {\n // It is ok to use global window here since the environment should always be the same for all windows in one session\n const userAgent = window.navigator.userAgent;\n\n return {\n isMac: window.navigator.appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isSafari:\n userAgent.indexOf('Safari') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n };\n}\n\n/**\n * @internal export for test only\n */\nexport function defaultTrustHtmlHandler(html: string) {\n return html;\n}\n\nfunction getPluginState(corePlugins: StandaloneEditorCorePlugins): StandaloneEditorCorePluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n };\n}\n\n// A fallback function, always return original color\nfunction getDarkColorFallback(color: string) {\n return color;\n}\n"]}
@@ -4,9 +4,9 @@ import type { ColorKeyAndValue, DarkColorHandler, ModeIndependentColor } from 'r
4
4
  */
5
5
  export declare class DarkColorHandlerImpl implements DarkColorHandler {
6
6
  private contentDiv;
7
+ private getDarkColor;
7
8
  private knownColors;
8
- readonly baseLightness: number;
9
- constructor(contentDiv: HTMLElement, baseDarkColor?: string);
9
+ constructor(contentDiv: HTMLElement, getDarkColor: (color: string) => string);
10
10
  /**
11
11
  * Get a copy of known colors
12
12
  * @returns
@@ -1,7 +1,5 @@
1
1
  var _a, _b;
2
- import * as Color from 'color';
3
2
  import { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';
4
- var DefaultLightness = 21.25; // Lightness for #333333
5
3
  var VARIABLE_REGEX = /^\s*var\(\s*(\-\-[a-zA-Z0-9\-_]+)\s*(?:,\s*(.*))?\)\s*$/;
6
4
  var VARIABLE_PREFIX = 'var(';
7
5
  var COLOR_VAR_PREFIX = 'darkColor';
@@ -24,10 +22,10 @@ var ColorAttributeName = [
24
22
  * @internal
25
23
  */
26
24
  var DarkColorHandlerImpl = /** @class */ (function () {
27
- function DarkColorHandlerImpl(contentDiv, baseDarkColor) {
25
+ function DarkColorHandlerImpl(contentDiv, getDarkColor) {
28
26
  this.contentDiv = contentDiv;
27
+ this.getDarkColor = getDarkColor;
29
28
  this.knownColors = {};
30
- this.baseLightness = getLightness(baseDarkColor);
31
29
  }
32
30
  /**
33
31
  * Get a copy of known colors
@@ -55,7 +53,7 @@ var DarkColorHandlerImpl = /** @class */ (function () {
55
53
  colorKey =
56
54
  colorKey || "--" + COLOR_VAR_PREFIX + "_" + lightModeColor.replace(/[^\d\w]/g, '_');
57
55
  if (!this.knownColors[colorKey]) {
58
- darkModeColor = darkModeColor || getDarkColor(lightModeColor, this.baseLightness);
56
+ darkModeColor = darkModeColor || this.getDarkColor(lightModeColor);
59
57
  this.knownColors[colorKey] = { lightModeColor: lightModeColor, darkModeColor: darkModeColor };
60
58
  this.contentDiv.style.setProperty(colorKey, darkModeColor);
61
59
  }
@@ -154,28 +152,4 @@ var DarkColorHandlerImpl = /** @class */ (function () {
154
152
  return DarkColorHandlerImpl;
155
153
  }());
156
154
  export { DarkColorHandlerImpl };
157
- function getDarkColor(color, baseLightness) {
158
- try {
159
- var computedColor = Color(color || undefined);
160
- var colorLab = computedColor.lab().array();
161
- var newLValue = (100 - colorLab[0]) * ((100 - baseLightness) / 100) + baseLightness;
162
- color = Color.lab(newLValue, colorLab[1], colorLab[2])
163
- .rgb()
164
- .alpha(computedColor.alpha())
165
- .toString();
166
- }
167
- catch (_a) { }
168
- return color;
169
- }
170
- function getLightness(color) {
171
- var result = DefaultLightness;
172
- if (color) {
173
- try {
174
- var computedColor = Color(color || undefined);
175
- result = computedColor.lab().array()[0];
176
- }
177
- catch (_a) { }
178
- }
179
- return result;
180
- }
181
155
  //# sourceMappingURL=DarkColorHandlerImpl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DarkColorHandlerImpl.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/DarkColorHandlerImpl.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAO3E,IAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,wBAAwB;AACxD,IAAM,cAAc,GAAG,yDAAyD,CAAC;AACjF,IAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,IAAM,gBAAgB,GAAG,W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IAAI;YACA,IAAM,aAAa,GAAG,KAAK,CAAC,KAAK,IAAI,SAAS,CAAC,CAAC;YAChD,MAAM,GAAG,aAAa,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;SAC3C;QAAC,WAAM,GAAE;KACb;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import * as Color from 'color';\nimport { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';\nimport type {\n ColorKeyAndValue,\n DarkColorHandler,\n ModeIndependentColor,\n} from 'roosterjs-editor-types';\n\nconst DefaultLightness = 21.25; // Lightness for #333333\nconst VARIABLE_REGEX = /^\\s*var\\(\\s*(\\-\\-[a-zA-Z0-9\\-_]+)\\s*(?:,\\s*(.*))?\\)\\s*$/;\nconst VARIABLE_PREFIX = 'var(';\nconst COLOR_VAR_PREFIX = 'darkColor';\nconst enum ColorAttributeEnum {\n CssColor = 0,\n HtmlColor = 1,\n}\nconst ColorAttributeName: { [key in ColorAttributeEnum]: string }[] = [\n {\n [ColorAttributeEnum.CssColor]: 'color',\n [ColorAttributeEnum.HtmlColor]: 'color',\n },\n {\n [ColorAttributeEnum.CssColor]: 'background-color',\n [ColorAttributeEnum.HtmlColor]: 'bgcolor',\n },\n];\n\n/**\n * @internal\n */\nexport class DarkColorHandlerImpl implements DarkColorHandler {\n private knownColors: Record<string, Readonly<ModeIndependentColor>> = {};\n readonly baseLightness: number;\n\n constructor(private contentDiv: HTMLElement, baseDarkColor?: string) {\n this.baseLightness = getLightness(baseDarkColor);\n }\n\n /**\n * Get a copy of known colors\n * @returns\n */\n getKnownColorsCopy() {\n return Object.values(this.knownColors);\n }\n\n /**\n * Given a light mode color value and an optional dark mode color value, register this color\n * so that editor can handle it, then return the CSS color value for current color mode.\n * @param lightModeColor Light mode color value\n * @param isDarkMode Whether current color mode is dark mode\n * @param darkModeColor Optional dark mode color value. If not passed, we will calculate one.\n */\n registerColor(lightModeColor: string, isDarkMode: boolean, darkModeColor?: string): string {\n const parsedColor = this.parseColorValue(lightModeColor);\n let colorKey: string | undefined;\n\n if (parsedColor) {\n lightModeColor = parsedColor.lightModeColor;\n darkModeColor = parsedColor.darkModeColor || darkModeColor;\n colorKey = parsedColor.key;\n }\n\n if (isDarkMode && lightModeColor) {\n colorKey =\n colorKey || `--${COLOR_VAR_PREFIX}_${lightModeColor.replace(/[^\\d\\w]/g, '_')}`;\n\n if (!this.knownColors[colorKey]) {\n darkModeColor = darkModeColor || getDarkColor(lightModeColor, this.baseLightness);\n\n this.knownColors[colorKey] = { lightModeColor, darkModeColor };\n this.contentDiv.style.setProperty(colorKey, darkModeColor);\n }\n\n return `var(${colorKey}, ${lightModeColor})`;\n } else {\n return lightModeColor;\n }\n }\n\n /**\n * Reset known color record, clean up registered color variables.\n */\n reset(): void {\n getObjectKeys(this.knownColors).forEach(key => this.contentDiv.style.removeProperty(key));\n this.knownColors = {};\n }\n\n /**\n * Parse an existing color value, if it is in variable-based color format, extract color key,\n * light color and query related dark color if any\n * @param color The color string to parse\n * @param isInDarkMode Whether current content is in dark mode. When set to true, if the color value is not in dark var format,\n * we will treat is as a dark mode color and try to find a matched dark mode color.\n */\n parseColorValue(color: string | undefined | null, isInDarkMode?: boolean): ColorKeyAndValue {\n let key: string | undefined;\n let lightModeColor = '';\n let darkModeColor: string | undefined;\n\n if (color) {\n const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null;\n\n if (match) {\n if (match[2]) {\n key = match[1];\n lightModeColor = match[2];\n darkModeColor = this.knownColors[key]?.darkModeColor;\n } else {\n lightModeColor = '';\n }\n } else if (isInDarkMode) {\n // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code\n // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related\n // light color as light mode color. Otherwise we need to drop this color to avoid show \"white on white\" content.\n lightModeColor = this.findLightColorFromDarkColor(color) || '';\n\n if (lightModeColor) {\n darkModeColor = color;\n }\n } else {\n lightModeColor = color;\n }\n }\n\n return { key, lightModeColor, darkModeColor };\n }\n\n /**\n * Find related light mode color from dark mode color.\n * @param darkColor The existing dark color\n */\n findLightColorFromDarkColor(darkColor: string): string | null {\n const rgbSearch = parseColor(darkColor);\n\n if (rgbSearch) {\n const key = getObjectKeys(this.knownColors).find(key => {\n const rgbCurrent = parseColor(this.knownColors[key].darkModeColor);\n\n return (\n rgbCurrent &&\n rgbCurrent[0] == rgbSearch[0] &&\n rgbCurrent[1] == rgbSearch[1] &&\n rgbCurrent[2] == rgbSearch[2]\n );\n });\n\n if (key) {\n return this.knownColors[key].lightModeColor;\n }\n }\n\n return null;\n }\n\n /**\n * Transform element color, from dark to light or from light to dark\n * @param element The element to transform color\n * @param fromDarkMode Whether this is transforming color from dark mode\n * @param toDarkMode Whether this is transforming color to dark mode\n */\n transformElementColor(element: HTMLElement, fromDarkMode: boolean, toDarkMode: boolean): void {\n ColorAttributeName.forEach((names, i) => {\n const color = this.parseColorValue(\n element.style.getPropertyValue(names[ColorAttributeEnum.CssColor]) ||\n element.getAttribute(names[ColorAttributeEnum.HtmlColor]),\n !!fromDarkMode\n ).lightModeColor;\n\n element.style.setProperty(names[ColorAttributeEnum.CssColor], null);\n element.removeAttribute(names[ColorAttributeEnum.HtmlColor]);\n\n if (color && color != 'inherit') {\n setColor(element, color, i != 0, toDarkMode, false /*shouldAdaptFontColor*/, this);\n }\n });\n }\n}\n\nfunction getDarkColor(color: string, baseLightness: number): string {\n try {\n const computedColor = Color(color || undefined);\n const colorLab = computedColor.lab().array();\n const newLValue = (100 - colorLab[0]) * ((100 - baseLightness) / 100) + baseLightness;\n color = Color.lab(newLValue, colorLab[1], colorLab[2])\n .rgb()\n .alpha(computedColor.alpha())\n .toString();\n } catch {}\n\n return color;\n}\n\nfunction getLightness(color?: string): number {\n let result = DefaultLightness;\n\n if (color) {\n try {\n const computedColor = Color(color || undefined);\n result = computedColor.lab().array()[0];\n } catch {}\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"Dark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AC;IAChB,CAAC;IAED;;;;;OAKG;IACH,oDAAqB,GAArB,UAAsB,OAAoB,EAAE,YAAqB,EAAE,UAAmB;QAAtF,iBAeC;QAdG,kBAAkB,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,CAAC;YAChC,IAAM,KAAK,GAAG,KAAI,CAAC,eAAe,CAC9B,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,kBAA6B,CAAC;gBAC9D,OAAO,CAAC,YAAY,CAAC,KAAK,mBAA8B,CAAC,EAC7D,CAAC,CAAC,YAAY,CACjB,CAAC,cAAc,CAAC;YAEjB,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,kBAA6B,EAAE,IAAI,CAAC,CAAC;YACpE,OAAO,CAAC,eAAe,CAAC,KAAK,mBAA8B,CAAC,CAAC;YAE7D,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,EAAE;gBAC7B,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,wBAAwB,EAAE,KAAI,CAAC,CAAC;aACtF;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,2BAAC;AAAD,CAAC,AAhJD,IAgJC","sourcesContent":["import { getObjectKeys, parseColor, setColor } from 'roosterjs-editor-dom';\nimport type {\n ColorKeyAndValue,\n DarkColorHandler,\n ModeIndependentColor,\n} from 'roosterjs-editor-types';\n\nconst VARIABLE_REGEX = /^\\s*var\\(\\s*(\\-\\-[a-zA-Z0-9\\-_]+)\\s*(?:,\\s*(.*))?\\)\\s*$/;\nconst VARIABLE_PREFIX = 'var(';\nconst COLOR_VAR_PREFIX = 'darkColor';\nconst enum ColorAttributeEnum {\n CssColor = 0,\n HtmlColor = 1,\n}\nconst ColorAttributeName: { [key in ColorAttributeEnum]: string }[] = [\n {\n [ColorAttributeEnum.CssColor]: 'color',\n [ColorAttributeEnum.HtmlColor]: 'color',\n },\n {\n [ColorAttributeEnum.CssColor]: 'background-color',\n [ColorAttributeEnum.HtmlColor]: 'bgcolor',\n },\n];\n\n/**\n * @internal\n */\nexport class DarkColorHandlerImpl implements DarkColorHandler {\n private knownColors: Record<string, Readonly<ModeIndependentColor>> = {};\n\n constructor(private contentDiv: HTMLElement, private getDarkColor: (color: string) => string) {}\n\n /**\n * Get a copy of known colors\n * @returns\n */\n getKnownColorsCopy() {\n return Object.values(this.knownColors);\n }\n\n /**\n * Given a light mode color value and an optional dark mode color value, register this color\n * so that editor can handle it, then return the CSS color value for current color mode.\n * @param lightModeColor Light mode color value\n * @param isDarkMode Whether current color mode is dark mode\n * @param darkModeColor Optional dark mode color value. If not passed, we will calculate one.\n */\n registerColor(lightModeColor: string, isDarkMode: boolean, darkModeColor?: string): string {\n const parsedColor = this.parseColorValue(lightModeColor);\n let colorKey: string | undefined;\n\n if (parsedColor) {\n lightModeColor = parsedColor.lightModeColor;\n darkModeColor = parsedColor.darkModeColor || darkModeColor;\n colorKey = parsedColor.key;\n }\n\n if (isDarkMode && lightModeColor) {\n colorKey =\n colorKey || `--${COLOR_VAR_PREFIX}_${lightModeColor.replace(/[^\\d\\w]/g, '_')}`;\n\n if (!this.knownColors[colorKey]) {\n darkModeColor = darkModeColor || this.getDarkColor(lightModeColor);\n\n this.knownColors[colorKey] = { lightModeColor, darkModeColor };\n this.contentDiv.style.setProperty(colorKey, darkModeColor);\n }\n\n return `var(${colorKey}, ${lightModeColor})`;\n } else {\n return lightModeColor;\n }\n }\n\n /**\n * Reset known color record, clean up registered color variables.\n */\n reset(): void {\n getObjectKeys(this.knownColors).forEach(key => this.contentDiv.style.removeProperty(key));\n this.knownColors = {};\n }\n\n /**\n * Parse an existing color value, if it is in variable-based color format, extract color key,\n * light color and query related dark color if any\n * @param color The color string to parse\n * @param isInDarkMode Whether current content is in dark mode. When set to true, if the color value is not in dark var format,\n * we will treat is as a dark mode color and try to find a matched dark mode color.\n */\n parseColorValue(color: string | undefined | null, isInDarkMode?: boolean): ColorKeyAndValue {\n let key: string | undefined;\n let lightModeColor = '';\n let darkModeColor: string | undefined;\n\n if (color) {\n const match = color.startsWith(VARIABLE_PREFIX) ? VARIABLE_REGEX.exec(color) : null;\n\n if (match) {\n if (match[2]) {\n key = match[1];\n lightModeColor = match[2];\n darkModeColor = this.knownColors[key]?.darkModeColor;\n } else {\n lightModeColor = '';\n }\n } else if (isInDarkMode) {\n // If editor is in dark mode but the color is not in dark color format, it is possible the color was inserted from external code\n // without any light color info. So we first try to see if there is a known dark color can match this color, and use its related\n // light color as light mode color. Otherwise we need to drop this color to avoid show \"white on white\" content.\n lightModeColor = this.findLightColorFromDarkColor(color) || '';\n\n if (lightModeColor) {\n darkModeColor = color;\n }\n } else {\n lightModeColor = color;\n }\n }\n\n return { key, lightModeColor, darkModeColor };\n }\n\n /**\n * Find related light mode color from dark mode color.\n * @param darkColor The existing dark color\n */\n findLightColorFromDarkColor(darkColor: string): string | null {\n const rgbSearch = parseColor(darkColor);\n\n if (rgbSearch) {\n const key = getObjectKeys(this.knownColors).find(key => {\n const rgbCurrent = parseColor(this.knownColors[key].darkModeColor);\n\n return (\n rgbCurrent &&\n rgbCurrent[0] == rgbSearch[0] &&\n rgbCurrent[1] == rgbSearch[1] &&\n rgbCurrent[2] == rgbSearch[2]\n );\n });\n\n if (key) {\n return this.knownColors[key].lightModeColor;\n }\n }\n\n return null;\n }\n\n /**\n * Transform element color, from dark to light or from light to dark\n * @param element The element to transform color\n * @param fromDarkMode Whether this is transforming color from dark mode\n * @param toDarkMode Whether this is transforming color to dark mode\n */\n transformElementColor(element: HTMLElement, fromDarkMode: boolean, toDarkMode: boolean): void {\n ColorAttributeName.forEach((names, i) => {\n const color = this.parseColorValue(\n element.style.getPropertyValue(names[ColorAttributeEnum.CssColor]) ||\n element.getAttribute(names[ColorAttributeEnum.HtmlColor]),\n !!fromDarkMode\n ).lightModeColor;\n\n element.style.setProperty(names[ColorAttributeEnum.CssColor], null);\n element.removeAttribute(names[ColorAttributeEnum.HtmlColor]);\n\n if (color && color != 'inherit') {\n setColor(element, color, i != 0, toDarkMode, false /*shouldAdaptFontColor*/, this);\n }\n });\n }\n}\n"]}
@@ -9,6 +9,7 @@ import { standaloneCoreApiMap } from './standaloneCoreApiMap';
9
9
  * @param options Editor options
10
10
  */
11
11
  export function createStandaloneEditorCore(contentDiv, options, unportedCoreApiMap, unportedCorePluginState, tempPlugins) {
12
+ var _a;
12
13
  var corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);
13
14
  return __assign(__assign(__assign({ contentDiv: contentDiv, api: __assign(__assign(__assign({}, standaloneCoreApiMap), unportedCoreApiMap), options.coreApiOverride), originalApi: __assign(__assign({}, standaloneCoreApiMap), unportedCoreApiMap), plugins: __spreadArray(__spreadArray([
14
15
  corePlugins.cache,
@@ -19,7 +20,7 @@ export function createStandaloneEditorCore(contentDiv, options, unportedCoreApiM
19
20
  corePlugins.entity
20
21
  ], __read(tempPlugins), false), [
21
22
  corePlugins.lifecycle,
22
- ], false), environment: createEditorEnvironment(), darkColorHandler: new DarkColorHandlerImpl(contentDiv, options.baseDarkColor), trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler }, createStandaloneEditorDefaultSettings(options)), getPluginState(corePlugins)), unportedCorePluginState);
23
+ ], false), environment: createEditorEnvironment(), darkColorHandler: new DarkColorHandlerImpl(contentDiv, (_a = options.getDarkColor) !== null && _a !== void 0 ? _a : getDarkColorFallback), trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler }, createStandaloneEditorDefaultSettings(options)), getPluginState(corePlugins)), unportedCorePluginState);
23
24
  }
24
25
  function createEditorEnvironment() {
25
26
  // It is ok to use global window here since the environment should always be the same for all windows in one session
@@ -49,4 +50,8 @@ function getPluginState(corePlugins) {
49
50
  selection: corePlugins.selection.getState(),
50
51
  };
51
52
  }
53
+ // A fallback function, always return original color
54
+ function getDarkColorFallback(color) {
55
+ return color;
56
+ }
52
57
  //# sourceMappingURL=createStandaloneEditorCore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createStandaloneEditorCore.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/createStandaloneEditorCore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAC;AACpG,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAY9D;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACtC,UAA0B,EAC1B,OAAgC,EAChC,kBAAsC,EACtC,uBAAgD,EAChD,WAA2B;IAE3B,IAAM,WAAW,GAAG,iCAAiC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAE3E,oCACI,UAAU,YAAA,EACV,GAAG,iCAAO,oBAAoB,GAAK,kBAAkB,GAAK,OAAO,CAAC,eAAe,GACjF,WAAW,wBAAO,oBAAoB,GAAK,kBAAkB,GAC7D,OAAO;YACH,WAAW,CAAC,KAAK;YACjB,WAAW,CAAC,MAAM;YAClB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,QAAQ;YACpB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,MAAM;kBACf,WAAW;YACd,WAAW,CAAC,SAAS;mBAEzB,WAAW,EAAE,uBAAuB,EAAE,EACtC,gBAAgB,EAAE,IAAI,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,EAC7E,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,uBAAuB,IACtE,qCAAqC,CAAC,OAAO,CAAC,GAC9C,cAAc,CAAC,WAAW,CAAC,GAC3B,uBAAuB,EAC5B;AACN,CAAC;AAED,SAAS,uBAAuB;IAC5B,oHAAoH;IACpH,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;IAE7C,OAAO;QACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;QACrC,QAAQ,EACJ,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC/B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;KACvC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAChD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,WAAwC;IAC5D,OAAO;QACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;KAC9C,CAAC;AACN,CAAC","sourcesContent":["import { createStandaloneEditorCorePlugins } from '../corePlugin/createStandaloneEditorCorePlugins';\nimport { createStandaloneEditorDefaultSettings } from './createStandaloneEditorDefaultSettings';\nimport { DarkColorHandlerImpl } from './DarkColorHandlerImpl';\nimport { standaloneCoreApiMap } from './standaloneCoreApiMap';\nimport type { EditorPlugin } from 'roosterjs-editor-types';\nimport type {\n EditorEnvironment,\n StandaloneEditorCore,\n StandaloneEditorCorePluginState,\n StandaloneEditorCorePlugins,\n StandaloneEditorOptions,\n UnportedCoreApiMap,\n UnportedCorePluginState,\n} from 'roosterjs-content-model-types';\n\n/**\n * A temporary function to create Standalone Editor core\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createStandaloneEditorCore(\n contentDiv: HTMLDivElement,\n options: StandaloneEditorOptions,\n unportedCoreApiMap: UnportedCoreApiMap,\n unportedCorePluginState: UnportedCorePluginState,\n tempPlugins: EditorPlugin[]\n): StandaloneEditorCore {\n const corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);\n\n return {\n contentDiv,\n api: { ...standaloneCoreApiMap, ...unportedCoreApiMap, ...options.coreApiOverride },\n originalApi: { ...standaloneCoreApiMap, ...unportedCoreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...tempPlugins,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(),\n darkColorHandler: new DarkColorHandlerImpl(contentDiv, options.baseDarkColor),\n trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,\n ...createStandaloneEditorDefaultSettings(options),\n ...getPluginState(corePlugins),\n ...unportedCorePluginState,\n };\n}\n\nfunction createEditorEnvironment(): EditorEnvironment {\n // It is ok to use global window here since the environment should always be the same for all windows in one session\n const userAgent = window.navigator.userAgent;\n\n return {\n isMac: window.navigator.appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isSafari:\n userAgent.indexOf('Safari') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n };\n}\n\n/**\n * @internal export for test only\n */\nexport function defaultTrustHtmlHandler(html: string) {\n return html;\n}\n\nfunction getPluginState(corePlugins: StandaloneEditorCorePlugins): StandaloneEditorCorePluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n };\n}\n"]}
1
+ {"version":3,"file":"createStandaloneEditorCore.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/editor/createStandaloneEditorCore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAC;AACpG,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAY9D;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACtC,UAA0B,EAC1B,OAAgC,EAChC,kBAAsC,EACtC,uBAAgD,EAChD,WAA2B;;IAE3B,IAAM,WAAW,GAAG,iCAAiC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAE3E,oCACI,UAAU,YAAA,EACV,GAAG,iCAAO,oBAAoB,GAAK,kBAAkB,GAAK,OAAO,CAAC,eAAe,GACjF,WAAW,wBAAO,oBAAoB,GAAK,kBAAkB,GAC7D,OAAO;YACH,WAAW,CAAC,KAAK;YACjB,WAAW,CAAC,MAAM;YAClB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,QAAQ;YACpB,WAAW,CAAC,SAAS;YACrB,WAAW,CAAC,MAAM;kBACf,WAAW;YACd,WAAW,CAAC,SAAS;mBAEzB,WAAW,EAAE,uBAAuB,EAAE,EACtC,gBAAgB,EAAE,IAAI,oBAAoB,CACtC,UAAU,EACV,MAAA,OAAO,CAAC,YAAY,mCAAI,oBAAoB,CAC/C,EACD,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,uBAAuB,IACtE,qCAAqC,CAAC,OAAO,CAAC,GAC9C,cAAc,CAAC,WAAW,CAAC,GAC3B,uBAAuB,EAC5B;AACN,CAAC;AAED,SAAS,uBAAuB;IAC5B,oHAAoH;IACpH,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;IAE7C,OAAO;QACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC;QACrC,QAAQ,EACJ,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YAChC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC/B,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC;KACvC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAChD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,WAAwC;IAC5D,OAAO;QACH,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC3C,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE;QACrC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE;KAC9C,CAAC;AACN,CAAC;AAED,oDAAoD;AACpD,SAAS,oBAAoB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { createStandaloneEditorCorePlugins } from '../corePlugin/createStandaloneEditorCorePlugins';\nimport { createStandaloneEditorDefaultSettings } from './createStandaloneEditorDefaultSettings';\nimport { DarkColorHandlerImpl } from './DarkColorHandlerImpl';\nimport { standaloneCoreApiMap } from './standaloneCoreApiMap';\nimport type { EditorPlugin } from 'roosterjs-editor-types';\nimport type {\n EditorEnvironment,\n StandaloneEditorCore,\n StandaloneEditorCorePluginState,\n StandaloneEditorCorePlugins,\n StandaloneEditorOptions,\n UnportedCoreApiMap,\n UnportedCorePluginState,\n} from 'roosterjs-content-model-types';\n\n/**\n * A temporary function to create Standalone Editor core\n * @param contentDiv Editor content DIV\n * @param options Editor options\n */\nexport function createStandaloneEditorCore(\n contentDiv: HTMLDivElement,\n options: StandaloneEditorOptions,\n unportedCoreApiMap: UnportedCoreApiMap,\n unportedCorePluginState: UnportedCorePluginState,\n tempPlugins: EditorPlugin[]\n): StandaloneEditorCore {\n const corePlugins = createStandaloneEditorCorePlugins(options, contentDiv);\n\n return {\n contentDiv,\n api: { ...standaloneCoreApiMap, ...unportedCoreApiMap, ...options.coreApiOverride },\n originalApi: { ...standaloneCoreApiMap, ...unportedCoreApiMap },\n plugins: [\n corePlugins.cache,\n corePlugins.format,\n corePlugins.copyPaste,\n corePlugins.domEvent,\n corePlugins.selection,\n corePlugins.entity,\n ...tempPlugins,\n corePlugins.lifecycle,\n ],\n environment: createEditorEnvironment(),\n darkColorHandler: new DarkColorHandlerImpl(\n contentDiv,\n options.getDarkColor ?? getDarkColorFallback\n ),\n trustedHTMLHandler: options.trustedHTMLHandler || defaultTrustHtmlHandler,\n ...createStandaloneEditorDefaultSettings(options),\n ...getPluginState(corePlugins),\n ...unportedCorePluginState,\n };\n}\n\nfunction createEditorEnvironment(): EditorEnvironment {\n // It is ok to use global window here since the environment should always be the same for all windows in one session\n const userAgent = window.navigator.userAgent;\n\n return {\n isMac: window.navigator.appVersion.indexOf('Mac') != -1,\n isAndroid: /android/i.test(userAgent),\n isSafari:\n userAgent.indexOf('Safari') >= 0 &&\n userAgent.indexOf('Chrome') < 0 &&\n userAgent.indexOf('Android') < 0,\n };\n}\n\n/**\n * @internal export for test only\n */\nexport function defaultTrustHtmlHandler(html: string) {\n return html;\n}\n\nfunction getPluginState(corePlugins: StandaloneEditorCorePlugins): StandaloneEditorCorePluginState {\n return {\n domEvent: corePlugins.domEvent.getState(),\n copyPaste: corePlugins.copyPaste.getState(),\n cache: corePlugins.cache.getState(),\n format: corePlugins.format.getState(),\n lifecycle: corePlugins.lifecycle.getState(),\n entity: corePlugins.entity.getState(),\n selection: corePlugins.selection.getState(),\n };\n}\n\n// A fallback function, always return original color\nfunction getDarkColorFallback(color: string) {\n return color;\n}\n"]}
package/package.json CHANGED
@@ -3,13 +3,12 @@
3
3
  "description": "Content Model for roosterjs (Under development)",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "color": "^3.0.0",
7
6
  "roosterjs-editor-types": "^8.59.0",
8
7
  "roosterjs-editor-dom": "^8.59.0",
9
- "roosterjs-content-model-dom": "^0.21.0",
10
- "roosterjs-content-model-types": "^0.21.0"
8
+ "roosterjs-content-model-dom": "^0.21.1",
9
+ "roosterjs-content-model-types": "^0.21.1"
11
10
  },
12
- "version": "0.21.0",
11
+ "version": "0.21.1",
13
12
  "main": "./lib/index.js",
14
13
  "typings": "./lib/index.d.ts",
15
14
  "module": "./lib-mjs/index.js",