Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
94dbec2
Incrementally update
tristen Mar 4, 2025
0e08763
Lose extensions on imports
tristen Mar 4, 2025
f81f483
Declare class
tristen Mar 4, 2025
60e274d
More conversion
tristen Mar 4, 2025
f8166b3
Move all source .js to .ts
tristen Mar 4, 2025
88f9cb1
Format everything
tristen Mar 4, 2025
6c95cc9
Fix bad reference to getFeaturesAt
tristen Mar 4, 2025
2098903
More TypeScript setup
tristen Mar 4, 2025
dd83eed
Convet more to TypeScript
tristen Mar 4, 2025
8cdbaf0
Tackle smaller libs
tristen Mar 4, 2025
0a746b8
Move feature_types to classes
tristen Mar 5, 2025
f7cc701
Start over again with @types/mapbox-gl-draw
tristen Mar 6, 2025
711f71c
Reformatting wave
tristen Mar 6, 2025
045467d
More typing
tristen Mar 6, 2025
5b71f7b
Simple typings for common selectors
tristen Mar 6, 2025
bf78fe6
More typings
tristen Mar 6, 2025
e1cc500
More type safety, nest properties in mode objects
tristen Mar 13, 2025
c865b76
More
tristen Mar 13, 2025
2923db4
More
tristen Mar 13, 2025
2f8abc0
Drop unused method
tristen Mar 13, 2025
9506e08
Bad typing for QRF
tristen Mar 13, 2025
7a00968
Add argument signatures to mode interface and do not recast
tristen Mar 13, 2025
1b4c52e
Walk back
tristen Mar 13, 2025
2792160
Reduce the scope of this PR by skipping bench stuff
tristen Mar 14, 2025
2e24ed1
Reduce scope further
tristen Mar 14, 2025
d23d156
Bad conditional
tristen Mar 14, 2025
05cf584
Walk back on eslint stuff
tristen Mar 14, 2025
3b48ac1
eslint changes
tristen Mar 14, 2025
1c2bc4c
Consistify direct select with object+property of other modes
tristen Mar 14, 2025
64cd9df
Mode state interface
tristen Mar 14, 2025
dd3b5d2
More typings for direct_select
tristen Mar 15, 2025
06ebad2
Organize, use ModeCTX directly
tristen Mar 15, 2025
5daaa4a
Simplify
tristen Mar 15, 2025
c6ec967
String is also accepted
tristen Mar 15, 2025
341d3ac
Fixes to store
tristen Mar 16, 2025
aa98282
More on store
tristen Mar 16, 2025
34798cf
Work on api
tristen Mar 16, 2025
fe4d933
More typing
tristen Mar 16, 2025
4755a90
Finish api
tristen Mar 16, 2025
7276daa
Add ts-node loader and drop js extensions in test files
tristen Mar 16, 2025
8560abb
Convert the rest of lib to named exports
tristen Mar 16, 2025
77877c4
Move test files to typescript
tristen Mar 16, 2025
cebd5ab
Simplify
tristen Mar 16, 2025
11fc1c4
Some type coersion for tests
tristen Mar 17, 2025
b32aad7
More typings for tests
tristen Mar 17, 2025
9b0ca09
More types more coercing for mocks
tristen Mar 17, 2025
a1e18d9
More typings for tests
tristen Mar 17, 2025
7f1f5c5
Do some spy mocking
tristen Mar 17, 2025
195b056
More spy coersion
tristen Mar 17, 2025
ac8d989
Finish up the pass on tsc errors in tests
tristen Mar 17, 2025
041405c
tsx is better?
tristen Mar 17, 2025
845a741
Fixes to TypeScript for tests
tristen Mar 17, 2025
31a7035
Lint fixes suspiciously light
tristen Mar 17, 2025
b54417b
Bad typo
tristen Mar 17, 2025
7257289
Need to confirm undefined here
tristen Mar 17, 2025
57a7828
Merge branch 'main' into tsc
tristen Mar 17, 2025
37b1e97
Not a major version bump
tristen Mar 17, 2025
bd51259
Fix rollup
tristen Mar 17, 2025
dde51f2
Drop `export` where it is not necessary
tristen Mar 17, 2025
d180d1f
Remove overriding method
tristen Mar 18, 2025
326426e
Merge branch 'main' into tsc
tristen Mar 18, 2025
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
45 changes: 1 addition & 44 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
{
"extends": [
"mourner",
"plugin:import/recommended"
],
"parser": "espree",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
},
"plugins": [
"import"
],
"globals": {
"document": true
},
"rules": {
"no-duplicate-imports": "off",
"import/no-duplicates": "error",
"import/no-commonjs": "error",

"indent": [2,2],
"array-bracket-spacing": "off",
"block-scoped-var": "error",
"consistent-return": "off",
"global-require": "off",
"key-spacing": "off",
"no-eq-null": "off",
"no-new": "off",
"no-var": "error",
"no-warning-comments": "error",
"object-curly-spacing": "off",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-template": "error",
"quotes": "off",
"space-before-function-paren": "off",
"template-curly-spacing": "error",
"camelcase": 0,
"no-console": ["error", { "allow": ["warn", "error"] }]
},
"env": {
"es6": true,
"browser": true
}
"parser": "@typescript-eslint/parser",
}
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
3 changes: 2 additions & 1 deletion bench/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Benchmarks
Benchmarks
---

