Skip to content

Commit ddf6942

Browse files
authored
Fix exported typescript typings for version 2.0 (#623)
* Improve camera options and export some types * Fix lint * Comment out exports to see if it fixes the failing tests * Export some stuff and don't export the others * More exports * small fixes - still far from working... * Allow running dts-bundle-generator * Added missing type declaration for grid-index * Fix lint * Rename duplicate grid index class * Improve typings for exported classes * Improve event types and map `on` signature * Added dts-builder-generator * Added changelog and renamed glsl * Fix typo * Rename es.js to mjs to allow import to know that this is an ES module
1 parent 50de937 commit ddf6942

23 files changed

Lines changed: 451 additions & 126 deletions

CHANGELOG.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
### Features and improvements
44

55
- *...Add new stuff here...*
6-
- Improve attribution controls accessibility. See [#359](https://github.com/maplibre/maplibre-gl-js/issues/359)
7-
- Allow maxPitch value up to 85, use values greater than 60 at your own risk (#574)
86

97
### 🐞 Bug fixes
108

@@ -19,8 +17,22 @@
1917
- ** Breaking Change ** stopped supporting IE (internet explorer)
2018
- ** Breaking Change ** removed all code related to `accessToken` and mapbox specific urls, including telemetry etc. Please do not use mapbox servers with this library.
2119
- ** Breaking Change ** removed `baseApiUrl` as it was used only for mapbox related urls
22-
- Added redraw function to map (#206)
23-
- Fix padding-top of the popup to improve readability of popup text (#354).
20+
- ** Breaking Change ** typescript typings have changed:
21+
- `Style` => `StypeSpecification`
22+
- `AnyLayer` => `LayerSpecification`
23+
- `AnySourceData` => `SourceSpecification`
24+
- `MapboxEvent` => `MapLibreEvent`
25+
- `MapboxOptions` => `MapOptions`
26+
- `MapBoxZoomEvent` => `MapLibreZoomEvent`
27+
- `*SourceRaw` + `*SourceOptions` => `*SourceSpecification`
28+
- `*Source` (source implementation definition) were removed
29+
- `*Layer` => `*LayerSpecification`
30+
- `*Paint` => `*LayerSpecification['paint']`
31+
- `*Layout` => `*LayerSpecification['layout']`
32+
- `MapboxGeoJSONFeature` => `GeoJSONFeature`
33+
- Added `redraw` function to map (#206)
34+
- Improve attribution controls accessibility. See [#359](https://github.com/maplibre/maplibre-gl-js/issues/359)
35+
- Allow maxPitch value up to 85, use values greater than 60 at your own risk (#574)
2436
- *...Add new stuff here...*
2537

2638
### 🐞 Bug fixes
@@ -29,6 +41,7 @@
2941
- Fix tile placeholder replacement to allow for placeholders to be in a URL more than once. (#348)
3042
- Fix type check for non dom environment. (#334)
3143
- Fix precision problem in patterns when overzoomed in OpenGL ES devices.
44+
- Fix padding-top of the popup to improve readability of popup text (#354).
3245

3346
## 1.15.2
3447

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import glob from 'glob';
3+
import child_process from 'child_process';
34

45
let args = process.argv.slice(2);
56
let outputBaseDir = args[0];
@@ -11,6 +12,8 @@ console.log(`Copying glsl files to ${outputBaseDir}, minify: ${minify}`);
1112
* This script is intended to copy the glsl file to the compilation output folder,
1213
* change their extension to .js and export the shaders as strings in javascript.
1314
* It will also minify them a bit if needed and change the extension to .js
15+
* After that it will create a combined typescript definition file and manipulate it a bit
16+
* It will also create a simple package.json file to allow importing this package in webpack
1417
*/
1518

1619
glob("./src/**/*.glsl", null, (err, files) => {
@@ -32,3 +35,17 @@ glob("./src/**/*.glsl", null, (err, files) => {
3235
}
3336
console.log(`Finished converting ${files.length} glsl files`);
3437
});
38+
39+
if (!fs.existsSync("dist")) {
40+
fs.mkdirSync("dist");
41+
}
42+
43+
console.log(`Starting bundling types`);
44+
const outputFile = "./dist/maplibre-gl.d.ts";
45+
child_process.execSync(`dts-bundle-generator --no-check --umd-module-name=maplibregl -o ${outputFile} ./src/index.ts`);
46+
let types = fs.readFileSync(outputFile, 'utf8');
47+
types = types.replace(/declare class/g, "export declare class");
48+
fs.writeFileSync(outputFile, types);
49+
console.log(`Finished bundling types`);
50+
51+
fs.writeFileSync("./dist/package.json", '{ "type": "commonjs" }');

package-lock.json

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maplibre-gl",
33
"description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library",
4-
"version": "2.0.0-pre.5",
4+
"version": "2.0.0-pre.6",
55
"main": "dist/maplibre-gl.js",
66
"style": "dist/maplibre-gl.css",
77
"license": "BSD-3-Clause",
@@ -12,7 +12,7 @@
1212
"engines": {
1313
"node": ">=14.0.0"
1414
},
15-
"types": "types/index.d.ts",
15+
"types": "dist/maplibre-gl.d.ts",
1616
"type": "module",
1717
"dependencies": {
1818
"@mapbox/geojson-rewind": "^0.5.0",
@@ -101,6 +101,7 @@
101101
"d3": "^4.12.0",
102102
"diff": "^4.0.1",
103103
"documentation": "~12.1.1",
104+
"dts-bundle-generator": "^6.0.0",
104105
"ejs": "^3.1.6",
105106
"eslint": "^7.32.0",
106107
"eslint-config-mourner": "^3.0.0",
@@ -172,10 +173,10 @@
172173
"./rollup/build/tsc/src/util/web_worker.js": "./build/web_worker_replacement.js"
173174
},
174175
"scripts": {
175-
"build-glsl": "node build/copy-glsl-files.js ./rollup/build/tsc/src/shaders",
176-
"build-glsl-min": "node build/copy-glsl-files.js ./rollup/build/tsc/src/shaders true",
177-
"build-tsc": "tsc && npm run build-glsl",
178-
"build-tsc-min": "tsc && npm run build-glsl-min",
176+
"build-post-ts": "node build/post-ts-build.js ./rollup/build/tsc/src/shaders",
177+
"build-post-ts-min": "node build/post-ts-build.js ./rollup/build/tsc/src/shaders true",
178+
"build-tsc": "tsc && npm run build-post-ts",
179+
"build-tsc-min": "tsc && npm run build-post-ts-min",
179180
"build-dev": "npm run build-tsc && rollup -c --environment BUILD:dev",
180181
"watch-dev": "npm run build-tsc && rollup -c --environment BUILD:dev --watch",
181182
"build-prod": "npm run build-tsc && rollup -c --environment BUILD:production",
@@ -214,7 +215,6 @@
214215
"build/",
215216
"dist/maplibre-gl*",
216217
"dist/style-spec/",
217-
"types/",
218218
"src/"
219219
]
220220
}

rollup.config.style-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const config = [{
1212
input: 'rollup/build/tsc/src/style-spec/style-spec.js',
1313
output: {
1414
name: 'maplibreGlStyleSpecification',
15-
file: `dist/style-spec/${esm ? 'index.es.js' : 'index.js'}`,
15+
file: `dist/style-spec/${esm ? 'index.mjs' : 'index.js'}`,
1616
format: esm ? 'esm' : 'umd',
1717
sourcemap: true
1818
},

src/data/feature_index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import loadGeometry from './load_geometry';
33
import toEvaluationFeature from './evaluation_feature';
44
import EXTENT from './extent';
55
import featureFilter from '../style-spec/feature_filter';
6-
import Grid from 'grid-index';
6+
import TransferableGridIndex from 'grid-index';
77
import DictionaryCoder from '../util/dictionary_coder';
88
import vt from '@mapbox/vector-tile';
99
import Protobuf from 'pbf';
@@ -45,8 +45,8 @@ class FeatureIndex {
4545
x: number;
4646
y: number;
4747
z: number;
48-
grid: Grid;
49-
grid3D: Grid;
48+
grid: TransferableGridIndex;
49+
grid3D: TransferableGridIndex;
5050
featureIndexArray: FeatureIndexArray;
5151
promoteId?: PromoteIdSpecification;
5252

@@ -61,8 +61,8 @@ class FeatureIndex {
6161
this.x = tileID.canonical.x;
6262
this.y = tileID.canonical.y;
6363
this.z = tileID.canonical.z;
64-
this.grid = new Grid(EXTENT, 16, 0);
65-
this.grid3D = new Grid(EXTENT, 16, 0);
64+
this.grid = new TransferableGridIndex(EXTENT, 16, 0);
65+
this.grid3D = new TransferableGridIndex(EXTENT, 16, 0);
6666
this.featureIndexArray = new FeatureIndexArray();
6767
this.promoteId = promoteId;
6868
}

src/geo/edge_insets.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,41 @@ class EdgeInsets {
9696
}
9797
}
9898

99+
/**
100+
* Options for setting padding on calls to methods such as {@link Map#fitBounds}, {@link Map#fitScreenCoordinates}, and {@link Map#setPadding}. Adjust these options to set the amount of padding in pixels added to the edges of the canvas. Set a uniform padding on all edges or individual values for each edge. All properties of this object must be
101+
* non-negative integers.
102+
*
103+
* @example
104+
* var bbox = [[-79, 43], [-73, 45]];
105+
* map.fitBounds(bbox, {
106+
* padding: {top: 10, bottom:25, left: 15, right: 5}
107+
* });
108+
*
109+
* @example
110+
* var bbox = [[-79, 43], [-73, 45]];
111+
* map.fitBounds(bbox, {
112+
* padding: 20
113+
* });
114+
* @see [Fit to the bounds of a LineString](https://maplibre.org/maplibre-gl-js-docs/example/zoomto-linestring/)
115+
* @see [Fit a map to a bounding box](https://maplibre.org/maplibre-gl-js-docs/example/fitbounds/)
116+
*/
99117
export type PaddingOptions = {
100-
top: number;
101-
bottom: number;
102-
right: number;
103-
left: number;
118+
/**
119+
* @property {number} top Padding in pixels from the top of the map canvas.
120+
*/
121+
top: number;
122+
/**
123+
* @property {number} bottom Padding in pixels from the bottom of the map canvas.
124+
*/
125+
bottom: number;
126+
/**
127+
* @property {number} left Padding in pixels from the left of the map canvas.
128+
*/
129+
right: number;
130+
/**
131+
* @property {number} right Padding in pixels from the right of the map canvas.
132+
*/
133+
left: number;
104134
};
105135

106136
export default EdgeInsets;

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="./types/glsl.d.ts" />
2+
/// <reference path="./types/non-typed-modules.d.ts" />
13
import assert from 'assert';
24
import {supported} from '@mapbox/mapbox-gl-supported';
35

@@ -235,6 +237,5 @@ Debug.extend(exported, {isSafari, getPerformanceMetrics: PerformanceUtils.getPer
235237
*/
236238

237239
export default exported;
238-
239240
// canary assert: used to confirm that asserts have been removed from production build
240241
assert(true, 'canary assert');

src/render/painter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ class Painter {
488488
this.id = layer.id;
489489

490490
this.gpuTimingStart(layer);
491-
draw[layer.type](painter, sourceCache, layer, coords, this.style.placement.variableOffsets);
491+
draw[layer.type](painter, sourceCache, layer as any, coords, this.style.placement.variableOffsets);
492492
this.gpuTimingEnd();
493493
}
494494

0 commit comments

Comments
 (0)