Skip to content

Commit

Permalink
Merge branch 'vite'
Browse files Browse the repository at this point in the history
  • Loading branch information
perliedman committed Dec 27, 2024
2 parents dcf7f1d + 3ce9a25 commit 24f820f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 84 deletions.
51 changes: 0 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
"zustand": "^3.5.1"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@eslint/js": "^9.17.0",
"@tailwindcss/forms": "^0.5.9",
"@testing-library/jest-dom": "^5.16.4",
Expand Down
5 changes: 1 addition & 4 deletions src/ControlDescriptionLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import ImageLayer from "ol/layer/Image";
import Static from "ol/source/ImageStatic";
import { useEffect, useState } from "react";
import { svgToUrl } from "./services/svg-to-bitmap";
import {
courseDefinitionToSvg,
getControlDescriptionExtent,
} from "./services/create-svg";
import { courseDefinitionToSvg } from "./services/create-svg";
import { transformExtent } from "./services/coordinates";

export function useControlDescriptions(
Expand Down
7 changes: 4 additions & 3 deletions src/ControlDescriptionSheet.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { controlDistance } from "./models/control";
import { courseDistance } from "./models/course";
import DefinitionTexts from "svg-control-descriptions/symbols/lang.json";
import Button from "./ui/Button";
import { useHotkeys } from "react-hotkeys-hook";
import { descriptionSymbols } from "./services/fetch-symbol-svg";

export default function ControlDescriptionSheet({
eventName,
Expand Down Expand Up @@ -156,8 +157,8 @@ function DescriptionSymbol({ symbol }) {
const [svg, setSvg] = useState();

useEffect(() => {
if (symbol) {
import(`svg-control-descriptions/symbols/${symbol}.svg`).then(setSvg);
if (symbol && symbol in descriptionSymbols) {
descriptionSymbols[symbol]().then(setSvg);
} else {
setSvg(null);
}
Expand Down
24 changes: 12 additions & 12 deletions src/services/create-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,18 @@ export async function courseDefinitionToSvg(eventName, course, mapScale) {
cellSize - 1 // TODO: LOL
),
text(
Math.round(
((controlDistance(
course.controls[index - 1],
course.controls[index]
) /
1000) *
// TODO: Use correct map scale
mapScale) /
10
) *
10 +
" m",
(index > 0
? Math.round(
((controlDistance(
course.controls[index - 1],
course.controls[index]
) /
1000) *
// TODO: Use correct map scale
mapScale) /
10
) * 10
: 0) + " m",
cellSize * 4 + cellSize / 2,
baseLine,
"black",
Expand Down
14 changes: 11 additions & 3 deletions src/services/fetch-symbol-svg.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import fetch from "./fetch";
import { getSvgDimensions } from "./svg-utils";

const symbols = import.meta.glob(
"../../node_modules/svg-control-descriptions/symbols/*.svg"
);

export const descriptionSymbols = {};
for (const path in symbols) {
const symbol = /symbols\/(.*)\.svg/.exec(path)[1];
descriptionSymbols[symbol] = symbols[path];
}

export default async function fetchSymbolSvg(symbol) {
const svgUrl = (
await import(`svg-control-descriptions/symbols/${symbol}.svg`)
).default;
const svgUrl = (await descriptionSymbols[symbol]()).default;
const symbolXml = await fetch(svgUrl, null, { format: "text" });
const svg = new window.DOMParser().parseFromString(
symbolXml,
Expand Down
10 changes: 1 addition & 9 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
import { nodePolyfills } from "vite-plugin-node-polyfills";

// https://vite.dev/config/
Expand All @@ -14,13 +12,7 @@ export default defineConfig({
global: "globalThis",
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
NodeModulesPolyfillPlugin(),
],
plugins: [],
},
},
});

0 comments on commit 24f820f

Please sign in to comment.