Benchmarks help us catch performance regressions and improve performance.

Expand Down
41 changes: 24 additions & 17 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main() {

draw_point_small: require('./tests/draw_point_small'),
draw_point_large: require('./tests/draw_point_large'),
draw_point_large_zoomed: require('./tests/draw_point_large_zoomed'),
draw_point_large_zoomed: require('./tests/draw_point_large_zoomed')
};

const benchmarkName = location.hash.substr(1);
Expand All @@ -46,7 +46,7 @@ function main() {

let innerHTML = '';

tests.forEach((test) => {
tests.forEach(test => {
innerHTML += '<div class="test">';
innerHTML += `<a href="#${test}">${test}</a>`;
innerHTML += '</div>';
Expand All @@ -59,7 +59,10 @@ function main() {

window.addEventListener('hashchange', () => location.reload(), false);

log('dark', 'please keep this window in the foreground and close the debugger');
log(
'dark',
'please keep this window in the foreground and close the debugger'
);

const Benchmark = benchmarks[benchmarkName];
if (!Benchmark) {
Expand All @@ -72,30 +75,30 @@ function main() {
createMap
});

bench.on('log', (event) => {
bench.on('log', event => {
log(event.color || 'blue', event.message);
});

bench.on('pass', (event) => {
bench.on('pass', event => {
log('green', `<strong class="prose-big">${event.message}</strong>`);
});

bench.on('fail', (event) => {
bench.on('fail', event => {
log('red', `<strong class="prose-big">${event.message}</strong>`);
});
}

function log(color, message) {
document.getElementById('logs').innerHTML += `<div class="log dark fill-${color}"><p>${message}</p></div>`;
document.getElementById('logs').innerHTML +=
`<div class="log dark fill-${color}"><p>${message}</p></div>`;
Comment thread Fixed
}

function getAccessToken() {
const accessToken = (
const accessToken =
process.env.MapboxAccessToken ||
process.env.MAPBOX_ACCESS_TOKEN ||
getURLParameter('access_token') ||
localStorage.getItem('accessToken')
);
process.env.MAPBOX_ACCESS_TOKEN ||
getURLParameter('access_token') ||
localStorage.getItem('accessToken');
localStorage.setItem('accessToken', accessToken);
return accessToken;
}
Expand All @@ -109,18 +112,22 @@ function getURLParameter(name) {
function createMap(options) {
const mapElement = document.getElementById('map');

options = Object.assign({width: 512, height: 512}, options);
options = Object.assign({ width: 512, height: 512 }, options);

mapElement.style.display = 'block';
mapElement.style.width = `${options.width}px`;
mapElement.style.height = `${options.height}px`;

mapboxgl.accessToken = getAccessToken();

const map = new mapboxgl.Map(Object.assign({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v12'
}, options));
const map = new mapboxgl.Map(
Object.assign(
{
container: 'map'
},
options
)
);

const draw = new MapboxDraw(options);

Expand Down
1 change: 0 additions & 1 deletion bench/lib/evented.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export default class Evented {
on(type, listener) {
if (!listener) {
Expand Down
4 changes: 3 additions & 1 deletion bench/lib/format_number.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

export default function formatNumber(x) {
return Math.round(x).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return Math.round(x)
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
4 changes: 2 additions & 2 deletions bench/lib/fps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default function() {
export default function () {
let frameCount = 0;
let start = null;
let running = false;

const frameCounter = function() {
const frameCounter = function () {
if (running) {
frameCount++;
requestAnimationFrame(frameCounter);
Expand Down
17 changes: 10 additions & 7 deletions bench/lib/mouse_drag.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import mouseEvents from './mouse_events';
import mousePath from './mouse_path';

export default function(start, map) {

export default function (start, map) {
const path = mousePath(start);
const events = mouseEvents(map);

events.push('mousedown', {
x: start.x,
y: start.y
}, true);
events.push(
'mousedown',
{
x: start.x,
y: start.y
},
true
);

for (let i = 0; i < path.length; i++) {
events.push('mousemove', path[i]);
Expand All @@ -23,7 +26,7 @@ export default function(start, map) {
y: start.y
});

return function(cb) {
return function (cb) {
events.run(cb);
};
}
4 changes: 2 additions & 2 deletions bench/lib/mouse_draw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mouseEvents from './mouse_events';
import mousePath from './mouse_path';

export default function(start, map) {
export default function (start, map) {
const path = mousePath(start);

const events = mouseEvents(map);
Expand All @@ -24,7 +24,7 @@ export default function(start, map) {

events.push('mouseup', path[path.length - 1]);

return function(cb) {
return function (cb) {
events.run(cb);
};
}
10 changes: 5 additions & 5 deletions bench/lib/mouse_events.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function(map) {
export default function (map) {
const events = [];

events.push = function(event, point, dp) {
events.push = function (event, point, dp) {
const payload = {
dropPoint: dp === undefined ? false : dp,
originalEvent: {
Expand All @@ -14,15 +14,15 @@ export default function(map) {
events[events.length] = [event, payload];
};

events.run = function(cb) {
events.run = function (cb) {
const one = 100 / events.length;
const runner = function(i) {
const runner = function (i) {
const event = events[i];
if (event === undefined) {
cb();
} else {
map.fire(event[0], event[1]);
map.fire('progress', {done:Math.ceil(one * i)});
map.fire('progress', { done: Math.ceil(one * i) });
setTimeout(() => {
runner(i + 1);
}, 0);
Expand Down
10 changes: 5 additions & 5 deletions bench/lib/mouse_path.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export default function(start) {
export default function (start) {
const path = [];

for (let i = 0; i < 7; i += .04) {
for (let i = 0; i < 7; i += 0.04) {
const A = 3;
const B = Math.PI / 2;
const SIZE = 100;
const OFFSET = 5;

const x = start.x + (Math.sin(i) * SIZE) + (i * OFFSET);
const y = start.y + (Math.sin(A * i + B) * SIZE) + (i * OFFSET);
path.push({x, y});
const x = start.x + Math.sin(i) * SIZE + i * OFFSET;
const y = start.y + Math.sin(A * i + B) * SIZE + i * OFFSET;
path.push({ x, y });
}

return path;
Expand Down
5 changes: 2 additions & 3 deletions bench/lib/mouse_trace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mouseEvents from './mouse_events';

export default function(ring, map) {

export default function (ring, map) {
const events = mouseEvents(map);

let lastPoint = null;
Expand All @@ -24,7 +23,7 @@ export default function(ring, map) {
events.push('mouseup', lastPoint);
}

return function(cb) {
return function (cb) {
events.run(cb);
};
}
6 changes: 3 additions & 3 deletions bench/lib/trace_progress.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function(features, map) {
export default function (features, map) {
const sizes = [];
let total = 0;
for (const feature of features) {
Expand All @@ -18,7 +18,7 @@ export default function(features, map) {
let pos = 0;
let lastDone = -1;

map.on('progress', (e) => {
map.on('progress', e => {
if (e.done < lastDone) {
pos++;
}
Expand All @@ -27,7 +27,7 @@ export default function(features, map) {
for (let i = 0; i < pos; i++) {
done += sizes[i];
}
done += (sizes[pos] * e.done / 100);
done += (sizes[pos] * e.done) / 100;
progressDiv.style.width = `${done}%`;
});
}
10 changes: 7 additions & 3 deletions bench/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export default {
plugins: [
json(),
replace({
'process.env.MapboxAccessToken': JSON.stringify(process.env.MapboxAccessToken),
'process.env.MAPBOX_ACCESS_TOKEN': JSON.stringify(process.env.MAPBOX_ACCESS_TOKEN),
'process.env.MapboxAccessToken': JSON.stringify(
process.env.MapboxAccessToken
),
'process.env.MAPBOX_ACCESS_TOKEN': JSON.stringify(
process.env.MAPBOX_ACCESS_TOKEN
),
preventAssignment: true
}),
resolve({
Expand All @@ -28,5 +32,5 @@ export default {
// https://github.com/mapbox/mapbox-gl-js/pull/6956
ignoreGlobal: true
})
],
]
};
14 changes: 8 additions & 6 deletions bench/tests/direct_select_large.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import formatNumber from '../lib/format_number';
import fpsRunner from '../lib/fps';
import DragMouse from '../lib/mouse_drag';

const START = {x: 445, y: 293};
const START = { x: 445, y: 293 };

export default class Benchmark extends Evented {
constructor(options) {
super();

const out = options.createMap({width: 1024});
const out = options.createMap({ width: 1024 });

// eslint-disable-next-line new-cap
const dragMouse = DragMouse(START, out.map);

const progressDiv = document.getElementById('progress');
out.map.on('progress', (e) => {
out.map.on('progress', e => {
progressDiv.style.width = `${e.done}%`;
});

Expand All @@ -27,15 +27,17 @@ export default class Benchmark extends Evented {
out.draw.changeMode('direct_select', { featureId: SouthAmerica.id });

setTimeout(() => {
this.fire('log', {message: 'normal - 41fps'});
this.fire('log', { message: 'normal - 41fps' });
const FPSControl = fpsRunner();
FPSControl.start();
dragMouse(() => {
const fps = FPSControl.stop();
if (fps < 55) {
this.fire('fail', {message: `${formatNumber(fps)} fps - expected 55fps or better`});
this.fire('fail', {
message: `${formatNumber(fps)} fps - expected 55fps or better`
});
} else {
this.fire('pass', {message: `${formatNumber(fps)} fps`});
this.fire('pass', { message: `${formatNumber(fps)} fps` });
}
});
}, 2000);
Expand Down
Loading