roosterjs-content-model-dom 0.26.2 → 0.26.4

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.
@@ -40,6 +40,7 @@ var KnownFontSizes = {
40
40
  };
41
41
  function normalizeFontSize(fontSize, contextFont, context) {
42
42
  var knownFontSize = KnownFontSizes[fontSize];
43
+ var isRemUnit = fontSize.endsWith('rem');
43
44
  if (knownFontSize) {
44
45
  return knownFontSize;
45
46
  }
@@ -47,12 +48,14 @@ function normalizeFontSize(fontSize, contextFont, context) {
47
48
  fontSize == 'larger' ||
48
49
  fontSize.endsWith('em') ||
49
50
  fontSize.endsWith('%') ||
50
- fontSize.endsWith('rem')) {
51
- if (!contextFont) {
51
+ isRemUnit) {
52
+ if (!contextFont && !isRemUnit) {
52
53
  return undefined;
53
54
  }
54
55
  else {
55
- var existingFontSize = (0, parseValueWithUnit_1.parseValueWithUnit)(contextFont, fontSize.endsWith('rem') ? context.rootFontSize : undefined /*element*/, 'px');
56
+ var existingFontSize = isRemUnit
57
+ ? context.rootFontSize
58
+ : (0, parseValueWithUnit_1.parseValueWithUnit)(contextFont);
56
59
  if (existingFontSize) {
57
60
  switch (fontSize) {
58
61
  case 'smaller':
@@ -1 +1 @@
1
- {"version":3,"file":"fontSizeFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/segment/fontSizeFormatHandler.ts"],"names":[],"mappings":";;;AAAA,iFAAqE;AACrE,kEAAiE;AAIjE;;GAEG;AACU,QAAA,qBAAqB,GAAkC;IAChE,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY;QAC1C,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC;QACjE,IAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,IAAI,YAAY,CAAC,aAAa,CAAC;QAEhF,0EAA0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AQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC1B;QACE,IAAI,CAAC,WAAW,EAAE;YACd,OAAO,SAAS,CAAC;SACpB;aAAM;YACH,IAAM,gBAAgB,GAAG,IAAA,uCAAkB,EACvC,WAAW,EACX,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,EACvE,IAAI,CACP,CAAC;YAEF,IAAI,gBAAgB,EAAE;gBAClB,QAAQ,QAAQ,EAAE;oBACd,KAAK,SAAS;wBACV,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;oBACjE,KAAK,QAAQ;wBACT,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;oBACjE;wBACI,OAAO,IAAA,uCAAkB,EAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;iBAC1E;aACJ;SACJ;KACJ;SAAM,IAAI,QAAQ,IAAI,SAAS,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,OAAO,EAAE;QAC7E,OAAO,SAAS,CAAC;KACpB;SAAM;QACH,OAAO,QAAQ,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { isSuperOrSubScript } from './superOrSubScriptFormatHandler';\nimport { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { EditorContext, FontSizeFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const fontSizeFormatHandler: FormatHandler<FontSizeFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const fontSize = element.style.fontSize || defaultStyle.fontSize;\n const verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;\n\n // when font size is 'smaller' and the style is for superscript/subscript,\n // the font size will be handled by superOrSubScript handler\n if (fontSize && !isSuperOrSubScript(fontSize, verticalAlign) && fontSize != 'inherit') {\n if (element.style.fontSize) {\n format.fontSize = normalizeFontSize(\n fontSize,\n context.segmentFormat.fontSize,\n context\n );\n } else if (defaultStyle.fontSize) {\n format.fontSize = fontSize;\n }\n }\n },\n apply: (format, element, context) => {\n if (format.fontSize && format.fontSize != context.implicitFormat.fontSize) {\n element.style.fontSize = format.fontSize;\n }\n },\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/font-size\nconst KnownFontSizes: Record<string, string> = {\n 'xx-small': '6.75pt',\n 'x-small': '7.5pt',\n small: '9.75pt',\n medium: '12pt',\n large: '13.5pt',\n 'x-large': '18pt',\n 'xx-large': '24pt',\n 'xxx-large': '36pt',\n};\n\nfunction normalizeFontSize(\n fontSize: string,\n contextFont: string | undefined,\n context: EditorContext\n): string | undefined {\n const knownFontSize = KnownFontSizes[fontSize];\n\n if (knownFontSize) {\n return knownFontSize;\n } else if (\n fontSize == 'smaller' ||\n fontSize == 'larger' ||\n fontSize.endsWith('em') ||\n fontSize.endsWith('%') ||\n fontSize.endsWith('rem')\n ) {\n if (!contextFont) {\n return undefined;\n } else {\n const existingFontSize = parseValueWithUnit(\n contextFont,\n fontSize.endsWith('rem') ? context.rootFontSize : undefined /*element*/,\n 'px'\n );\n\n if (existingFontSize) {\n switch (fontSize) {\n case 'smaller':\n return Math.round((existingFontSize * 500) / 6) / 100 + 'px';\n case 'larger':\n return Math.round((existingFontSize * 600) / 5) / 100 + 'px';\n default:\n return parseValueWithUnit(fontSize, existingFontSize, 'px') + 'px';\n }\n }\n }\n } else if (fontSize == 'inherit' || fontSize == 'revert' || fontSize == 'unset') {\n return undefined;\n } else {\n return fontSize;\n }\n}\n"]}
1
+ {"version":3,"file":"fontSizeFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/segment/fontS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QAAQ,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { isSuperOrSubScript } from './superOrSubScriptFormatHandler';\nimport { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { EditorContext, FontSizeFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const fontSizeFormatHandler: FormatHandler<FontSizeFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const fontSize = element.style.fontSize || defaultStyle.fontSize;\n const verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;\n\n // when font size is 'smaller' and the style is for superscript/subscript,\n // the font size will be handled by superOrSubScript handler\n if (fontSize && !isSuperOrSubScript(fontSize, verticalAlign) && fontSize != 'inherit') {\n if (element.style.fontSize) {\n format.fontSize = normalizeFontSize(\n fontSize,\n context.segmentFormat.fontSize,\n context\n );\n } else if (defaultStyle.fontSize) {\n format.fontSize = fontSize;\n }\n }\n },\n apply: (format, element, context) => {\n if (format.fontSize && format.fontSize != context.implicitFormat.fontSize) {\n element.style.fontSize = format.fontSize;\n }\n },\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/font-size\nconst KnownFontSizes: Record<string, string> = {\n 'xx-small': '6.75pt',\n 'x-small': '7.5pt',\n small: '9.75pt',\n medium: '12pt',\n large: '13.5pt',\n 'x-large': '18pt',\n 'xx-large': '24pt',\n 'xxx-large': '36pt',\n};\n\nfunction normalizeFontSize(\n fontSize: string,\n contextFont: string | undefined,\n context: EditorContext\n): string | undefined {\n const knownFontSize = KnownFontSizes[fontSize];\n const isRemUnit = fontSize.endsWith('rem');\n\n if (knownFontSize) {\n return knownFontSize;\n } else if (\n fontSize == 'smaller' ||\n fontSize == 'larger' ||\n fontSize.endsWith('em') ||\n fontSize.endsWith('%') ||\n isRemUnit\n ) {\n if (!contextFont && !isRemUnit) {\n return undefined;\n } else {\n const existingFontSize = isRemUnit\n ? context.rootFontSize\n : parseValueWithUnit(contextFont);\n\n if (existingFontSize) {\n switch (fontSize) {\n case 'smaller':\n return Math.round((existingFontSize * 500) / 6) / 100 + 'px';\n case 'larger':\n return Math.round((existingFontSize * 600) / 5) / 100 + 'px';\n default:\n return parseValueWithUnit(fontSize, existingFontSize, 'px') + 'px';\n }\n }\n }\n } else if (fontSize == 'inherit' || fontSize == 'revert' || fontSize == 'unset') {\n return undefined;\n } else {\n return fontSize;\n }\n}\n"]}
@@ -39,6 +39,7 @@ define(["require", "exports", "./superOrSubScriptFormatHandler", "../utils/parse
39
39
  };
40
40
  function normalizeFontSize(fontSize, contextFont, context) {
41
41
  var knownFontSize = KnownFontSizes[fontSize];
42
+ var isRemUnit = fontSize.endsWith('rem');
42
43
  if (knownFontSize) {
43
44
  return knownFontSize;
44
45
  }
@@ -46,12 +47,14 @@ define(["require", "exports", "./superOrSubScriptFormatHandler", "../utils/parse
46
47
  fontSize == 'larger' ||
47
48
  fontSize.endsWith('em') ||
48
49
  fontSize.endsWith('%') ||
49
- fontSize.endsWith('rem')) {
50
- if (!contextFont) {
50
+ isRemUnit) {
51
+ if (!contextFont && !isRemUnit) {
51
52
  return undefined;
52
53
  }
53
54
  else {
54
- var existingFontSize = (0, parseValueWithUnit_1.parseValueWithUnit)(contextFont, fontSize.endsWith('rem') ? context.rootFontSize : undefined /*element*/, 'px');
55
+ var existingFontSize = isRemUnit
56
+ ? context.rootFontSize
57
+ : (0, parseValueWithUnit_1.parseValueWithUnit)(contextFont);
55
58
  if (existingFontSize) {
56
59
  switch (fontSize) {
57
60
  case 'smaller':
@@ -1 +1 @@
1
- {"version":3,"file":"fontSizeFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/segment/fontSizeFormatHandler.ts"],"names":[],"mappings":";;;;IAKA;;OAEG;IACU,QAAA,qBAAqB,GAAkC;QAChE,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY;YAC1C,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,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ACH,QAAQ,IAAI,SAAS;YACrB,QAAQ,IAAI,QAAQ;YACpB,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;YACvB,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YACtB,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAC1B;YACE,IAAI,CAAC,WAAW,EAAE;gBACd,OAAO,SAAS,CAAC;aACpB;iBAAM;gBACH,IAAM,gBAAgB,GAAG,IAAA,uCAAkB,EACvC,WAAW,EACX,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,EACvE,IAAI,CACP,CAAC;gBAEF,IAAI,gBAAgB,EAAE;oBAClB,QAAQ,QAAQ,EAAE;wBACd,KAAK,SAAS;4BACV,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;wBACjE,KAAK,QAAQ;4BACT,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;wBACjE;4BACI,OAAO,IAAA,uCAAkB,EAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;qBAC1E;iBACJ;aACJ;SACJ;aAAM,IAAI,QAAQ,IAAI,SAAS,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,OAAO,EAAE;YAC7E,OAAO,SAAS,CAAC;SACpB;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { isSuperOrSubScript } from './superOrSubScriptFormatHandler';\nimport { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { EditorContext, FontSizeFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const fontSizeFormatHandler: FormatHandler<FontSizeFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const fontSize = element.style.fontSize || defaultStyle.fontSize;\n const verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;\n\n // when font size is 'smaller' and the style is for superscript/subscript,\n // the font size will be handled by superOrSubScript handler\n if (fontSize && !isSuperOrSubScript(fontSize, verticalAlign) && fontSize != 'inherit') {\n if (element.style.fontSize) {\n format.fontSize = normalizeFontSize(\n fontSize,\n context.segmentFormat.fontSize,\n context\n );\n } else if (defaultStyle.fontSize) {\n format.fontSize = fontSize;\n }\n }\n },\n apply: (format, element, context) => {\n if (format.fontSize && format.fontSize != context.implicitFormat.fontSize) {\n element.style.fontSize = format.fontSize;\n }\n },\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/font-size\nconst KnownFontSizes: Record<string, string> = {\n 'xx-small': '6.75pt',\n 'x-small': '7.5pt',\n small: '9.75pt',\n medium: '12pt',\n large: '13.5pt',\n 'x-large': '18pt',\n 'xx-large': '24pt',\n 'xxx-large': '36pt',\n};\n\nfunction normalizeFontSize(\n fontSize: string,\n contextFont: string | undefined,\n context: EditorContext\n): string | undefined {\n const knownFontSize = KnownFontSizes[fontSize];\n\n if (knownFontSize) {\n return knownFontSize;\n } else if (\n fontSize == 'smaller' ||\n fontSize == 'larger' ||\n fontSize.endsWith('em') ||\n fontSize.endsWith('%') ||\n fontSize.endsWith('rem')\n ) {\n if (!contextFont) {\n return undefined;\n } else {\n const existingFontSize = parseValueWithUnit(\n contextFont,\n fontSize.endsWith('rem') ? context.rootFontSize : undefined /*element*/,\n 'px'\n );\n\n if (existingFontSize) {\n switch (fontSize) {\n case 'smaller':\n return Math.round((existingFontSize * 500) / 6) / 100 + 'px';\n case 'larger':\n return Math.round((existingFontSize * 600) / 5) / 100 + 'px';\n default:\n return parseValueWithUnit(fontSize, existingFontSize, 'px') + 'px';\n }\n }\n }\n } else if (fontSize == 'inherit' || fontSize == 'revert' || fontSize == 'unset') {\n return undefined;\n } else {\n return fontSize;\n }\n}\n"]}
1
+ {"version":3,"file":"fontSizeFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/segment/fontSizeFormatHandler.ts"],"names":[],"mappings":";;;;IAKA;;OAEG;IACU,QAAA,qBAAqB,GAAkC;QAChE,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY;YAC1C,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC;YACjE,IAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,IAAI,YAAY,CAAC,aAAa,CAAC;YAEhF,0EAA0E;YAC1E,4DAA4D;YAC5D,IAAI,QAAQ,IAAI,CAAC,IAAA,kDAAkB,EAAC,QAAQ,EAAE,aAAa,CAAC,IAAI,QAAQ,IAAI,SAAS,EAAE;gBACnF,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE;oBACxB,MAAM,CAAC,QAAQ,GAAG,iBAAiB,CAC/B,QAAQ,EACR,OAAO,CAAC,aAAa,CAAC,QAAQ,EAC9B,OAAO,CACV,CAAC;iBACL;qBAAM,IAAI,YAAY,CAAC,QAAQ,EAAE;oBAC9B,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;iBAC9B;aACJ;QACL,CAAC;QACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO;YAC5B,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE;gBACvE,OAAO,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;aAC5C;QACL,CAAC;KACJ,CAAC;IAEF,6DAA6D;IAC7D,IAAM,cAAc,GAA2B;QAC3C,UAAU,EAAE,QAAQ;QACpB,SAAS,EAAE,OAAO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AM,IAAI,QAAQ,IAAI,SAAS,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,OAAO,EAAE;YAC7E,OAAO,SAAS,CAAC;SACpB;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { isSuperOrSubScript } from './superOrSubScriptFormatHandler';\nimport { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { EditorContext, FontSizeFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const fontSizeFormatHandler: FormatHandler<FontSizeFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const fontSize = element.style.fontSize || defaultStyle.fontSize;\n const verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;\n\n // when font size is 'smaller' and the style is for superscript/subscript,\n // the font size will be handled by superOrSubScript handler\n if (fontSize && !isSuperOrSubScript(fontSize, verticalAlign) && fontSize != 'inherit') {\n if (element.style.fontSize) {\n format.fontSize = normalizeFontSize(\n fontSize,\n context.segmentFormat.fontSize,\n context\n );\n } else if (defaultStyle.fontSize) {\n format.fontSize = fontSize;\n }\n }\n },\n apply: (format, element, context) => {\n if (format.fontSize && format.fontSize != context.implicitFormat.fontSize) {\n element.style.fontSize = format.fontSize;\n }\n },\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/font-size\nconst KnownFontSizes: Record<string, string> = {\n 'xx-small': '6.75pt',\n 'x-small': '7.5pt',\n small: '9.75pt',\n medium: '12pt',\n large: '13.5pt',\n 'x-large': '18pt',\n 'xx-large': '24pt',\n 'xxx-large': '36pt',\n};\n\nfunction normalizeFontSize(\n fontSize: string,\n contextFont: string | undefined,\n context: EditorContext\n): string | undefined {\n const knownFontSize = KnownFontSizes[fontSize];\n const isRemUnit = fontSize.endsWith('rem');\n\n if (knownFontSize) {\n return knownFontSize;\n } else if (\n fontSize == 'smaller' ||\n fontSize == 'larger' ||\n fontSize.endsWith('em') ||\n fontSize.endsWith('%') ||\n isRemUnit\n ) {\n if (!contextFont && !isRemUnit) {\n return undefined;\n } else {\n const existingFontSize = isRemUnit\n ? context.rootFontSize\n : parseValueWithUnit(contextFont);\n\n if (existingFontSize) {\n switch (fontSize) {\n case 'smaller':\n return Math.round((existingFontSize * 500) / 6) / 100 + 'px';\n case 'larger':\n return Math.round((existingFontSize * 600) / 5) / 100 + 'px';\n default:\n return parseValueWithUnit(fontSize, existingFontSize, 'px') + 'px';\n }\n }\n }\n } else if (fontSize == 'inherit' || fontSize == 'revert' || fontSize == 'unset') {\n return undefined;\n } else {\n return fontSize;\n }\n}\n"]}
@@ -37,6 +37,7 @@ var KnownFontSizes = {
37
37
  };
38
38
  function normalizeFontSize(fontSize, contextFont, context) {
39
39
  var knownFontSize = KnownFontSizes[fontSize];
40
+ var isRemUnit = fontSize.endsWith('rem');
40
41
  if (knownFontSize) {
41
42
  return knownFontSize;
42
43
  }
@@ -44,12 +45,14 @@ function normalizeFontSize(fontSize, contextFont, context) {
44
45
  fontSize == 'larger' ||
45
46
  fontSize.endsWith('em') ||
46
47
  fontSize.endsWith('%') ||
47
- fontSize.endsWith('rem')) {
48
- if (!contextFont) {
48
+ isRemUnit) {
49
+ if (!contextFont && !isRemUnit) {
49
50
  return undefined;
50
51
  }
51
52
  else {
52
- var existingFontSize = parseValueWithUnit(contextFont, fontSize.endsWith('rem') ? context.rootFontSize : undefined /*element*/, 'px');
53
+ var existingFontSize = isRemUnit
54
+ ? context.rootFontSize
55
+ : parseValueWithUnit(contextFont);
53
56
  if (existingFontSize) {
54
57
  switch (fontSize) {
55
58
  case 'smaller':
@@ -1 +1 @@
1
- {"version":3,"file":"fontSizeFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/segment/fontSizeFormatHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA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ubScript } from './superOrSubScriptFormatHandler';\nimport { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { EditorContext, FontSizeFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const fontSizeFormatHandler: FormatHandler<FontSizeFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const fontSize = element.style.fontSize || defaultStyle.fontSize;\n const verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;\n\n // when font size is 'smaller' and the style is for superscript/subscript,\n // the font size will be handled by superOrSubScript handler\n if (fontSize && !isSuperOrSubScript(fontSize, verticalAlign) && fontSize != 'inherit') {\n if (element.style.fontSize) {\n format.fontSize = normalizeFontSize(\n fontSize,\n context.segmentFormat.fontSize,\n context\n );\n } else if (defaultStyle.fontSize) {\n format.fontSize = fontSize;\n }\n }\n },\n apply: (format, element, context) => {\n if (format.fontSize && format.fontSize != context.implicitFormat.fontSize) {\n element.style.fontSize = format.fontSize;\n }\n },\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/font-size\nconst KnownFontSizes: Record<string, string> = {\n 'xx-small': '6.75pt',\n 'x-small': '7.5pt',\n small: '9.75pt',\n medium: '12pt',\n large: '13.5pt',\n 'x-large': '18pt',\n 'xx-large': '24pt',\n 'xxx-large': '36pt',\n};\n\nfunction normalizeFontSize(\n fontSize: string,\n contextFont: string | undefined,\n context: EditorContext\n): string | undefined {\n const knownFontSize = KnownFontSizes[fontSize];\n\n if (knownFontSize) {\n return knownFontSize;\n } else if (\n fontSize == 'smaller' ||\n fontSize == 'larger' ||\n fontSize.endsWith('em') ||\n fontSize.endsWith('%') ||\n fontSize.endsWith('rem')\n ) {\n if (!contextFont) {\n return undefined;\n } else {\n const existingFontSize = parseValueWithUnit(\n contextFont,\n fontSize.endsWith('rem') ? context.rootFontSize : undefined /*element*/,\n 'px'\n );\n\n if (existingFontSize) {\n switch (fontSize) {\n case 'smaller':\n return Math.round((existingFontSize * 500) / 6) / 100 + 'px';\n case 'larger':\n return Math.round((existingFontSize * 600) / 5) / 100 + 'px';\n default:\n return parseValueWithUnit(fontSize, existingFontSize, 'px') + 'px';\n }\n }\n }\n } else if (fontSize == 'inherit' || fontSize == 'revert' || fontSize == 'unset') {\n return undefined;\n } else {\n return fontSize;\n }\n}\n"]}
1
+ {"version":3,"file":"fontSizeFormatHandler.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-dom/lib/formatHandlers/segment/fontSizeFormatHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAIjE;;GAEG;AACH,MAAM,CAAC,IAAM,qBAAqB,GAAkC;IAChE,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY;QAC1C,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC;QACjE,IAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,IAAI,YAAY,CAAC,aAAa,CAAC;QAEhF,0EAA0E;QAC1E,4DAA4D;QAC5D,IAAI,QAAQ,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,aAAa,CAAC,IAAI,QAAQ,IAAI,SAAS,EAAE;YACnF,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACxB,MAAM,CAAC,QAAQ,GAAG,iBAAiB,CAC/B,QAAQ,EACR,OAAO,CAAC,aAAa,CAAC,QAAQ,EAC9B,OAAO,CACV,CAAC;aACL;iBAAM,IAAI,YAAY,CAAC,QAAQ,EAAE;gBAC9B,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;aAC9B;SACJ;IACL,CAAC;IACD,KAAK,EAAE,UAAC,MAAM,EAAE,OAAO,EAAE,OAAO;QAC5B,IAAI,MAAM,CAAC,QAAQ,IAAI,MA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OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;oBACjE;wBACI,OAAO,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;iBAC1E;aACJ;SACJ;KACJ;SAAM,IAAI,QAAQ,IAAI,SAAS,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,OAAO,EAAE;QAC7E,OAAO,SAAS,CAAC;KACpB;SAAM;QACH,OAAO,QAAQ,CAAC;KACnB;AACL,CAAC","sourcesContent":["import { isSuperOrSubScript } from './superOrSubScriptFormatHandler';\nimport { parseValueWithUnit } from '../utils/parseValueWithUnit';\nimport type { EditorContext, FontSizeFormat } from 'roosterjs-content-model-types';\nimport type { FormatHandler } from '../FormatHandler';\n\n/**\n * @internal\n */\nexport const fontSizeFormatHandler: FormatHandler<FontSizeFormat> = {\n parse: (format, element, context, defaultStyle) => {\n const fontSize = element.style.fontSize || defaultStyle.fontSize;\n const verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;\n\n // when font size is 'smaller' and the style is for superscript/subscript,\n // the font size will be handled by superOrSubScript handler\n if (fontSize && !isSuperOrSubScript(fontSize, verticalAlign) && fontSize != 'inherit') {\n if (element.style.fontSize) {\n format.fontSize = normalizeFontSize(\n fontSize,\n context.segmentFormat.fontSize,\n context\n );\n } else if (defaultStyle.fontSize) {\n format.fontSize = fontSize;\n }\n }\n },\n apply: (format, element, context) => {\n if (format.fontSize && format.fontSize != context.implicitFormat.fontSize) {\n element.style.fontSize = format.fontSize;\n }\n },\n};\n\n// https://developer.mozilla.org/en-US/docs/Web/CSS/font-size\nconst KnownFontSizes: Record<string, string> = {\n 'xx-small': '6.75pt',\n 'x-small': '7.5pt',\n small: '9.75pt',\n medium: '12pt',\n large: '13.5pt',\n 'x-large': '18pt',\n 'xx-large': '24pt',\n 'xxx-large': '36pt',\n};\n\nfunction normalizeFontSize(\n fontSize: string,\n contextFont: string | undefined,\n context: EditorContext\n): string | undefined {\n const knownFontSize = KnownFontSizes[fontSize];\n const isRemUnit = fontSize.endsWith('rem');\n\n if (knownFontSize) {\n return knownFontSize;\n } else if (\n fontSize == 'smaller' ||\n fontSize == 'larger' ||\n fontSize.endsWith('em') ||\n fontSize.endsWith('%') ||\n isRemUnit\n ) {\n if (!contextFont && !isRemUnit) {\n return undefined;\n } else {\n const existingFontSize = isRemUnit\n ? context.rootFontSize\n : parseValueWithUnit(contextFont);\n\n if (existingFontSize) {\n switch (fontSize) {\n case 'smaller':\n return Math.round((existingFontSize * 500) / 6) / 100 + 'px';\n case 'larger':\n return Math.round((existingFontSize * 600) / 5) / 100 + 'px';\n default:\n return parseValueWithUnit(fontSize, existingFontSize, 'px') + 'px';\n }\n }\n }\n } else if (fontSize == 'inherit' || fontSize == 'revert' || fontSize == 'unset') {\n return undefined;\n } else {\n return fontSize;\n }\n}\n"]}
package/package.json CHANGED
@@ -3,9 +3,9 @@
3
3
  "description": "Content Model for roosterjs (Under development)",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-types": "^0.26.2"
6
+ "roosterjs-content-model-types": "^0.26.4"
7
7
  },
8
- "version": "0.26.2",
8
+ "version": "0.26.4",
9
9
  "main": "./lib/index.js",
10
10
  "typings": "./lib/index.d.ts",
11
11
  "module": "./lib-mjs/index.js",