refactor: full module deps

This commit is contained in:
Artemy 2024-01-23 20:15:29 +03:00
parent 98daedc9c2
commit d6d614195d
6 changed files with 2857 additions and 118 deletions

26
.eslintrc.cjs Normal file
View file

@ -0,0 +1,26 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}

2819
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,9 @@
"description": "Site that displays CIMEngine maps",
"main": "index.js",
"scripts": {
"build": "rollup --config src/rollup.config.js"
"build": "rollup --config src/rollup.config.js",
"serve": "serve dist -p 8080",
"dev": "npm run build && npm run serve"
},
"type": "module",
"keywords": [],
@ -13,11 +15,23 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.1",
"@rollup/plugin-node-resolve": "^15.1.0",
"eslint": "^8.56.0",
"rollup": "^3.25.1",
"rollup-plugin-copy": "^3.4.0"
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-import-css": "^3.4.0",
"serve": "^14.2.1"
},
"dependencies": {
"@mapbox-controls/compass": "^1.1.0",
"@mapbox-controls/inspect": "^1.1.0",
"@mapbox-controls/ruler": "^1.1.0",
"@mapbox-controls/styles": "^1.1.0",
"@mapbox-controls/zoom": "^1.1.0",
"@rollup/plugin-terser": "^0.4.4",
"@turf/area": "^6.5.0",
"mapbox-gl-controls": "^2.3.5"
"bootstrap": "^5.3.2",
"mapbox-gl": "^2.15.0",
"mapbox-gl-controls": "^2.3.5",
"showdown": "^2.1.0"
}
}

View file

@ -14,17 +14,7 @@
<link rel="stylesheet" href="./index.css">
<link rel="icon" type="image/x-icon" href="https://i.imgur.com/i0yls6d.png">
<link href="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mapbox-gl-controls@2.3/lib/controls.min.css">
<link href="https://watergis.github.io/mapbox-gl-export/mapbox-gl-export.css" rel="stylesheet" />
<style>
body {
margin: 0;
@ -41,29 +31,7 @@
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- <div class="menu">
<div class="row">
<div class="col-md-2">
<img class="w-50" src="https://erth2.github.io/movc/icons/movc-logo.png">
</div>
<div class="col-md-8">
<h4>Map of ERTH2</h4>
</div>
</div>
</div> -->
<div id="map"></div>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js"></script>
<script type="text/javascript" src="https://unpkg.com/showdown/dist/showdown.min.js"></script>
<script src="https://watergis.github.io/mapbox-gl-export/mapbox-gl-export.js"></script>
<script src="./index.bundle.js" async defer></script>
</body>
</html>

View file

@ -1,9 +1,22 @@
import {
StylesControl,
ZoomControl,
CompassControl,
InspectControl,
} from "mapbox-gl-controls";
import "./index.css";
import "bootstrap";
import "bootstrap/dist/css/bootstrap.min.css";
import StylesControl from "@mapbox-controls/styles";
import ZoomControl from "@mapbox-controls/zoom";
import CompassControl from "@mapbox-controls/compass";
import InspectControl from "@mapbox-controls/inspect";
import "@mapbox-controls/styles/src/index.css";
import "@mapbox-controls/zoom/src/index.css";
import "@mapbox-controls/compass/src/index.css";
import "@mapbox-controls/inspect/src/index.css";
import mapboxgl from "mapbox-gl";
import "mapbox-gl/dist/mapbox-gl.css";
import showdown from "showdown";
function loginfo(...str) {
let info = str.shift();
@ -29,9 +42,29 @@ window.onload = async () => {
).json()
)[mapId];
const geoURL = params.geoURL || mapDataFromId.geoURL;
const countryInfoUrl = params.countryInfoURL || mapDataFromId.countryInfoURL;
const debug = params.debug || false;
if (mapDataFromId.external) {
mapDataFromId = await (await fetch(mapDataFromId.external)).json();
}
if (!mapDataFromId) {
alert(`Map ${mapId} not found`);
}
if (mapDataFromId.icon) {
document.getElementById("icon").setAttribute("href", mapDataFromId.icon);
}
let geoURL, countryInfoUrl, debug;
if (params.external) {
const data = await (await fetch(params.external)).json();
geoURL = data.geoURL;
}
geoURL = params.geoURL || mapDataFromId.geoURL;
countryInfoUrl = params.countryInfoURL || mapDataFromId.countryInfoURL;
debug = params.debug || false;
mapboxgl.accessToken =
"pk.eyJ1IjoiYXJ0ZWdvc2VyIiwiYSI6ImNrcDViN3BhcDAwbW0ydnBnOXZ0ZzFreXUifQ.FIVtaBNr9dr_TIw672Zqdw";
@ -64,18 +97,7 @@ window.onload = async () => {
);
map.addControl(new ZoomControl(), "top-right");
map.addControl(new CompassControl(), "top-right");
map.addControl(
new MapboxExportControl({
PageSize: Size.A3,
PageOrientation: PageOrientation.Portrait,
Format: Format.PNG,
DPI: DPI[96],
Crosshair: true,
PrintableArea: true,
}),
"top-right"
);
map.addControl(new CompassControl(), "bottom-right");
if (debug) {
map.addControl(new InspectControl(), "bottom-right");

View file

@ -1,23 +1,29 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import copy from "rollup-plugin-copy";
import css from "rollup-plugin-import-css";
import terser from "@rollup/plugin-terser";
export default [
{
input: "src/index.js",
output: {
file: "dist/index.bundle.js",
format: "iife",
format: "esm",
sourcemap: true,
plugins: [terser()],
},
context: "window",
plugins: [
css({
output: "index.css",
minify: true,
}),
resolve(),
commonjs({ sourceMap: false }),
commonjs(),
copy({
targets: [
{ src: "src/index.html", dest: "dist" },
{ src: "src/index.css", dest: "dist" },
{ src: "icons/*", dest: "dist/icons" },
],
}),