diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..2cb7d2a --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +**/*.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..a83b081 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,30 @@ +{ + "root": true, + "env": { + "browser": true, + "es2020": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "prettier", + "prettier/@typescript-eslint" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 11, + "sourceType": "module" + }, + "plugins": ["unused-imports", "@typescript-eslint", "prettier"], + "rules": { + "prettier/prettier": "error", + "no-unused-vars": "off", + "unused-imports/no-unused-imports-ts": "error", + "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/ban-ts-comment": "off" + } +} diff --git a/.forgejo/workflows/check.yml b/.forgejo/workflows/check.yml deleted file mode 100644 index b611423..0000000 --- a/.forgejo/workflows/check.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Check - -on: - push: - branches: ['main'] - pull_request: - branches: ['main'] - -jobs: - check: - runs-on: docker - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: '22.x' - check-latest: true - - # package-lock.json is gitignored, so cache the global npm download cache - # keyed on package.json rather than relying on `npm ci` + a lockfile. - - name: Cache npm dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: ${{ runner.os }}-npm-${{ hashFiles('package.json') }} - restore-keys: | - ${{ runner.os }}-npm- - - - name: Install dependencies - run: npm install - - - name: Check formatting - run: npm run format - - - name: Lint - run: npm run lint - - - name: Type-check - run: npm test - - - name: Build - run: npm run build diff --git a/.forgejo/workflows/publish.yml b/.forgejo/workflows/publish.yml deleted file mode 100644 index ea3663b..0000000 --- a/.forgejo/workflows/publish.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Publish - -on: - push: - branches: ['main'] - tags: ['*'] - workflow_dispatch: - -concurrency: - group: 'pages' - cancel-in-progress: false - -jobs: - build: - runs-on: docker - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: '22.x' - check-latest: true - - - name: Cache npm dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: ${{ runner.os }}-npm-${{ hashFiles('package.json') }} - restore-keys: | - ${{ runner.os }}-npm- - - - name: Install dependencies - run: npm install - - - name: Check formatting - run: npm run format - - - name: Lint - run: npm run lint - - - name: Type-check - run: npm test - - - name: Build library and docs - run: npm run build - - - name: Deploy docs to pages mount - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - uses: http://forgejo:3000/andras/ci-actions/deploy-pages@main - with: - source: docs - target: sdf-2d-docs - - publish-npm: - needs: build - runs-on: docker - if: startsWith(github.ref, 'refs/tags/') - - steps: - - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: '22.x' - check-latest: true - registry-url: 'https://registry.npmjs.org' - - - name: Cache npm dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: ${{ runner.os }}-npm-${{ hashFiles('package.json') }} - restore-keys: | - ${{ runner.os }}-npm- - - - name: Install dependencies - run: npm install - - - name: Build library - run: npm run build - - - name: Publish to NPM - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/custom.d.ts b/custom.d.ts index 0d0511c..f1f7948 100644 --- a/custom.d.ts +++ b/custom.d.ts @@ -3,6 +3,3 @@ declare module '*.glsl' { const content: string; export default content; } - -/** Injected at build time by webpack's DefinePlugin. @internal */ -declare const __VERSION__: string; diff --git a/eslint.config.mjs b/eslint.config.mjs deleted file mode 100644 index 3f45f24..0000000 --- a/eslint.config.mjs +++ /dev/null @@ -1,43 +0,0 @@ -import js from '@eslint/js'; -import tsPlugin from '@typescript-eslint/eslint-plugin'; -import prettier from 'eslint-plugin-prettier'; -import prettierConfig from 'eslint-config-prettier'; -import unusedImports from 'eslint-plugin-unused-imports'; -import globals from 'globals'; - -export default [ - { - ignores: ['lib/**', 'docs/**', 'node_modules/**', '**/*.js', '**/*.mjs', '**/*.cjs'], - }, - js.configs.recommended, - tsPlugin.configs['flat/eslint-recommended'], - ...tsPlugin.configs['flat/recommended'], - prettierConfig, - { - files: ['src/**/*.ts'], - languageOptions: { - ecmaVersion: 2020, - sourceType: 'module', - globals: { - ...globals.browser, - __VERSION__: 'readonly', - }, - }, - plugins: { - 'unused-imports': unusedImports, - prettier, - }, - rules: { - 'prettier/prettier': 'error', - // Newly part of eslint:recommended in v9+; would require ES2022 Error `cause`. - 'preserve-caught-error': 'off', - 'no-unused-vars': 'off', - 'unused-imports/no-unused-imports': 'error', - '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/ban-ts-comment': 'off', - }, - }, -]; diff --git a/package.json b/package.json index a03c6f7..97b7bd9 100644 --- a/package.json +++ b/package.json @@ -35,12 +35,7 @@ "scripts": { "start": "rm -rf lib/* && webpack --mode development -w", "build": "rm -rf lib/* docs/* && npx typedoc && webpack --mode production", - "test": "tsc --noEmit", - "format": "prettier --check \"src/**/*.{ts,json}\"", - "format:fix": "prettier --write \"src/**/*.{ts,json}\"", - "lint": "eslint src", - "lint:fix": "eslint src --fix", - "fix": "npm run lint:fix && npm run format:fix" + "lint": "eslint src/**/*.{js,ts,json} --fix && prettier --write src/**/*.{js,ts,json}" }, "main": "lib/main.js", "types": "lib/src/main.d.ts", @@ -51,26 +46,26 @@ "src/main.ts" ], "dependencies": { - "gl-matrix": "^3.4.4", + "gl-matrix": "^3.3.0", "resize-observer-polyfill": "^1.5.1" }, "devDependencies": { - "@eslint/js": "^10.0.1", - "@typescript-eslint/eslint-plugin": "^8.60.1", - "@typescript-eslint/parser": "^8.60.1", - "eslint": "^10.4.1", - "eslint-config-prettier": "^10.1.8", - "eslint-plugin-prettier": "^5.5.6", - "eslint-plugin-unused-imports": "^4.4.1", - "globals": "^17.6.0", - "prettier": "^3.8.3", - "raw-loader": "^4.0.2", - "terser-webpack-plugin": "^5.6.1", - "ts-loader": "^9.6.0", - "typedoc": "^0.28.19", - "typedoc-plugin-extras": "^4.0.1", - "typescript": "^6.0.3", - "webpack": "^5.107.2", - "webpack-cli": "^7.0.3" + "@typescript-eslint/eslint-plugin": "^3.10.1", + "@typescript-eslint/parser": "^3.10.1", + "eslint": "^7.9.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-import": "^2.22.0", + "eslint-plugin-json-format": "^2.0.1", + "eslint-plugin-prettier": "^3.1.4", + "eslint-plugin-unused-imports": "^0.1.3", + "prettier": "^2.1.2", + "raw-loader": "^4.0.1", + "terser-webpack-plugin": "^2.3.8", + "ts-loader": "^8.0.3", + "typedoc": "^0.19.2", + "typedoc-plugin-extras": "^1.1.6", + "typescript": "^3.9.7", + "webpack": "^4.44.2", + "webpack-cli": "^3.3.11" } } diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh deleted file mode 100755 index a39bcb6..0000000 --- a/scripts/bump-version.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -set -e - -if [[ -z $1 ]]; then - echo "Usage: $0 {patch|minor|major}" - exit 1 -fi - -if [[ $1 =~ ^(patch|minor|major)$ ]]; then - echo "Creating a new '$1' version" -else - echo "Invalid argument: $1" - echo "Usage: $0 {patch|minor|major}" - exit 1 -fi - -if [[ -n $(git status --porcelain) ]]; then - echo "Your working directory is not clean. Please commit or stash your changes before proceeding." - exit 1 -else - echo "Your working directory is clean." -fi - -echo "Bumping version" -# Bump package.json only; we create the commit and tag ourselves below so the -# tag matches the bare version (e.g. 0.7.7) that publish.yml triggers on. -npm version "$1" --no-git-tag-version - -# Commit and tag -git add . -TAG=$(node -p "require('./package.json').version") -git commit -m "Bump version to $TAG" - -git push -echo "Tagging $TAG" -git tag -a "$TAG" -m "Release $TAG" -git push origin "$TAG" -echo "Done" diff --git a/src/drawables/lights/light-drawable.ts b/src/drawables/lights/light-drawable.ts index 2fb0534..dfa75aa 100644 --- a/src/drawables/lights/light-drawable.ts +++ b/src/drawables/lights/light-drawable.ts @@ -5,11 +5,7 @@ import { Drawable } from '../../main'; export abstract class LightDrawable extends Drawable { protected lightnessRatio = 1; - constructor( - public center: vec2, - public color: vec3, - public intensity: number - ) { + constructor(public center: vec2, public color: vec3, public intensity: number) { super(); } diff --git a/src/drawables/shapes/circle-factory.ts b/src/drawables/shapes/circle-factory.ts index b88b5cd..f611bea 100644 --- a/src/drawables/shapes/circle-factory.ts +++ b/src/drawables/shapes/circle-factory.ts @@ -7,10 +7,7 @@ import { EmptyDrawable } from '../empty-drawable'; * @category Drawable */ class CircleBase extends EmptyDrawable { - constructor( - public center: vec2, - public radius: number - ) { + constructor(public center: vec2, public radius: number) { super(); } } diff --git a/src/drawables/shapes/colorful-circle.ts b/src/drawables/shapes/colorful-circle.ts index 1a2e8d9..a06465e 100644 --- a/src/drawables/shapes/colorful-circle.ts +++ b/src/drawables/shapes/colorful-circle.ts @@ -35,11 +35,7 @@ export class ColorfulCircle extends Drawable { empty: new ColorfulCircle(vec2.create(), 0, 0), }; - constructor( - public center: vec2, - public radius: number, - public colorIndex: number - ) { + constructor(public center: vec2, public radius: number, public colorIndex: number) { super(); } diff --git a/src/drawables/shapes/hexagon-factory.ts b/src/drawables/shapes/hexagon-factory.ts index 956b896..ba9ecc9 100644 --- a/src/drawables/shapes/hexagon-factory.ts +++ b/src/drawables/shapes/hexagon-factory.ts @@ -7,10 +7,7 @@ import { EmptyDrawable } from '../empty-drawable'; * @category Drawable */ class HexagonBase extends EmptyDrawable { - constructor( - public center: vec2, - public radius: number - ) { + constructor(public center: vec2, public radius: number) { super(); } } diff --git a/src/drawables/shapes/meta-circle-factory.ts b/src/drawables/shapes/meta-circle-factory.ts index cf8b548..c716fbd 100644 --- a/src/drawables/shapes/meta-circle-factory.ts +++ b/src/drawables/shapes/meta-circle-factory.ts @@ -8,10 +8,7 @@ import { numberToGlslFloat } from '../../helper/number-to-glsl-float'; * @category Drawable */ class MetaCircleBase extends EmptyDrawable { - constructor( - public center: vec2, - public radius: number - ) { + constructor(public center: vec2, public radius: number) { super(); } } diff --git a/src/drawables/shapes/noisy-polygon-factory.ts b/src/drawables/shapes/noisy-polygon-factory.ts index 3ca55fa..d1ff919 100644 --- a/src/drawables/shapes/noisy-polygon-factory.ts +++ b/src/drawables/shapes/noisy-polygon-factory.ts @@ -112,9 +112,9 @@ export const NoisyPolygonFactory = ( }, uniformCountMacroName: `NOISY_POLYGON${vertexCount}_COUNT`, shaderCombinationSteps: [0, 1, 2, 3, 8, 16], - empty: new NoisyPolygon( + empty: (new NoisyPolygon( new Array(vertexCount).fill(vec2.create()) - ) as unknown as Drawable, + ) as unknown) as Drawable, }; public randomOffset = 0; diff --git a/src/drawables/shapes/rotated-rectangle-factory.ts b/src/drawables/shapes/rotated-rectangle-factory.ts index 1672669..c740ece 100644 --- a/src/drawables/shapes/rotated-rectangle-factory.ts +++ b/src/drawables/shapes/rotated-rectangle-factory.ts @@ -7,11 +7,7 @@ import { EmptyDrawable } from '../empty-drawable'; * @category Drawable */ class RotatedRectangleBase extends EmptyDrawable { - constructor( - public center: vec2, - public size: vec2, - public rotation: number - ) { + constructor(public center: vec2, public size: vec2, public rotation: number) { super(); } } diff --git a/src/graphics/graphics-library/parallel-compiler.ts b/src/graphics/graphics-library/parallel-compiler.ts index bb170cb..268c039 100644 --- a/src/graphics/graphics-library/parallel-compiler.ts +++ b/src/graphics/graphics-library/parallel-compiler.ts @@ -135,7 +135,7 @@ export class ParallelCompiler { private prettyPrintErrorsIfThereAreAny(shader: ShaderWithSource) { try { this.checkShader(shader); - } catch (e: any) { + } catch (e) { for (const match of e.toString().matchAll(/ERROR: 0:(\d+): (.*)$/gm)) { const line = Number.parseInt(match[1]); const error = match[2]; diff --git a/src/graphics/graphics-library/texture/color-texture.ts b/src/graphics/graphics-library/texture/color-texture.ts index 8da3b36..eaab31b 100644 --- a/src/graphics/graphics-library/texture/color-texture.ts +++ b/src/graphics/graphics-library/texture/color-texture.ts @@ -1,5 +1,4 @@ import { vec2 } from 'gl-matrix'; -import { tryEnableExtension } from '../helper/enable-extension'; import { UniversalRenderingContext } from '../universal-rendering-context'; import { Texture } from './texture'; import { FilteringOptions } from './texture-options'; @@ -8,31 +7,24 @@ import { FilteringOptions } from './texture-options'; export class ColorTexture extends Texture { public static readonly textureUnitId = 0; - private floatEnabled = false; - constructor(gl: UniversalRenderingContext) { super(gl, ColorTexture.textureUnitId, { minFilter: FilteringOptions.LINEAR, maxFilter: FilteringOptions.LINEAR, }); - - const bufferFloatExtension = tryEnableExtension(gl, 'EXT_color_buffer_float'); - const floatLinearExtension = tryEnableExtension(gl, 'OES_texture_float_linear'); - this.floatEnabled = gl.isWebGL2 && !!bufferFloatExtension && !!floatLinearExtension; } public setSize(size: vec2) { this.bind(); - const gl2 = this.gl as WebGL2RenderingContext; this.gl.texImage2D( this.gl.TEXTURE_2D, 0, - this.floatEnabled ? gl2.RGBA16F : this.gl.RGBA, + this.gl.RGBA, size.x, size.y, 0, this.gl.RGBA, - this.floatEnabled ? gl2.HALF_FLOAT : this.gl.UNSIGNED_BYTE, + this.gl.UNSIGNED_BYTE, null ); } diff --git a/src/graphics/graphics-library/texture/palette-texture.ts b/src/graphics/graphics-library/texture/palette-texture.ts index faee8a1..f98dcc5 100644 --- a/src/graphics/graphics-library/texture/palette-texture.ts +++ b/src/graphics/graphics-library/texture/palette-texture.ts @@ -6,10 +6,7 @@ import { Texture } from './texture'; export class PaletteTexture extends Texture { public static readonly textureUnitId = 2; - constructor( - gl: UniversalRenderingContext, - private readonly paletteSize: number - ) { + constructor(gl: UniversalRenderingContext, private readonly paletteSize: number) { super(gl, PaletteTexture.textureUnitId); } diff --git a/src/graphics/rendering/renderer/renderer-implementation.ts b/src/graphics/rendering/renderer/renderer-implementation.ts index f5b8480..872b94a 100644 --- a/src/graphics/rendering/renderer/renderer-implementation.ts +++ b/src/graphics/rendering/renderer/renderer-implementation.ts @@ -230,8 +230,7 @@ export class RendererImplementation implements Renderer { this.stopwatch.start(); } else { this.stopwatch.tryGetResults(); - this.gl.insights.gpuRenderTimeInMilliseconds = - this.stopwatch.resultsInMilliseconds; + this.gl.insights.gpuRenderTimeInMilliseconds = this.stopwatch.resultsInMilliseconds; } } diff --git a/src/main.ts b/src/main.ts index 1fa29db..c98086c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,11 +23,6 @@ declare global { x: number; y: number; } - - interface Iterable { - x: T; - y: T; - } } applyArrayPlugins(); diff --git a/src/run-animation.ts b/src/run-animation.ts index 47a4b0b..98c49d3 100644 --- a/src/run-animation.ts +++ b/src/run-animation.ts @@ -60,7 +60,7 @@ export async function runAnimation( const deltaTimeCalculator = new DeltaTimeCalculator(); let triggerIsOver: () => void; - const isOver = new Promise((resolve) => (triggerIsOver = resolve)); + const isOver = new Promise((resolve) => (triggerIsOver = resolve)); renderer.setRuntimeSettings(settings); const autoscaler = new FpsQualityAutoscaler(renderer); diff --git a/tsconfig.json b/tsconfig.json index ad5e2cd..b8c22f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,9 +5,7 @@ "declaration": true, "declarationMap": true, "target": "es5", - "ignoreDeprecations": "6.0", "esModuleInterop": true, - "skipLibCheck": true, "strict": true, "downlevelIteration": true, "moduleResolution": "Node", diff --git a/typedoc.json b/typedoc.json index c6072da..5de5e0c 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,15 +1,18 @@ { + "mode": "file", "out": "docs", "name": "SDF-2D", - "entryPoints": ["src"], - "entryPointStrategy": "expand", + "includeDeclarations": true, "excludeExternals": true, + "excludeNotExported": true, "excludePrivate": true, - "excludeInternal": true, + "stripInternal": true, + "media": "media", "includeVersion": true, "hideGenerator": true, - "readme": "documentation-readme.md", + "inputFiles": "src", "favicon": "media/favicon.ico", - "skipErrorChecking": true, - "plugin": ["typedoc-plugin-extras"] + "ignoreCompilerErrors": true, + "listInvalidSymbolLinks": true, + "readme": "documentation-readme.md" } diff --git a/webpack.config.js b/webpack.config.js index f28bacf..2c57e7f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -38,6 +38,7 @@ module.exports = { usedExports: true, minimizer: [ new TerserJSPlugin({ + sourceMap: true, test: /\.js$/i, }), ],