roosterjs-content-model-core 9.9.1 → 9.9.2

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.
@@ -23,13 +23,15 @@ function retrieveCssRules(doc) {
23
23
  styles.forEach(function (styleNode) {
24
24
  var _a;
25
25
  var sheet = styleNode.sheet;
26
- for (var ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {
27
- var rule = sheet.cssRules[ruleIndex];
28
- if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {
29
- result.push({
30
- selectors: splitSelectors(rule.selectorText),
31
- text: rule.style.cssText,
32
- });
26
+ if (sheet) {
27
+ for (var ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {
28
+ var rule = sheet.cssRules[ruleIndex];
29
+ if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {
30
+ result.push({
31
+ selectors: splitSelectors(rule.selectorText),
32
+ text: rule.style.cssText,
33
+ });
34
+ }
33
35
  }
34
36
  }
35
37
  (_a = styleNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(styleNode);
@@ -1 +1 @@
1
- {"version":3,"file":"convertInlineCss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts"],"names":[],"mappings":";;;;AAAA,2EAAsD;AAUtD;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,YAAoB;IACxC,IAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,EAAR,CAAQ,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,GAAa;IAC1C,IAAM,MAAM,GAAG,IAAA,qCAAO,EAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,IAAM,MAAM,G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IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;gBAArE,CAAqE,CACxE,CAAC;aACL;;;;;;;;;;IAhBL,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBAApC,CAAC;KAiBT;AACL,CAAC;AAnBD,4CAmBC","sourcesContent":["import { toArray } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface CssRule {\n selectors: string[];\n text: string;\n}\n\n/**\n * @internal\n *\n * Splits CSS selectors, avoiding splits within parentheses\n * @param selectorText The CSS selector string\n * @return Array of trimmed selectors\n */\nfunction splitSelectors(selectorText: string) {\n const regex = /(?![^(]*\\)),/;\n return selectorText.split(regex).map(s => s.trim());\n}\n\n/**\n * @internal\n */\nexport function retrieveCssRules(doc: Document): CssRule[] {\n const styles = toArray(doc.querySelectorAll('style'));\n const result: CssRule[] = [];\n\n styles.forEach(styleNode => {\n const sheet = styleNode.sheet as CSSStyleSheet;\n\n for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {\n const rule = sheet.cssRules[ruleIndex] as CSSStyleRule;\n\n if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {\n result.push({\n selectors: splitSelectors(rule.selectorText),\n text: rule.style.cssText,\n });\n }\n }\n\n styleNode.parentNode?.removeChild(styleNode);\n });\n\n return result;\n}\n\n/**\n * @internal\n */\nexport function convertInlineCss(root: ParentNode, cssRules: CssRule[]) {\n for (let i = cssRules.length - 1; i >= 0; i--) {\n const { selectors, text } = cssRules[i];\n\n for (const selector of selectors) {\n if (!selector || !selector.trim()) {\n continue;\n }\n\n const nodes = toArray(root.querySelectorAll(selector));\n\n // Always put existing styles after so that they have higher priority\n // Which means if both global style and inline style apply to the same element,\n // inline style will have higher priority\n nodes.forEach(node =>\n node.setAttribute('style', text + (node.getAttribute('style') || ''))\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"convertInlineCss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts"],"names":[],"mappings":";;;;AAAA,2EAAsD;AAUtD;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,YAAoB;IACxC,IAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,EAAR,CAAQ,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,GAAa;IAC1C,IAAM,MAAM,GAAG,IAAA,qCAAO,EAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,IAAM,MAAM,GAAc,EAAE,CAAC;IAE7B,MAAM,CAAC,OAAO,CAAC,UAAA,SAAS;;QACpB,IAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;QAE9B,IAAI,KAAK,EAAE;YACP,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;gBACpE,IAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAiB,CAAC;gBAEvD,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;oBACtD,MAAM,CAAC,IAAI,CAAC;wBACR,SAAS,EAAE,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC;wBAC5C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;qBAC3B,CAAC,CAAC;iBACN;aACJ;SACJ;QAED,MAAA,SAAS,CAAC,UAAU,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAClB,CAAC;AAxBD,4CAwBC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAgB,EAAE,QAAmB;4BACzD,CAAC;;QACA,IAAA,KAAsB,QAAQ,CAAC,CAAC,CAAC,EAA/B,SAAS,eAAA,EAAE,IAAI,UAAgB,CAAC;;YAExC,KAAuB,IAAA,6BAAA,sBAAA,SAAS,CAAA,CAAA,oCAAA,2DAAE;gBAA7B,IAAM,QAAQ,sBAAA;gBACf,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE;oBAC/B,SAAS;iBACZ;gBAED,IAAM,KAAK,GAAG,IAAA,qCAAO,EAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAEvD,qEAAqE;gBACrE,+EAA+E;gBAC/E,yCAAyC;gBACzC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;oBACd,OAAA,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;gBAArE,CAAqE,CACxE,CAAC;aACL;;;;;;;;;;IAhBL,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBAApC,CAAC;KAiBT;AACL,CAAC;AAnBD,4CAmBC","sourcesContent":["import { toArray } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface CssRule {\n selectors: string[];\n text: string;\n}\n\n/**\n * @internal\n *\n * Splits CSS selectors, avoiding splits within parentheses\n * @param selectorText The CSS selector string\n * @return Array of trimmed selectors\n */\nfunction splitSelectors(selectorText: string) {\n const regex = /(?![^(]*\\)),/;\n return selectorText.split(regex).map(s => s.trim());\n}\n\n/**\n * @internal\n */\nexport function retrieveCssRules(doc: Document): CssRule[] {\n const styles = toArray(doc.querySelectorAll('style'));\n const result: CssRule[] = [];\n\n styles.forEach(styleNode => {\n const sheet = styleNode.sheet;\n\n if (sheet) {\n for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {\n const rule = sheet.cssRules[ruleIndex] as CSSStyleRule;\n\n if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {\n result.push({\n selectors: splitSelectors(rule.selectorText),\n text: rule.style.cssText,\n });\n }\n }\n }\n\n styleNode.parentNode?.removeChild(styleNode);\n });\n\n return result;\n}\n\n/**\n * @internal\n */\nexport function convertInlineCss(root: ParentNode, cssRules: CssRule[]) {\n for (let i = cssRules.length - 1; i >= 0; i--) {\n const { selectors, text } = cssRules[i];\n\n for (const selector of selectors) {\n if (!selector || !selector.trim()) {\n continue;\n }\n\n const nodes = toArray(root.querySelectorAll(selector));\n\n // Always put existing styles after so that they have higher priority\n // Which means if both global style and inline style apply to the same element,\n // inline style will have higher priority\n nodes.forEach(node =>\n node.setAttribute('style', text + (node.getAttribute('style') || ''))\n );\n }\n }\n}\n"]}
@@ -22,13 +22,15 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
22
22
  styles.forEach(function (styleNode) {
23
23
  var _a;
24
24
  var sheet = styleNode.sheet;
25
- for (var ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {
26
- var rule = sheet.cssRules[ruleIndex];
27
- if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {
28
- result.push({
29
- selectors: splitSelectors(rule.selectorText),
30
- text: rule.style.cssText,
31
- });
25
+ if (sheet) {
26
+ for (var ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {
27
+ var rule = sheet.cssRules[ruleIndex];
28
+ if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {
29
+ result.push({
30
+ selectors: splitSelectors(rule.selectorText),
31
+ text: rule.style.cssText,
32
+ });
33
+ }
32
34
  }
33
35
  }
34
36
  (_a = styleNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(styleNode);
@@ -1 +1 @@
1
- {"version":3,"file":"convertInlineCss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts"],"names":[],"mappings":";;;;IAUA;;;;;;OAMG;IACH,SAAS,cAAc,CAAC,YAAoB;QACxC,IAAM,KAAK,GAAG,cAAc,CAAC;QAC7B,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,EAAR,CAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,SAAgB,gBAAgB,CAAC,GAAa;QAC1C,IAAM,MAAM,GAAG,IAAA,qCAAO,EAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QACtD,IAAM,MAAM,GAAc,EAAE,CAAC;QAE7B,MAAM,CAAC,OAAO,CAAC,UAAA,SAAS;;YACpB,IAAM,KAAK,GAAG,SAAS,CAAC,KAAsB,CAAC;YAE/C,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;gBACpE,IAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAiB,CAAC;gBAEvD,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;oBACtD,MAAM,CAAC,IAAI,CAAC;wBACR,SAAS,EAAE,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC;wBAC5C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;qBAC3B,CAAC,CAAC;iBACN;aACJ;YAED,MAAA,SAAS,CAAC,UAAU,0CAAE,WAAW,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAClB,CAAC;IAtBD,4CAsBC;IAED;;OAEG;IACH,SAAgB,gBAAgB,CAAC,IAAgB,EAAE,QAAmB;gCACzD,CAAC;;YACA,IAAA,KAAsB,QAAQ,CAAC,CAAC,CAAC,EAA/B,SAAS,eAAA,EAAE,IAAI,UAAgB,CAAC;;gBAExC,KAAuB,IAAA,6BAAA,sBAAA,SAAS,CAAA,CAAA,oCAAA,2DAAE;oBAA7B,IAAM,QAAQ,sBAAA;oBACf,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE;wBAC/B,SAAS;qBACZ;oBAED,IAAM,KAAK,GAAG,IAAA,qCAAO,EAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAEvD,qEAAqE;oBACrE,+EAA+E;oBAC/E,yCAAyC;oBACzC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;wBACd,OAAA,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;oBAArE,CAAqE,CACxE,CAAC;iBACL;;;;;;;;;;QAhBL,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;oBAApC,CAAC;SAiBT;IACL,CAAC;IAnBD,4CAmBC","sourcesContent":["import { toArray } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface CssRule {\n selectors: string[];\n text: string;\n}\n\n/**\n * @internal\n *\n * Splits CSS selectors, avoiding splits within parentheses\n * @param selectorText The CSS selector string\n * @return Array of trimmed selectors\n */\nfunction splitSelectors(selectorText: string) {\n const regex = /(?![^(]*\\)),/;\n return selectorText.split(regex).map(s => s.trim());\n}\n\n/**\n * @internal\n */\nexport function retrieveCssRules(doc: Document): CssRule[] {\n const styles = toArray(doc.querySelectorAll('style'));\n const result: CssRule[] = [];\n\n styles.forEach(styleNode => {\n const sheet = styleNode.sheet as CSSStyleSheet;\n\n for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {\n const rule = sheet.cssRules[ruleIndex] as CSSStyleRule;\n\n if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {\n result.push({\n selectors: splitSelectors(rule.selectorText),\n text: rule.style.cssText,\n });\n }\n }\n\n styleNode.parentNode?.removeChild(styleNode);\n });\n\n return result;\n}\n\n/**\n * @internal\n */\nexport function convertInlineCss(root: ParentNode, cssRules: CssRule[]) {\n for (let i = cssRules.length - 1; i >= 0; i--) {\n const { selectors, text } = cssRules[i];\n\n for (const selector of selectors) {\n if (!selector || !selector.trim()) {\n continue;\n }\n\n const nodes = toArray(root.querySelectorAll(selector));\n\n // Always put existing styles after so that they have higher priority\n // Which means if both global style and inline style apply to the same element,\n // inline style will have higher priority\n nodes.forEach(node =>\n node.setAttribute('style', text + (node.getAttribute('style') || ''))\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"convertInlineCss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts"],"names":[],"mappings":";;;;IAUA;;;;;;OAMG;IACH,SAAS,cAAc,CAAC,YAAoB;QACxC,IAAM,KAAK,GAAG,cAAc,CAAC;QAC7B,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,EAAR,CAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,SAAgB,gBAAgB,CAAC,GAAa;QAC1C,IAAM,MAAM,GAAG,IAAA,qCAAO,EAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QACtD,IAAM,MAAM,GAAc,EAAE,CAAC;QAE7B,MAAM,CAAC,OAAO,CAAC,UAAA,SAAS;;YACpB,IAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;YAE9B,IAAI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AC,IAAI,EAAE,CAAC,CAAC;oBAArE,CAAqE,CACxE,CAAC;iBACL;;;;;;;;;;QAhBL,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;oBAApC,CAAC;SAiBT;IACL,CAAC;IAnBD,4CAmBC","sourcesContent":["import { toArray } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface CssRule {\n selectors: string[];\n text: string;\n}\n\n/**\n * @internal\n *\n * Splits CSS selectors, avoiding splits within parentheses\n * @param selectorText The CSS selector string\n * @return Array of trimmed selectors\n */\nfunction splitSelectors(selectorText: string) {\n const regex = /(?![^(]*\\)),/;\n return selectorText.split(regex).map(s => s.trim());\n}\n\n/**\n * @internal\n */\nexport function retrieveCssRules(doc: Document): CssRule[] {\n const styles = toArray(doc.querySelectorAll('style'));\n const result: CssRule[] = [];\n\n styles.forEach(styleNode => {\n const sheet = styleNode.sheet;\n\n if (sheet) {\n for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {\n const rule = sheet.cssRules[ruleIndex] as CSSStyleRule;\n\n if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {\n result.push({\n selectors: splitSelectors(rule.selectorText),\n text: rule.style.cssText,\n });\n }\n }\n }\n\n styleNode.parentNode?.removeChild(styleNode);\n });\n\n return result;\n}\n\n/**\n * @internal\n */\nexport function convertInlineCss(root: ParentNode, cssRules: CssRule[]) {\n for (let i = cssRules.length - 1; i >= 0; i--) {\n const { selectors, text } = cssRules[i];\n\n for (const selector of selectors) {\n if (!selector || !selector.trim()) {\n continue;\n }\n\n const nodes = toArray(root.querySelectorAll(selector));\n\n // Always put existing styles after so that they have higher priority\n // Which means if both global style and inline style apply to the same element,\n // inline style will have higher priority\n nodes.forEach(node =>\n node.setAttribute('style', text + (node.getAttribute('style') || ''))\n );\n }\n }\n}\n"]}
@@ -20,13 +20,15 @@ export function retrieveCssRules(doc) {
20
20
  styles.forEach(function (styleNode) {
21
21
  var _a;
22
22
  var sheet = styleNode.sheet;
23
- for (var ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {
24
- var rule = sheet.cssRules[ruleIndex];
25
- if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {
26
- result.push({
27
- selectors: splitSelectors(rule.selectorText),
28
- text: rule.style.cssText,
29
- });
23
+ if (sheet) {
24
+ for (var ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {
25
+ var rule = sheet.cssRules[ruleIndex];
26
+ if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {
27
+ result.push({
28
+ selectors: splitSelectors(rule.selectorText),
29
+ text: rule.style.cssText,
30
+ });
31
+ }
30
32
  }
31
33
  }
32
34
  (_a = styleNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(styleNode);
@@ -1 +1 @@
1
- {"version":3,"file":"convertInlineCss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAUtD;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,YAAoB;IACxC,IAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,EAAR,CAAQ,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAa;IAC1C,IAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,IAAM,MAAM,GAAc,EAAE,CAAC;IAE7B,MAAM,CAAC,OAAO,CAAC,UAAA,SAAS;;QACpB,IAAM,KAAK,GAAG,SAAS,CAAC,KAAsB,CAAC;QAE/C,K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C;aACL;;;;;;;;;;IAhBL,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBAApC,CAAC;KAiBT;AACL,CAAC","sourcesContent":["import { toArray } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface CssRule {\n selectors: string[];\n text: string;\n}\n\n/**\n * @internal\n *\n * Splits CSS selectors, avoiding splits within parentheses\n * @param selectorText The CSS selector string\n * @return Array of trimmed selectors\n */\nfunction splitSelectors(selectorText: string) {\n const regex = /(?![^(]*\\)),/;\n return selectorText.split(regex).map(s => s.trim());\n}\n\n/**\n * @internal\n */\nexport function retrieveCssRules(doc: Document): CssRule[] {\n const styles = toArray(doc.querySelectorAll('style'));\n const result: CssRule[] = [];\n\n styles.forEach(styleNode => {\n const sheet = styleNode.sheet as CSSStyleSheet;\n\n for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {\n const rule = sheet.cssRules[ruleIndex] as CSSStyleRule;\n\n if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {\n result.push({\n selectors: splitSelectors(rule.selectorText),\n text: rule.style.cssText,\n });\n }\n }\n\n styleNode.parentNode?.removeChild(styleNode);\n });\n\n return result;\n}\n\n/**\n * @internal\n */\nexport function convertInlineCss(root: ParentNode, cssRules: CssRule[]) {\n for (let i = cssRules.length - 1; i >= 0; i--) {\n const { selectors, text } = cssRules[i];\n\n for (const selector of selectors) {\n if (!selector || !selector.trim()) {\n continue;\n }\n\n const nodes = toArray(root.querySelectorAll(selector));\n\n // Always put existing styles after so that they have higher priority\n // Which means if both global style and inline style apply to the same element,\n // inline style will have higher priority\n nodes.forEach(node =>\n node.setAttribute('style', text + (node.getAttribute('style') || ''))\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"convertInlineCss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts"],"names":[],"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A,IAAA,KAAsB,QAAQ,CAAC,CAAC,CAAC,EAA/B,SAAS,eAAA,EAAE,IAAI,UAAgB,CAAC;;YAExC,KAAuB,IAAA,6BAAA,SAAA,SAAS,CAAA,CAAA,oCAAA,2DAAE;gBAA7B,IAAM,QAAQ,sBAAA;gBACf,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE;oBAC/B,SAAS;iBACZ;gBAED,IAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAEvD,qEAAqE;gBACrE,+EAA+E;gBAC/E,yCAAyC;gBACzC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;oBACd,OAAA,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;gBAArE,CAAqE,CACxE,CAAC;aACL;;;;;;;;;;IAhBL,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBAApC,CAAC;KAiBT;AACL,CAAC","sourcesContent":["import { toArray } from 'roosterjs-content-model-dom';\n\n/**\n * @internal\n */\nexport interface CssRule {\n selectors: string[];\n text: string;\n}\n\n/**\n * @internal\n *\n * Splits CSS selectors, avoiding splits within parentheses\n * @param selectorText The CSS selector string\n * @return Array of trimmed selectors\n */\nfunction splitSelectors(selectorText: string) {\n const regex = /(?![^(]*\\)),/;\n return selectorText.split(regex).map(s => s.trim());\n}\n\n/**\n * @internal\n */\nexport function retrieveCssRules(doc: Document): CssRule[] {\n const styles = toArray(doc.querySelectorAll('style'));\n const result: CssRule[] = [];\n\n styles.forEach(styleNode => {\n const sheet = styleNode.sheet;\n\n if (sheet) {\n for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) {\n const rule = sheet.cssRules[ruleIndex] as CSSStyleRule;\n\n if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) {\n result.push({\n selectors: splitSelectors(rule.selectorText),\n text: rule.style.cssText,\n });\n }\n }\n }\n\n styleNode.parentNode?.removeChild(styleNode);\n });\n\n return result;\n}\n\n/**\n * @internal\n */\nexport function convertInlineCss(root: ParentNode, cssRules: CssRule[]) {\n for (let i = cssRules.length - 1; i >= 0; i--) {\n const { selectors, text } = cssRules[i];\n\n for (const selector of selectors) {\n if (!selector || !selector.trim()) {\n continue;\n }\n\n const nodes = toArray(root.querySelectorAll(selector));\n\n // Always put existing styles after so that they have higher priority\n // Which means if both global style and inline style apply to the same element,\n // inline style will have higher priority\n nodes.forEach(node =>\n node.setAttribute('style', text + (node.getAttribute('style') || ''))\n );\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "roosterjs-content-model-dom": "^9.9.1",
7
7
  "roosterjs-content-model-types": "^9.9.1"
8
8
  },
9
- "version": "9.9.1",
9
+ "version": "9.9.2",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",