Skip to content

Bump tmp and eslint #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

21 changes: 21 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import openlayers from 'eslint-config-openlayers';

export default [
...openlayers,
{
name: 'test-config',
files: ['test/**/*'],
languageOptions: {
globals: {
after: 'readonly',
afterEach: 'readonly',
before: 'readonly',
beforeEach: 'readonly',
expect: 'readonly',
describe: 'readonly',
it: 'readonly',
where: 'readonly',
},
},
},
];
71 changes: 47 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var fontWeights = {
const fontWeights = {
thin: 100,
hairline: 100,
'ultra-light': 200,
Expand All @@ -22,46 +22,57 @@ var fontWeights = {
fat: 900,
poster: 900,
'ultra-black': 950,
'extra-black': 950
'extra-black': 950,
};
var sp = ' ';
var italicRE = /(italic|oblique)$/i;
const sp = ' ';
const italicRE = /(italic|oblique)$/i;

var fontCache = {};
const fontCache = {};

/**
* @param {string|Array<string>} fonts Mapbox GL Style fontstack or single font, e.g. `['Open Sans Regular', 'Arial Unicode MS Regular']` or `'Open Sans Regular'`.
* @param {number} size Font size in pixels.
* @param {string|number} [lineHeight] Line height as css line-height.
* @returns {string} CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.
* @return {string} CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.
*/
export default function(fonts, size, lineHeight) {
var cssData = fontCache[fonts];
export default function (fonts, size, lineHeight) {
let 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') {
let weight = 400;
let style = 'normal';
const fontFamilies = [];
let haveWeight, haveStyle;
for (let i = 0, ii = fonts.length; i < ii; ++i) {
const font = fonts[i];
const parts = font.split(' ');
let 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, '');
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) {
for (const w in fontWeights) {
const 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)) {
Expand All @@ -74,7 +85,8 @@ export default function(fonts, size, lineHeight) {
weight = maybeWeight;
haveWeight = true;
}
var fontFamily = parts.join(sp)
let fontFamily = parts
.join(sp)
.replace('Klokantech Noto Sans', 'Noto Sans')
.replace('DIN Pro', 'Barlow')
.replace('Arial Unicode MS', 'Arial');
Expand All @@ -84,7 +96,18 @@ export default function(fonts, size, lineHeight) {
fontFamilies.push(fontFamily);
}
// CSS font property: font-style font-weight font-size/line-height font-family
cssData = fontCache[fonts] = [style, weight, fontFamilies];
cssData = [style, weight, fontFamilies];
fontCache[fonts] = cssData;
}
return cssData[0] + sp + cssData[1] + sp + size + 'px' + (lineHeight ? '/' + lineHeight : '') + sp + cssData[2];
return (
cssData[0] +
sp +
cssData[1] +
sp +
size +
'px' +
(lineHeight ? '/' + lineHeight : '') +
sp +
cssData[2]
);
}
Loading