@react-google-maps/api
Advanced tools
Comparing version 1.2.0-alpha.9 to 1.2.0-alpha.10
{ | ||
"name": "@react-google-maps/api", | ||
"version": "1.2.0-alpha.9", | ||
"version": "1.2.0-alpha.10", | ||
"description": "React.js Google Maps API integration", | ||
@@ -96,3 +96,3 @@ "license": "MIT", | ||
"awesome-typescript-loader": "5.2.1", | ||
"eslint": "5.15.3", | ||
"eslint": "5.16.0", | ||
"eslint-config-standard": "12.0.0", | ||
@@ -119,8 +119,8 @@ "eslint-config-standard-react": "7.0.2", | ||
"husky": "1.3.1", | ||
"react": "16.8.5", | ||
"react": "16.8.6", | ||
"react-docgen-typescript": "1.12.3", | ||
"react-dom": "16.8.5", | ||
"react-dom": "16.8.6", | ||
"react-styleguidist": "8.0.6", | ||
"rimraf": "2.6.3", | ||
"typescript": "3.3.4000", | ||
"typescript": "3.4.1", | ||
"webpack": "4.29.6" | ||
@@ -127,0 +127,0 @@ }, |
@@ -28,4 +28,9 @@ import { isBrowser } from "./isbrowser" | ||
script.onerror = reject | ||
document.head.appendChild(script) | ||
}) | ||
// eslint-disable-next-line @getify/proper-arrows/name | ||
.catch(err => { | ||
console.error('injectScript error: ', err) | ||
}) | ||
} |
@@ -0,49 +1,50 @@ | ||
const isRobotoStyle = (element: HTMLElement) => { | ||
// roboto font download | ||
if ( | ||
(element as HTMLLinkElement).href && | ||
(element as HTMLLinkElement).href.indexOf( | ||
"https://fonts.googleapis.com/css?family=Roboto" | ||
) === 0 | ||
) { | ||
return true | ||
} | ||
// roboto style elements | ||
if ( | ||
element.tagName.toLowerCase() === "style" && | ||
// @ts-ignore | ||
element.styleSheet && | ||
// @ts-ignore | ||
element.styleSheet.cssText && | ||
// @ts-ignore | ||
element.styleSheet.cssText.replace("\r\n", "").indexOf(".gm-style") === 0 | ||
) { | ||
// @ts-ignore | ||
element.styleSheet.cssText = "" | ||
return true | ||
} | ||
// roboto style elements for other browsers | ||
if ( | ||
element.tagName.toLowerCase() === "style" && | ||
element.innerHTML && | ||
element.innerHTML.replace("\r\n", "").indexOf(".gm-style") === 0 | ||
) { | ||
element.innerHTML = "" | ||
return true | ||
} | ||
// when google tries to add empty style | ||
if ( | ||
element.tagName.toLowerCase() === "style" && | ||
// @ts-ignore | ||
!element.styleSheet && | ||
!element.innerHTML | ||
) { | ||
return true | ||
} | ||
return false | ||
} | ||
// Preventing the Google Maps libary from downloading an extra font | ||
export const preventGoogleFonts = () => { | ||
const isRobotoStyle = (element: HTMLElement) => { | ||
// roboto font download | ||
if ( | ||
(element as HTMLLinkElement).href && | ||
(element as HTMLLinkElement).href.indexOf( | ||
"https://fonts.googleapis.com/css?family=Roboto" | ||
) === 0 | ||
) { | ||
return true | ||
} | ||
// roboto style elements | ||
if ( | ||
element.tagName.toLowerCase() === "style" && | ||
// @ts-ignore | ||
element.styleSheet && | ||
// @ts-ignore | ||
element.styleSheet.cssText && | ||
// @ts-ignore | ||
element.styleSheet.cssText.replace("\r\n", "").indexOf(".gm-style") === 0 | ||
) { | ||
// @ts-ignore | ||
element.styleSheet.cssText = "" | ||
return true | ||
} | ||
// roboto style elements for other browsers | ||
if ( | ||
element.tagName.toLowerCase() === "style" && | ||
element.innerHTML && | ||
element.innerHTML.replace("\r\n", "").indexOf(".gm-style") === 0 | ||
) { | ||
element.innerHTML = "" | ||
return true | ||
} | ||
// when google tries to add empty style | ||
if ( | ||
element.tagName.toLowerCase() === "style" && | ||
// @ts-ignore | ||
!element.styleSheet && | ||
!element.innerHTML | ||
) { | ||
return true | ||
} | ||
return false | ||
} | ||
console.log('preventGoogleFonts run') | ||
// we override these methods only for one particular head element | ||
@@ -53,2 +54,4 @@ // default methods for other elements are not affected | ||
const trueInsertBefore = head.insertBefore.bind(head) | ||
// TODO: adding return before reflect solves the TS issue | ||
@@ -61,6 +64,9 @@ //@ts-ignore | ||
if (!isRobotoStyle(newElement)) { | ||
Reflect.apply(head.insertBefore, head, [newElement, referenceElement]) | ||
Reflect.apply(trueInsertBefore, head, [newElement, referenceElement]) | ||
} | ||
} | ||
const trueAppend = head.appendChild.bind(head) | ||
// TODO: adding return before reflect solves the TS issue | ||
@@ -70,5 +76,5 @@ //@ts-ignore | ||
if (!isRobotoStyle(textNode)) { | ||
Reflect.apply(head.appendChild, head, [textNode]) | ||
Reflect.apply(trueAppend, head, [textNode]) | ||
} | ||
} | ||
} |
332929
7392