single-file-helper.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * Copyright 2010-2019 Gildas Lormeau
  3. * contact : gildas.lormeau <at> gmail.com
  4. *
  5. * This file is part of SingleFile.
  6. *
  7. * The code in this file is free software: you can redistribute it and/or
  8. * modify it under the terms of the GNU Affero General Public License
  9. * (GNU AGPL) as published by the Free Software Foundation, either version 3
  10. * of the License, or (at your option) any later version.
  11. *
  12. * The code in this file is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  15. * General Public License for more details.
  16. *
  17. * As additional permission under GNU AGPL version 3 section 7, you may
  18. * distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
  19. * AGPL normally required by section 4, provided you include this license
  20. * notice and a URL through which recipients can access the Corresponding
  21. * Source.
  22. */
  23. /* global CustomEvent, addEventListener, dispatchEvent */
  24. this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
  25. const singlefile = this.singlefile;
  26. const ON_BEFORE_CAPTURE_EVENT_NAME = "single-file-on-before-capture";
  27. const ON_AFTER_CAPTURE_EVENT_NAME = "single-file-on-after-capture";
  28. const REMOVED_CONTENT_ATTRIBUTE_NAME = "data-single-file-removed-content";
  29. const HIDDEN_CONTENT_ATTRIBUTE_NAME = "data-single-file-hidden-content";
  30. const PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME = "data-single-file-preserved-space-element";
  31. const SHADOW_ROOT_ATTRIBUTE_NAME = "data-single-file-shadow-root-element";
  32. const WIN_ID_ATTRIBUTE_NAME = "data-single-file-win-id";
  33. const IMAGE_ATTRIBUTE_NAME = "data-single-file-image";
  34. const POSTER_ATTRIBUTE_NAME = "data-single-file-poster";
  35. const CANVAS_ATTRIBUTE_NAME = "data-single-file-canvas";
  36. const HTML_IMPORT_ATTRIBUTE_NAME = "data-single-file-import";
  37. const INPUT_VALUE_ATTRIBUTE_NAME = "data-single-file-input-value";
  38. const LAZY_SRC_ATTRIBUTE_NAME = "data-single-file-lazy-loaded-src";
  39. const STYLESHEET_ATTRIBUTE_NAME = "data-single-file-stylesheet";
  40. const DISABLED_NOSCRIPT_ATTRIBUTE_NAME = "data-single-file-disabled-noscript";
  41. const SELECTED_CONTENT_ATTRIBUTE_NAME = "data-single-file-selected-content";
  42. const ASYNC_SCRIPT_ATTRIBUTE_NAME = "data-single-file-async-script";
  43. const IGNORED_REMOVED_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT", "SCRIPT", "HEAD"];
  44. const REGEXP_SIMPLE_QUOTES_STRING = /^'(.*?)'$/;
  45. const REGEXP_DOUBLE_QUOTES_STRING = /^"(.*?)"$/;
  46. const FONT_WEIGHTS = {
  47. normal: "400",
  48. bold: "700"
  49. };
  50. addEventListener("single-file-user-script-init", () => singlefile.lib.helper.waitForUserScript = async eventPrefixName => {
  51. const event = new CustomEvent(eventPrefixName + "-request", { cancelable: true });
  52. const promiseResponse = new Promise(resolve => addEventListener(eventPrefixName + "-response", resolve));
  53. dispatchEvent(event);
  54. if (event.defaultPrevented) {
  55. await promiseResponse;
  56. }
  57. });
  58. return {
  59. initDoc,
  60. preProcessDoc,
  61. postProcessDoc,
  62. serialize,
  63. removeQuotes,
  64. ON_BEFORE_CAPTURE_EVENT_NAME,
  65. ON_AFTER_CAPTURE_EVENT_NAME,
  66. WIN_ID_ATTRIBUTE_NAME,
  67. PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
  68. REMOVED_CONTENT_ATTRIBUTE_NAME,
  69. HIDDEN_CONTENT_ATTRIBUTE_NAME,
  70. IMAGE_ATTRIBUTE_NAME,
  71. POSTER_ATTRIBUTE_NAME,
  72. CANVAS_ATTRIBUTE_NAME,
  73. INPUT_VALUE_ATTRIBUTE_NAME,
  74. SHADOW_ROOT_ATTRIBUTE_NAME,
  75. HTML_IMPORT_ATTRIBUTE_NAME,
  76. LAZY_SRC_ATTRIBUTE_NAME,
  77. STYLESHEET_ATTRIBUTE_NAME,
  78. SELECTED_CONTENT_ATTRIBUTE_NAME,
  79. ASYNC_SCRIPT_ATTRIBUTE_NAME
  80. };
  81. function initDoc(doc) {
  82. doc.querySelectorAll("meta[http-equiv=refresh]").forEach(element => {
  83. element.removeAttribute("http-equiv");
  84. element.setAttribute("disabled-http-equiv", "refresh");
  85. });
  86. }
  87. function preProcessDoc(doc, win, options) {
  88. doc.querySelectorAll("noscript").forEach(element => {
  89. element.setAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME, element.textContent);
  90. element.textContent = "";
  91. });
  92. initDoc(doc);
  93. if (doc.head) {
  94. doc.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach(element => element.hidden = true);
  95. }
  96. let elementsInfo;
  97. if (win && doc.documentElement) {
  98. elementsInfo = getElementsInfo(win, doc, doc.documentElement, options);
  99. } else {
  100. elementsInfo = {
  101. canvases: [],
  102. images: [],
  103. posters: [],
  104. usedFonts: [],
  105. shadowRoots: [],
  106. imports: [],
  107. markedElements: []
  108. };
  109. }
  110. return {
  111. canvases: elementsInfo.canvases,
  112. fonts: getFontsData(doc),
  113. stylesheets: getStylesheetsData(doc),
  114. images: elementsInfo.images,
  115. posters: elementsInfo.posters,
  116. usedFonts: Array.from(elementsInfo.usedFonts.values()),
  117. shadowRoots: elementsInfo.shadowRoots,
  118. imports: elementsInfo.imports,
  119. referrer: doc.referrer,
  120. markedElements: elementsInfo.markedElements
  121. };
  122. }
  123. function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map(), canvases: [], images: [], posters: [], shadowRoots: [], imports: [], markedElements: [] }, ascendantHidden) {
  124. const elements = Array.from(element.childNodes).filter(node => node instanceof win.HTMLElement);
  125. elements.forEach(element => {
  126. let elementHidden, computedStyle;
  127. if (options.removeHiddenElements || options.removeUnusedFonts || options.compressHTML) {
  128. computedStyle = win.getComputedStyle(element);
  129. if (options.removeHiddenElements) {
  130. if (ascendantHidden) {
  131. Array.from(element.childNodes).filter(node => node instanceof win.HTMLElement).forEach(element => {
  132. if (!IGNORED_REMOVED_TAG_NAMES.includes(element.tagName)) {
  133. element.setAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME, "");
  134. data.markedElements.push(element);
  135. }
  136. });
  137. }
  138. elementHidden = ascendantHidden || testHiddenElement(element, computedStyle, data.markedElements);
  139. }
  140. if (!elementHidden) {
  141. if (options.compressHTML && computedStyle) {
  142. const whiteSpace = computedStyle.getPropertyValue("white-space");
  143. if (whiteSpace && whiteSpace.startsWith("pre")) {
  144. element.setAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME, "");
  145. data.markedElements.push(element);
  146. }
  147. }
  148. if (options.removeUnusedFonts) {
  149. getUsedFont(computedStyle, options, data.usedFonts);
  150. getUsedFont(win.getComputedStyle(element, ":first-letter"), options, data.usedFonts);
  151. getUsedFont(win.getComputedStyle(element, ":before"), options, data.usedFonts);
  152. getUsedFont(win.getComputedStyle(element, ":after"), options, data.usedFonts);
  153. }
  154. }
  155. }
  156. getResourcesInfo(win, doc, element, options, data, elementHidden, computedStyle);
  157. if (element.shadowRoot) {
  158. const shadowRootInfo = {};
  159. element.setAttribute(SHADOW_ROOT_ATTRIBUTE_NAME, data.shadowRoots.length);
  160. data.markedElements.push(element);
  161. data.shadowRoots.push(shadowRootInfo);
  162. getElementsInfo(win, doc, element.shadowRoot, options, data, elementHidden);
  163. shadowRootInfo.content = element.shadowRoot.innerHTML;
  164. shadowRootInfo.delegatesFocus = element.shadowRoot.delegatesFocus;
  165. shadowRootInfo.mode = element.shadowRoot.mode;
  166. if (element.shadowRoot.adoptedStyleSheets && element.shadowRoot.adoptedStyleSheets.length) {
  167. shadowRootInfo.adoptedStyleSheets = Array.from(element.shadowRoot.adoptedStyleSheets).map(stylesheet => Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n"));
  168. }
  169. }
  170. getElementsInfo(win, doc, element, options, data, elementHidden);
  171. });
  172. return data;
  173. }
  174. function getResourcesInfo(win, doc, element, options, data, elementHidden, computedStyle) {
  175. if (element.tagName == "CANVAS") {
  176. try {
  177. const size = getSize(win, element, computedStyle);
  178. data.canvases.push({ dataURI: element.toDataURL("image/png", ""), width: size.width, height: size.height });
  179. element.setAttribute(CANVAS_ATTRIBUTE_NAME, data.canvases.length - 1);
  180. data.markedElements.push(element);
  181. } catch (error) {
  182. // ignored
  183. }
  184. }
  185. if (element.tagName == "IMG") {
  186. const imageData = {
  187. currentSrc: elementHidden ?
  188. "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" :
  189. (options.loadDeferredImages && element.getAttribute(LAZY_SRC_ATTRIBUTE_NAME)) || element.currentSrc
  190. };
  191. data.images.push(imageData);
  192. element.setAttribute(IMAGE_ATTRIBUTE_NAME, data.images.length - 1);
  193. data.markedElements.push(element);
  194. element.removeAttribute(LAZY_SRC_ATTRIBUTE_NAME);
  195. computedStyle = computedStyle || win.getComputedStyle(element);
  196. if (computedStyle) {
  197. imageData.size = getSize(win, element, computedStyle);
  198. const boxShadow = computedStyle.getPropertyValue("box-shadow");
  199. const backgroundImage = computedStyle.getPropertyValue("background-image");
  200. if ((!boxShadow || boxShadow == "none") &&
  201. (!backgroundImage || backgroundImage == "none") &&
  202. (imageData.size.pxWidth > 1 || imageData.size.pxHeight > 1)) {
  203. imageData.replaceable = true;
  204. imageData.backgroundColor = computedStyle.getPropertyValue("background-color");
  205. imageData.objectFit = computedStyle.getPropertyValue("object-fit");
  206. imageData.boxSizing = computedStyle.getPropertyValue("box-sizing");
  207. imageData.objectPosition = computedStyle.getPropertyValue("object-position");
  208. }
  209. }
  210. }
  211. if (element.tagName == "VIDEO") {
  212. if (!element.poster) {
  213. const canvasElement = doc.createElement("canvas");
  214. const context = canvasElement.getContext("2d");
  215. canvasElement.width = element.clientWidth;
  216. canvasElement.height = element.clientHeight;
  217. try {
  218. context.drawImage(element, 0, 0, canvasElement.width, canvasElement.height);
  219. data.posters.push(canvasElement.toDataURL("image/png", ""));
  220. element.setAttribute(POSTER_ATTRIBUTE_NAME, data.posters.length - 1);
  221. data.markedElements.push(element);
  222. } catch (error) {
  223. // ignored
  224. }
  225. }
  226. }
  227. if (element.tagName == "IFRAME") {
  228. if (elementHidden) {
  229. element.setAttribute("src", "data:text/html,");
  230. }
  231. }
  232. if (element.tagName == "LINK") {
  233. if (element.import) {
  234. data.imports.push({ content: serialize(element.import) });
  235. element.setAttribute(HTML_IMPORT_ATTRIBUTE_NAME, data.imports.length - 1);
  236. data.markedElements.push(element);
  237. }
  238. }
  239. if (element.tagName == "INPUT") {
  240. if (element.type != "password") {
  241. element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.value);
  242. data.markedElements.push(element);
  243. }
  244. if (element.type == "radio" || element.type == "checkbox") {
  245. element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.checked);
  246. data.markedElements.push(element);
  247. }
  248. }
  249. if (element.tagName == "TEXTAREA") {
  250. element.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, element.value);
  251. data.markedElements.push(element);
  252. }
  253. if (element.tagName == "SELECT") {
  254. element.querySelectorAll("option").forEach(option => {
  255. if (option.selected) {
  256. option.setAttribute(INPUT_VALUE_ATTRIBUTE_NAME, "");
  257. data.markedElements.push(option);
  258. }
  259. });
  260. }
  261. if (element.tagName == "SCRIPT") {
  262. if (element.async && element.getAttribute("async") != "" && element.getAttribute("async") != "async") {
  263. element.setAttribute(ASYNC_SCRIPT_ATTRIBUTE_NAME, "");
  264. data.markedElements.push(element);
  265. }
  266. element.textContent = element.textContent.replace(/<\/script>/gi, "<\\/script>");
  267. }
  268. }
  269. function getUsedFont(computedStyle, options, usedFonts) {
  270. if (computedStyle) {
  271. const fontStyle = computedStyle.getPropertyValue("font-style") || "normal";
  272. computedStyle.getPropertyValue("font-family").split(",").forEach(fontFamilyName => {
  273. fontFamilyName = normalizeFontFamily(fontFamilyName);
  274. if (!options.loadedFonts || options.loadedFonts.find(font => normalizeFontFamily(font.family) == fontFamilyName && font.style == fontStyle)) {
  275. const fontWeight = getFontWeight(computedStyle.getPropertyValue("font-weight"));
  276. const fontVariant = computedStyle.getPropertyValue("font-variant") || "normal";
  277. const value = [fontFamilyName, fontWeight, fontStyle, fontVariant];
  278. usedFonts.set(JSON.stringify(value), [fontFamilyName, fontWeight, fontStyle, fontVariant]);
  279. }
  280. });
  281. }
  282. }
  283. function normalizeFontFamily(fontFamilyName) {
  284. return removeQuotes(fontFamilyName.trim()).toLowerCase();
  285. }
  286. function testHiddenElement(element, computedStyle, markedElements) {
  287. let hidden = false;
  288. if (computedStyle) {
  289. const display = computedStyle.getPropertyValue("display");
  290. const opacity = computedStyle.getPropertyValue("opacity");
  291. const visibility = computedStyle.getPropertyValue("visibility");
  292. hidden = display == "none";
  293. if (hidden) {
  294. if (element.style.getPropertyValue("display") != "none" && !IGNORED_REMOVED_TAG_NAMES.includes(element.tagName)) {
  295. element.setAttribute(HIDDEN_CONTENT_ATTRIBUTE_NAME, "");
  296. markedElements.push(element);
  297. }
  298. } else if ((opacity == "0" || visibility == "hidden") && element.getBoundingClientRect) {
  299. const boundingRect = element.getBoundingClientRect();
  300. hidden = !boundingRect.width && !boundingRect.height;
  301. }
  302. }
  303. return Boolean(hidden);
  304. }
  305. function postProcessDoc(doc, markedElements) {
  306. doc.querySelectorAll("[" + DISABLED_NOSCRIPT_ATTRIBUTE_NAME + "]").forEach(element => {
  307. element.textContent = element.getAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME);
  308. element.removeAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME);
  309. });
  310. doc.querySelectorAll("meta[disabled-http-equiv]").forEach(element => {
  311. element.setAttribute("http-equiv", element.getAttribute("disabled-http-equiv"));
  312. element.removeAttribute("disabled-http-equiv");
  313. });
  314. if (doc.head) {
  315. doc.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach(element => element.removeAttribute("hidden"));
  316. }
  317. if (!markedElements) {
  318. const singleFileAttributes = [REMOVED_CONTENT_ATTRIBUTE_NAME, HIDDEN_CONTENT_ATTRIBUTE_NAME, PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME, IMAGE_ATTRIBUTE_NAME, POSTER_ATTRIBUTE_NAME, CANVAS_ATTRIBUTE_NAME, INPUT_VALUE_ATTRIBUTE_NAME, SHADOW_ROOT_ATTRIBUTE_NAME, HTML_IMPORT_ATTRIBUTE_NAME, STYLESHEET_ATTRIBUTE_NAME, ASYNC_SCRIPT_ATTRIBUTE_NAME];
  319. markedElements = doc.querySelectorAll(singleFileAttributes.map(name => "[" + name + "]").join(","));
  320. }
  321. markedElements.forEach(element => {
  322. element.removeAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME);
  323. element.removeAttribute(HIDDEN_CONTENT_ATTRIBUTE_NAME);
  324. element.removeAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME);
  325. element.removeAttribute(IMAGE_ATTRIBUTE_NAME);
  326. element.removeAttribute(POSTER_ATTRIBUTE_NAME);
  327. element.removeAttribute(CANVAS_ATTRIBUTE_NAME);
  328. element.removeAttribute(INPUT_VALUE_ATTRIBUTE_NAME);
  329. element.removeAttribute(SHADOW_ROOT_ATTRIBUTE_NAME);
  330. element.removeAttribute(HTML_IMPORT_ATTRIBUTE_NAME);
  331. element.removeAttribute(STYLESHEET_ATTRIBUTE_NAME);
  332. element.removeAttribute(ASYNC_SCRIPT_ATTRIBUTE_NAME);
  333. });
  334. }
  335. function getStylesheetsData(doc) {
  336. if (doc) {
  337. const contents = [];
  338. doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
  339. try {
  340. const tempStyleElement = doc.createElement("style");
  341. tempStyleElement.textContent = styleElement.textContent;
  342. doc.body.appendChild(tempStyleElement);
  343. const stylesheet = tempStyleElement.sheet;
  344. tempStyleElement.remove();
  345. if (!stylesheet || stylesheet.cssRules.length != styleElement.sheet.cssRules.length) {
  346. styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
  347. contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
  348. }
  349. } catch (error) {
  350. // ignored
  351. }
  352. });
  353. return contents;
  354. }
  355. }
  356. function getSize(win, imageElement, computedStyle) {
  357. let pxWidth = imageElement.naturalWidth;
  358. let pxHeight = imageElement.naturalHeight;
  359. if (!pxWidth && !pxHeight) {
  360. computedStyle = computedStyle || win.getComputedStyle(imageElement);
  361. let removeBorderWidth = false;
  362. if (computedStyle.getPropertyValue("box-sizing") == "content-box") {
  363. const boxSizingValue = imageElement.style.getPropertyValue("box-sizing");
  364. const boxSizingPriority = imageElement.style.getPropertyPriority("box-sizing");
  365. const clientWidth = imageElement.clientWidth;
  366. imageElement.style.setProperty("box-sizing", "border-box", "important");
  367. removeBorderWidth = imageElement.clientWidth != clientWidth;
  368. if (boxSizingValue) {
  369. imageElement.style.setProperty("box-sizing", boxSizingValue, boxSizingPriority);
  370. } else {
  371. imageElement.style.removeProperty("box-sizing");
  372. }
  373. }
  374. let paddingLeft, paddingRight, paddingTop, paddingBottom, borderLeft, borderRight, borderTop, borderBottom;
  375. paddingLeft = getWidth("padding-left", computedStyle);
  376. paddingRight = getWidth("padding-right", computedStyle);
  377. paddingTop = getWidth("padding-top", computedStyle);
  378. paddingBottom = getWidth("padding-bottom", computedStyle);
  379. if (removeBorderWidth) {
  380. borderLeft = getWidth("border-left-width", computedStyle);
  381. borderRight = getWidth("border-right-width", computedStyle);
  382. borderTop = getWidth("border-top-width", computedStyle);
  383. borderBottom = getWidth("border-bottom-width", computedStyle);
  384. } else {
  385. borderLeft = borderRight = borderTop = borderBottom = 0;
  386. }
  387. pxWidth = Math.max(0, imageElement.clientWidth - paddingLeft - paddingRight - borderLeft - borderRight);
  388. pxHeight = Math.max(0, imageElement.clientHeight - paddingTop - paddingBottom - borderTop - borderBottom);
  389. }
  390. return { pxWidth, pxHeight };
  391. }
  392. function getWidth(styleName, computedStyle) {
  393. if (computedStyle.getPropertyValue(styleName).endsWith("px")) {
  394. return parseFloat(computedStyle.getPropertyValue(styleName));
  395. }
  396. }
  397. function getFontsData() {
  398. if (singlefile.lib.processors.hooks.content.frames) {
  399. return singlefile.lib.processors.hooks.content.frames.getFontsData();
  400. }
  401. }
  402. function serialize(doc) {
  403. const docType = doc.doctype;
  404. let docTypeString = "";
  405. if (docType) {
  406. docTypeString = "<!DOCTYPE " + docType.nodeName;
  407. if (docType.publicId) {
  408. docTypeString += " PUBLIC \"" + docType.publicId + "\"";
  409. if (docType.systemId) {
  410. docTypeString += " \"" + docType.systemId + "\"";
  411. }
  412. } else if (docType.systemId) {
  413. docTypeString += " SYSTEM \"" + docType.systemId + "\"";
  414. } if (docType.internalSubset) {
  415. docTypeString += " [" + docType.internalSubset + "]";
  416. }
  417. docTypeString += "> ";
  418. }
  419. return docTypeString + doc.documentElement.outerHTML;
  420. }
  421. function removeQuotes(string) {
  422. if (string.match(REGEXP_SIMPLE_QUOTES_STRING)) {
  423. string = string.replace(REGEXP_SIMPLE_QUOTES_STRING, "$1");
  424. } else {
  425. string = string.replace(REGEXP_DOUBLE_QUOTES_STRING, "$1");
  426. }
  427. return string.trim();
  428. }
  429. function getFontWeight(weight) {
  430. return FONT_WEIGHTS[weight] || weight;
  431. }
  432. })();