This commit is contained in:
22
node_modules/mapbox-to-css-font/LICENSE
generated
vendored
Normal file
22
node_modules/mapbox-to-css-font/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
Copyright 2016-present mapbox-to-css-font contributors
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
27
node_modules/mapbox-to-css-font/README.md
generated
vendored
Normal file
27
node_modules/mapbox-to-css-font/README.md
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Mapbox to CSS Font
|
||||
|
||||
Utility to convert Mapbox GL Style fontstacks or fonts names to CSS compatible font definitions.
|
||||
|
||||
For fontstacks, the style and weight of the primary font (first font in the fontstack) will also be used for the fallback fonts.
|
||||
|
||||
The ["Klokantech Noto Sans"](https://github.com/klokantech/klokantech-gl-fonts) font is recognized and returned as "Noto Sans", so it can be loaded as web font from Google fonts.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var parseFont = require('mapbox-to-css-font');
|
||||
parseFont('Open Sans Regular', 16, 1.2);
|
||||
// returns 'normal 400 16px/1.2 "Open Sans"'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `fonts` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)|[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Mapbox GL Style fontstack or single font, e.g. `['Open Sans Regular', 'Arial Unicode MS Regular']` or `'Open Sans Regular'`.
|
||||
|
||||
- `size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Font size in pixels.
|
||||
|
||||
- `lineHeight` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Line height as css [line-height](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height). Optional.
|
||||
|
||||
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.
|
||||
82
node_modules/mapbox-to-css-font/index.js
generated
vendored
Normal file
82
node_modules/mapbox-to-css-font/index.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
var fontWeights = {
|
||||
thin: 100,
|
||||
hairline: 100,
|
||||
'ultra-light': 200,
|
||||
'extra-light': 200,
|
||||
light: 300,
|
||||
book: 300,
|
||||
regular: 400,
|
||||
normal: 400,
|
||||
plain: 400,
|
||||
roman: 400,
|
||||
standard: 400,
|
||||
medium: 500,
|
||||
'semi-bold': 600,
|
||||
'demi-bold': 600,
|
||||
bold: 700,
|
||||
'extra-bold': 800,
|
||||
'ultra-bold': 800,
|
||||
heavy: 900,
|
||||
black: 900,
|
||||
'heavy-black': 900,
|
||||
fat: 900,
|
||||
poster: 900,
|
||||
'ultra-black': 950,
|
||||
'extra-black': 950
|
||||
};
|
||||
var sp = ' ';
|
||||
var italicRE = /(italic|oblique)$/i;
|
||||
|
||||
var fontCache = {};
|
||||
|
||||
module.exports = function(fonts, size, lineHeight) {
|
||||
var cssData = fontCache[fonts];
|
||||
if (!cssData) {
|
||||
if (!Array.isArray(fonts)) {
|
||||
fonts = [fonts];
|
||||
}
|
||||
var weight = 400;
|
||||
var style = 'normal';
|
||||
var fontFamilies = [];
|
||||
var haveWeight, haveStyle;
|
||||
for (var i = 0, ii = fonts.length; i < ii; ++i) {
|
||||
var font = fonts[i];
|
||||
var parts = font.split(' ');
|
||||
var maybeWeight = parts[parts.length - 1].toLowerCase();
|
||||
if (maybeWeight == 'normal' || maybeWeight == 'italic' || maybeWeight == 'oblique') {
|
||||
style = haveStyle ? style : maybeWeight;
|
||||
haveStyle = true;
|
||||
parts.pop();
|
||||
maybeWeight = parts[parts.length - 1].toLowerCase();
|
||||
} else if (italicRE.test(maybeWeight)) {
|
||||
maybeWeight = maybeWeight.replace(italicRE, '');
|
||||
style = haveStyle ? style : parts[parts.length - 1].replace(maybeWeight, '');
|
||||
haveStyle = true;
|
||||
}
|
||||
for (var w in fontWeights) {
|
||||
var previousPart = parts.length > 1 ? parts[parts.length - 2].toLowerCase() : '';
|
||||
if (maybeWeight == w || maybeWeight == w.replace('-', '') || previousPart + '-' + maybeWeight == w) {
|
||||
weight = haveWeight ? weight : fontWeights[w];
|
||||
parts.pop();
|
||||
if (previousPart && w.startsWith(previousPart)) {
|
||||
parts.pop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!haveWeight && typeof maybeWeight == 'number') {
|
||||
weight = maybeWeight;
|
||||
haveWeight = true;
|
||||
}
|
||||
var fontFamily = parts.join(sp)
|
||||
.replace('Klokantech Noto Sans', 'Noto Sans');
|
||||
if (fontFamily.indexOf(sp) !== -1) {
|
||||
fontFamily = '"' + fontFamily + '"';
|
||||
}
|
||||
fontFamilies.push(fontFamily);
|
||||
}
|
||||
// CSS font property: font-style font-weight font-size/line-height font-family
|
||||
cssData = fontCache[fonts] = [style, weight, fontFamilies];
|
||||
}
|
||||
return cssData[0] + sp + cssData[1] + sp + size + 'px' + (lineHeight ? '/' + lineHeight : '') + sp + cssData[2];
|
||||
};
|
||||
29
node_modules/mapbox-to-css-font/package.json
generated
vendored
Normal file
29
node_modules/mapbox-to-css-font/package.json
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "mapbox-to-css-font",
|
||||
"version": "2.4.5",
|
||||
"description": "Utility to convert Mapbox GL Style font names to CSS font definitions",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/openlayers/mapbox-to-css-font.git"
|
||||
},
|
||||
"keywords": [
|
||||
"mapbox",
|
||||
"font"
|
||||
],
|
||||
"author": "Andreas Hocevar",
|
||||
"license": "BSD-2-Clause",
|
||||
"scripts": {
|
||||
"lint": "eslint *.js test",
|
||||
"pretest": "npm run lint",
|
||||
"test": "mocha test/index.test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.15.0",
|
||||
"eslint-config-openlayers": "^11.0.0",
|
||||
"karma-mocha": "^2.0.1",
|
||||
"mocha": "^10.2.0",
|
||||
"should": "^13.2.3",
|
||||
"sinon": "^7.2.7"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user