This repository was archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove polyfill-service dependency
Fixes a lot of warnings regarding outdated dependecies and allows to install gemini with yarn. Close #673, close #635
- Loading branch information
Showing
13 changed files
with
292 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
/*jshint newcap:false*/ | ||
var Sizzle = require('sizzle'); | ||
|
||
exports.queryFirst = function(selector) { | ||
var elems = Sizzle(exports.trim(selector) + ':first'); | ||
return elems.length > 0 ? elems[0] : null; | ||
}; | ||
|
||
exports.queryAll = function(selector) { | ||
return Sizzle(selector); | ||
}; | ||
|
||
exports.trim = function(str) { | ||
// trim spaces, unicode BOM and NBSP and the beginning and the end of the line | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill | ||
return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | ||
}; | ||
|
||
exports.getComputedStyle = require('./polyfills/getComputedStyle').getComputedStyle; | ||
exports.matchMedia = require('./polyfills/matchMedia').matchMedia; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
exports.queryFirst = function(selector) { | ||
return document.querySelector(selector); | ||
}; | ||
|
||
exports.queryAll = function(selector) { | ||
return document.querySelectorAll(selector); | ||
}; | ||
|
||
exports.getComputedStyle = function(element, pseudoElement) { | ||
return getComputedStyle(element, pseudoElement); | ||
}; | ||
|
||
exports.matchMedia = function(mediaQuery) { | ||
return matchMedia(mediaQuery); | ||
}; | ||
|
||
exports.trim = function(str) { | ||
return str.trim(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Financial Times | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
114 changes: 114 additions & 0 deletions
114
lib/browser/client-scripts/polyfills/getComputedStyle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Adapted from: https://raw.githubusercontent.com/Financial-Times/polyfill-service | ||
*/ | ||
function getComputedStylePixel(element, property, fontSize) { | ||
var | ||
// Internet Explorer sometimes struggles to read currentStyle until the element's document is accessed. | ||
value = element.document && element.currentStyle[property].match(/([\d\.]+)(%|cm|em|in|mm|pc|pt|)/) || [0, 0, ''], | ||
size = value[1], | ||
suffix = value[2], | ||
rootSize; | ||
|
||
fontSize = !fontSize ? fontSize : /%|em/.test(suffix) && element.parentElement ? getComputedStylePixel(element.parentElement, 'fontSize', null) : 16; | ||
rootSize = property === 'fontSize' ? fontSize : /width/i.test(property) ? element.clientWidth : element.clientHeight; | ||
|
||
return suffix === '%' ? size / 100 * rootSize : | ||
suffix === 'cm' ? size * 0.3937 * 96 : | ||
suffix === 'em' ? size * fontSize : | ||
suffix === 'in' ? size * 96 : | ||
suffix === 'mm' ? size * 0.3937 * 96 / 10 : | ||
suffix === 'pc' ? size * 12 * 96 / 72 : | ||
suffix === 'pt' ? size * 96 / 72 : | ||
size; | ||
} | ||
|
||
function setShortStyleProperty(style, property) { | ||
var | ||
borderSuffix = property === 'border' ? 'Width' : '', | ||
t = property + 'Top' + borderSuffix, | ||
r = property + 'Right' + borderSuffix, | ||
b = property + 'Bottom' + borderSuffix, | ||
l = property + 'Left' + borderSuffix; | ||
|
||
style[property] = (style[t] === style[r] && style[t] === style[b] && style[t] === style[l] ? [style[t]] : | ||
style[t] === style[b] && style[l] === style[r] ? [style[t], style[r]] : | ||
style[l] === style[r] ? [style[t], style[r], style[b]] : | ||
[style[t], style[r], style[b], style[l]]).join(' '); | ||
} | ||
|
||
// <CSSStyleDeclaration> | ||
function CSSStyleDeclaration(element) { | ||
var currentStyle = element.currentStyle, | ||
fontSize = getComputedStylePixel(element, 'fontSize'), | ||
unCamelCase = function(match) { | ||
return '-' + match.toLowerCase(); | ||
}, | ||
property; | ||
|
||
for (property in currentStyle) { | ||
Array.prototype.push.call(this, property === 'styleFloat' ? 'float' : property.replace(/[A-Z]/, unCamelCase)); | ||
|
||
if (property === 'width') { | ||
this[property] = element.offsetWidth + 'px'; | ||
} else if (property === 'height') { | ||
this[property] = element.offsetHeight + 'px'; | ||
} else if (property === 'styleFloat') { | ||
this.float = currentStyle[property]; | ||
} else if (/margin.|padding.|border.+W/.test(property) && this[property] !== 'auto') { | ||
this[property] = Math.round(getComputedStylePixel(element, property, fontSize)) + 'px'; | ||
} else if (/^outline/.test(property)) { | ||
// errors on checking outline | ||
try { | ||
this[property] = currentStyle[property]; | ||
} catch (error) { | ||
this.outlineColor = currentStyle.color; | ||
this.outlineStyle = this.outlineStyle || 'none'; | ||
this.outlineWidth = this.outlineWidth || '0px'; | ||
this.outline = [this.outlineColor, this.outlineWidth, this.outlineStyle].join(' '); | ||
} | ||
} else { | ||
this[property] = currentStyle[property]; | ||
} | ||
} | ||
|
||
setShortStyleProperty(this, 'margin'); | ||
setShortStyleProperty(this, 'padding'); | ||
setShortStyleProperty(this, 'border'); | ||
|
||
this.fontSize = Math.round(fontSize) + 'px'; | ||
} | ||
|
||
CSSStyleDeclaration.prototype = { | ||
constructor: CSSStyleDeclaration, | ||
// <CSSStyleDeclaration>.getPropertyPriority | ||
getPropertyPriority: function() { | ||
throw new Error('NotSupportedError: DOM Exception 9'); | ||
}, | ||
// <CSSStyleDeclaration>.getPropertyValue | ||
getPropertyValue: function(property) { | ||
return this[property.replace(/-\w/g, function(match) { | ||
return match[1].toUpperCase(); | ||
})]; | ||
}, | ||
// <CSSStyleDeclaration>.item | ||
item: function(index) { | ||
return this[index]; | ||
}, | ||
// <CSSStyleDeclaration>.removeProperty | ||
removeProperty: function() { | ||
throw new Error('NoModificationAllowedError: DOM Exception 7'); | ||
}, | ||
// <CSSStyleDeclaration>.setProperty | ||
setProperty: function() { | ||
throw new Error('NoModificationAllowedError: DOM Exception 7'); | ||
}, | ||
// <CSSStyleDeclaration>.getPropertyCSSValue | ||
getPropertyCSSValue: function() { | ||
throw new Error('NotSupportedError: DOM Exception 9'); | ||
} | ||
}; | ||
|
||
// <Global>.getComputedStyle | ||
exports.getComputedStyle = function getComputedStyle(element) { | ||
return new CSSStyleDeclaration(element); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Adapted from: https://raw.githubusercontent.com/Financial-Times/polyfill-service | ||
*/ | ||
function evalQuery(query) { | ||
/* jshint evil: true */ | ||
query = (query || 'true') | ||
.replace(/^only\s+/, '') | ||
.replace(/(device)-([\w.]+)/g, '$1.$2') | ||
.replace(/([\w.]+)\s*:/g, 'media.$1 ===') | ||
.replace(/min-([\w.]+)\s*===/g, '$1 >=') | ||
.replace(/max-([\w.]+)\s*===/g, '$1 <=') | ||
.replace(/all|screen/g, '1') | ||
.replace(/print/g, '0') | ||
.replace(/,/g, '||') | ||
.replace(/\band\b/g, '&&') | ||
.replace(/dpi/g, '') | ||
.replace(/(\d+)(cm|em|in|dppx|mm|pc|pt|px|rem)/g, function($0, $1, $2) { | ||
return $1 * ( | ||
$2 === 'cm' ? 0.3937 * 96 : ( | ||
$2 === 'em' || $2 === 'rem' ? 16 : ( | ||
$2 === 'in' || $2 === 'dppx' ? 96 : ( | ||
$2 === 'mm' ? 0.3937 * 96 / 10 : ( | ||
$2 === 'pc' ? 12 * 96 / 72 : ( | ||
$2 === 'pt' ? 96 / 72 : 1 | ||
) | ||
) | ||
) | ||
) | ||
) | ||
); | ||
}); | ||
return new Function('media', 'try{ return !!(%s) }catch(e){ return false }' | ||
.replace('%s', query) | ||
)({ | ||
width: global.innerWidth, | ||
height: global.innerHeight, | ||
orientation: global.orientation || 'landscape', | ||
device: { | ||
width: global.screen.width, | ||
height: global.screen.height, | ||
orientation: global.screen.orientation || global.orientation || 'landscape' | ||
} | ||
}); | ||
} | ||
|
||
function MediaQueryList() { | ||
this.matches = false; | ||
this.media = 'invalid'; | ||
} | ||
|
||
MediaQueryList.prototype.addListener = function addListener(listener) { | ||
this.addListener.listeners.push(listener); | ||
}; | ||
|
||
MediaQueryList.prototype.removeListener = function removeListener(listener) { | ||
this.addListener.listeners.splice(this.addListener.listeners.indexOf(listener), 1); | ||
}; | ||
|
||
// <Global>.matchMedia | ||
exports.matchMedia = function matchMedia(query) { | ||
var | ||
list = new MediaQueryList(); | ||
|
||
if (arguments.length === 0) { | ||
throw new TypeError('Not enough arguments to matchMedia'); | ||
} | ||
|
||
list.media = String(query); | ||
list.matches = evalQuery(list.media); | ||
list.addListener.listeners = []; | ||
|
||
window.addEventListener('resize', function() { | ||
var listeners = [].concat(list.addListener.listeners), matches = evalQuery(list.media); | ||
|
||
if (matches !== list.matches) { | ||
list.matches = matches; | ||
for (var index = 0, length = listeners.length; index < length; ++index) { | ||
listeners[index].call(global, list); | ||
} | ||
} | ||
}); | ||
|
||
return list; | ||
}; |
Oops, something went wrong.