From 002864fd96eecb5c63918c5982c7b6718ccad085 Mon Sep 17 00:00:00 2001 From: Liam Egan Date: Sat, 21 Nov 2026 14:33:37 -0700 Subject: [PATCH] Adding full library and API documentation, removing old demos and typedocs, and adding roadmap and known bugs items --- .github/workflows/docs.yml | 4 +- .github/workflows/test.yml | 4 + .gitignore | 9 +- .husky/pre-commit | 4 +- KNOWN-ISSUES.md | 89 + README.md | 17 +- ROADMAP.md | 90 + demos/_layout.pug | 49 - demos/camera-cp.css | 156 - demos/camera-cp.html | 40 - demos/camera-cp.js | 186 - demos/camera.html | 1 - demos/camera.pug | 164 - demos/camera.ts | 279 - demos/color.html | 1 - demos/color.pug | 108 - demos/color.ts | 151 - demos/colormath.html | 1 - demos/colormath.pug | 114 - demos/colormath.ts | 340 - demos/colorspaces.html | 1 - demos/colorspaces.pug | 110 - demos/colorspaces.ts | 292 - demos/gradients.html | 1 - demos/gradients.pug | 184 - demos/gradients.ts | 318 - demos/harmonies-cp.html | 461 -- demos/harmonies.css | 109 - demos/harmonies.html | 1 - demos/harmonies.pug | 105 - demos/harmonies.ts | 352 - demos/index.html | 1 - demos/index.pug | 46 - demos/main.ts | 1130 ---- demos/plane.html | 1 - demos/plane.pug | 73 - demos/plane.ts | 202 - demos/ray.html | 1 - demos/ray.pug | 113 - demos/ray.ts | 211 - demos/style.css | 810 --- deploy-docs.yml | 31 - docs/.vitepress/config.mts | 142 + docs/.vitepress/theme/components/Example.vue | 170 + .../theme/components/PageHeader.vue | 42 + docs/.vitepress/theme/custom.css | 345 + docs/.vitepress/theme/index.ts | 19 + docs/README.md | 60 + docs/colour/color.md | 74 + docs/colour/colour-spaces.md | 58 + docs/colour/gradients.md | 52 + docs/examples/colour-spaces.js | 36 + docs/examples/gradients.js | 31 + docs/examples/intro.js | 40 + docs/examples/lib/draw.js | 109 + docs/examples/lib/stage.js | 123 + docs/examples/lib/wire.js | 37 + docs/examples/mat3-transform.js | 40 + docs/examples/mat4-hierarchy.js | 35 + docs/examples/plane-distance.js | 37 + docs/examples/projection.js | 43 + docs/examples/quat-slerp.js | 48 + docs/examples/ray-cast.js | 60 + docs/examples/scalars.js | 43 + docs/examples/vec2-projection.js | 47 + docs/examples/vec3-normal.js | 56 + docs/geometry/plane.md | 61 + docs/geometry/ray.md | 71 + docs/getting-started/conventions.md | 115 + docs/getting-started/installation.md | 63 + docs/guides/webgl.md | 68 + docs/index.md | 49 + docs/matrices/2d-transforms.md | 86 + docs/matrices/3d-transforms.md | 103 + docs/matrices/projection.md | 80 + docs/public/favicon.svg | 6 + docs/public/logo.svg | 6 + docs/rotation/quaternions.md | 95 + docs/typedoc.json | 71 + docs/utilities/scalars.md | 87 + docs/vectors/swizzling.md | 72 + docs/vectors/vec2.md | 106 + docs/vectors/vec3.md | 95 + docs/vectors/vec4.md | 52 + package-lock.json | 5666 ++++++++++++----- package.json | 17 +- src/Color.ts | 256 +- src/Mat2.ts | 257 +- src/Mat3.ts | 381 +- src/Mat4.ts | 559 +- src/Plane.ts | 89 +- src/Quat.ts | 166 +- src/Ray.ts | 78 +- src/Utils.ts | 95 + src/Vec2.ts | 640 +- src/Vec3.ts | 695 +- src/Vec4.ts | 752 +-- src/index.ts | 12 + src/types.ts | 75 +- tsconfig.json | 15 +- vite.site.config.ts | 47 - 101 files changed, 9936 insertions(+), 9257 deletions(-) create mode 100644 KNOWN-ISSUES.md create mode 100644 ROADMAP.md delete mode 100644 demos/_layout.pug delete mode 100644 demos/camera-cp.css delete mode 100644 demos/camera-cp.html delete mode 100644 demos/camera-cp.js delete mode 100644 demos/camera.html delete mode 100644 demos/camera.pug delete mode 100644 demos/camera.ts delete mode 100644 demos/color.html delete mode 100644 demos/color.pug delete mode 100644 demos/color.ts delete mode 100644 demos/colormath.html delete mode 100644 demos/colormath.pug delete mode 100644 demos/colormath.ts delete mode 100644 demos/colorspaces.html delete mode 100644 demos/colorspaces.pug delete mode 100644 demos/colorspaces.ts delete mode 100644 demos/gradients.html delete mode 100644 demos/gradients.pug delete mode 100644 demos/gradients.ts delete mode 100644 demos/harmonies-cp.html delete mode 100644 demos/harmonies.css delete mode 100644 demos/harmonies.html delete mode 100644 demos/harmonies.pug delete mode 100644 demos/harmonies.ts delete mode 100644 demos/index.html delete mode 100644 demos/index.pug delete mode 100644 demos/main.ts delete mode 100644 demos/plane.html delete mode 100644 demos/plane.pug delete mode 100644 demos/plane.ts delete mode 100644 demos/ray.html delete mode 100644 demos/ray.pug delete mode 100644 demos/ray.ts delete mode 100644 demos/style.css delete mode 100644 deploy-docs.yml create mode 100644 docs/.vitepress/config.mts create mode 100644 docs/.vitepress/theme/components/Example.vue create mode 100644 docs/.vitepress/theme/components/PageHeader.vue create mode 100644 docs/.vitepress/theme/custom.css create mode 100644 docs/.vitepress/theme/index.ts create mode 100644 docs/README.md create mode 100644 docs/colour/color.md create mode 100644 docs/colour/colour-spaces.md create mode 100644 docs/colour/gradients.md create mode 100644 docs/examples/colour-spaces.js create mode 100644 docs/examples/gradients.js create mode 100644 docs/examples/intro.js create mode 100644 docs/examples/lib/draw.js create mode 100644 docs/examples/lib/stage.js create mode 100644 docs/examples/lib/wire.js create mode 100644 docs/examples/mat3-transform.js create mode 100644 docs/examples/mat4-hierarchy.js create mode 100644 docs/examples/plane-distance.js create mode 100644 docs/examples/projection.js create mode 100644 docs/examples/quat-slerp.js create mode 100644 docs/examples/ray-cast.js create mode 100644 docs/examples/scalars.js create mode 100644 docs/examples/vec2-projection.js create mode 100644 docs/examples/vec3-normal.js create mode 100644 docs/geometry/plane.md create mode 100644 docs/geometry/ray.md create mode 100644 docs/getting-started/conventions.md create mode 100644 docs/getting-started/installation.md create mode 100644 docs/guides/webgl.md create mode 100644 docs/index.md create mode 100644 docs/matrices/2d-transforms.md create mode 100644 docs/matrices/3d-transforms.md create mode 100644 docs/matrices/projection.md create mode 100644 docs/public/favicon.svg create mode 100644 docs/public/logo.svg create mode 100644 docs/rotation/quaternions.md create mode 100644 docs/typedoc.json create mode 100644 docs/utilities/scalars.md create mode 100644 docs/vectors/swizzling.md create mode 100644 docs/vectors/vec2.md create mode 100644 docs/vectors/vec3.md create mode 100644 docs/vectors/vec4.md delete mode 100644 vite.site.config.ts diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 9f6aa45..52bd5d1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -41,7 +41,7 @@ jobs: run: npm install - name: Build Site - run: npm run build:site + run: npm run docs:build - name: Setup Pages uses: actions/configure-pages@v5 @@ -49,7 +49,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: "./dist-site" + path: "./docs/.vitepress/dist" - name: Deploy to GitHub Pages id: deployment diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3261f4f..9737daa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,3 +34,7 @@ jobs: - name: Check run: npm run check + + # TypeDoc fails on an undocumented export, and VitePress on a dead link + - name: Build docs + run: npm run docs:build diff --git a/.gitignore b/.gitignore index 0a54638..1f5010f 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ node_modules build/ dist/ -dist-site/ -documentation/ -.vscode/ \ No newline at end of file +.vscode/ + +# The docs site's generated API pages and build +docs/api/ +docs/.vitepress/dist/ +docs/.vitepress/cache/ diff --git a/.husky/pre-commit b/.husky/pre-commit index 7243535..ab618e5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,2 @@ -npm run document -git add ./ +# Fails on an undocumented export or a broken {@link}, as the docs build does +npm run docs:api diff --git a/KNOWN-ISSUES.md b/KNOWN-ISSUES.md new file mode 100644 index 0000000..955b096 --- /dev/null +++ b/KNOWN-ISSUES.md @@ -0,0 +1,89 @@ +# Known issues + +Bugs and allocation problems found while documenting the library, to fix in later releases. The TSDoc comments describe what the code does today, and the guides avoid the broken parts. Fixing one is a behaviour change, so each needs a changeset, a test, and an update to the comment that describes the current behaviour. + +## Rotation direction + +- **`Mat2.fromAngle` and `Mat3.fromAngle` turn the wrong way.** They build the transpose of a rotation, so `fromAngle(r)` equals `identity().rotate(-r)`: clockwise, where `Vec2.rotate` and `Mat2`/`Mat3.rotate` turn counter-clockwise. +- **`Mat3.fromQuat` rotates by the inverse of the quaternion.** It returns the transpose of `Mat4.fromQuat`'s upper 3×3. `new Vec3(1, 0, 0).transformByMat3(Mat3.fromQuat(q))` disagrees with `transformByQuat(q)`. + +## Swizzle setters + +The getters are right; these setters write the wrong components. + +- **`Vec3.yzx` and `Vec3.zxy` are swapped**, and so are `Vec4.yzx` and `Vec4.zxy`. `v.yzx = [a, b, c]` sets x = b, y = c, z = a, where it should set y = a, z = b, x = c. +- **`Vec3.zy` and `Vec4.zy` write in reverse**: z = v.y and y = v.x, where it should be z = v.x and y = v.y. +- **`xx`, `yy` and `zz` (Vec2, Vec3) take their value from the second component** (`v.y`). Using the first would match the other setters. + +## Vectors + +- **The `lengthSquared` setter sets the wrong length** (Vec2, Vec3, Vec4). It scales by `value / lengthSquared`, so the new squared length is `value² / old`. It should scale by `Math.sqrt(value / lengthSquared)`. +- **Setting `length` or `lengthSquared` on a zero vector stores NaN**, which the getters then hide by reading it as 0. +- **`Vec3.cross` and `Vec4.cross` don't change the vector in place**, unlike every other method without the `New` suffix, so `cross` and `crossNew` do the same thing. +- **`Vec4.getAngle` returns the angle between two rotations**, `acos(2·dot² − 1)`, not the angle between two 4D vectors. It can also return NaN when rounding pushes the dot product just past 1. +- **`inverse` has no divide-by-zero guard** (Vec2, Vec3, Vec4): a zero component becomes `Infinity`, where `divide` gives 0. +- **`Vec2.slope`'s setter flips vectors that point left**, because it sets the angle to `Math.atan(value)`, which is always between -90° and 90°. +- **The x, y, z and w setters accept NaN** and store it; the getters hide it as 0. +- `Vec2.rotateDegByNew` names its parameter `radian`, though it takes degrees. + +## Matrices + +- **`Mat4.transformToNew` adds to the translation instead of setting it.** It calls `transform` rather than `transformTo`. +- **`Mat4.rotation` is only right for a uniform scale.** It divides each row by a scale factor where it should divide each column by its own. The same bug is in gl-matrix. +- **`Mat2.columnArray` and `Mat3.columnArray` are row-major.** `array` is already column-major; `columnArray` returns the transpose. +- **`invert` leaves a singular matrix unchanged without saying so** (Mat2, Mat3, Mat4), where `Mat3.fromMat4` returns null for the same case. +- `Mat4.fromRotation` types its `axis` as `any` rather than `Vec3Like`, and `Mat3.translate` takes a `Vec2` rather than a `Vec2Like` and has no `translateNew`. + +## Quaternions + +- **`Quat.inverse()`, inherited from Vec4, takes the reciprocal of each component**, which is easy to confuse with `invert()`. `Quat.lerp`, `Quat.interpolate` and `cross` return a `Vec4` rather than a `Quat`. +- `Quat.rotateX`, `rotateY` and `rotateZ` ignore their `origin` argument, which is there only to match Vec4. + +## Color + +- **`Color.fromHSV` throws on a negative hue**: `i % 6` is negative, so the lookup is undefined. +- **`Color.fromHex` misreads 4- and 8-digit hex** rather than reading the alpha or rejecting it (`'#ff000080'` comes out bluish with alpha 1). Strings that aren't hex give black, and since `ColorLike` strings go through `fromHex`, CSS strings such as `'rgb(…)'` aren't supported. +- **`toHex` and `toCSS` don't clamp**, so a channel outside 0–1 gives a broken hex string or an out-of-range `rgb()` value. + +## Plane and Ray + +- **`Ray.intersectBox` returns null when the ray starts inside the box**, where `intersectSphere` returns the exit point. A ray with a zero component whose origin lies exactly on a slab plane gives 0/0 = NaN. +- `Plane`'s constructor doesn't normalise the normal, so `distanceTo` and `projectPoint` are wrong for a non-unit normal unless you call `normalize()`. + +## Allocation in per-frame methods + +Many methods documented as "in place" still allocate temporary objects, which adds garbage-collection pressure in render loops. wtc-gl works around this with its own allocation-free copies in `packages/wtc-gl/src/core/matrix.ts`; once these are fixed it can drop that file. Benchmark before and after (Vitest's `bench`) so the gains are measured, not assumed. + +### Internal temporaries (no API change) + +These can use local numbers instead of temporary objects, with identical results: + +- **Scalar arithmetic** (Vec2, Vec3, Vec4): `addScalar`, `subtractScalar`, `multiplyScalar` and `divideScalar` each build a temporary vector, and `scale` and `normalise` go through them. `v.normalise().scale(10)` allocates two vectors. +- **`transformByMat2`, `transformByMat3`, `transformByMat4`** (Vec2, Vec3, Vec4) clone the vector and read the matrix's `.array`, which builds a new array of up to 16 numbers. Transforming 1,000 points allocates 2,000 objects. They can read the matrix's elements directly. +- **`transformByQuat`** (Vec3, Vec4) clones the vector and builds two temporary vectors. +- **`rotateX`, `rotateY` and `rotateZ`** (Vec3, Vec4) call `subtractNew`, and **`distance`** calls `subtractNew` to measure a length. +- **Matrix `multiply`, `rotate`, `invert` and `adjoint`** (Mat2, Mat3, Mat4) clone the matrix first. `Mat4.rotate` also builds a second Mat4. A clone runs the constructor and all 16 type-checked setters. +- **`Quat.multiply` and `Quat.rotateX`, `rotateY`, `rotateZ`** clone the quaternion. +- **`Plane` and `Ray`** run every point through `Vec3.interpolate`, which allocates a Vec3 even when given one, then use `subtractNew`, `addNew` and `multiplyScalarNew` along the way. They could read x, y and z from the `Vec3Like` directly. +- **`Vec2.getAngle`, `Vec3.getAngle` and `Vec4.getAngle`** clone both vectors to normalise them, where they could divide the dot product by the two lengths. + +### New allocation-free API (additive) + +The common per-frame operations need forms that write into an object you already have: + +- **Writing to a typed array:** `toArray(out, offset = 0)` on vectors, quaternions, matrices and `Color`, so uniforms can be filled without making a new array each frame (wtc-gl's `writeMat4` and `writeMat3`). +- **Multiplying two matrices into this one:** `multiplyMatrices(a, b)` (or a static `Mat4.multiply(out, a, b)`), for model-view-projection and parent-child chains without `multiplyNew`. +- **Composing in place:** `Mat4.compose(q, position, scale)`, the in-place counterpart of `fromRotationTranslationScale` (wtc-gl's `composeMat4`). +- **Decomposing into existing objects:** `getTranslation(out)`, `getScaling(out)` and `getRotation(out)`, since the `translation`, `scaling` and `rotation` getters allocate. +- **In-place interpolation:** `lerp(v, t)` on vectors and `slerp(q, t)` on Quat, since `Vec*.lerp` and `Quat.slerp` are static and allocate. `Color` already has an in-place `lerp`. +- **Setting from loose values without allocating:** a `set(x, y, z)` / `copy(v)` pair (`reset` and `resetToVector` exist, but `resetToVector` silently ignores anything that isn't the same class), and `Quat.setFromAxisAngle` and `setFromEuler` (wtc-gl's `quatFromEuler`). +- **A normal matrix into an existing Mat3:** `Mat3.normalFromMat4(m)`, the in-place counterpart of `fromMat4` (wtc-gl's `normalMatrix`). + +### Field access (measure first) + +Every component read goes through a getter that does `this.#x || 0`, and every write through a setter that type-checks and can throw. That isn't allocation, but it is the cost on every operation. Plain public fields, or a `Float32Array`/`Float64Array` backing store (which would also make `toArray` a single `set`), would be faster. This changes behaviour, though: NaN would be visible, bad values wouldn't throw, and a typed array changes precision or what `.array` returns. It needs a benchmark and probably a major version. + +## Scalar functions + +- `pingpong` returns negative values for a negative `t`, because `%` keeps the sign. +- `map` divides by zero when `inMin === inMax`, and `smoothstep` and `smootherstep` return NaN when `edge0 === edge1`. diff --git a/README.md b/README.md index dc06a4d..c3d4ac1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [wtc-math](https://github.com/wethegit/wtc-math#readme) _1.3.0_ +# [wtc-math](https://github.com/wethegit/wtc-math#readme) > A math library for JavaScript and TypeScript — vectors, matrices, quaternions, and utilities for 3D graphics and creative coding. @@ -63,4 +63,17 @@ import type { Vec2Like, Vec3Like, Vec4Like, QuatLike, Mat2Like, Mat3Like, Mat4Li ## Documentation -Full API docs: [wethegit.github.io/wtc-math](https://wethegit.github.io/wtc-math/) +[The documentation](https://wethegit.github.io/wtc-math/) has guides, live examples and the API reference. + +## Development + +| Command | What it does | +| --- | --- | +| `npm run docs:dev` | Generates the API pages and starts the docs site. | +| `npm run docs:build` | Builds the docs for GitHub Pages. | +| `npm test` | Runs the tests. | +| `npm run check` | Type-checks, tests and builds. This is what CI runs. | + +The docs are in `docs/`; [docs/README.md](docs/README.md) covers writing pages and examples. The API reference is generated from the TSDoc comments in `src/`, and the docs build (and the pre-commit hook) fail on an undocumented export. + +Bugs found but not yet fixed are listed in [KNOWN-ISSUES.md](KNOWN-ISSUES.md), and planned work in [ROADMAP.md](ROADMAP.md). diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..3b28f26 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,90 @@ +# Roadmap + +Planned work on wtc-math, roughly in the order it should happen. Bugs and the allocation problems in existing methods are listed separately in [KNOWN-ISSUES.md](KNOWN-ISSUES.md). + +## Order of work + +1. **Tests first.** Add a failing regression test for each item in [KNOWN-ISSUES.md](KNOWN-ISSUES.md) before fixing it, and benchmarks (Vitest's `bench`) for the hot paths: `normalise`, transforming a batch of points, and a parent-child matrix chain. +2. **Bug fixes and allocation work** from [KNOWN-ISSUES.md](KNOWN-ISSUES.md). +3. **New features**, below. They should follow the allocation-free pattern from step 2: methods that change `this`, `New` variants that allocate, and statics that take an optional `out`. +4. **Package and tooling** updates can happen any time, each in its own PR. + +Each change to the published package needs a changeset (`npm run changeset`) and docs: TSDoc on every new export (the docs build fails without it) and a guide page or section for anything a reader would look for. + +## Package and tooling + +### Package + +- **Move `typescript` from `dependencies` to `devDependencies`.** It's published as a runtime dependency (1.4.0 lists `typescript: ^6.0.3`), so every install of wtc-math also installs TypeScript. Nothing uses it at runtime. +- **Add `"sideEffects": false`** to `package.json`. No module in `src/` runs anything when imported, so bundlers can drop what a project doesn't use. +- **Update the metadata.** The `description` only mentions vectors, matrices and quaternions; add colours, `Plane`, `Ray` and the scalar functions. Point `homepage` at the docs site, [wethegit.github.io/wtc-math](https://wethegit.github.io/wtc-math/), and add keywords such as colour, OKLCH, ray and plane. +- **Change `husky install` to `husky`** in the `prepare` script. `husky install` is deprecated in husky v9 and prints a warning. +- **Release a patch** for the above. npm only shows the new README after a release. + +### Code style + +- **Add Prettier and ESLint**, configured as in wtc-gl, with lint-staged in the pre-commit hook. `src/` mixes `var`, double quotes and tabs. Reformat everything in one PR of its own, before or after the bug fixes but not mixed in with them, so the fix diffs stay readable. Add the commit to `.git-blame-ignore-revs`. +- **Merge `src/common.ts` into `Utils.ts`.** It duplicates `degToRad` and `radToDeg` as `degreesToRadian` and `radianToDegrees`. +- **Trim `tsdoc.json`.** The `@chainable`, `@constructor` and `@static` tag definitions are no longer used. + +### CI + +- **Bring `docs.yml` in line with `release.yml`**: `npm ci` with the npm cache instead of `npm install`, and current versions of the checkout, setup-node and Pages actions. +- **Check `dependabot.yml`'s `reviewers` setting**, which GitHub may have deprecated in favour of a `CODEOWNERS` file, and switch to `CODEOWNERS` if so. + +### wtc-gl + +- **Point wtc-gl's API links at the new reference.** Its TypeDoc `externalSymbolLinkMappings` send every wtc-math type to the site root; map them to the class pages instead, such as `https://wethegit.github.io/wtc-math/api/wtc-math/classes/Vec3`. Its `api/wtc-math.md` page could link to the [conventions](https://wethegit.github.io/wtc-math/getting-started/conventions) guide. +- **Delete `core/matrix.ts`** once wtc-math's in-place methods stop allocating and it has `multiplyMatrices`, `compose`, `toArray` and the rest of the allocation-free API. + +## New features + +### From wtc-gl + +wtc-gl implements these itself. Moving them here lets it delete the code, and makes them available to projects that don't use wtc-gl. + +- **`Frustum`**: six planes from a view-projection matrix, with `setFromMatrix(m)`, `intersectsSphere(centre, radius)`, `intersectsBox(min, max)` and `containsPoint(p)`. Replaces `Camera.updateFrustum`, `setPlane`, `planeDistance` and `frustumIntersectsSphere` in wtc-gl. +- **`Box3` and `Sphere` bounds**: build from points, `expandByPoint`, `containsPoint`, `intersectsBox` and `intersectsSphere`, centre and size, and `applyMat4(m)`. Replaces wtc-gl's `core/bounds.ts` (`worldBoundingSphere`) and `Raycast`'s private `boxDistance`. +- **A fuller `Ray`**: + - Return the hit distance `t` as well as the point, or add `intersect…Distance` methods, since sorting hits needs the distance. wtc-gl's `Raycast` returns distances. + - `intersectTriangle(a, b, c, cullBackFaces)` using Möller–Trumbore, as wtc-gl's `Raycast` does. + - `applyMat4(m)`, to take a ray into a model's local space. + - `Ray.fromCamera(ndc, inverseViewProjection)`. The [Ray guide](docs/geometry/ray.md#picking-with-the-pointer) currently has readers write this by hand. +- **`Vec3.project(viewProjection)` and `Vec3.unproject(inverseViewProjection)`**, matching wtc-gl's `Camera.project` and `Camera.unproject`. +- **sRGB and linear colour**: `Color.toLinear()` and `Color.fromLinear(r, g, b, a)`. `Color` already converts internally for OKLab, and wtc-gl does it again in `loaders/gltf/colour.ts`. Lighting maths and shaders work in linear colour. +- **Curve evaluation**: point and derivative at `t` for quadratic and cubic Béziers and Catmull-Rom splines, as plain functions. wtc-gl's `path/segments.ts` has its own. Its `Path` class, with tilt and frames, is renderer-specific and stays in wtc-gl. + +### Creative coding + +- **Frame-rate-independent damping**: `damp(a, b, lambda, dt)`, with `Vec2`, `Vec3`, `Vec4` and `Quat` versions, and a critically damped spring like Unity's `SmoothDamp` that keeps a velocity. Once it exists, update the docs that suggest `lerp(x, target, 0.1)` each frame ([Vec2](docs/vectors/vec2.md#interpolation), [scalar functions](docs/utilities/scalars.md#lerp)), which settles faster on a 120 Hz screen than a 60 Hz one. +- **Noise**: seeded simplex noise in 2D, 3D and 4D, and fractal (fBm) noise built on it. +- **Seeded randomness**: a small seeded generator (such as mulberry32), `randomRange`, and random points in and on a circle and a sphere. +- **Easing functions**: in, out and in-out forms of quad, cubic, quart, expo, sine, back and elastic. +- **More scalar functions**: + - `inverseLerp(a, b, v)`. + - A `mod` that's always positive. Use it in `pingpong`, which fixes the negative `t` bug. + - `fract`, `step`, `wrap(v, min, max)` and `approxEqual(a, b, epsilon)`. + - `lerpAngle` and `angleDelta`, which take the shortest way around the circle, so a turn from 350° to 10° doesn't go the long way. +- **Vector operations GLSL has and wtc-math lacks**: + - `reflect(normal)` and `refract(normal, eta)`. + - Component-wise `min`, `max`, `clamp` and `abs`. + - `equals(v, epsilon)`. + - `projectOnto(v)` and `projectOnPlane(normal)`. + - `Vec2.fromAngle(angle, length)`. + - Spherical and cylindrical conversion. Today `radius`, `phi` and `theta` are only other names for x, y and z. +- **Quaternions**: + - `Quat.fromUnitVectors(a, b)`, the rotation that turns one direction into another, for aligning an object to a normal or a velocity. + - `Quat.lookRotation(forward, up)`. + - `toEuler(order)` and `toAxisAngle()`. + - `rotateTowards(q, maxAngle)`. + +### Web + +- **CSS transforms**: `Mat4.toCSS()` giving `matrix3d(…)` and `Mat3.toCSS()` giving `matrix(…)`, for driving DOM elements from a camera or a 2D transform. +- **CSS colours**: + - `toCSS('oklch')` and the other modern formats. + - `Color.fromCSS(string)` to parse `rgb()`, `hsl()`, `oklch()` and 3-, 4-, 6- and 8-digit hex. This also fixes `fromHex` misreading 8-digit hex, and lets `ColorLike` strings be any CSS colour. +- **Accessibility**: WCAG `luminance()` and `Color.contrastRatio(a, b)`, for checking text against a background. +- **Palette adjustments in OKLCH**: `lighten`, `darken`, `saturate`, `desaturate` and `withAlpha`. +- **Gamut mapping**: bring out-of-gamut OKLCH colours into sRGB by reducing chroma rather than clipping each channel, so `fromOklch` stops shifting hue at the extremes. The [colour spaces guide](docs/colour/colour-spaces.md#oklab-and-oklch) warns about this today. +- **Reading from typed arrays**: `fromArray(array, offset)` on vectors, quaternions, matrices and `Color`, the counterpart of the `toArray(out, offset)` planned in [KNOWN-ISSUES.md](KNOWN-ISSUES.md#new-allocation-free-api-additive). For reading geometry attributes and buffers. diff --git a/demos/_layout.pug b/demos/_layout.pug deleted file mode 100644 index 1e8ac56..0000000 --- a/demos/_layout.pug +++ /dev/null @@ -1,49 +0,0 @@ -doctype html -html(lang="en") - head - meta(charset="UTF-8") - meta(name="viewport" content="width=device-width, initial-scale=1.0") - title - block title - | wtc-math - link(rel="preconnect" href="https://fonts.googleapis.com") - link(rel="preconnect" href="https://fonts.gstatic.com" crossorigin) - link(href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;0,600;1,300&display=swap" rel="stylesheet") - link(rel="stylesheet" href="./style.css") - block head - - body - header - div.wordmark - span.w-lib wtc - span.w-dot · - span.w-mod math - block header-desc - p.header-desc Interactive playground — vectors, matrices, quaternions - block header-links - a.header-link(href="https://github.com/wethegit/wtc-math" target="_blank" rel="noopener") github ↗ - details.nav-dropdown - summary demos - div.dropdown-menu - a.dropdown-item(href="./camera.html") camera to css transform - a.dropdown-item(href="./gradients.html") colour gradients - a.dropdown-item(href="./color.html") colour class - a.dropdown-item(href="./colorspaces.html") colour spaces - a.dropdown-item(href="./plane.html") plane - a.dropdown-item(href="./ray.html") ray - a.dropdown-item(href="./colormath.html") colour math - a.dropdown-item(href="./harmonies.html") colour harmonies - - block main - - footer - span wtc-math - span.footer-sep · - block footer-links - a.footer-link(href="https://github.com/wethegit/wtc-math" target="_blank" rel="noopener") github - span.footer-sep · - a.footer-link(href="./docs/index.html") docs - block footer-right - span.footer-right MIT licence · We The Collective - - block scripts diff --git a/demos/camera-cp.css b/demos/camera-cp.css deleted file mode 100644 index 3cdd0ae..0000000 --- a/demos/camera-cp.css +++ /dev/null @@ -1,156 +0,0 @@ -@import url("https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;500;600;700;800;900&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap"); - -*, -*::before, -*::after { - box-sizing: border-box; - margin: 0; - padding: 0; -} - -html, -body { - height: 100%; - overflow: hidden; - background: #eee9e3; - color: #1e0f0f; - font-family: "Inter", sans-serif; - font-size: 14px; - line-height: 1.5; - -webkit-font-smoothing: antialiased; -} - -#viewport { - --green: #0d7a40; - --green-border: rgba(13, 122, 64, 0.32); - --purple: #5533cc; - --amber: #9a6a00; - --amber-border: rgba(154, 106, 0, 0.38); - --red: #cc2233; - --faceSize: 300px; - --halfFaceSize: calc(var(--faceSize) * 0.5); - - position: fixed; - inset: 0; - overflow: hidden; - cursor: grab; - touch-action: none; - user-select: none; -} - -#scene-3d { - position: absolute; - top: 50%; - left: 50%; - width: 0; - height: 0; - transform-style: preserve-3d; -} - -.css-cube { - position: absolute; - transform-style: preserve-3d; -} - -.cube-face { - position: absolute; - width: var(--faceSize); - height: var(--faceSize); - margin: calc(var(--halfFaceSize) * -1); - border: 1px solid; - display: flex; - align-items: center; - justify-content: center; - font-family: "Inter", sans-serif; - font-size: 10px; - font-weight: 700; - text-transform: uppercase; -} - -.cube-face.front { - transform: translateZ(var(--halfFaceSize)); - background: color-mix(in srgb, var(--green) 10%, transparent); - border-color: color-mix(in srgb, var(--green) 35%, transparent); - color: color-mix(in srgb, var(--green) 65%, transparent); -} -.cube-face.back { - transform: rotateY(180deg) translateZ(var(--halfFaceSize)); - background: color-mix(in srgb, var(--green) 5%, transparent); - border-color: color-mix(in srgb, var(--green) 18%, transparent); - color: color-mix(in srgb, var(--green) 35%, transparent); -} -.cube-face.right { - transform: rotateY(90deg) translateZ(var(--halfFaceSize)); - background: color-mix(in srgb, var(--purple) 10%, transparent); - border-color: color-mix(in srgb, var(--purple) 35%, transparent); - color: color-mix(in srgb, var(--purple) 65%, transparent); -} -.cube-face.left { - transform: rotateY(-90deg) translateZ(var(--halfFaceSize)); - background: color-mix(in srgb, var(--purple) 5%, transparent); - border-color: color-mix(in srgb, var(--purple) 18%, transparent); - color: color-mix(in srgb, var(--purple) 35%, transparent); -} -.cube-face.top { - transform: rotateX(90deg) translateZ(var(--halfFaceSize)); - background: color-mix(in srgb, var(--amber) 10%, transparent); - border-color: color-mix(in srgb, var(--amber) 35%, transparent); - color: color-mix(in srgb, var(--amber) 65%, transparent); -} -.cube-face.bottom { - transform: rotateX(-90deg) translateZ(var(--halfFaceSize)); - background: color-mix(in srgb, var(--amber) 5%, transparent); - border-color: color-mix(in srgb, var(--amber) 18%, transparent); - color: color-mix(in srgb, var(--amber) 35%, transparent); -} - -#scene-canvas { - position: absolute; - top: 0; - left: 0; - pointer-events: none; -} - -.info-overlay { - position: fixed; - bottom: 20px; - left: 20px; - display: flex; - flex-direction: column; - gap: 8px; - max-width: min(420px, calc(100vw - 40px)); - pointer-events: none; -} - -.info-panel { - background: rgba(255, 255, 255, 0.68); - border: 1px solid rgba(100, 40, 40, 0.12); - border-radius: 6px; - padding: 7px 11px; - font-family: "JetBrains Mono", monospace; - font-size: 11px; - line-height: 1.7; - pointer-events: auto; -} - -.panel--quat { - border-left: 2px solid rgba(154, 106, 0, 0.38); - color: #9a6a00; - white-space: nowrap; -} - -.panel--lookat { - border-left: 2px solid rgba(13, 122, 64, 0.32); - color: #0d7a40; - white-space: pre; -} - -.panel--code { - color: #6b4040; - white-space: pre; - overflow-x: auto; - max-height: 180px; - overflow-y: auto; - scrollbar-width: thin; - scrollbar-color: rgba(100, 40, 40, 0.22) transparent; -} diff --git a/demos/camera-cp.html b/demos/camera-cp.html deleted file mode 100644 index ada7152..0000000 --- a/demos/camera-cp.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - Camera to CSS Transform — wtc-math - - - - - - - -
-
-
-
front
-
back
-
right
-
left
-
top
-
bottom
-
-
- -
- -
- wtc·math -
- -
-
q = { x: 0.000, y: 0.000, z: 0.000, w: 1.000 }
-
forward = { x: 0.000, y: 0.000, z: -1.000 }
-

-
- - - - diff --git a/demos/camera-cp.js b/demos/camera-cp.js deleted file mode 100644 index 4f0f637..0000000 --- a/demos/camera-cp.js +++ /dev/null @@ -1,186 +0,0 @@ -import { Vec3, Mat4, Quat } from "https://esm.sh/wtc-math@1.3.0"; -import { Pane } from "https://esm.sh/tweakpane@4.0.5"; - -/* -Uses wtc-math - https://github.com/wethegit/wtc-math - to control -a 3D camera for CSS transformations. - -1. Creates a quaternion from the provided yaw and pitch -2. Creates a transformation matrix from the quaternion -3. Adds the 3D transformation matrix to the associated CSS property - -*/ - -console.clear(); - -// const SCALE = -50; - -const PARAMS = { yaw: 30, pitch: 20, radius: 5 }; - -const viewport = document.getElementById("viewport"); -const scene3d = document.getElementById("scene-3d"); -const canvas = document.getElementById("scene-canvas"); -const quatBox = document.getElementById("quat-box"); -const lookatBox = document.getElementById("lookat-box"); -const codeBox = document.getElementById("code-box"); - -const pane = new Pane({ title: "Camera Orbit" }); -pane - .addBinding(PARAMS, "yaw", { min: -180, max: 180, step: 1, label: "yaw °" }) - .on("change", scheduleRender); -pane - .addBinding(PARAMS, "pitch", { min: -89, max: 89, step: 1, label: "pitch °" }) - .on("change", scheduleRender); -pane - .addBinding(PARAMS, "radius", { - min: 0.02, - max: 12, - step: 0.01, - label: "radius", - }) - .on("change", scheduleRender); - -const fmt3 = (n) => n.toFixed(3); -const fmt2 = (n) => parseFloat(n.toFixed(2)).toString(); - -// CSS perspective = distance from CSS camera to the z=0 screen plane. -// For the mathematical camera to appear truly "inside" the cube, the front -// face must exceed perspectivePx in CSS z — i.e. it must pass behind the CSS -// camera and get clipped. Front-face CSS z = halfFacePx - r * scale. -// With scale = halfFacePx the cube is exactly 1 world unit in half-extent, and -// the face clips when (1 - r) * halfFacePx > perspectivePx, i.e. r < 0.75. -const FOV = Math.PI / 2; -let scale = 1; -let cachedVw = 0; -let cachedVh = 0; -let rafPending = false; - -function updateMetrics() { - const vw = viewport.clientWidth; - const vh = viewport.clientHeight; - if (!vw || !vh) return; - - const perspectivePx = vh / 2 / Math.tan(FOV / 2); - const halfFacePx = perspectivePx * 4; // face clips at r < 0.75 world units - scale = halfFacePx; // 1 world unit = halfFacePx px - viewport.style.perspective = `${perspectivePx}px`; - viewport.style.setProperty("--halfFaceSize", `${halfFacePx}px`); - viewport.style.setProperty("--faceSize", `${halfFacePx * 2}px`); - - // Only resize the canvas when the viewport actually changes size. - // Setting canvas.width inside a perspective 3D context forces a full - // compositing-layer repaint even when the value is the same, which - // causes the flicker during drag. - if (vw !== cachedVw || vh !== cachedVh) { - const dpr = window.devicePixelRatio || 1; - canvas.width = vw * dpr; - canvas.height = vh * dpr; - canvas.style.width = `${vw}px`; - canvas.style.height = `${vh}px`; - cachedVw = vw; - cachedVh = vh; - } -} - -function scheduleRender() { - if (rafPending) return; - rafPending = true; - requestAnimationFrame(() => { rafPending = false; render(); }); -} - -function toCssMatrix(view) { - const m = [...view.array]; - m[12] *= scale; - m[13] *= scale; - m[14] *= scale; - return `matrix3d(${m.join(",")})`; -} - -function render() { - const vw = viewport.clientWidth; - const vh = viewport.clientHeight; - if (!vw || !vh) return; - - const yaw = (PARAMS.yaw * Math.PI) / 180; - const pitch = (PARAMS.pitch * Math.PI) / 180; - - const qYaw = Quat.fromAxisAngle(new Vec3(0, 1, 0), yaw); - const qPitch = Quat.fromAxisAngle(new Vec3(1, 0, 0), -pitch); - const q = qYaw.multiplyNew(qPitch); - - const rotMat = Mat4.fromQuat(q.array); - const eye = new Vec3(0, 0, PARAMS.radius).transformByMat4New(rotMat); - const target = new Vec3(0, 0, 0); - const forward = target.subtractNew(eye).normaliseNew(); - - const view = Mat4.lookAt(eye, target, [0, 1, 0]); - scene3d.style.transform = toCssMatrix(view); - - // Info - quatBox.textContent = `q = { x: ${fmt3(q.x)}, y: ${fmt3(q.y)}, z: ${fmt3(q.z)}, w: ${fmt3(q.w)} }`; - lookatBox.textContent = [ - `forward = { x: ${fmt3(forward.x)}, y: ${fmt3(forward.y)}, z: ${fmt3(forward.z)} }`, - `eye = { x: ${fmt3(eye.x)}, y: ${fmt3(eye.y)}, z: ${fmt3(eye.z)} }`, - ].join("\n"); - codeBox.textContent = [ - `// Orbit: rotate default eye (0,0,r) by quaternion`, - `const qYaw = Quat.fromAxisAngle(new Vec3(0,1,0), ${fmt2(yaw)});`, - `const qPitch = Quat.fromAxisAngle(new Vec3(1,0,0), ${fmt2(-pitch)});`, - `const q = qYaw.multiplyNew(qPitch);`, - `// { x:${fmt3(q.x)}, y:${fmt3(q.y)}, z:${fmt3(q.z)}, w:${fmt3(q.w)} }`, - ``, - `const rotMat = Mat4.fromQuat(q.array);`, - `const eye = new Vec3(0, 0, ${fmt2(PARAMS.radius)})`, - ` .transformByMat4New(rotMat);`, - `// { x:${fmt3(eye.x)}, y:${fmt3(eye.y)}, z:${fmt3(eye.z)} }`, - ``, - `const target = new Vec3(0, 0, 0);`, - `const forward = target.subtractNew(eye).normaliseNew();`, - `// { x:${fmt3(forward.x)}, y:${fmt3(forward.y)}, z:${fmt3(forward.z)} }`, - ``, - `const view = Mat4.lookAt(eye, target, [0,1,0]);`, - `scene.style.transform = \`matrix3d(\${view.array.join(',')})\`;`, - ].join("\n"); -} - -const DRAG_SENSITIVITY = 0.4; -let isDragging = false; -let lastX = 0, - lastY = 0; -viewport.addEventListener("pointerdown", (e) => { - isDragging = true; - lastX = e.clientX; - lastY = e.clientY; - viewport.setPointerCapture(e.pointerId); - viewport.style.cursor = "grabbing"; -}); -viewport.addEventListener("pointermove", (e) => { - if (!isDragging) return; - const dx = e.clientX - lastX; - const dy = e.clientY - lastY; - lastX = e.clientX; - lastY = e.clientY; - - let newYaw = PARAMS.yaw + -dx * DRAG_SENSITIVITY; - newYaw = ((((newYaw + 180) % 360) + 360) % 360) - 180; - const newPitch = Math.max( - -89, - Math.min(89, PARAMS.pitch - dy * DRAG_SENSITIVITY), - ); - - PARAMS.yaw = newYaw; - PARAMS.pitch = newPitch; - - pane.refresh(); - scheduleRender(); -}); - -viewport.addEventListener("pointerup", (e) => { - isDragging = false; - viewport.releasePointerCapture(e.pointerId); - viewport.style.cursor = "grab"; -}); - -window.addEventListener("resize", () => { updateMetrics(); scheduleRender(); }); -updateMetrics(); -render(); diff --git a/demos/camera.html b/demos/camera.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/camera.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/camera.pug b/demos/camera.pug deleted file mode 100644 index b113e24..0000000 --- a/demos/camera.pug +++ /dev/null @@ -1,164 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Camera CSS Transform - -block head - style. - .ctrl-label { width: 60px; } - - .quat-box { - background: var(--surface-2); - border: 1px solid var(--border); - border-left: 2px solid var(--amber-border); - border-radius: 0 var(--r) var(--r) 0; - padding: 6px 10px; - font-size: var(--fs-sm); - color: var(--amber); - line-height: 1.7; - } - - .code-box { - background: var(--surface); - border: 1px solid var(--border); - border-radius: var(--r); - padding: 9px 11px; - font-size: var(--fs-sm); - line-height: 1.75; - color: var(--text-mid); - white-space: pre; - overflow-x: auto; - flex: 1; - min-height: 0; - } - - .viewport-wrap { - position: relative; - overflow: hidden; - background: var(--surface); - } - - .scene-3d { - position: absolute; - top: 50%; left: 50%; - width: 0; height: 0; - transform-style: preserve-3d; - } - - .css-cube { - position: absolute; - transform-style: preserve-3d; - } - - .cube-face { - position: absolute; - width: 280px; height: 280px; - margin: -140px; - border: 1px solid; - display: flex; - align-items: center; - justify-content: center; - font-family: var(--font); - font-size: var(--fs-md); - font-weight: 500; - letter-spacing: 0.06em; - text-transform: uppercase; - backface-visibility: visible; - } - - .cube-face.front { transform: translateZ(140px); background: color-mix(in srgb, var(--green) 4%, transparent); border-color: color-mix(in srgb, var(--green) 22%, transparent); color: color-mix(in srgb, var(--green) 50%, transparent); } - .cube-face.back { transform: rotateY(180deg) translateZ(140px); background: color-mix(in srgb, var(--green) 2%, transparent); border-color: color-mix(in srgb, var(--green) 10%, transparent); color: color-mix(in srgb, var(--green) 30%, transparent); } - .cube-face.right { transform: rotateY(90deg) translateZ(140px); background: color-mix(in srgb, var(--purple) 4%, transparent); border-color: color-mix(in srgb, var(--purple) 22%, transparent); color: color-mix(in srgb, var(--purple) 50%, transparent); } - .cube-face.left { transform: rotateY(-90deg) translateZ(140px); background: color-mix(in srgb, var(--purple) 2%, transparent); border-color: color-mix(in srgb, var(--purple) 10%, transparent); color: color-mix(in srgb, var(--purple) 30%, transparent); } - .cube-face.top { transform: rotateX(90deg) translateZ(140px); background: color-mix(in srgb, var(--amber) 4%, transparent); border-color: color-mix(in srgb, var(--amber) 22%, transparent); color: color-mix(in srgb, var(--amber) 50%, transparent); } - .cube-face.bottom { transform: rotateX(-90deg) translateZ(140px); background: color-mix(in srgb, var(--amber) 2%, transparent); border-color: color-mix(in srgb, var(--amber) 10%, transparent); color: color-mix(in srgb, var(--amber) 30%, transparent); } - - #scene-canvas { - position: absolute; - top: 0; left: 0; - pointer-events: none; - } - - .pt-label { - position: absolute; - top: 0; left: 0; - font-family: var(--font); - font-size: var(--fs-sm); - font-weight: 500; - pointer-events: none; - white-space: nowrap; - background: var(--label-bg); - padding: 1px 5px; - border-radius: 2px; - text-shadow: 0 0 6px currentColor; - transform-origin: top left; - } - - .pt-label--x { color: var(--red); } - .pt-label--y { color: var(--green); } - .pt-label--z { color: var(--purple); } - - .lookat-box { - background: var(--surface-2); - border: 1px solid var(--border); - border-left: 2px solid var(--green-border); - border-radius: 0 var(--r) var(--r) 0; - padding: 6px 10px; - font-size: var(--fs-sm); - color: var(--green); - line-height: 1.7; - } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Camera to CSS Transform - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Orbit (via Quaternion) - div.ctrl-row - span.ctrl-label yaw ° - input.ctrl-slider(type="range" id="yaw" min="-180" max="180" step="1" value="30") - input.ctrl-num(type="number" id="yawn" min="-180" max="180" step="1" value="30") - div.ctrl-row - span.ctrl-label pitch ° - input.ctrl-slider(type="range" id="pitch" min="-89" max="89" step="1" value="20") - input.ctrl-num(type="number" id="pitchn" min="-89" max="89" step="1" value="20") - div.ctrl-row - span.ctrl-label radius - input.ctrl-slider(type="range" id="radius" min="2" max="12" step="0.1" value="5") - input.ctrl-num(type="number" id="radiusn" min="2" max="12" step="0.1" value="5") - div.quat-box#quat-box q = { x: 0.000, y: 0.000, z: 0.000, w: 1.000 } - - div.ctrl-section - h3 Look At Vector - div.lookat-box#lookat-box forward = { x: 0.000, y: 0.000, z: -1.000 } - - div.ctrl-section.ctrl-section--fill - h3 Live Code - pre.code-box#code-box - - div.viewport-wrap#viewport - div.scene-3d#scene-3d - div.css-cube - div.cube-face.front front - div.cube-face.back back - div.cube-face.right right - div.cube-face.left left - div.cube-face.top top - div.cube-face.bottom bottom - canvas#scene-canvas - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Mat4 + Quat to CSS transform - -block scripts - script(type="module" src="./camera.ts") diff --git a/demos/camera.ts b/demos/camera.ts deleted file mode 100644 index 06541c1..0000000 --- a/demos/camera.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { Vec3, Mat4, Quat } from "../src/index"; - -// Constants - -const SCALE = 100; // px per world unit - -// Scene labels - -const LABELS: Array<{ - pos: [number, number, number]; - text: string; - cls: string; -}> = [ - { pos: [2.2, 0, 0], text: "+X", cls: "pt-label--x" }, - { pos: [0, 2.2, 0], text: "+Y", cls: "pt-label--y" }, - { pos: [0, 0, 2.2], text: "+Z", cls: "pt-label--z" }, -]; - -// State - -let yawDeg = 30; -let pitchDeg = 20; -let radius = 5; - -// DOM - -const viewport = document.getElementById("viewport")!; -const scene3d = document.getElementById("scene-3d")!; -const canvas = document.getElementById("scene-canvas") as HTMLCanvasElement; -const quatBox = document.getElementById("quat-box")!; -const lookatBox = document.getElementById("lookat-box")!; -const codeBox = document.getElementById("code-box")!; - -function getEl(id: string) { - return document.getElementById(id) as T; -} - -const sliders = { - yaw: getEl("yaw"), - pitch: getEl("pitch"), - radius: getEl("radius"), -}; -const nums = { - yaw: getEl("yawn"), - pitch: getEl("pitchn"), - radius: getEl("radiusn"), -}; - -const labelEls = LABELS.map((l) => { - const el = document.createElement("div"); - el.className = `pt-label ${l.cls}`; - el.textContent = l.text; - viewport.appendChild(el); - return el; -}); - -// Helpers - -const fmt3 = (n: number) => n.toFixed(3); -const fmt2 = (n: number) => parseFloat(n.toFixed(2)).toString(); - -function projectPoint( - wx: number, - wy: number, - wz: number, - pv: Mat4, - vw: number, - vh: number, -) { - const m = pv.array; - const cx = m[0] * wx + m[4] * wy + m[8] * wz + m[12]; - const cy = m[1] * wx + m[5] * wy + m[9] * wz + m[13]; - const cz = m[2] * wx + m[6] * wy + m[10] * wz + m[14]; - const cw = m[3] * wx + m[7] * wy + m[11] * wz + m[15]; - - if (cw < 0.01) return null; - - return { - sx: ((cx / cw) * 0.5 + 0.5) * vw, - sy: (1 - ((cy / cw) * 0.5 + 0.5)) * vh, - depth: cz / cw, - inFrustum: - Math.abs(cx / cw) < 1.2 && Math.abs(cy / cw) < 1.2 && cz / cw < 1, - }; -} - -// Convert our row-major view matrix to a CSS matrix3d string. -// Reading our row-major array directly into CSS matrix3d (column-major) is -// equivalent to transposing it — which is exactly what the row->column-vector -// convention change requires. We also scale the translation components. -function toCssMatrix(view: Mat4): string { - const m = [...view.array]; - m[12] *= SCALE; - m[13] *= SCALE; - m[14] *= SCALE; - return `matrix3d(${m.join(",")})`; -} - -// Render - -function render() { - const vw = viewport.clientWidth; - const vh = viewport.clientHeight; - if (vw === 0 || vh === 0) return; - - // Canvas setup - const dpr = window.devicePixelRatio || 1; - canvas.width = vw * dpr; - canvas.height = vh * dpr; - canvas.style.width = `${vw}px`; - canvas.style.height = `${vh}px`; - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - ctx.clearRect(0, 0, vw, vh); - - const yaw = (yawDeg * Math.PI) / 180; - const pitch = (pitchDeg * Math.PI) / 180; - - // Build quaternion: yaw rotates around world Y, pitch around local X. - // Negate pitch so positive degrees move the camera upward. - const qYaw = Quat.fromAxisAngle(new Vec3(0, 1, 0), yaw); - const qPitch = Quat.fromAxisAngle(new Vec3(1, 0, 0), -pitch); - const q = qYaw.multiplyNew(qPitch) as Quat; - - // Rotate the default eye position (0, 0, radius) by the quaternion to - // get the camera's world-space position on the orbit sphere. - const rotMat = Mat4.fromQuat(q.array)!; - const eye = new Vec3(0, 0, radius).transformByMat4New(rotMat); - - // Camera always looks at the cube — the origin. - const target = new Vec3(0, 0, 0); - const forward = target.subtractNew(eye).normaliseNew(); - - // Build view matrix and projection - const view = Mat4.lookAt(eye, target, [0, 1, 0])!; - const fov = Math.PI / 3; // 60° - const proj = Mat4.perspective(fov, vw / vh, 0.1, 100); - const pv = view.multiplyNew(proj); // P * V - - // Apply perspective + view matrix to the CSS 3D scene - const fPx = vh / 2 / Math.tan(fov / 2); - viewport.style.perspective = `${fPx}px`; - scene3d.style.transform = toCssMatrix(view); - - // Read theme colours from CSS custom properties - const cs = getComputedStyle(document.documentElement); - const colRed = cs.getPropertyValue("--red").trim(); - const colGreen = cs.getPropertyValue("--green").trim(); - const colPurple = cs.getPropertyValue("--purple").trim(); - - // Axis lines (canvas) - const origin = projectPoint(0, 0, 0, pv, vw, vh); - const axisPts: [[number, number, number], string][] = [ - [[2, 0, 0], colRed], - [[0, 2, 0], colGreen], - [[0, 0, 2], colPurple], - ]; - if (origin?.inFrustum) { - for (const [[x, y, z], col] of axisPts) { - const ap = projectPoint(x, y, z, pv, vw, vh); - if (!ap?.inFrustum) continue; - ctx.strokeStyle = col; - ctx.lineWidth = 1.5; - ctx.beginPath(); - ctx.moveTo(origin.sx, origin.sy); - ctx.lineTo(ap.sx, ap.sy); - ctx.stroke(); - } - } - - // Look-at reticle: projected onto the cube centre (origin) - if (origin?.inFrustum) { - const { sx, sy } = origin; - const r = 12; - ctx.save(); - ctx.globalAlpha = 0.75; - ctx.strokeStyle = colGreen; - ctx.lineWidth = 1; - ctx.setLineDash([3, 3]); - ctx.beginPath(); - ctx.moveTo(sx - r, sy); - ctx.lineTo(sx + r, sy); - ctx.stroke(); - ctx.beginPath(); - ctx.moveTo(sx, sy - r); - ctx.lineTo(sx, sy + r); - ctx.stroke(); - ctx.setLineDash([]); - ctx.beginPath(); - ctx.arc(sx, sy, r * 0.35, 0, Math.PI * 2); - ctx.stroke(); - ctx.globalAlpha = 0.6; - ctx.fillStyle = colGreen; - ctx.font = '11px "IBM Plex Mono"'; - ctx.textAlign = "left"; - ctx.fillText("lookat", sx + r + 3, sy + 3); - ctx.restore(); - } - - // Floating axis labels - LABELS.forEach((l, i) => { - const pp = projectPoint(l.pos[0], l.pos[1], l.pos[2], pv, vw, vh); - const el = labelEls[i]; - if (!pp || !pp.inFrustum) { - el.style.display = "none"; - return; - } - const t = Math.max(0, Math.min(1, 1 - (pp.depth + 1) / 2)); - el.style.display = "block"; - el.style.transform = `translate(${pp.sx}px,${pp.sy}px) translate(-50%,-50%)`; - el.style.opacity = String(0.35 + t * 0.65); - el.style.fontSize = `${11 + t * 3}px`; - }); - - // Info panels - quatBox.textContent = `q = { x: ${fmt3(q.x)}, y: ${fmt3(q.y)}, z: ${fmt3(q.z)}, w: ${fmt3(q.w)} }`; - - lookatBox.textContent = [ - `forward = { x: ${fmt3(forward.x)}, y: ${fmt3(forward.y)}, z: ${fmt3(forward.z)} }`, - `eye = { x: ${fmt3(eye.x)}, y: ${fmt3(eye.y)}, z: ${fmt3(eye.z)} }`, - ].join("\n"); - - codeBox.textContent = [ - `// Orbit: rotate default eye (0,0,r) by quaternion`, - `const qYaw = Quat.fromAxisAngle(new Vec3(0,1,0), ${fmt2(yaw)});`, - `const qPitch = Quat.fromAxisAngle(new Vec3(1,0,0), ${fmt2(-pitch)});`, - `const q = qYaw.multiplyNew(qPitch);`, - `// { x:${fmt3(q.x)}, y:${fmt3(q.y)}, z:${fmt3(q.z)}, w:${fmt3(q.w)} }`, - ``, - `const rotMat = Mat4.fromQuat(q.array);`, - `const eye = new Vec3(0, 0, ${fmt2(radius)})`, - ` .transformByMat4New(rotMat);`, - `// { x:${fmt3(eye.x)}, y:${fmt3(eye.y)}, z:${fmt3(eye.z)} }`, - ``, - `// Look-at vector: eye -> origin`, - `const target = new Vec3(0, 0, 0);`, - `const forward = target.subtractNew(eye).normaliseNew();`, - `// { x:${fmt3(forward.x)}, y:${fmt3(forward.y)}, z:${fmt3(forward.z)} }`, - ``, - `// View matrix + CSS`, - `const view = Mat4.lookAt(eye, target, [0,1,0]);`, - `scene.style.transform = \`matrix3d(\${view.array})\`;`, - ].join("\n"); -} - -// Controls wiring - -type Key = keyof typeof sliders; - -function wireSliderNum(key: Key, onChanged: (v: number) => void) { - const s = sliders[key]; - const n = nums[key]; - s.addEventListener("input", () => { - const v = parseFloat(s.value); - n.value = String(v); - onChanged(v); - render(); - }); - n.addEventListener("change", () => { - const v = parseFloat(n.value); - s.value = String(v); - onChanged(v); - render(); - }); -} - -wireSliderNum("yaw", (v) => { - yawDeg = v; -}); -wireSliderNum("pitch", (v) => { - pitchDeg = v; -}); -wireSliderNum("radius", (v) => { - radius = v; -}); - -window.addEventListener("resize", render); - -render(); diff --git a/demos/color.html b/demos/color.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/color.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/color.pug b/demos/color.pug deleted file mode 100644 index 4a5bc49..0000000 --- a/demos/color.pug +++ /dev/null @@ -1,108 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Colour - -block head - style. - .swatch { - height: 40px; - border-radius: var(--r); - border: 1px solid var(--border); - flex: 1; - } - .color-row { - display: flex; - align-items: center; - gap: 8px; - } - .color-pick { - width: 36px; - height: 26px; - border: 1px solid var(--border); - border-radius: var(--r); - padding: 1px; - background: var(--surface-2); - cursor: pointer; - flex-shrink: 0; - } - .color-info { - font-size: var(--fs-sm); - color: var(--text-dim); - line-height: 1.8; - } - .lerp-swatch { - width: 100%; - height: 32px; - border-radius: var(--r); - border: 1px solid var(--border); - } - .lerp-info { - font-size: var(--fs-sm); - color: var(--amber); - background: var(--amber-dim); - border-left: 2px solid var(--amber-border); - padding: 5px 10px; - border-radius: 0 var(--r) var(--r) 0; - line-height: 1.8; - } - .canvas-fill { - flex: 1; - overflow: hidden; - position: relative; - background: var(--surface); - } - #color-canvas { - display: block; - width: 100%; - height: 100%; - } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Colour - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Colour A - div.color-row - input.color-pick(type="color" id="colorA" value="#e63b5e") - div.swatch#swatchA - pre.color-info#infoA - - div.ctrl-section - h3 Colour B - div.color-row - input.color-pick(type="color" id="colorB" value="#22aaff") - div.swatch#swatchB - pre.color-info#infoB - - div.ctrl-section - h3 Color.lerp(a, b, t) - div.ctrl-row - span.ctrl-label t - input.ctrl-slider(type="range" id="tSlider" min="0" max="1" step="0.01" value="0.5") - input.ctrl-num(type="number" id="tNum" min="0" max="1" step="0.01" value="0.5") - div.lerp-swatch#lerpSwatch - pre.lerp-info#lerpInfo - - div.ctrl-section.ctrl-section--fill - h3 How it works - p.info-text #[code.txt-green Color] stores RGBA in #[code.txt-amber 0–1] space. #[code.txt-green Color.fromHex()] parses hex strings. #[code.txt-green toHSL()] decomposes to hue (0–360°), saturation, and lightness. The canvas shows a hue wheel built entirely from #[code.txt-green Color.fromHSL(h, 0.85, 0.55)] — one colour per degree — with the lerped result in the centre and a gradient strip at the bottom. - - div.canvas-fill#canvas-fill - canvas#color-canvas - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Color · fromHex · fromHSL · lerp - -block scripts - script(type="module" src="./color.ts") diff --git a/demos/color.ts b/demos/color.ts deleted file mode 100644 index fbb0316..0000000 --- a/demos/color.ts +++ /dev/null @@ -1,151 +0,0 @@ -import { Color } from "../src/Color"; - -const colorAInput = document.getElementById("colorA") as HTMLInputElement; -const colorBInput = document.getElementById("colorB") as HTMLInputElement; -const swatchA = document.getElementById("swatchA") as HTMLDivElement; -const swatchB = document.getElementById("swatchB") as HTMLDivElement; -const infoA = document.getElementById("infoA") as HTMLPreElement; -const infoB = document.getElementById("infoB") as HTMLPreElement; -const tSlider = document.getElementById("tSlider") as HTMLInputElement; -const tNum = document.getElementById("tNum") as HTMLInputElement; -const lerpSwatch = document.getElementById("lerpSwatch") as HTMLDivElement; -const lerpInfo = document.getElementById("lerpInfo") as HTMLPreElement; -const canvasFill = document.getElementById("canvas-fill") as HTMLDivElement; -const canvas = document.getElementById("color-canvas") as HTMLCanvasElement; - -function fmt(c: Color): string { - const [h, s, l] = c.toHSL(); - return [ - `hex ${c.toHex()}`, - `rgb (${(c.r * 255) | 0}, ${(c.g * 255) | 0}, ${(c.b * 255) | 0})`, - `hsl (${h.toFixed(1)}°, ${(s * 100).toFixed(1)}%, ${(l * 100).toFixed(1)}%)`, - ].join("\n"); -} - -function render() { - const t = parseFloat(tSlider.value); - const a = Color.fromHex(colorAInput.value); - const b = Color.fromHex(colorBInput.value); - const lerped = Color.lerp(a, b, t); - - swatchA.style.background = a.toCSS(); - swatchB.style.background = b.toCSS(); - lerpSwatch.style.background = lerped.toCSS(); - infoA.textContent = fmt(a); - infoB.textContent = fmt(b); - lerpInfo.textContent = fmt(lerped); - - drawCanvas(a, b, t); -} - -function drawCanvas(colorA: Color, colorB: Color, t: number) { - const W = canvasFill.clientWidth; - const H = canvasFill.clientHeight; - if (W === 0 || H === 0) return; - - const dpr = window.devicePixelRatio || 1; - canvas.width = W * dpr; - canvas.height = H * dpr; - canvas.style.width = `${W}px`; - canvas.style.height = `${H}px`; - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - - const bg = getComputedStyle(document.documentElement) - .getPropertyValue("--surface") - .trim(); - ctx.fillStyle = bg; - ctx.fillRect(0, 0, W, H); - - const stripH = 28; - const stripPad = 20; - const stripY = H - stripH - stripPad; - const stripX = stripPad; - const stripW = W - stripPad * 2; - - // Hue wheel - const cx = W / 2; - const cy = (stripY - stripPad) / 2; - const outerR = Math.min(W / 2, cy) - 16; - const ringWidth = outerR * 0.28; - const innerR = outerR - ringWidth; - - for (let i = 0; i < 360; i++) { - const a0 = (i / 360) * Math.PI * 2 - Math.PI / 2; - const a1 = ((i + 1.5) / 360) * Math.PI * 2 - Math.PI / 2; - ctx.beginPath(); - ctx.arc(cx, cy, outerR, a0, a1); - ctx.arc(cx, cy, innerR, a1, a0, true); - ctx.closePath(); - ctx.fillStyle = Color.fromHSL(i, 0.85, 0.55).toCSS(); - ctx.fill(); - } - - // Centre fill — lerped colour - ctx.beginPath(); - ctx.arc(cx, cy, innerR - 4, 0, Math.PI * 2); - ctx.fillStyle = bg; - ctx.fill(); - - ctx.beginPath(); - ctx.arc(cx, cy, innerR - 10, 0, Math.PI * 2); - ctx.fillStyle = Color.lerp(colorA, colorB, t).toCSS(); - ctx.fill(); - - // Markers on the ring for A and B - for (const [col, label] of [ - [colorA, "A"], - [colorB, "B"], - ] as [Color, string][]) { - const [hue] = col.toHSL(); - const angle = (hue / 360) * Math.PI * 2 - Math.PI / 2; - const markerR = innerR + ringWidth / 2; - const mx = cx + Math.cos(angle) * markerR; - const my = cy + Math.sin(angle) * markerR; - ctx.beginPath(); - ctx.arc(mx, my, 6, 0, Math.PI * 2); - ctx.fillStyle = col.toCSS(); - ctx.fill(); - ctx.strokeStyle = "rgba(255,255,255,0.7)"; - ctx.lineWidth = 1.5; - ctx.stroke(); - ctx.font = `600 10px var(--font)`; - ctx.fillStyle = "rgba(255,255,255,0.8)"; - ctx.textAlign = "center"; - ctx.textBaseline = "middle"; - ctx.fillText(label, mx, my); - } - ctx.textAlign = "left"; - ctx.textBaseline = "alphabetic"; - - // Lerp strip - for (let i = 0; i <= stripW; i++) { - ctx.fillStyle = Color.lerp(colorA, colorB, i / stripW).toCSS(); - ctx.fillRect(stripX + i, stripY, 1, stripH); - } - - // t marker - const mx = stripX + t * stripW; - ctx.beginPath(); - ctx.moveTo(mx, stripY - 5); - ctx.lineTo(mx - 5, stripY - 11); - ctx.lineTo(mx + 5, stripY - 11); - ctx.closePath(); - ctx.fillStyle = "rgba(0,0,0,0.75)"; - ctx.fill(); -} - -colorAInput.addEventListener("input", render); -colorBInput.addEventListener("input", render); - -tSlider.addEventListener("input", () => { - tNum.value = tSlider.value; - render(); -}); -tNum.addEventListener("change", () => { - tSlider.value = tNum.value; - render(); -}); - -window.addEventListener("resize", render); -render(); diff --git a/demos/colormath.html b/demos/colormath.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/colormath.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/colormath.pug b/demos/colormath.pug deleted file mode 100644 index 124dee5..0000000 --- a/demos/colormath.pug +++ /dev/null @@ -1,114 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Colour Math - -block head - style. - .color-pick { - width: 36px; - height: 26px; - border: 1px solid var(--border); - border-radius: var(--r); - padding: 1px; - background: var(--surface-2); - cursor: pointer; - flex-shrink: 0; - } - .swatch-inline { - flex: 1; - height: 26px; - border-radius: var(--r); - border: 1px solid var(--border); - } - .de-display { - display: flex; - align-items: baseline; - gap: 10px; - } - .de-val { - font-size: var(--fs-lg); - font-weight: 600; - color: var(--amber); - } - .de-label { - font-size: var(--fs-sm); - color: var(--text-dim); - font-style: italic; - } - .temp-result { - display: flex; - align-items: center; - gap: 8px; - margin-top: 4px; - } - .temp-swatch { - width: 32px; - height: 18px; - border-radius: var(--r); - border: 1px solid var(--border); - flex-shrink: 0; - } - .temp-label { - font-size: var(--fs-sm); - color: var(--text-dim); - } - .canvas-fill { - flex: 1; - overflow: hidden; - background: var(--surface); - } - #cm-canvas { display: block; width: 100%; height: 100%; } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Colour Math - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Base colour - div.ctrl-row - input.color-pick(type="color" id="baseColor" value="#3a86ff") - div.swatch-inline#baseSwatch - - div.ctrl-section - h3 Compare (ΔE) - div.ctrl-row - input.color-pick(type="color" id="compareColor" value="#ff006e") - div.swatch-inline#compareSwatch - div.de-display - span.de-val#deVal — - span.de-label#deLabel - - div.ctrl-section - h3 Temperature - div.ctrl-row - span.ctrl-label K - input.ctrl-slider(type="range" id="tempSlider" min="1000" max="12000" step="50" value="5500") - input.ctrl-num(type="number" id="tempNum" min="1000" max="12000" step="50" value="5500") - div.temp-result - div.temp-swatch#tempSwatch - span.temp-label#tempLabel - - div.ctrl-section.ctrl-section--fill - h3 How it works - p.info-text #[strong.txt-mid Harmonies] extract #[code.txt-amber [L, C, H]] with #[code.txt-green toOklch()] then rebuild at fixed hue offsets. Equal L and C means every swatch is perceptually balanced. - p.info-text #[strong.txt-mid ΔE] is Euclidean distance in Oklab space — #[code.txt-green √(ΔL²+Δa²+Δb²)]. Below 0.02 is imperceptible; above 0.15 is clearly distinct. - p.info-text #[strong.txt-mid Blackbody] maps Kelvin to CIE xy via Kang's polynomial, converts through XYZ→linear sRGB, normalises to the brightest channel, then gamma-encodes. - - div.canvas-fill#canvas-fill - canvas#cm-canvas - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Color · harmonies · ΔE · blackbody - -block scripts - script(type="module" src="./colormath.ts") diff --git a/demos/colormath.ts b/demos/colormath.ts deleted file mode 100644 index 0d1a19b..0000000 --- a/demos/colormath.ts +++ /dev/null @@ -1,340 +0,0 @@ -import { Color } from "../src/Color"; - -// DOM -const baseInput = document.getElementById("baseColor") as HTMLInputElement; -const compareInput = document.getElementById("compareColor") as HTMLInputElement; -const baseSwatch = document.getElementById("baseSwatch") as HTMLDivElement; -const compareSwatch = document.getElementById("compareSwatch") as HTMLDivElement; -const deVal = document.getElementById("deVal") as HTMLSpanElement; -const deLabel = document.getElementById("deLabel") as HTMLSpanElement; -const tempSlider = document.getElementById("tempSlider") as HTMLInputElement; -const tempNum = document.getElementById("tempNum") as HTMLInputElement; -const tempSwatch = document.getElementById("tempSwatch") as HTMLDivElement; -const tempLabel = document.getElementById("tempLabel") as HTMLSpanElement; -const canvasFill = document.getElementById("canvas-fill") as HTMLDivElement; -const canvas = document.getElementById("cm-canvas") as HTMLCanvasElement; - -// ── Harmony types ──────────────────────────────────────────────────────────── - -const HARMONIES: [string, number[]][] = [ - ["Complementary", [0, 180]], - ["Triadic", [0, 120, 240]], - ["Analogous", [-30, -15, 0, 15, 30]], - ["Split-comp", [0, 150, 210]], - ["Tetradic", [0, 90, 180, 270]], -]; - -// ── ΔE in Oklab ────────────────────────────────────────────────────────────── - -function deltaE(a: Color, b: Color): number { - const [L1, a1, b1] = a.toOklab(); - const [L2, a2, b2] = b.toOklab(); - return Math.sqrt((L2 - L1) ** 2 + (a2 - a1) ** 2 + (b2 - b1) ** 2); -} - -const DE_THRESHOLDS: [number, string][] = [ - [0.02, "imperceptible"], - [0.05, "just noticeable"], - [0.10, "similar"], - [0.20, "distinct"], -]; - -function deInterpret(de: number): string { - for (const [thresh, label] of [...DE_THRESHOLDS].reverse()) { - if (de >= thresh) return label; - } - return "imperceptible"; -} - -// ── Blackbody: Kang et al. polynomial → CIE xy → XYZ → sRGB ───────────────── - -function kelvinToColor(T: number): Color { - // CIE xy chromaticity - const x = T < 4000 - ? -0.2661239e9 / T ** 3 - 0.2343580e6 / T ** 2 + 0.8776956e3 / T + 0.179910 - : -3.0258469e9 / T ** 3 + 2.1070379e6 / T ** 2 + 0.2226347e3 / T + 0.240390; - - const y = T < 2222 - ? -1.1063814 * x ** 3 - 1.34811020 * x ** 2 + 2.18555832 * x - 0.20219683 - : T < 4000 - ? -0.9549476 * x ** 3 - 1.37418593 * x ** 2 + 2.09137015 * x - 0.16748867 - : 3.0817580 * x ** 3 - 5.87338670 * x ** 2 + 3.75112997 * x - 0.37001483; - - // xy → XYZ (Y = 1) - const X = x / y, Z = (1 - x - y) / y; - - // XYZ → linear sRGB (D65 matrix) - const lr = 3.2406 * X - 1.5372 - 0.4986 * Z; - const lg = -0.9689 * X + 1.8758 + 0.0415 * Z; - const lb = 0.0557 * X - 0.2040 + 1.0570 * Z; - - // Normalise to brightest channel then gamma-encode - const m = Math.max(lr, lg, lb); - const enc = (c: number) => { - const v = Math.max(0, c / m); - return v <= 0.0031308 ? 12.92 * v : 1.055 * v ** (1 / 2.4) - 0.055; - }; - return new Color(enc(lr), enc(lg), enc(lb)); -} - -const TEMP_LABELS: [number, string][] = [ - [1000, "1kK"], - [1900, "candle"], - [2700, "tungsten"], - [5500, "daylight"], - [6500, "D65"], - [10000, "blue sky"], - [12000, "12kK"], -]; - -// ── Draw ───────────────────────────────────────────────────────────────────── - -function sectionHead(ctx: CanvasRenderingContext2D, text: string, x: number, y: number, col: string) { - ctx.font = `600 9px var(--font)`; - ctx.fillStyle = col; - ctx.textAlign = "left"; - ctx.fillText(text, x, y + 9); -} - -function draw() { - const W = canvasFill.clientWidth; - const H = canvasFill.clientHeight; - if (!W || !H) return; - - const dpr = window.devicePixelRatio || 1; - canvas.width = W * dpr; - canvas.height = H * dpr; - canvas.style.width = `${W}px`; - canvas.style.height = `${H}px`; - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - - const cs = getComputedStyle(document.documentElement); - const bg = cs.getPropertyValue("--surface").trim(); - const border = cs.getPropertyValue("--border").trim(); - const textMid = cs.getPropertyValue("--text-mid").trim(); - const textDim = cs.getPropertyValue("--text-dim").trim(); - const amber = cs.getPropertyValue("--amber").trim(); - - ctx.fillStyle = bg; - ctx.fillRect(0, 0, W, H); - - const PAD = 20; - const LABEL_W = 72; - const colX = PAD + LABEL_W; - const colW = W - colX - PAD; - - const base = Color.fromHex(baseInput.value); - const compare = Color.fromHex(compareInput.value); - const [bL, bC, bH] = base.toOklch(); - const de = deltaE(base, compare); - const tempK = parseInt(tempSlider.value); - const tempCol = kelvinToColor(tempK); - - // Update sidebar - baseSwatch.style.background = base.toCSS(); - compareSwatch.style.background = compare.toCSS(); - deVal.textContent = de.toFixed(4); - deLabel.textContent = deInterpret(de); - tempSwatch.style.background = tempCol.toCSS(); - tempLabel.textContent = `${tempK.toLocaleString()}K → ${tempCol.toHex()}`; - - // ── 1. Harmonies ────────────────────────────────────────────────────────── - - let y = PAD; - sectionHead(ctx, "COLOUR HARMONIES · Oklch hue offsets", PAD, y, textDim); - y += 18; - - const harmTotalH = H * 0.46 - 18 - PAD; - const rowH = Math.min(48, (harmTotalH - (HARMONIES.length - 1) * 5) / HARMONIES.length); - const swW = Math.min(rowH * 1.15, (colW - (5 - 1) * 5) / 5); - const swGap = 5; - - for (const [name, offsets] of HARMONIES) { - ctx.font = `500 10px var(--font)`; - ctx.fillStyle = textMid; - ctx.textAlign = "right"; - ctx.fillText(name, colX - 8, y + rowH / 2 + 3); - ctx.textAlign = "left"; - - for (let i = 0; i < offsets.length; i++) { - const hue = ((bH + offsets[i]) % 360 + 360) % 360; - const c = Color.fromOklch(bL, bC, hue); - const sx = colX + i * (swW + swGap); - - ctx.fillStyle = c.toCSS(); - ctx.beginPath(); - (ctx as any).roundRect(sx, y, swW, rowH, 3); - ctx.fill(); - - if (offsets[i] === 0) { - ctx.strokeStyle = "rgba(255,255,255,0.45)"; - ctx.lineWidth = 1.5; - ctx.beginPath(); - (ctx as any).roundRect(sx, y, swW, rowH, 3); - ctx.stroke(); - } - - ctx.font = `400 9px var(--font)`; - ctx.fillStyle = "rgba(255,255,255,0.45)"; - ctx.textAlign = "center"; - ctx.fillText(`${Math.round(hue)}°`, sx + swW / 2, y + rowH - 5); - } - ctx.textAlign = "left"; - - y += rowH + 5; - } - - y += 18; - - // ── 2. ΔE ───────────────────────────────────────────────────────────────── - - sectionHead(ctx, "ΔE · PERCEPTUAL DISTANCE · Oklab Euclidean", PAD, y, textDim); - y += 18; - - const circR = Math.min(24, (H * 0.14) / 2); - const circY = y + circR; - const cAx = colX + circR; - const cBx = colX + circR * 3.6; - - // Base circle - ctx.beginPath(); - ctx.arc(cAx, circY, circR, 0, Math.PI * 2); - ctx.fillStyle = base.toCSS(); - ctx.fill(); - - // Compare circle - ctx.beginPath(); - ctx.arc(cBx, circY, circR, 0, Math.PI * 2); - ctx.fillStyle = compare.toCSS(); - ctx.fill(); - - // Line + ΔE label between them - ctx.strokeStyle = "rgba(0,0,0,0.25)"; - ctx.lineWidth = 1; - ctx.setLineDash([3, 4]); - ctx.beginPath(); - ctx.moveTo(cAx + circR + 3, circY); - ctx.lineTo(cBx - circR - 3, circY); - ctx.stroke(); - ctx.setLineDash([]); - - const midX = (cAx + cBx) / 2; - ctx.font = `600 14px var(--font)`; - ctx.fillStyle = amber; - ctx.textAlign = "center"; - ctx.fillText(`${de.toFixed(3)}`, midX, circY - circR - 5); - ctx.font = `400 9px var(--font)`; - ctx.fillStyle = textDim; - ctx.fillText("ΔE", midX, circY + circR + 12); - ctx.textAlign = "left"; - - // Gauge bar - const gaugeY = y + circR * 2 + 18; - const gaugeH = 8; - const MAX_DE = 0.45; - - const grad = ctx.createLinearGradient(colX, 0, colX + colW, 0); - grad.addColorStop(0, "rgba(57,255,138,0.35)"); - grad.addColorStop(0.11, "rgba(57,255,138,0.15)"); - grad.addColorStop(0.33, "rgba(255,201,64,0.25)"); - grad.addColorStop(1, "rgba(255,85,102,0.35)"); - ctx.fillStyle = grad; - ctx.beginPath(); - (ctx as any).roundRect(colX, gaugeY, colW, gaugeH, gaugeH / 2); - ctx.fill(); - ctx.strokeStyle = border; - ctx.lineWidth = 1; - ctx.beginPath(); - (ctx as any).roundRect(colX, gaugeY, colW, gaugeH, gaugeH / 2); - ctx.stroke(); - - // Threshold ticks - ctx.font = `400 9px var(--font)`; - for (const [thresh, label] of DE_THRESHOLDS) { - const tx = colX + (thresh / MAX_DE) * colW; - ctx.strokeStyle = "rgba(0,0,0,0.15)"; - ctx.lineWidth = 1; - ctx.setLineDash([2, 3]); - ctx.beginPath(); - ctx.moveTo(tx, gaugeY - 3); - ctx.lineTo(tx, gaugeY + gaugeH + 3); - ctx.stroke(); - ctx.setLineDash([]); - ctx.fillStyle = textDim; - ctx.textAlign = "center"; - ctx.fillText(label, tx, gaugeY + gaugeH + 13); - } - ctx.textAlign = "left"; - - // Marker dot - const markerX = colX + Math.min(de / MAX_DE, 1) * colW; - ctx.beginPath(); - ctx.arc(markerX, gaugeY + gaugeH / 2, gaugeH / 2 + 2, 0, Math.PI * 2); - ctx.fillStyle = amber; - ctx.fill(); - - y = gaugeY + gaugeH + 24 + 10; - - // ── 3. Blackbody ────────────────────────────────────────────────────────── - - sectionHead(ctx, "BLACKBODY RADIATION · Kang polynomial → XYZ → sRGB", PAD, y, textDim); - y += 18; - - const bbH = H - y - PAD; - if (bbH < 24) return; - - const stripH = Math.min(52, bbH * 0.6); - const MIN_K = 1000, MAX_K = 12000; - - for (let i = 0; i <= colW; i++) { - const K = MIN_K + (i / colW) * (MAX_K - MIN_K); - ctx.fillStyle = kelvinToColor(K).toCSS(); - ctx.fillRect(colX + i, y, 1, stripH); - } - ctx.strokeStyle = border; - ctx.lineWidth = 1; - ctx.strokeRect(colX, y, colW, stripH); - - // Current temp marker - const tPct = (tempK - MIN_K) / (MAX_K - MIN_K); - const tX = colX + tPct * colW; - ctx.strokeStyle = "rgba(255,255,255,0.8)"; - ctx.lineWidth = 1.5; - ctx.setLineDash([3, 3]); - ctx.beginPath(); - ctx.moveTo(tX, y - 5); - ctx.lineTo(tX, y + stripH + 5); - ctx.stroke(); - ctx.setLineDash([]); - - // Temp labels - ctx.font = `400 9px var(--font)`; - for (const [K, label] of TEMP_LABELS) { - const lx = colX + ((K - MIN_K) / (MAX_K - MIN_K)) * colW; - ctx.fillStyle = textDim; - ctx.textAlign = "center"; - ctx.fillText(label, lx, y + stripH + 13); - ctx.strokeStyle = "rgba(255,255,255,0.08)"; - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.moveTo(lx, y); - ctx.lineTo(lx, y + stripH); - ctx.stroke(); - } - ctx.textAlign = "left"; -} - -// Events - -baseInput.addEventListener("input", draw); -compareInput.addEventListener("input", draw); - -function syncSlider(slider: HTMLInputElement, num: HTMLInputElement) { - slider.addEventListener("input", () => { num.value = slider.value; draw(); }); - num.addEventListener("change", () => { slider.value = num.value; draw(); }); -} -syncSlider(tempSlider, tempNum); - -window.addEventListener("resize", draw); -draw(); diff --git a/demos/colorspaces.html b/demos/colorspaces.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/colorspaces.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/colorspaces.pug b/demos/colorspaces.pug deleted file mode 100644 index ef63f1f..0000000 --- a/demos/colorspaces.pug +++ /dev/null @@ -1,110 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Colour Spaces - -block head - style. - .color-pick { - width: 36px; - height: 26px; - border: 1px solid var(--border); - border-radius: var(--r); - padding: 1px; - background: var(--surface-2); - cursor: pointer; - flex-shrink: 0; - } - .swatch-inline { - flex: 1; - height: 26px; - border-radius: var(--r); - border: 1px solid var(--border); - } - .anim-btn { - flex: 1; - background: var(--surface-2); - border: 1px solid var(--border); - border-radius: var(--r); - color: var(--text-mid); - font-family: var(--font); - font-size: var(--fs-sm); - padding: 4px 10px; - cursor: pointer; - transition: color 0.1s, border-color 0.1s, background 0.1s; - } - .anim-btn:hover { color: var(--text); border-color: var(--border-hi); } - .anim-btn.active { - color: var(--green); - border-color: var(--green-border); - background: var(--green-dim); - } - .canvas-fill { - flex: 1; - overflow: hidden; - background: var(--surface); - } - #cs-canvas { display: block; width: 100%; height: 100%; } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Colour Spaces - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Colour A - div.ctrl-row - input.color-pick(type="color" id="colorA" value="#e83868") - div.swatch-inline#swatchA - - div.ctrl-section - h3 Colour B - div.ctrl-row - input.color-pick(type="color" id="colorB" value="#1ab8ff") - div.swatch-inline#swatchB - - div.ctrl-section - h3 Blend - div.ctrl-row - button.anim-btn#animBtn animate - div.ctrl-row - span.ctrl-label t - input.ctrl-slider(type="range" id="tSlider" min="0" max="1" step="0.001" value="0.5") - input.ctrl-num(type="number" id="tNum" min="0" max="1" step="0.001" value="0.500") - - div.ctrl-section - h3 Palette (Oklch) - div.ctrl-row - span.ctrl-label n - input.ctrl-slider(type="range" id="palN" min="3" max="16" step="1" value="8") - input.ctrl-num(type="number" id="palNn" min="3" max="16" step="1" value="8") - div.ctrl-row - span.ctrl-label L - input.ctrl-slider(type="range" id="palL" min="0.3" max="0.85" step="0.01" value="0.65") - input.ctrl-num(type="number" id="palLn" min="0.3" max="0.85" step="0.01" value="0.65") - div.ctrl-row - span.ctrl-label C - input.ctrl-slider(type="range" id="palC" min="0.05" max="0.32" step="0.01" value="0.16") - input.ctrl-num(type="number" id="palCn" min="0.05" max="0.32" step="0.01" value="0.16") - - div.ctrl-section.ctrl-section--fill - h3 How it works - p.info-text #[strong.txt-mid sRGB] blends raw channel values — reds and blues through muddy grey. #[strong.txt-mid Oklab] works in a perceptually uniform space, preserving brightness. #[strong.txt-mid Oklch] takes the shortest arc through hue, keeping colours vivid all the way across. - p.info-text The palette uses #[code.txt-green Color.fromOklch(L, C, H)] at evenly spaced hues — equal lightness and chroma means every swatch looks equally "loud". - - div.canvas-fill#canvas-fill - canvas#cs-canvas - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Color · sRGB · Oklab · Oklch - -block scripts - script(type="module" src="./colorspaces.ts") diff --git a/demos/colorspaces.ts b/demos/colorspaces.ts deleted file mode 100644 index 12646f8..0000000 --- a/demos/colorspaces.ts +++ /dev/null @@ -1,292 +0,0 @@ -import { Color } from "../src/Color"; - -// DOM -const gi = (id: string) => document.getElementById(id) as HTMLInputElement; -const colorAInput = gi("colorA"); -const colorBInput = gi("colorB"); -const swatchA = document.getElementById("swatchA") as HTMLDivElement; -const swatchB = document.getElementById("swatchB") as HTMLDivElement; -const tSlider = gi("tSlider"); -const tNum = gi("tNum"); -const animBtn = document.getElementById("animBtn") as HTMLButtonElement; -const palN = gi("palN"); const palNn = gi("palNn"); -const palL = gi("palL"); const palLn = gi("palLn"); -const palC = gi("palC"); const palCn = gi("palCn"); -const canvasFill = document.getElementById("canvas-fill") as HTMLDivElement; -const canvas = document.getElementById("cs-canvas") as HTMLCanvasElement; - -// State -let t = 0.5; -let animating = false; -let animStart = 0; -let raf = 0; - -const STRIPS = [ - { label: "sRGB", formula: "Color.lerp(a, b, t)", fn: (a: Color, b: Color, t: number) => Color.lerp(a, b, t) }, - { label: "Oklab", formula: "Color.lerpOklab(a, b, t)", fn: (a: Color, b: Color, t: number) => Color.lerpOklab(a, b, t) }, - { label: "Oklch", formula: "Color.lerpOklch(a, b, t)", fn: (a: Color, b: Color, t: number) => Color.lerpOklch(a, b, t) }, -]; - -// Animation - -function tick(ts: number) { - if (!animating) return; - if (animStart === 0) animStart = ts; - t = Math.sin(((ts - animStart) / 1400)) * 0.5 + 0.5; - tSlider.value = String(t); - tNum.value = t.toFixed(3); - draw(); - raf = requestAnimationFrame(tick); -} - -animBtn.addEventListener("click", () => { - animating = !animating; - animBtn.classList.toggle("active", animating); - if (animating) { - animStart = 0; - raf = requestAnimationFrame(tick); - } else { - cancelAnimationFrame(raf); - } -}); - -// Render - -function draw() { - const W = canvasFill.clientWidth; - const H = canvasFill.clientHeight; - if (!W || !H) return; - - const dpr = window.devicePixelRatio || 1; - canvas.width = W * dpr; - canvas.height = H * dpr; - canvas.style.width = `${W}px`; - canvas.style.height = `${H}px`; - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - - const cs = getComputedStyle(document.documentElement); - const bg = cs.getPropertyValue("--surface").trim(); - const border = cs.getPropertyValue("--border").trim(); - const textMid = cs.getPropertyValue("--text-mid").trim(); - const textDim = cs.getPropertyValue("--text-dim").trim(); - - ctx.fillStyle = bg; - ctx.fillRect(0, 0, W, H); - - const colorA = Color.fromHex(colorAInput.value); - const colorB = Color.fromHex(colorBInput.value); - swatchA.style.background = colorA.toCSS(); - swatchB.style.background = colorB.toCSS(); - - const n = parseInt(palN.value); - const palLv = parseFloat(palL.value); - const palCv = parseFloat(palC.value); - - const PAD = 20; - const LABEL_W = 56; - const stripX = PAD + LABEL_W; - const stripW = W - stripX - PAD; - const STRIP_H = Math.max(40, Math.min(64, (H * 0.38) / STRIPS.length - 14)); - const STRIP_GAP = 12; - // The lerp strips leave room on the right for the result dots - const DOT_R = 10; - const DOT_GAP = 10; - const lerpW = stripW - DOT_GAP - DOT_R * 2; - - // ── Section 1: Lerp comparison ─────────────────────────────────────────── - - let y = PAD + 4; - - sectionLabel(ctx, "LERP COMPARISON", PAD, y, textDim); - y += 18; - - const stripTops: number[] = []; - - for (const strip of STRIPS) { - stripTops.push(y); - - // Label - ctx.font = `500 11px var(--font)`; - ctx.fillStyle = textMid; - ctx.textAlign = "right"; - ctx.fillText(strip.label, PAD + LABEL_W - 8, y + STRIP_H / 2 + 4); - - // Formula (small, below label) - ctx.font = `300 9px var(--font)`; - ctx.fillStyle = textDim; - ctx.fillText(strip.formula, PAD + LABEL_W - 8, y + STRIP_H / 2 + 15); - ctx.textAlign = "left"; - - // Gradient strip — one pixel column at a time - for (let i = 0; i <= lerpW; i++) { - ctx.fillStyle = strip.fn(colorA, colorB, i / lerpW).toCSS(); - ctx.fillRect(stripX + i, y, 1, STRIP_H); - } - - // Border - ctx.strokeStyle = border; - ctx.lineWidth = 1; - ctx.strokeRect(stripX, y, lerpW, STRIP_H); - - y += STRIP_H + STRIP_GAP; - } - - // t indicator across all strips - const tX = stripX + t * lerpW; - ctx.save(); - ctx.strokeStyle = "rgba(255,255,255,0.75)"; - ctx.lineWidth = 1.5; - ctx.setLineDash([3, 4]); - ctx.beginPath(); - ctx.moveTo(tX, stripTops[0] - 2); - ctx.lineTo(tX, stripTops[stripTops.length - 1] + STRIP_H + 2); - ctx.stroke(); - ctx.restore(); - - // t label above first strip - ctx.font = `500 10px var(--font)`; - ctx.fillStyle = "rgba(0,0,0,0.55)"; - ctx.textAlign = "center"; - ctx.fillText(`t=${t.toFixed(2)}`, tX, stripTops[0] - 7); - ctx.textAlign = "left"; - - // Lerped colour dots at current t, right of strips - for (let i = 0; i < STRIPS.length; i++) { - const c = STRIPS[i].fn(colorA, colorB, t); - const dx = stripX + lerpW + DOT_GAP + DOT_R; - const dy = stripTops[i] + STRIP_H / 2; - ctx.beginPath(); - ctx.arc(dx, dy, DOT_R, 0, Math.PI * 2); - ctx.fillStyle = c.toCSS(); - ctx.fill(); - } - - y += 20; - - // ── Section 2: Oklch palette ───────────────────────────────────────────── - - sectionLabel(ctx, "OKLCH PALETTE", PAD, y, textDim); - y += 18; - - const swatchGap = 6; - const swatchH = Math.max(36, Math.min(52, H * 0.1)); - const availW = W - PAD * 2; - const swatchW = Math.min(60, (availW - swatchGap * (n - 1)) / n); - const rowW = n * swatchW + (n - 1) * swatchGap; - const rowX = PAD + (availW - rowW) / 2; - - for (let i = 0; i < n; i++) { - const hue = (i / n) * 360; - const c = Color.fromOklch(palLv, palCv, hue); - const sx = rowX + i * (swatchW + swatchGap); - - ctx.fillStyle = c.toCSS(); - ctx.beginPath(); - (ctx as CanvasRenderingContext2D & { roundRect: Function }).roundRect(sx, y, swatchW, swatchH, 4); - ctx.fill(); - - ctx.font = `400 9px var(--font)`; - ctx.fillStyle = textDim; - ctx.textAlign = "center"; - ctx.fillText(c.toHex(), sx + swatchW / 2, y + swatchH + 11); - } - ctx.textAlign = "left"; - - y += swatchH + 20 + 14; - - // ── Section 3: Oklch H × L field ───────────────────────────────────────── - - const fieldH = H - y - PAD - 4; - if (fieldH < 30) return; - - sectionLabel(ctx, "OKLCH FIELD · x = hue · y = lightness", PAD, y, textDim); - y += 18; - - const fieldActualH = H - y - PAD; - if (fieldActualH < 10) return; - - // Column-gradient approximation: accurate in X, smooth in Y - for (let fx = 0; fx < stripW; fx++) { - const hue = (fx / stripW) * 360; - const top = Color.fromOklch(0.88, palCv, hue).toCSS(); - const mid = Color.fromOklch(0.50, palCv, hue).toCSS(); - const bot = Color.fromOklch(0.18, palCv, hue).toCSS(); - const grad = ctx.createLinearGradient(0, y, 0, y + fieldActualH); - grad.addColorStop(0, top); - grad.addColorStop(0.5, mid); - grad.addColorStop(1, bot); - ctx.fillStyle = grad; - ctx.fillRect(stripX + fx, y, 1, fieldActualH); - } - - // Y-axis labels (lightness) - ctx.font = `400 9px var(--font)`; - ctx.fillStyle = textDim; - for (const [label, pct] of [["L 0.9", 0], ["L 0.5", 0.5], ["L 0.2", 1]] as [string, number][]) { - const ly = y + pct * fieldActualH; - ctx.textAlign = "right"; - ctx.fillText(label, stripX - 6, ly + 4); - ctx.strokeStyle = "rgba(255,255,255,0.08)"; - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.moveTo(stripX, ly); - ctx.lineTo(stripX + stripW, ly); - ctx.stroke(); - } - ctx.textAlign = "left"; - - // Border - ctx.strokeStyle = border; - ctx.lineWidth = 1; - ctx.strokeRect(stripX, y, stripW, fieldActualH); -} - -function sectionLabel( - ctx: CanvasRenderingContext2D, - text: string, - x: number, - y: number, - color: string -) { - ctx.font = `600 9px var(--font)`; - ctx.fillStyle = color; - ctx.fillText(text, x, y + 9); -} - -// Sync slider ↔ number input pairs - -function sync( - slider: HTMLInputElement, - num: HTMLInputElement, - cb?: (v: number) => void -) { - const handler = (src: HTMLInputElement, dst: HTMLInputElement) => () => { - dst.value = src.value; - cb?.(parseFloat(src.value)); - if (!animating) draw(); - }; - slider.addEventListener("input", handler(slider, num)); - num.addEventListener("change", handler(num, slider)); -} - -tSlider.addEventListener("input", () => { - t = parseFloat(tSlider.value); - tNum.value = t.toFixed(3); - if (!animating) draw(); -}); -tNum.addEventListener("change", () => { - t = parseFloat(tNum.value); - tSlider.value = String(t); - if (!animating) draw(); -}); - -colorAInput.addEventListener("input", () => { if (!animating) draw(); }); -colorBInput.addEventListener("input", () => { if (!animating) draw(); }); - -sync(palN, palNn); -sync(palL, palLn); -sync(palC, palCn); - -window.addEventListener("resize", draw); -draw(); diff --git a/demos/gradients.html b/demos/gradients.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/gradients.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/gradients.pug b/demos/gradients.pug deleted file mode 100644 index 95e4d6f..0000000 --- a/demos/gradients.pug +++ /dev/null @@ -1,184 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Colour Gradients - -block head - style. - .ctrl-label { width: 16px; } - - .color-row { - display: flex; - align-items: center; - gap: 10px; - } - - .color-label { - color: var(--text-mid); - width: 16px; - } - - .color-swatch-input { - width: 36px; - height: 24px; - border: 1px solid var(--border); - border-radius: var(--r); - padding: 1px; - background: var(--surface-2); - cursor: pointer; - flex-shrink: 0; - } - - .color-vec { - font-size: var(--fs-sm); - color: var(--text-dim); - flex: 1; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - - .result-swatch { - width: 100%; - height: 32px; - border-radius: var(--r); - border: 1px solid var(--border); - flex-shrink: 0; - } - - .result-vec { - font-size: var(--fs-sm); - color: var(--amber); - background: var(--amber-dim); - border-left: 2px solid var(--amber-border); - padding: 5px 8px; - border-radius: 0 var(--r) var(--r) 0; - line-height: 1.6; - word-break: break-all; - } - - .grad-panel { - display: flex; - flex-direction: column; - overflow-y: auto; - padding: 14px 20px; - gap: 10px; - background: var(--surface); - } - - .grad-strip { - display: flex; - flex-direction: column; - gap: 5px; - } - - .grad-header { - display: flex; - align-items: baseline; - justify-content: space-between; - gap: 10px; - } - - .grad-name { - font-weight: 500; - color: var(--text); - } - - .grad-formula { - color: var(--text-dim); - font-style: italic; - } - - .grad-row { - display: flex; - align-items: center; - gap: 10px; - } - - .grad-canvas { - flex: 1; - height: 28px; - border-radius: var(--r); - border: 1px solid var(--border); - display: block; - } - - .grad-dot { - width: 28px; - height: 28px; - border-radius: 50%; - border: 1px solid var(--dot-border); - flex-shrink: 0; - } - - .grad-val { - font-size: var(--fs-sm); - color: var(--text-dim); - white-space: nowrap; - } - - .grad-section-header { - font-size: var(--fs-xs); - font-weight: 600; - letter-spacing: 0.12em; - text-transform: uppercase; - color: var(--text-mid); - padding-bottom: 4px; - border-bottom: 1px solid var(--border); - margin-top: 16px; - } - .grad-section-header:first-child { - margin-top: 0; - } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Colour Gradients via Vec4 - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Colour A - div.color-row - span.color-label A - input.color-swatch-input(type="color" id="colorA" value="#e63b5e") - span.color-vec#vecA Vec4(0.90, 0.23, 0.37, 1.00) - - div.ctrl-section - h3 Colour B - div.color-row - span.color-label B - input.color-swatch-input(type="color" id="colorB" value="#22b0f0") - span.color-vec#vecB Vec4(0.13, 0.69, 0.94, 1.00) - - div.ctrl-section - h3 Position - div.ctrl-row - span.ctrl-label t - input.ctrl-slider(type="range" id="tSlider" min="0" max="1" step="0.01" value="0.5") - input.ctrl-num(type="number" id="tNum" min="0" max="1" step="0.01" value="0.5") - - div.ctrl-section - h3 Result at t - div.result-swatch#result-swatch - div.result-vec#result-vec - - div.ctrl-section.ctrl-section--fill - h3 How it works - p.info-text #[code.txt-green Vec4] stores colour as #[code.txt-amber (r, g, b, a)] in 0–1 space. #[code.txt-green Vec4.lerp(a, b, t)] blends each channel. The easing strips above apply timing curves to #[code.txt-amber t] before lerping — all still in sRGB, so the midpoint can look muddy. - p.info-text The colour-space strips below convert to a perceptually uniform space first. #[strong.txt-mid Gamma-correct] linearises sRGB before blending. #[strong.txt-mid Oklab] works in a space designed to match human perception — no muddy grey midpoints. #[strong.txt-mid Oklch] is Oklab in polar form, lerping hue angle via the shortest arc for natural colour wheel transitions. - - div.grad-panel#grad-panel - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Vec4 colour lerp · easing + Oklab · Oklch - -block scripts - script(type="module" src="./gradients.ts") diff --git a/demos/gradients.ts b/demos/gradients.ts deleted file mode 100644 index a9d332b..0000000 --- a/demos/gradients.ts +++ /dev/null @@ -1,318 +0,0 @@ -import { Vec4 } from '../src/index'; - -// Colour conversion helpers - -function srgbToLinear(c: number): number { - return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; -} - -function linearToSrgb(c: number): number { - return c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055; -} - -function clamp01(v: number): number { - return Math.max(0, Math.min(1, v)); -} - -// sRGB Vec4 -> [L, a, b] in Oklab -function vec4ToOklab(v: Vec4): [number, number, number] { - const r = srgbToLinear(v.x); - const g = srgbToLinear(v.y); - const b = srgbToLinear(v.z); - - const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b; - const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b; - const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b; - - const l_ = Math.cbrt(l); - const m_ = Math.cbrt(m); - const s_ = Math.cbrt(s); - - return [ - 0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_, - 1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_, - 0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_, - ]; -} - -// [L, a, b] Oklab -> sRGB Vec4 -function oklabToVec4(L: number, a: number, b: number, alpha: number): Vec4 { - const l_ = L + 0.3963377774 * a + 0.2158037573 * b; - const m_ = L - 0.1055613458 * a - 0.0638541728 * b; - const s_ = L - 0.0894841775 * a - 1.2914855480 * b; - - const l = l_ * l_ * l_; - const m = m_ * m_ * m_; - const s = s_ * s_ * s_; - - const linR = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s; - const linG = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s; - const linB = -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s; - - return new Vec4( - clamp01(linearToSrgb(Math.max(0, linR))), - clamp01(linearToSrgb(Math.max(0, linG))), - clamp01(linearToSrgb(Math.max(0, linB))), - alpha, - ); -} - -// sRGB Vec4 -> [L, C, H] in Oklch -function vec4ToOklch(v: Vec4): [number, number, number] { - const [L, a, b] = vec4ToOklab(v); - return [L, Math.sqrt(a * a + b * b), Math.atan2(b, a)]; -} - -// Lerp hue angle via shortest arc -function lerpHue(a: number, b: number, t: number): number { - let diff = b - a; - if (diff > Math.PI) diff -= 2 * Math.PI; - if (diff < -Math.PI) diff += 2 * Math.PI; - return a + diff * t; -} - -// Interpolation functions - -function lerpSrgb(a: Vec4, b: Vec4, t: number): Vec4 { - return Vec4.lerp(a, b, t) as Vec4; -} - -function lerpLinearLight(a: Vec4, b: Vec4, t: number): Vec4 { - const aL = new Vec4(srgbToLinear(a.x), srgbToLinear(a.y), srgbToLinear(a.z), a.w); - const bL = new Vec4(srgbToLinear(b.x), srgbToLinear(b.y), srgbToLinear(b.z), b.w); - const mixed = Vec4.lerp(aL, bL, t) as Vec4; - return new Vec4( - clamp01(linearToSrgb(mixed.x)), - clamp01(linearToSrgb(mixed.y)), - clamp01(linearToSrgb(mixed.z)), - mixed.w, - ); -} - -function lerpOklab(a: Vec4, b: Vec4, t: number): Vec4 { - const [La, aa, ba] = vec4ToOklab(a); - const [Lb, ab, bb] = vec4ToOklab(b); - return oklabToVec4( - La + (Lb - La) * t, - aa + (ab - aa) * t, - ba + (bb - ba) * t, - a.w + (b.w - a.w) * t, - ); -} - -function lerpOklch(a: Vec4, b: Vec4, t: number): Vec4 { - const [La, Ca, Ha] = vec4ToOklch(a); - const [Lb, Cb, Hb] = vec4ToOklch(b); - return oklabToVec4( - La + (Lb - La) * t, - (Ca + (Cb - Ca) * t) * Math.cos(lerpHue(Ha, Hb, t)), - (Ca + (Cb - Ca) * t) * Math.sin(lerpHue(Ha, Hb, t)), - a.w + (b.w - a.w) * t, - ); -} - -// Mode definitions - -interface Mode { - name: string; - formula: string; - interpolate: (a: Vec4, b: Vec4, t: number) => Vec4; -} - -const EASING_MODES: Mode[] = [ - { - name: 'Linear', - formula: 'Vec4.lerp(a, b, t)', - interpolate: (a, b, t) => lerpSrgb(a, b, t), - }, - { - name: 'Smoothstep', - formula: 'Vec4.lerp(a, b, t²(3−2t))', - interpolate: (a, b, t) => lerpSrgb(a, b, t * t * (3 - 2 * t)), - }, - { - name: 'Ease In — cubic', - formula: 'Vec4.lerp(a, b, t³)', - interpolate: (a, b, t) => lerpSrgb(a, b, t * t * t), - }, - { - name: 'Ease Out — cubic', - formula: 'Vec4.lerp(a, b, 1−(1−t)³)', - interpolate: (a, b, t) => lerpSrgb(a, b, 1 - (1 - t) ** 3), - }, - { - name: 'Ease In-Out — sine', - formula: 'Vec4.lerp(a, b, −(cos(πt)−1)/2)', - interpolate: (a, b, t) => lerpSrgb(a, b, -(Math.cos(Math.PI * t) - 1) / 2), - }, -]; - -const SPACE_MODES: Mode[] = [ - { - name: 'Gamma-correct (linear light)', - formula: 'linearise -> lerp -> re-linearise', - interpolate: lerpLinearLight, - }, - { - name: 'Oklab', - formula: 'sRGB -> Oklab -> lerp L,a,b -> sRGB', - interpolate: lerpOklab, - }, - { - name: 'Oklch — hue arc', - formula: 'sRGB -> Oklch -> lerp L,C,H -> sRGB', - interpolate: lerpOklch, - }, -]; - -// State - -function hexToVec4(hex: string): Vec4 { - const r = parseInt(hex.slice(1, 3), 16) / 255; - const g = parseInt(hex.slice(3, 5), 16) / 255; - const b = parseInt(hex.slice(5, 7), 16) / 255; - return new Vec4(r, g, b, 1); -} - -function vec4ToCss(v: Vec4): string { - return `rgb(${Math.round(v.x * 255)}, ${Math.round(v.y * 255)}, ${Math.round(v.z * 255)})`; -} - -function fmtVec4(v: Vec4): string { - return `Vec4(${v.x.toFixed(2)}, ${v.y.toFixed(2)}, ${v.z.toFixed(2)}, ${v.w.toFixed(2)})`; -} - -let colA = hexToVec4('#e63b5e'); -let colB = hexToVec4('#22b0f0'); -let t = 0.5; - -// DOM - -const colorAInput = document.getElementById('colorA') as HTMLInputElement; -const colorBInput = document.getElementById('colorB') as HTMLInputElement; -const tSlider = document.getElementById('tSlider') as HTMLInputElement; -const tNum = document.getElementById('tNum') as HTMLInputElement; -const vecAEl = document.getElementById('vecA')!; -const vecBEl = document.getElementById('vecB')!; -const resultSwatch = document.getElementById('result-swatch')!; -const resultVec = document.getElementById('result-vec')!; -const gradPanel = document.getElementById('grad-panel')!; - -// Build gradient strip elements - -interface Strip { - canvas: HTMLCanvasElement; - dot: HTMLDivElement; - val: HTMLSpanElement; - mode: Mode; -} - -function buildStrips(modes: Mode[], sectionTitle: string): Strip[] { - const sectionEl = document.createElement('div'); - sectionEl.className = 'grad-section-header'; - sectionEl.textContent = sectionTitle; - gradPanel.appendChild(sectionEl); - - return modes.map(mode => { - const container = document.createElement('div'); - container.className = 'grad-strip'; - - const header = document.createElement('div'); - header.className = 'grad-header'; - header.innerHTML = `${mode.name}${mode.formula}`; - - const row = document.createElement('div'); - row.className = 'grad-row'; - - const cvs = document.createElement('canvas'); - cvs.className = 'grad-canvas'; - - const dot = document.createElement('div'); - dot.className = 'grad-dot'; - - const val = document.createElement('span'); - val.className = 'grad-val'; - - row.appendChild(cvs); - row.appendChild(dot); - container.appendChild(header); - container.appendChild(row); - container.appendChild(val); - gradPanel.appendChild(container); - - return { canvas: cvs, dot, val, mode }; - }); -} - -const easingStrips = buildStrips(EASING_MODES, 'Easing — in sRGB space'); -const spaceStrips = buildStrips(SPACE_MODES, 'Colour-space interpolation'); -const allStrips = [...easingStrips, ...spaceStrips]; - -// Render - -function renderStrip(strip: Strip) { - const cvs = strip.canvas; - const W = cvs.clientWidth; - const H = cvs.clientHeight; - if (W === 0) return; - - const dpr = window.devicePixelRatio || 1; - cvs.width = W * dpr; - cvs.height = H * dpr; - - const ctx = cvs.getContext('2d')!; - ctx.scale(dpr, dpr); - - for (let px = 0; px < W; px++) { - const pxT = px / (W - 1); - const col = strip.mode.interpolate(colA, colB, pxT); - ctx.fillStyle = vec4ToCss(col); - ctx.fillRect(px, 0, 1, H); - } - - // t marker line - const markerX = t * (W - 1); - ctx.strokeStyle = 'rgba(255,255,255,0.85)'; - ctx.lineWidth = 1.5; - ctx.beginPath(); - ctx.moveTo(markerX, 0); - ctx.lineTo(markerX, H); - ctx.stroke(); -} - -function renderAll() { - vecAEl.textContent = fmtVec4(colA); - vecBEl.textContent = fmtVec4(colB); - - const linearCol = Vec4.lerp(colA, colB, t) as Vec4; - resultSwatch.style.background = vec4ToCss(linearCol); - resultVec.textContent = fmtVec4(linearCol); - - for (const strip of allStrips) { - renderStrip(strip); - const col = strip.mode.interpolate(colA, colB, t); - strip.dot.style.background = vec4ToCss(col); - strip.val.textContent = fmtVec4(col); - } -} - -// Controls wiring - -colorAInput.addEventListener('input', () => { colA = hexToVec4(colorAInput.value); renderAll(); }); -colorBInput.addEventListener('input', () => { colB = hexToVec4(colorBInput.value); renderAll(); }); - -tSlider.addEventListener('input', () => { - t = parseFloat(tSlider.value); - tNum.value = String(t); - renderAll(); -}); - -tNum.addEventListener('change', () => { - t = Math.max(0, Math.min(1, parseFloat(tNum.value))); - tSlider.value = String(t); - renderAll(); -}); - -window.addEventListener('resize', renderAll); - -renderAll(); diff --git a/demos/harmonies-cp.html b/demos/harmonies-cp.html deleted file mode 100644 index 527bda4..0000000 --- a/demos/harmonies-cp.html +++ /dev/null @@ -1,461 +0,0 @@ - - - - - - Colour Harmonies - - - - -
-
- -

Left and right arrows change the hue, up and down change the lightness, Page Up and Page Down change the chroma. Hold Shift for bigger steps.

-

-
-
- - - - -
-
- - - - - diff --git a/demos/harmonies.css b/demos/harmonies.css deleted file mode 100644 index d3fd2c2..0000000 --- a/demos/harmonies.css +++ /dev/null @@ -1,109 +0,0 @@ -@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap'); - -:root { - color-scheme: light; - - --bg: #f0f2f8; - --surface: #ffffff; - --border: rgba(0,0,0,0.08); - --border-hi: rgba(0,0,0,0.15); - --text-mid: #4b5570; - --text-dim: #7880a0; - --green: #0d8040; - --purple: #5533cc; - --amber: #a07000; - --red: #cc2233; - --font: 'Inter', sans-serif; - --toggles-h: 52px; -} - -*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } - -html, body { - height: 100%; - overflow: hidden; - background: var(--bg); - font-family: var(--font); - -webkit-font-smoothing: antialiased; -} - -.harm-wrap { - display: flex; - flex-direction: column; - height: 100%; - background: var(--surface); -} - -.harm-canvas-area { - flex: 1; - overflow: hidden; - position: relative; - min-height: 0; -} - -#harm-canvas { - display: block; - width: 100%; - height: 100%; -} - -/* Inset, since the canvas area clips overflow */ -#harm-canvas:focus-visible { - outline: 2px solid var(--green); - outline-offset: -2px; -} - -.visually-hidden { - position: absolute; - width: 1px; - height: 1px; - overflow: hidden; - clip-path: inset(50%); - white-space: nowrap; -} - -.harm-toggles { - flex-shrink: 0; - display: flex; - justify-content: center; - align-items: center; - gap: 8px; - height: var(--toggles-h); - padding: 0 20px; - border-top: 1px solid var(--border); - background: var(--bg); -} - -.harm-chip { - display: flex; - align-items: center; - gap: 7px; - padding: 5px 14px; - border-radius: 999px; - border: 1px solid var(--border); - background: transparent; - color: var(--text-dim); - font: 500 12px/1 var(--font); - letter-spacing: 0.02em; - cursor: pointer; - transition: border-color 0.15s, color 0.15s; - -webkit-appearance: none; - appearance: none; -} - -.harm-chip.active { - border-color: var(--accent); - color: var(--text-mid); -} - -.harm-dot { - width: 6px; - height: 6px; - border-radius: 50%; - background: var(--accent); - flex-shrink: 0; - opacity: 0.25; - transition: opacity 0.15s; -} - -.harm-chip.active .harm-dot { opacity: 1; } diff --git a/demos/harmonies.html b/demos/harmonies.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/harmonies.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/harmonies.pug b/demos/harmonies.pug deleted file mode 100644 index 06eb7ab..0000000 --- a/demos/harmonies.pug +++ /dev/null @@ -1,105 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Colour Harmonies - -block head - style. - .harm-main { - height: calc(100vh - var(--header-h) - var(--footer-h)); - display: flex; - flex-direction: column; - background: var(--surface); - } - .harm-canvas-area { - flex: 1; - overflow: hidden; - position: relative; - min-height: 0; - } - #harm-canvas { - display: block; - width: 100%; - height: 100%; - } - /* Inset, since the canvas area clips overflow */ - #harm-canvas:focus-visible { - outline: 2px solid var(--focus-ring); - outline-offset: -2px; - } - .harm-toggles { - flex-shrink: 0; - display: flex; - justify-content: center; - align-items: center; - gap: 8px; - height: 54px; - padding: 0 20px; - border-top: 1px solid var(--border); - background: var(--bg); - } - .harm-chip { - display: flex; - align-items: center; - gap: 7px; - padding: 5px 16px; - border-radius: 999px; - border: 1px solid var(--border); - background: transparent; - color: var(--text-dim); - font: 500 var(--fs-sm)/1 var(--font); - letter-spacing: 0.04em; - cursor: pointer; - transition: border-color 0.15s, color 0.15s; - -webkit-appearance: none; - appearance: none; - } - .harm-chip.active { - border-color: var(--accent); - color: var(--text-mid); - } - .harm-dot { - width: 7px; - height: 7px; - border-radius: 50%; - background: var(--accent); - flex-shrink: 0; - opacity: 0.25; - transition: opacity 0.15s; - } - .harm-chip.active .harm-dot { - opacity: 1; - } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Colour Harmonies - -block main - main.harm-main - div.harm-canvas-area#harm-canvas-area - canvas#harm-canvas(tabindex="0" role="slider" aria-label="Base hue" aria-valuemin="0" aria-valuemax="359") - div.harm-toggles - button.harm-chip.active(type="button" data-key="triadic" style="--accent: var(--amber)") - span.harm-dot - span Triadic - button.harm-chip.active(type="button" data-key="analogous" style="--accent: var(--green)") - span.harm-dot - span Analogous - button.harm-chip.active(type="button" data-key="split-comp" style="--accent: var(--purple)") - span.harm-dot - span Split-comp - button.harm-chip.active(type="button" data-key="tetradic" style="--accent: var(--red)") - span.harm-dot - span Tetradic - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right drag · hover to inspect - -block scripts - script(type="module" src="./harmonies.ts") diff --git a/demos/harmonies.ts b/demos/harmonies.ts deleted file mode 100644 index 2eea7ac..0000000 --- a/demos/harmonies.ts +++ /dev/null @@ -1,352 +0,0 @@ -import { Color } from "../src/Color"; - -const canvas = document.getElementById("harm-canvas") as HTMLCanvasElement; -const container = document.getElementById("harm-canvas-area") as HTMLDivElement; - -// ── Harmony definitions ─────────────────────────────────────────────────────── - -const HARMONIES = [ - { key: "triadic", offsets: [120, 240], label: "Triadic", cssVar: "--amber" }, - { key: "analogous", offsets: [-30, -15, 15, 30], label: "Analogous", cssVar: "--green" }, - { key: "split-comp", offsets: [150, 210], label: "Split-comp", cssVar: "--purple" }, - { key: "tetradic", offsets: [90, 180, 270], label: "Tetradic", cssVar: "--red" }, -] as const; - -type HarmKey = typeof HARMONIES[number]["key"]; - -// ── State ───────────────────────────────────────────────────────────────────── - -let baseHue = 200; -let isDragging = false; -const enabled = new Set(HARMONIES.map(h => h.key) as HarmKey[]); - -interface DotInfo { - x: number; y: number; - hue: number; - color: Color; - key: HarmKey | null; - accent: string; - offset: number; - label: string; - r: number; -} - -let dots: DotInfo[] = []; -let hoveredIdx = -1; -let hoveredKey: HarmKey | null = null; - -// ── Geometry ────────────────────────────────────────────────────────────────── - -function hue2angle(hue: number): number { - return (hue / 360) * Math.PI * 2 - Math.PI / 2; -} - -function angle2hue(a: number): number { - return (((a + Math.PI / 2) / (Math.PI * 2)) * 360 + 360) % 360; -} - -function normHue(h: number): number { - return ((h % 360) + 360) % 360; -} - -// ── Draw ────────────────────────────────────────────────────────────────────── - -function draw() { - canvas.setAttribute("aria-valuenow", String(Math.round(baseHue) % 360)); - canvas.setAttribute("aria-valuetext", `${Math.round(baseHue) % 360}°`); - - const W = container.clientWidth; - const H = container.clientHeight; - if (!W || !H) return; - - const dpr = window.devicePixelRatio || 1; - canvas.width = W * dpr; - canvas.height = H * dpr; - canvas.style.width = `${W}px`; - canvas.style.height = `${H}px`; - - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - - const cs = getComputedStyle(document.documentElement); - const bg = cs.getPropertyValue("--surface").trim(); - const border = cs.getPropertyValue("--border").trim(); - - const accentMap: Record = {}; - for (const h of HARMONIES) { - accentMap[h.key] = cs.getPropertyValue(h.cssVar).trim(); - } - - ctx.fillStyle = bg; - ctx.fillRect(0, 0, W, H); - - const cx = W / 2; - const cy = H / 2; - const minDim = Math.min(W, H); - const outerR = minDim * 0.43; - const innerR = minDim * 0.30; - const ringMid = (outerR + innerR) / 2; - const centerR = innerR * 0.55; - - // ── Hue ring ── - const SLICES = 720; - for (let i = 0; i < SLICES; i++) { - const a1 = (i / SLICES) * Math.PI * 2 - Math.PI / 2; - const a2 = ((i + 1) / SLICES) * Math.PI * 2 - Math.PI / 2; - ctx.fillStyle = Color.fromOklch(0.70, 0.13, (i / SLICES) * 360).toCSS(); - ctx.beginPath(); - ctx.arc(cx, cy, outerR, a1, a2); - ctx.arc(cx, cy, innerR, a2, a1, true); - ctx.closePath(); - ctx.fill(); - } - - // Inner dark fill - ctx.fillStyle = bg; - ctx.beginPath(); - ctx.arc(cx, cy, innerR, 0, Math.PI * 2); - ctx.fill(); - - // Centre swatch - const baseColor = Color.fromOklch(0.70, 0.13, baseHue); - ctx.fillStyle = baseColor.toCSS(); - ctx.beginPath(); - ctx.arc(cx, cy, centerR, 0, Math.PI * 2); - ctx.fill(); - ctx.strokeStyle = border; - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.arc(cx, cy, centerR, 0, Math.PI * 2); - ctx.stroke(); - - // ── Build dot list ── - function dotPos(hue: number): [number, number] { - const a = hue2angle(hue); - return [cx + Math.cos(a) * ringMid, cy + Math.sin(a) * ringMid]; - } - - const newDots: DotInfo[] = []; - - for (const h of HARMONIES) { - if (!enabled.has(h.key)) continue; - for (const offset of h.offsets) { - const hue = normHue(baseHue + offset); - const [x, y] = dotPos(hue); - newDots.push({ - x, y, hue, - color: Color.fromOklch(0.70, 0.13, hue), - key: h.key, accent: accentMap[h.key], - offset, label: h.label, r: 9, - }); - } - } - - const [bx, by] = dotPos(baseHue); - newDots.push({ - x: bx, y: by, hue: baseHue, color: baseColor, - key: null, accent: "rgba(255,255,255,0.85)", - offset: 0, label: "Base", r: 13, - }); - - dots = newDots; - - // ── Connection lines ── - for (const dot of dots) { - if (!dot.key) continue; - const lit = dot.key === hoveredKey; - ctx.strokeStyle = dot.accent + (lit ? "55" : "18"); - ctx.lineWidth = 1; - ctx.setLineDash([3, 4]); - ctx.beginPath(); - ctx.moveTo(cx, cy); - ctx.lineTo(dot.x, dot.y); - ctx.stroke(); - } - ctx.setLineDash([]); - - // ── Dots ── - let tooltipDot: DotInfo | null = null; - - for (let i = 0; i < dots.length; i++) { - const dot = dots[i]; - const isHov = i === hoveredIdx; - const isSib = !!(dot.key && dot.key === hoveredKey && !isHov); - const r = isHov ? dot.r * 1.5 : isSib ? dot.r * 1.15 : dot.r; - - if (isHov && dot.key) { - ctx.shadowColor = dot.accent; - ctx.shadowBlur = 16; - } - - ctx.beginPath(); - ctx.arc(dot.x, dot.y, r, 0, Math.PI * 2); - ctx.fillStyle = dot.color.toCSS(); - ctx.fill(); - ctx.shadowBlur = 0; - - ctx.strokeStyle = dot.key ? dot.accent : "rgba(255,255,255,0.85)"; - ctx.lineWidth = isHov ? 2 : 1.5; - ctx.beginPath(); - ctx.arc(dot.x, dot.y, r, 0, Math.PI * 2); - ctx.stroke(); - - if (isHov && dot.key) tooltipDot = dot; - } - - // ── Tooltip ── - if (tooltipDot) { - const d = tooltipDot; - const sign = d.offset > 0 ? "+" : ""; - const line1 = d.color.toHex(); - const line2 = `${d.label} ${sign}${d.offset}°`; - - ctx.font = `500 11px var(--font)`; - const tw = Math.max(ctx.measureText(line1).width, ctx.measureText(line2).width) + 18; - const th = 38; - const gap = d.r * 1.5 + 10; - - let tx = d.x + gap; - let ty = d.y - th / 2; - if (tx + tw > W - 8) tx = d.x - gap - tw; - ty = Math.max(8, Math.min(ty, H - th - 8)); - - // Fresh path, or the fill would also cover the last dot drawn - ctx.beginPath(); - (ctx as any).roundRect(tx, ty, tw, th, 4); - ctx.fillStyle = "rgba(0,0,0,0.84)"; - ctx.fill(); - ctx.strokeStyle = d.accent + "40"; - ctx.lineWidth = 1; - ctx.stroke(); - - ctx.textAlign = "left"; - ctx.fillStyle = d.accent; - ctx.fillText(line1, tx + 9, ty + 14); - ctx.fillStyle = "rgba(255,255,255,0.35)"; - ctx.fillText(line2, tx + 9, ty + 28); - } -} - -// ── Interaction ─────────────────────────────────────────────────────────────── - -function angleFromMouse(e: MouseEvent): number { - const r = canvas.getBoundingClientRect(); - return Math.atan2( - e.clientY - r.top - r.height / 2, - e.clientX - r.left - r.width / 2, - ); -} - -function checkHover(e: MouseEvent) { - const r = canvas.getBoundingClientRect(); - const mx = e.clientX - r.left; - const my = e.clientY - r.top; - - let best = -1, bestDist = Infinity; - let bestKey: HarmKey | null = null; - - for (let i = 0; i < dots.length; i++) { - const d = dots[i]; - if (!d.key) continue; - const dx = mx - d.x, dy = my - d.y; - const dist = Math.sqrt(dx * dx + dy * dy); - if (dist < d.r * 2.2 && dist < bestDist) { - best = i; bestDist = dist; bestKey = d.key; - } - } - - if (best !== hoveredIdx) { - hoveredIdx = best; - hoveredKey = bestKey; - draw(); - } -} - -canvas.addEventListener("mousedown", e => { - isDragging = true; - hoveredIdx = -1; - hoveredKey = null; - canvas.style.cursor = "grabbing"; - baseHue = angle2hue(angleFromMouse(e)); - draw(); -}); - -window.addEventListener("mousemove", e => { - if (isDragging) { - baseHue = angle2hue(angleFromMouse(e)); - draw(); - } else { - checkHover(e); - } -}); - -window.addEventListener("mouseup", () => { - if (!isDragging) return; - isDragging = false; - canvas.style.cursor = "grab"; -}); - -// Touch -function touchAngle(t: Touch): number { - const r = canvas.getBoundingClientRect(); - return Math.atan2( - t.clientY - r.top - r.height / 2, - t.clientX - r.left - r.width / 2, - ); -} - -canvas.addEventListener("touchstart", e => { - e.preventDefault(); - isDragging = true; - baseHue = angle2hue(touchAngle(e.touches[0])); - draw(); -}, { passive: false }); - -canvas.addEventListener("touchmove", e => { - e.preventDefault(); - baseHue = angle2hue(touchAngle(e.touches[0])); - draw(); -}, { passive: false }); - -canvas.addEventListener("touchend", () => { isDragging = false; }); - -// Keyboard — the canvas is a role="slider" for the base hue -const HUE_KEYS: Record number> = { - ArrowRight: (h, big) => h + (big ? 15 : 1), - ArrowUp: (h, big) => h + (big ? 15 : 1), - ArrowLeft: (h, big) => h - (big ? 15 : 1), - ArrowDown: (h, big) => h - (big ? 15 : 1), - PageUp: h => h + 30, - PageDown: h => h - 30, - Home: () => 0, - End: () => 359, -}; - -canvas.addEventListener("keydown", e => { - const step = HUE_KEYS[e.key]; - if (!step) return; - e.preventDefault(); - baseHue = normHue(Math.round(step(baseHue, e.shiftKey))); - draw(); -}); - -// ── Toggle chips ────────────────────────────────────────────────────────────── - -document.querySelectorAll(".harm-chip").forEach(btn => { - btn.addEventListener("click", () => { - const key = btn.dataset.key as HarmKey; - if (enabled.has(key)) { - enabled.delete(key); - btn.classList.remove("active"); - } else { - enabled.add(key); - btn.classList.add("active"); - } - if (hoveredKey === key) { hoveredIdx = -1; hoveredKey = null; } - draw(); - }); -}); - -window.addEventListener("resize", draw); -canvas.style.cursor = "grab"; -draw(); diff --git a/demos/index.html b/demos/index.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/index.pug b/demos/index.pug deleted file mode 100644 index 024ea88..0000000 --- a/demos/index.pug +++ /dev/null @@ -1,46 +0,0 @@ -extends ./_layout - -block title - | wtc-math — playground - -append header-links - a.header-link(href="./docs/index.html") docs ↗ - -block main - nav.tab-nav(role="tablist") - button.tab-btn(role="tab" data-tab="0") Vec2 - button.tab-btn(role="tab" data-tab="1") Vec3 - button.tab-btn(role="tab" data-tab="2") Vec4 - button.tab-btn(role="tab" data-tab="3") Mat2 - button.tab-btn(role="tab" data-tab="4") Mat3 - button.tab-btn(role="tab" data-tab="5") Mat4 - button.tab-btn(role="tab" data-tab="6") Quat - - main.main - div.col-left - div.intro - p.intro-text A lightweight math library for JavaScript — vectors, matrices, and quaternions for 3D graphics and simulations. No dependencies. - div.intro-install - code.install-cmd npm install wtc-math - div.intro-links - a.intro-link(href="https://github.com/wethegit/wtc-math" target="_blank" rel="noopener") github ↗ - a.intro-link(href="./docs/index.html") docs ↗ - div.tab-desc#tab-desc - div.examples#examples(role="list") - - div.tryit - div.tryit-header - span.tryit-label try it - span.tryit-hint all classes available in scope - textarea.tryit-input#tryit-input(spellcheck="false" rows="2") - div.tryit-output - span.output-prompt › - span.output-value#output-value — - - div.col-right - div.canvas-wrap - canvas#canvas - div.canvas-legend#canvas-legend - -block scripts - script(type="module" src="./main.ts") diff --git a/demos/main.ts b/demos/main.ts deleted file mode 100644 index db004e8..0000000 --- a/demos/main.ts +++ /dev/null @@ -1,1130 +0,0 @@ -import { Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Quat } from '../src/index'; - -// Types - -interface Input { - label: string; - name: string; - value: number; - min: number; - max: number; - step: number; -} - -interface Example { - id: string; - title: string; - inputs: Input[]; - preview: (v: Record) => string; - compute: (v: Record) => unknown; - visualize: (ctx: CanvasRenderingContext2D, size: number, v: Record) => void; - legend?: Array<{ label: string; color: string }>; -} - -interface Tab { - name: string; - description: string; - placeholder: string; - examples: Example[]; -} - -// Palette - -const P = { - green: '#0d8040', - purple: '#5533cc', - amber: '#a07000', - dim: 'rgba(0,0,0,0.07)', - axis: 'rgba(0,0,0,0.14)', - grid: 'rgba(0,0,0,0.04)', - bg: '#f0f2f8', -}; - -// Canvas Utilities - -function setupCanvas(canvas: HTMLCanvasElement) { - const wrap = canvas.parentElement!; - const size = Math.min(wrap.clientWidth - 32, wrap.clientHeight - 32); - const dpr = window.devicePixelRatio || 1; - canvas.width = size * dpr; - canvas.height = size * dpr; - canvas.style.width = `${size}px`; - canvas.style.height = `${size}px`; - const ctx = canvas.getContext('2d')!; - ctx.scale(dpr, dpr); - return { ctx, size }; -} - -function n2(v: number) { - const s = parseFloat(v.toFixed(2)).toString(); - return s; -} - -function drawGrid(ctx: CanvasRenderingContext2D, size: number) { - const cx = size / 2, cy = size / 2; - const unit = size / 10; - - ctx.clearRect(0, 0, size, size); - - // minor grid - ctx.strokeStyle = P.grid; - ctx.lineWidth = 1; - for (let i = -6; i <= 6; i++) { - ctx.beginPath(); ctx.moveTo(cx + i * unit, 0); ctx.lineTo(cx + i * unit, size); ctx.stroke(); - ctx.beginPath(); ctx.moveTo(0, cy + i * unit); ctx.lineTo(size, cy + i * unit); ctx.stroke(); - } - - // axes - ctx.strokeStyle = P.axis; - ctx.lineWidth = 1; - ctx.beginPath(); ctx.moveTo(0, cy); ctx.lineTo(size, cy); ctx.stroke(); - ctx.beginPath(); ctx.moveTo(cx, 0); ctx.lineTo(cx, size); ctx.stroke(); - - // axis labels - ctx.fillStyle = 'rgba(0,0,0,0.18)'; - ctx.font = '9px "IBM Plex Mono"'; - ctx.textAlign = 'right'; - ctx.fillText('+x', size - 3, cy - 4); - ctx.textAlign = 'left'; - ctx.fillText('+y', cx + 4, 11); - - return { cx, cy, unit }; -} - -function arrow( - ctx: CanvasRenderingContext2D, - ox: number, oy: number, - tx: number, ty: number, - color: string, - glow = true -) { - if (Math.abs(tx - ox) < 0.5 && Math.abs(ty - oy) < 0.5) return; - - ctx.save(); - if (glow) { ctx.shadowColor = color; ctx.shadowBlur = 10; } - - ctx.strokeStyle = color; - ctx.fillStyle = color; - ctx.lineWidth = 1.5; - - ctx.beginPath(); - ctx.moveTo(ox, oy); - ctx.lineTo(tx, ty); - ctx.stroke(); - - const angle = Math.atan2(ty - oy, tx - ox); - const headLen = 8; - ctx.beginPath(); - ctx.moveTo(tx, ty); - ctx.lineTo(tx - headLen * Math.cos(angle - 0.42), ty - headLen * Math.sin(angle - 0.42)); - ctx.lineTo(tx - headLen * Math.cos(angle + 0.42), ty - headLen * Math.sin(angle + 0.42)); - ctx.closePath(); - ctx.fill(); - - ctx.restore(); -} - -function label( - ctx: CanvasRenderingContext2D, - x: number, y: number, - text: string, - color: string -) { - ctx.fillStyle = color; - ctx.font = '10px "IBM Plex Mono"'; - ctx.textAlign = 'left'; - ctx.textBaseline = 'alphabetic'; - ctx.fillText(text, x + 5, y - 5); -} - -function dot(ctx: CanvasRenderingContext2D, x: number, y: number, color: string, r = 4) { - ctx.save(); - ctx.shadowColor = color; - ctx.shadowBlur = 12; - ctx.fillStyle = color; - ctx.beginPath(); - ctx.arc(x, y, r, 0, Math.PI * 2); - ctx.fill(); - ctx.restore(); -} - -// Vec3 Isometric - -const ISO_X: [number, number] = [Math.sqrt(3) / 2, 0.5]; -const ISO_Y: [number, number] = [0, -1 ]; -const ISO_Z: [number, number] = [-Math.sqrt(3) / 2, 0.5]; - -function toIso(x: number, y: number, z: number, scale: number): [number, number] { - return [ - (x * ISO_X[0] + y * ISO_Y[0] + z * ISO_Z[0]) * scale, - (x * ISO_X[1] + y * ISO_Y[1] + z * ISO_Z[1]) * scale, - ]; -} - -interface IsoVector { x: number; y: number; z: number; color: string; label: string; } - -function drawIso(ctx: CanvasRenderingContext2D, size: number, vectors: IsoVector[]) { - const cx = size / 2, cy = size * 0.55; - const scale = size / 9; - - ctx.clearRect(0, 0, size, size); - - // Axis lines - const axLen = 3.2; - [ - { v: [axLen, 0, 0] as [number,number,number], c: 'rgba(0,0,0,0.12)', t: 'x' }, - { v: [0, axLen, 0] as [number,number,number], c: 'rgba(0,0,0,0.12)', t: 'y' }, - { v: [0, 0, axLen] as [number,number,number], c: 'rgba(0,0,0,0.12)', t: 'z' }, - ].forEach(({ v, c, t }) => { - const [sx, sy] = toIso(...v, scale); - ctx.strokeStyle = c; - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.moveTo(cx, cy); - ctx.lineTo(cx + sx, cy + sy); - ctx.stroke(); - ctx.fillStyle = 'rgba(0,0,0,0.2)'; - ctx.font = '9px "IBM Plex Mono"'; - ctx.fillText(t, cx + sx + 4, cy + sy + 4); - }); - - // Vectors - vectors.forEach(vec => { - const [sx, sy] = toIso(vec.x, vec.y, vec.z, scale); - arrow(ctx, cx, cy, cx + sx, cy + sy, vec.color); - label(ctx, cx + sx, cy + sy, vec.label, vec.color); - }); -} - -// Matrix Grid - -function drawMatrixGrid( - ctx: CanvasRenderingContext2D, - size: number, - values: number[], - rows: number, - cols: number -) { - ctx.clearRect(0, 0, size, size); - - const pad = 20; - const cellW = (size - pad * 2) / cols; - const cellH = Math.min((size - pad * 2) / rows, cellW); - const startX = pad; - const startY = (size - cellH * rows) / 2; - - const maxAbs = Math.max(...values.map(Math.abs), 0.0001); - - for (let r = 0; r < rows; r++) { - for (let c = 0; c < cols; c++) { - const v = values[r * cols + c]; - const t = v / maxAbs; - const x = startX + c * cellW; - const y = startY + r * cellH; - - // Background - const alpha = Math.min(Math.abs(t) * 0.18, 0.18); - ctx.fillStyle = t > 0 - ? `rgba(13,128,64,${alpha})` - : t < 0 - ? `rgba(85,51,204,${alpha})` - : 'rgba(0,0,0,0.02)'; - ctx.fillRect(x + 1, y + 1, cellW - 2, cellH - 2); - - // Border - ctx.strokeStyle = 'rgba(0,0,0,0.07)'; - ctx.lineWidth = 1; - ctx.strokeRect(x + 0.5, y + 0.5, cellW - 1, cellH - 1); - - // Value - const isZero = Math.abs(v) < 0.0001; - ctx.fillStyle = isZero - ? 'rgba(0,0,0,0.2)' - : t > 0 - ? P.green - : P.purple; - ctx.font = `${Math.min(cellW * 0.28, 13)}px "IBM Plex Mono"`; - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - const disp = isZero ? '0' : parseFloat(v.toFixed(3)).toString(); - ctx.fillText(disp, x + cellW / 2, y + cellH / 2); - } - } - - ctx.textAlign = 'left'; - ctx.textBaseline = 'alphabetic'; -} - -// Result Formatter - -function fmt(v: number) { - return parseFloat(v.toFixed(4)).toString(); -} - -function formatResult(v: unknown): string { - if (v === null || v === undefined) return String(v); - if (typeof v === 'number') return fmt(v); - if (typeof v === 'boolean') return String(v); - if (typeof v === 'string') return `"${v}"`; - - const o = v as Record; - - // Detect by available components - if (typeof o.x === 'number' && typeof o.y === 'number') { - if (typeof o.z === 'number' && typeof o.w === 'number') - return `{ x:${fmt(o.x)}, y:${fmt(o.y)}, z:${fmt(o.z)}, w:${fmt(o.w)} }`; - if (typeof o.z === 'number') - return `{ x:${fmt(o.x)}, y:${fmt(o.y)}, z:${fmt(o.z)} }`; - return `{ x:${fmt(o.x)}, y:${fmt(o.y)} }`; - } - - if (Array.isArray(o.array)) - return `[ ${(o.array as number[]).map(fmt).join(', ')} ]`; - - return JSON.stringify(v); -} - -// Tab Definitions - -const TABS: Tab[] = [ - - // Vec2 - { - name: 'Vec2', - description: '2D vector — x, y components. Supports add, subtract, scale, rotate, dot product, and lerp.', - placeholder: "new Vec2(1, 2).addNew(new Vec2(3, 4))", - examples: [ - - { - id: 'v2-add', - title: 'Add', - inputs: [ - { label: 'a.x', name: 'ax', value: 2, min: -5, max: 5, step: 0.1 }, - { label: 'a.y', name: 'ay', value: 1, min: -5, max: 5, step: 0.1 }, - { label: 'b.x', name: 'bx', value: -1, min: -5, max: 5, step: 0.1 }, - { label: 'b.y', name: 'by', value: 3, min: -5, max: 5, step: 0.1 }, - ], - preview: (v) => `new Vec2(${v.ax},${v.ay}).addNew(new Vec2(${v.bx},${v.by}))`, - compute: (v) => new Vec2(v.ax, v.ay).addNew(new Vec2(v.bx, v.by)), - legend: [ - { label: 'a', color: P.green }, - { label: 'b', color: P.purple }, - { label: 'a + b', color: P.amber }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - const [rx, ry] = [v.ax + v.bx, v.ay + v.by]; - - // Parallelogram ghost lines - ctx.setLineDash([3, 4]); - ctx.strokeStyle = 'rgba(0,0,0,0.1)'; - ctx.lineWidth = 1; - ctx.beginPath(); ctx.moveTo(cx + v.ax*u, cy - v.ay*u); ctx.lineTo(cx + rx*u, cy - ry*u); ctx.stroke(); - ctx.beginPath(); ctx.moveTo(cx + v.bx*u, cy - v.by*u); ctx.lineTo(cx + rx*u, cy - ry*u); ctx.stroke(); - ctx.setLineDash([]); - - arrow(ctx, cx, cy, cx + v.ax*u, cy - v.ay*u, P.green); - arrow(ctx, cx, cy, cx + v.bx*u, cy - v.by*u, P.purple); - arrow(ctx, cx, cy, cx + rx*u, cy - ry*u, P.amber); - - label(ctx, cx + v.ax*u, cy - v.ay*u, `a`, P.green); - label(ctx, cx + v.bx*u, cy - v.by*u, `b`, P.purple); - label(ctx, cx + rx*u, cy - ry*u, `a+b`, P.amber); - }, - }, - - { - id: 'v2-scale', - title: 'Scale', - inputs: [ - { label: 'x', name: 'x', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 'y', name: 'y', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 's', name: 's', value: 2, min: -4, max: 4, step: 0.1 }, - ], - preview: (v) => `new Vec2(${v.x},${v.y}).scaleNew(${v.s})`, - compute: (v) => new Vec2(v.x, v.y).scaleNew(v.s), - legend: [ - { label: 'v', color: P.green }, - { label: 'v × s', color: P.amber }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - arrow(ctx, cx, cy, cx + v.x*u, cy - v.y*u, P.green); - arrow(ctx, cx, cy, cx + v.x*v.s*u, cy - v.y*v.s*u, P.amber); - label(ctx, cx + v.x*u, cy - v.y*u, `v`, P.green); - label(ctx, cx + v.x*v.s*u, cy - v.y*v.s*u, `v×${n2(v.s)}`, P.amber); - }, - }, - - { - id: 'v2-dot', - title: 'Dot Product', - inputs: [ - { label: 'a.x', name: 'ax', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 'a.y', name: 'ay', value: 0, min: -4, max: 4, step: 0.1 }, - { label: 'b.x', name: 'bx', value: 0.7, min: -4, max: 4, step: 0.1 }, - { label: 'b.y', name: 'by', value: 0.7, min: -4, max: 4, step: 0.1 }, - ], - preview: (v) => `new Vec2(${v.ax},${v.ay}).dot(new Vec2(${v.bx},${v.by}))`, - compute: (v) => new Vec2(v.ax, v.ay).dot(new Vec2(v.bx, v.by)), - legend: [ - { label: 'a', color: P.green }, - { label: 'b', color: P.purple }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - const a = new Vec2(v.ax, v.ay); - const b = new Vec2(v.bx, v.by); - const d = a.dot(b); - - arrow(ctx, cx, cy, cx + v.ax*u, cy - v.ay*u, P.green); - arrow(ctx, cx, cy, cx + v.bx*u, cy - v.by*u, P.purple); - - // Angle arc - const ang1 = Math.atan2(-v.ay, v.ax); - const ang2 = Math.atan2(-v.by, v.bx); - ctx.save(); - ctx.strokeStyle = P.amber; - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.arc(cx, cy, 22, Math.min(ang1, ang2), Math.max(ang1, ang2)); - ctx.stroke(); - ctx.restore(); - - label(ctx, cx + v.ax*u, cy - v.ay*u, 'a', P.green); - label(ctx, cx + v.bx*u, cy - v.by*u, 'b', P.purple); - - ctx.fillStyle = P.amber; - ctx.font = '11px "IBM Plex Mono"'; - ctx.textAlign = 'left'; - ctx.fillText(`· = ${fmt(d)}`, cx + 26, cy - 26); - }, - }, - - { - id: 'v2-rotate', - title: 'Rotate', - inputs: [ - { label: 'x', name: 'x', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 'y', name: 'y', value: 0, min: -4, max: 4, step: 0.1 }, - { label: 'deg', name: 'deg', value: 45, min: -360, max: 360, step: 1 }, - ], - preview: (v) => `new Vec2(${v.x},${v.y}).rotateNew(${v.deg}*Math.PI/180)`, - compute: (v) => new Vec2(v.x, v.y).rotateNew(v.deg * Math.PI / 180), - legend: [ - { label: 'original', color: P.green }, - { label: 'rotated', color: P.amber }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - const r = new Vec2(v.x, v.y).rotateNew(v.deg * Math.PI / 180); - - // Arc - const len = Math.sqrt(v.x**2 + v.y**2); - const ang0 = Math.atan2(-v.y, v.x); - const ang1 = ang0 - v.deg * Math.PI / 180; - ctx.save(); - ctx.strokeStyle = 'rgba(160,112,0,0.3)'; - ctx.lineWidth = 1; - ctx.setLineDash([3, 4]); - ctx.beginPath(); - const [as, ae] = ang1 < ang0 ? [ang1, ang0] : [ang0, ang1]; - ctx.arc(cx, cy, len * u, as, ae); - ctx.stroke(); - ctx.setLineDash([]); - ctx.restore(); - - arrow(ctx, cx, cy, cx + v.x*u, cy - v.y*u, P.green); - arrow(ctx, cx, cy, cx + r.x*u, cy - r.y*u, P.amber); - label(ctx, cx + v.x*u, cy - v.y*u, 'v', P.green); - label(ctx, cx + r.x*u, cy - r.y*u, `${v.deg}°`, P.amber); - }, - }, - - { - id: 'v2-lerp', - title: 'Lerp', - inputs: [ - { label: 'a.x', name: 'ax', value: -2, min: -4, max: 4, step: 0.1 }, - { label: 'a.y', name: 'ay', value: -1, min: -4, max: 4, step: 0.1 }, - { label: 'b.x', name: 'bx', value: 3, min: -4, max: 4, step: 0.1 }, - { label: 'b.y', name: 'by', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 't', name: 't', value: 0.5, min: 0, max: 1, step: 0.01 }, - ], - preview: (v) => `Vec2.lerp(new Vec2(${v.ax},${v.ay}), new Vec2(${v.bx},${v.by}), ${v.t})`, - compute: (v) => Vec2.lerp(new Vec2(v.ax, v.ay), new Vec2(v.bx, v.by), v.t), - legend: [ - { label: 'a', color: P.green }, - { label: 'b', color: P.purple }, - { label: `t`, color: P.amber }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - const r = Vec2.lerp(new Vec2(v.ax, v.ay), new Vec2(v.bx, v.by), v.t); - - ctx.setLineDash([4, 5]); - ctx.strokeStyle = 'rgba(0,0,0,0.1)'; - ctx.lineWidth = 1; - ctx.beginPath(); - ctx.moveTo(cx + v.ax*u, cy - v.ay*u); - ctx.lineTo(cx + v.bx*u, cy - v.by*u); - ctx.stroke(); - ctx.setLineDash([]); - - dot(ctx, cx + v.ax*u, cy - v.ay*u, P.green, 5); - dot(ctx, cx + v.bx*u, cy - v.by*u, P.purple, 5); - dot(ctx, cx + r.x*u, cy - r.y*u, P.amber, 6); - - label(ctx, cx + v.ax*u, cy - v.ay*u, 'a', P.green); - label(ctx, cx + v.bx*u, cy - v.by*u, 'b', P.purple); - label(ctx, cx + r.x*u, cy - r.y*u, `t=${v.t}`, P.amber); - }, - }, - ], - }, - - // Vec3 - { - name: 'Vec3', - description: '3D vector — x, y, z components. Supports cross product, dot product, normalise, lerp.', - placeholder: "new Vec3(1,0,0).crossNew(new Vec3(0,1,0))", - examples: [ - - { - id: 'v3-add', - title: 'Add', - inputs: [ - { label: 'a.x', name: 'ax', value: 1, min: -3, max: 3, step: 0.1 }, - { label: 'a.y', name: 'ay', value: 2, min: -3, max: 3, step: 0.1 }, - { label: 'a.z', name: 'az', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'b.x', name: 'bx', value: 1, min: -3, max: 3, step: 0.1 }, - { label: 'b.y', name: 'by', value: -1, min: -3, max: 3, step: 0.1 }, - { label: 'b.z', name: 'bz', value: 2, min: -3, max: 3, step: 0.1 }, - ], - preview: (v) => `new Vec3(${v.ax},${v.ay},${v.az}).addNew(new Vec3(${v.bx},${v.by},${v.bz}))`, - compute: (v) => new Vec3(v.ax, v.ay, v.az).addNew(new Vec3(v.bx, v.by, v.bz)), - legend: [ - { label: 'a', color: P.green }, - { label: 'b', color: P.purple }, - { label: 'a + b', color: P.amber }, - ], - visualize(ctx, size, v) { - drawIso(ctx, size, [ - { x: v.ax, y: v.ay, z: v.az, color: P.green, label: 'a' }, - { x: v.bx, y: v.by, z: v.bz, color: P.purple, label: 'b' }, - { x: v.ax+v.bx, y: v.ay+v.by, z: v.az+v.bz, color: P.amber, label: 'a+b' }, - ]); - }, - }, - - { - id: 'v3-cross', - title: 'Cross Product', - inputs: [ - { label: 'a.x', name: 'ax', value: 1, min: -3, max: 3, step: 0.1 }, - { label: 'a.y', name: 'ay', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'a.z', name: 'az', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'b.x', name: 'bx', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'b.y', name: 'by', value: 1, min: -3, max: 3, step: 0.1 }, - { label: 'b.z', name: 'bz', value: 0, min: -3, max: 3, step: 0.1 }, - ], - preview: (v) => `new Vec3(${v.ax},${v.ay},${v.az}).crossNew(new Vec3(${v.bx},${v.by},${v.bz}))`, - compute: (v) => new Vec3(v.ax, v.ay, v.az).crossNew(new Vec3(v.bx, v.by, v.bz)), - legend: [ - { label: 'a', color: P.green }, - { label: 'b', color: P.purple }, - { label: 'a×b', color: P.amber }, - ], - visualize(ctx, size, v) { - const c = new Vec3(v.ax, v.ay, v.az).crossNew(new Vec3(v.bx, v.by, v.bz)); - drawIso(ctx, size, [ - { x: v.ax, y: v.ay, z: v.az, color: P.green, label: 'a' }, - { x: v.bx, y: v.by, z: v.bz, color: P.purple, label: 'b' }, - { x: c.x, y: c.y, z: c.z, color: P.amber, label: 'a×b' }, - ]); - }, - }, - - { - id: 'v3-normalise', - title: 'Normalise', - inputs: [ - { label: 'x', name: 'x', value: 3, min: -5, max: 5, step: 0.1 }, - { label: 'y', name: 'y', value: 1, min: -5, max: 5, step: 0.1 }, - { label: 'z', name: 'z', value: 2, min: -5, max: 5, step: 0.1 }, - ], - preview: (v) => `new Vec3(${v.x},${v.y},${v.z}).normaliseNew()`, - compute: (v) => new Vec3(v.x, v.y, v.z).normaliseNew(), - legend: [ - { label: 'v', color: P.green }, - { label: 'n̂', color: P.amber }, - ], - visualize(ctx, size, v) { - const n = new Vec3(v.x, v.y, v.z).normaliseNew(); - drawIso(ctx, size, [ - { x: v.x, y: v.y, z: v.z, color: P.green, label: 'v' }, - { x: n.x, y: n.y, z: n.z, color: P.amber, label: '|v|=1' }, - ]); - }, - }, - - { - id: 'v3-dot', - title: 'Dot Product', - inputs: [ - { label: 'a.x', name: 'ax', value: 1, min: -3, max: 3, step: 0.1 }, - { label: 'a.y', name: 'ay', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'a.z', name: 'az', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'b.x', name: 'bx', value: 0.5, min: -3, max: 3, step: 0.1 }, - { label: 'b.y', name: 'by', value: 0.5, min: -3, max: 3, step: 0.1 }, - { label: 'b.z', name: 'bz', value: 0.7, min: -3, max: 3, step: 0.1 }, - ], - preview: (v) => `new Vec3(${v.ax},${v.ay},${v.az}).dot(new Vec3(${v.bx},${v.by},${v.bz}))`, - compute: (v) => new Vec3(v.ax, v.ay, v.az).dot(new Vec3(v.bx, v.by, v.bz)), - legend: [ - { label: 'a', color: P.green }, - { label: 'b', color: P.purple }, - ], - visualize(ctx, size, v) { - drawIso(ctx, size, [ - { x: v.ax, y: v.ay, z: v.az, color: P.green, label: 'a' }, - { x: v.bx, y: v.by, z: v.bz, color: P.purple, label: 'b' }, - ]); - }, - }, - ], - }, - - // Vec4 - { - name: 'Vec4', - description: '4D vector — x, y, z, w components. Basis for quaternions and homogeneous coordinates.', - placeholder: "new Vec4(1,2,3,1).addNew(new Vec4(0,1,0,0))", - examples: [ - - { - id: 'v4-create', - title: 'Create', - inputs: [ - { label: 'x', name: 'x', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 'y', name: 'y', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 'z', name: 'z', value: 3, min: -4, max: 4, step: 0.1 }, - { label: 'w', name: 'w', value: 1, min: -4, max: 4, step: 0.1 }, - ], - preview: (v) => `new Vec4(${v.x},${v.y},${v.z},${v.w})`, - compute: (v) => new Vec4(v.x, v.y, v.z, v.w), - visualize(ctx, size, v) { - drawMatrixGrid(ctx, size, [v.x, v.y, v.z, v.w], 1, 4); - }, - }, - - { - id: 'v4-add', - title: 'Add', - inputs: [ - { label: 'a.x', name: 'ax', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 'a.y', name: 'ay', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 'a.z', name: 'az', value: 3, min: -4, max: 4, step: 0.1 }, - { label: 'a.w', name: 'aw', value: 0, min: -4, max: 4, step: 0.1 }, - { label: 'b.x', name: 'bx', value: -1, min: -4, max: 4, step: 0.1 }, - { label: 'b.y', name: 'by', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 'b.z', name: 'bz', value: -1, min: -4, max: 4, step: 0.1 }, - { label: 'b.w', name: 'bw', value: 1, min: -4, max: 4, step: 0.1 }, - ], - preview: (v) => `new Vec4(${v.ax},${v.ay},${v.az},${v.aw}).addNew(new Vec4(${v.bx},${v.by},${v.bz},${v.bw}))`, - compute: (v) => new Vec4(v.ax, v.ay, v.az, v.aw).addNew(new Vec4(v.bx, v.by, v.bz, v.bw)), - visualize(ctx, size, v) { - const r = new Vec4(v.ax, v.ay, v.az, v.aw).addNew(new Vec4(v.bx, v.by, v.bz, v.bw)); - drawMatrixGrid(ctx, size, [ - v.ax, v.ay, v.az, v.aw, - v.bx, v.by, v.bz, v.bw, - r.x, r.y, r.z, r.w, - ], 3, 4); - }, - }, - ], - }, - - // Mat2 - { - name: 'Mat2', - description: '2×2 matrix — rotation, scaling in 2D. Can transform Vec2 via transformByMat2.', - placeholder: "Mat2.fromAngle(Math.PI / 4)", - examples: [ - - { - id: 'm2-identity', - title: 'Identity', - inputs: [], - preview: () => `Mat2.identity()`, - compute: () => Mat2.identity(), - visualize(ctx, size) { - drawMatrixGrid(ctx, size, Mat2.identity().array, 2, 2); - }, - }, - - { - id: 'm2-rotate', - title: 'Rotation', - inputs: [ - { label: 'angle (°)', name: 'deg', value: 45, min: -180, max: 180, step: 1 }, - ], - preview: (v) => `Mat2.fromAngle(${v.deg} * Math.PI / 180)`, - compute: (v) => Mat2.fromAngle(v.deg * Math.PI / 180), - visualize(ctx, size, v) { - drawMatrixGrid(ctx, size, Mat2.fromAngle(v.deg * Math.PI / 180).array, 2, 2); - }, - }, - - { - id: 'm2-transform', - title: 'Transform Vec2', - inputs: [ - { label: 'v.x', name: 'vx', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 'v.y', name: 'vy', value: 0, min: -4, max: 4, step: 0.1 }, - { label: 'angle (°)', name: 'deg', value: 45, min: -180, max: 180, step: 1 }, - ], - preview: (v) => `new Vec2(${v.vx},${v.vy}).transformByMat2(Mat2.fromAngle(${v.deg}*Math.PI/180))`, - compute: (v) => { - const m = Mat2.fromAngle(v.deg * Math.PI / 180); - return new Vec2(v.vx, v.vy).transformByMat2New(m); - }, - legend: [ - { label: 'original', color: P.green }, - { label: 'transformed', color: P.amber }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - const m = Mat2.fromAngle(v.deg * Math.PI / 180); - const r = new Vec2(v.vx, v.vy).transformByMat2New(m); - arrow(ctx, cx, cy, cx + v.vx*u, cy - v.vy*u, P.green); - arrow(ctx, cx, cy, cx + r.x*u, cy - r.y*u, P.amber); - label(ctx, cx + v.vx*u, cy - v.vy*u, 'v', P.green); - label(ctx, cx + r.x*u, cy - r.y*u, `v'`, P.amber); - }, - }, - ], - }, - - // Mat3 - { - name: 'Mat3', - description: '3×3 matrix — 2D transforms with translation, or normal matrices for 3D.', - placeholder: "Mat3.identity()", - examples: [ - - { - id: 'm3-identity', - title: 'Identity', - inputs: [], - preview: () => `Mat3.identity()`, - compute: () => Mat3.identity(), - visualize(ctx, size) { - drawMatrixGrid(ctx, size, Mat3.identity().array, 3, 3); - }, - }, - - { - id: 'm3-transform-v2', - title: 'Transform Vec2', - inputs: [ - { label: 'v.x', name: 'vx', value: 2, min: -4, max: 4, step: 0.1 }, - { label: 'v.y', name: 'vy', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 'angle (°)', name: 'deg', value: 30, min: -180, max: 180, step: 1 }, - { label: 'tx', name: 'tx', value: 1, min: -4, max: 4, step: 0.1 }, - { label: 'ty', name: 'ty', value: 0, min: -4, max: 4, step: 0.1 }, - ], - preview: (v) => `new Vec2(${v.vx},${v.vy}).transformByMat3(mat3)`, - compute: (v) => { - const r = v.deg * Math.PI / 180; - const c = Math.cos(r), s = Math.sin(r); - const m = new Mat3(c, s, 0, -s, c, 0, v.tx, v.ty, 1); - return new Vec2(v.vx, v.vy).transformByMat3New(m); - }, - legend: [ - { label: 'original', color: P.green }, - { label: 'transformed', color: P.amber }, - ], - visualize(ctx, size, v) { - const { cx, cy, unit: u } = drawGrid(ctx, size); - const r = v.deg * Math.PI / 180; - const c = Math.cos(r), s = Math.sin(r); - const m = new Mat3(c, s, 0, -s, c, 0, v.tx, v.ty, 1); - const res = new Vec2(v.vx, v.vy).transformByMat3New(m); - arrow(ctx, cx, cy, cx + v.vx*u, cy - v.vy*u, P.green); - arrow(ctx, cx, cy, cx + res.x*u, cy - res.y*u, P.amber); - label(ctx, cx + v.vx*u, cy - v.vy*u, 'v', P.green); - label(ctx, cx + res.x*u, cy - res.y*u, `v'`, P.amber); - }, - }, - ], - }, - - // Mat4 - { - name: 'Mat4', - description: '4×4 matrix — 3D transforms, perspective projection, view matrices.', - placeholder: "Mat4.perspective(Math.PI/3, 16/9, 0.1, 100)", - examples: [ - - { - id: 'm4-identity', - title: 'Identity', - inputs: [], - preview: () => `new Mat4()`, - compute: () => new Mat4(), - visualize(ctx, size) { - drawMatrixGrid(ctx, size, new Mat4().array, 4, 4); - }, - }, - - { - id: 'm4-perspective', - title: 'Perspective', - inputs: [ - { label: 'fov (°)', name: 'fov', value: 60, min: 10, max: 170, step: 1 }, - { label: 'aspect', name: 'asp', value: 1.78, min: 0.5, max: 3, step: 0.01 }, - { label: 'near', name: 'near', value: 0.1, min: 0.01, max: 10, step: 0.01 }, - { label: 'far', name: 'far', value: 100, min: 10, max: 1000, step: 1 }, - ], - preview: (v) => `Mat4.perspective(${v.fov}*π/180, ${n2(v.asp)}, ${v.near}, ${v.far})`, - compute: (v) => Mat4.perspective(v.fov * Math.PI / 180, v.asp, v.near, v.far), - visualize(ctx, size, v) { - const m = Mat4.perspective(v.fov * Math.PI / 180, v.asp, v.near, v.far); - drawMatrixGrid(ctx, size, m.array, 4, 4); - }, - }, - - { - id: 'm4-xrot', - title: 'X Rotation', - inputs: [ - { label: 'angle (°)', name: 'deg', value: 30, min: -180, max: 180, step: 1 }, - ], - preview: (v) => `Mat4.fromXRotation(${v.deg}*Math.PI/180)`, - compute: (v) => Mat4.fromXRotation(v.deg * Math.PI / 180), - visualize(ctx, size, v) { - drawMatrixGrid(ctx, size, Mat4.fromXRotation(v.deg * Math.PI / 180).array, 4, 4); - }, - }, - ], - }, - - // Quat - { - name: 'Quat', - description: 'Quaternion — encodes 3D rotation as (x, y, z, w). Avoids gimbal lock.', - placeholder: "Quat.fromAxisAngle(new Vec3(0,1,0), Math.PI/4)", - examples: [ - - { - id: 'q-axis-angle', - title: 'From Axis/Angle', - inputs: [ - { label: 'axis.x', name: 'ax', value: 0, min: -1, max: 1, step: 0.01 }, - { label: 'axis.y', name: 'ay', value: 1, min: -1, max: 1, step: 0.01 }, - { label: 'axis.z', name: 'az', value: 0, min: -1, max: 1, step: 0.01 }, - { label: 'angle (°)', name: 'deg', value: 45, min: -180, max: 180, step: 1 }, - ], - preview: (v) => `Quat.fromAxisAngle(new Vec3(${v.ax},${v.ay},${v.az}), ${v.deg}*π/180)`, - compute: (v) => Quat.fromAxisAngle(new Vec3(v.ax, v.ay, v.az), v.deg * Math.PI / 180), - visualize(ctx, size, v) { - const q = Quat.fromAxisAngle(new Vec3(v.ax, v.ay, v.az), v.deg * Math.PI / 180); - drawMatrixGrid(ctx, size, [q.x, q.y, q.z, q.w], 1, 4); - }, - }, - - { - id: 'q-multiply', - title: 'Multiply', - inputs: [ - { label: 'a° around Y', name: 'adeg', value: 30, min: -180, max: 180, step: 1 }, - { label: 'b° around X', name: 'bdeg', value: 45, min: -180, max: 180, step: 1 }, - ], - preview: (v) => `quatA.multiply(quatB)`, - compute: (v) => { - const a = Quat.fromAxisAngle(new Vec3(0, 1, 0), v.adeg * Math.PI / 180); - const b = Quat.fromAxisAngle(new Vec3(1, 0, 0), v.bdeg * Math.PI / 180); - return a.multiply(b); - }, - visualize(ctx, size, v) { - const a = Quat.fromAxisAngle(new Vec3(0, 1, 0), v.adeg * Math.PI / 180); - const b = Quat.fromAxisAngle(new Vec3(1, 0, 0), v.bdeg * Math.PI / 180); - a.multiply(b); - drawMatrixGrid(ctx, size, [a.x, a.y, a.z, a.w], 1, 4); - }, - }, - - { - id: 'q-from-mat3', - title: 'Rotate vector', - inputs: [ - { label: 'v.x', name: 'vx', value: 1, min: -3, max: 3, step: 0.1 }, - { label: 'v.y', name: 'vy', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'v.z', name: 'vz', value: 0, min: -3, max: 3, step: 0.1 }, - { label: 'angle (°)', name: 'deg', value: 90, min: -180, max: 180, step: 1 }, - ], - preview: (v) => `// rotate Vec3 by quaternion via Mat3\nMat3.fromQuat(q).transformVec3(v)`, - compute: (v) => { - const q = Quat.fromAxisAngle(new Vec3(0, 1, 0), v.deg * Math.PI / 180); - const m3 = Mat3.fromQuat(q.array); - return new Vec3(v.vx, v.vy, v.vz).transformByMat3New(m3); - }, - legend: [ - { label: 'original', color: P.green }, - { label: 'rotated', color: P.amber }, - ], - visualize(ctx, size, v) { - const q = Quat.fromAxisAngle(new Vec3(0, 1, 0), v.deg * Math.PI / 180); - const m3 = Mat3.fromQuat(q.array); - const r = new Vec3(v.vx, v.vy, v.vz).transformByMat3New(m3); - drawIso(ctx, size, [ - { x: v.vx, y: v.vy, z: v.vz, color: P.green, label: 'v' }, - { x: r.x, y: r.y, z: r.z, color: P.amber, label: "v'" }, - ]); - }, - }, - ], - }, - -]; - -// State - -let activeTab = 0; -let activeExample = 0; -const inputValues: Record = {}; - -// DOM refs - -const tabBtns = Array.from(document.querySelectorAll('.tab-btn')); -const tabDescEl = document.getElementById('tab-desc')!; -const examplesEl = document.getElementById('examples')!; -const canvasEl = document.getElementById('canvas') as HTMLCanvasElement; -const legendEl = document.getElementById('canvas-legend')!; -const tryitInputEl = document.getElementById('tryit-input') as HTMLTextAreaElement; -const outputValEl = document.getElementById('output-value')!; - -let canvasCtx: CanvasRenderingContext2D; -let canvasSize: number; - -// Rendering - -function getValues(): Record { - return { ...inputValues }; -} - -function renderLegend() { - const ex = TABS[activeTab].examples[activeExample]; - legendEl.innerHTML = ''; - if (!ex.legend) return; - ex.legend.forEach(({ label: lbl, color }) => { - const item = document.createElement('span'); - item.className = 'legend-item'; - item.innerHTML = `${lbl}`; - legendEl.appendChild(item); - }); -} - -function renderCanvas() { - const ex = TABS[activeTab].examples[activeExample]; - if (!canvasCtx) return; - ex.visualize(canvasCtx, canvasSize, getValues()); -} - -function computeResult(ex: Example, vals: Record): string { - try { - return formatResult(ex.compute(vals)); - } catch (e) { - return `Error: ${(e as Error).message}`; - } -} - -function renderExamples() { - const tab = TABS[activeTab]; - examplesEl.innerHTML = ''; - - tab.examples.forEach((ex, idx) => { - const isActive = idx === activeExample; - const vals = getValues(); - const resultStr = computeResult(ex, vals); - const previewStr = ex.preview(vals); - - const item = document.createElement('div'); - item.className = `example-item${isActive ? ' active' : ''}`; - item.setAttribute('role', 'listitem'); - - item.innerHTML = ` -
- ${String(idx + 1).padStart(2, '0')} -
-
${ex.title}
-
${previewStr}
-
- ▶ -
- ${isActive ? ` -
-
${resultStr}
- ${ex.inputs.length ? `
` : ''} -
` : ''} - `; - - item.querySelector('.example-header')!.addEventListener('click', () => { - setExample(idx); - }); - - examplesEl.appendChild(item); - - // Build input controls - if (isActive && ex.inputs.length) { - const grid = item.querySelector('.inputs-grid')!; - ex.inputs.forEach(inp => { - if (!(inp.name in inputValues)) inputValues[inp.name] = inp.value; - const group = document.createElement('div'); - group.className = 'input-group'; - group.innerHTML = ` -
${inp.label}
-
- - -
- `; - - const slider = group.querySelector('.input-slider')!; - const number = group.querySelector('.input-number')!; - - const sync = (val: number) => { - inputValues[inp.name] = val; - slider.value = String(val); - number.value = String(val); - updateAll(); - }; - - slider.addEventListener('input', () => sync(parseFloat(slider.value))); - number.addEventListener('change', () => sync(parseFloat(number.value))); - - grid.appendChild(group); - }); - } - }); -} - -function updateAll() { - const tab = TABS[activeTab]; - const ex = tab.examples[activeExample]; - const vals = getValues(); - - // Update active example's result & preview - const activeItem = examplesEl.querySelector('.example-item.active'); - if (activeItem) { - const resultEl = activeItem.querySelector('.example-result'); - const previewEl = activeItem.querySelector('.example-preview'); - if (resultEl) resultEl.textContent = computeResult(ex, vals); - if (previewEl) previewEl.textContent = ex.preview(vals); - } - - renderCanvas(); -} - -function setExample(idx: number) { - // Reset input values for the new example - const ex = TABS[activeTab].examples[idx]; - ex.inputs.forEach(inp => { inputValues[inp.name] = inp.value; }); - activeExample = idx; - renderExamples(); - renderLegend(); - renderCanvas(); -} - -function setTab(idx: number) { - activeTab = idx; - activeExample = 0; - - tabBtns.forEach((btn, i) => btn.classList.toggle('active', i === idx)); - - const tab = TABS[idx]; - tabDescEl.textContent = tab.description; - tryitInputEl.placeholder = tab.placeholder; - tryitInputEl.value = ''; - outputValEl.textContent = '—'; - outputValEl.classList.remove('err'); - - // Reset input state for new tab's first example - tab.examples[0]?.inputs.forEach(inp => { inputValues[inp.name] = inp.value; }); - - renderExamples(); - renderLegend(); - renderCanvas(); -} - -// Try It Evaluator - -function evaluate(code: string) { - const fn = new Function( - 'Vec2', 'Vec3', 'Vec4', 'Mat2', 'Mat3', 'Mat4', 'Quat', 'Math', - `"use strict"; return (${code})` - ); - return fn(Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Quat, Math); -} - -let evalTimer: ReturnType | null = null; - -tryitInputEl.addEventListener('input', () => { - if (evalTimer) clearTimeout(evalTimer); - evalTimer = setTimeout(() => { - const code = tryitInputEl.value.trim(); - if (!code) { - outputValEl.textContent = '—'; - outputValEl.classList.remove('err'); - return; - } - try { - const result = evaluate(code); - outputValEl.textContent = formatResult(result); - outputValEl.classList.remove('err'); - } catch (e) { - outputValEl.textContent = (e as Error).message; - outputValEl.classList.add('err'); - } - }, 120); -}); - -// Tab buttons - -tabBtns.forEach((btn, idx) => { - btn.addEventListener('click', () => setTab(idx)); -}); - -// Init - -function init() { - const result = setupCanvas(canvasEl); - canvasCtx = result.ctx; - canvasSize = result.size; - - setTab(0); -} - -window.addEventListener('resize', () => { - const result = setupCanvas(canvasEl); - canvasCtx = result.ctx; - canvasSize = result.size; - renderCanvas(); -}); - -init(); - -// Close demos dropdown when clicking outside it -const demosDropdown = document.querySelector('.nav-dropdown'); -if (demosDropdown) { - document.addEventListener('click', e => { - if (!demosDropdown.contains(e.target as Node)) { - demosDropdown.removeAttribute('open'); - } - }); -} diff --git a/demos/plane.html b/demos/plane.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/plane.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/plane.pug b/demos/plane.pug deleted file mode 100644 index d84cf11..0000000 --- a/demos/plane.pug +++ /dev/null @@ -1,73 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Plane - -block head - style. - .result-box { - font-size: var(--fs-sm); - color: var(--amber); - background: var(--amber-dim); - border-left: 2px solid var(--amber-border); - padding: 6px 10px; - border-radius: 0 var(--r) var(--r) 0; - line-height: 1.8; - white-space: pre; - } - .canvas-fill { - flex: 1; - overflow: hidden; - position: relative; - background: var(--surface); - cursor: crosshair; - } - #plane-canvas { - display: block; - width: 100%; - height: 100%; - } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Plane - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Normal angle - div.ctrl-row - span.ctrl-label ° - input.ctrl-slider(type="range" id="angleSlider" min="0" max="360" step="1" value="45") - input.ctrl-num(type="number" id="angleNum" min="0" max="360" step="1" value="45") - - div.ctrl-section - h3 Offset (constant) - div.ctrl-row - span.ctrl-label d - input.ctrl-slider(type="range" id="constSlider" min="-4" max="4" step="0.1" value="0") - input.ctrl-num(type="number" id="constNum" min="-4" max="4" step="0.1" value="0") - - div.ctrl-section - h3 Result (mouse = point) - pre.result-box#resultBox distanceTo: — - - div.ctrl-section.ctrl-section--fill - h3 How it works - p.info-text A #[code.txt-green Plane] is defined by a unit #[code.txt-amber normal] vector and a scalar #[code.txt-amber constant] (#[em d] in #[em nx·x + nz·z + d = 0]). Move the mouse over the canvas to position a point. #[code.txt-green distanceTo(p)] returns the signed distance — positive on the normal side, negative on the other. #[code.txt-green projectPoint(p)] drops a perpendicular onto the plane surface (dashed line). - - div.canvas-fill#canvas-fill - canvas#plane-canvas - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Plane · distanceTo · projectPoint - -block scripts - script(type="module" src="./plane.ts") diff --git a/demos/plane.ts b/demos/plane.ts deleted file mode 100644 index 14b8187..0000000 --- a/demos/plane.ts +++ /dev/null @@ -1,202 +0,0 @@ -import { Vec3 } from "../src/Vec3"; -import { Plane } from "../src/Plane"; - -const SCALE = 60; - -const canvasFill = document.getElementById("canvas-fill") as HTMLDivElement; -const canvas = document.getElementById("plane-canvas") as HTMLCanvasElement; -const angleSlider = document.getElementById("angleSlider") as HTMLInputElement; -const angleNum = document.getElementById("angleNum") as HTMLInputElement; -const constSlider = document.getElementById("constSlider") as HTMLInputElement; -const constNum = document.getElementById("constNum") as HTMLInputElement; -const resultBox = document.getElementById("resultBox") as HTMLPreElement; - -let mousePt = new Vec3(2, 0, 1.5); -let angleDeg = 45; -let constant = 0; - -function getPlane(): Plane { - const rad = (angleDeg * Math.PI) / 180; - return new Plane(new Vec3(Math.cos(rad), 0, Math.sin(rad)), constant); -} - -function w2c(x: number, z: number, cx: number, cy: number): [number, number] { - return [cx + x * SCALE, cy - z * SCALE]; -} - -function c2w(px: number, py: number, cx: number, cy: number): [number, number] { - return [(px - cx) / SCALE, (cy - py) / SCALE]; -} - -function arrow( - ctx: CanvasRenderingContext2D, - x1: number, - y1: number, - x2: number, - y2: number -) { - ctx.beginPath(); - ctx.moveTo(x1, y1); - ctx.lineTo(x2, y2); - ctx.stroke(); - const angle = Math.atan2(y2 - y1, x2 - x1); - ctx.beginPath(); - ctx.moveTo(x2, y2); - ctx.lineTo(x2 - 9 * Math.cos(angle - 0.38), y2 - 9 * Math.sin(angle - 0.38)); - ctx.lineTo(x2 - 9 * Math.cos(angle + 0.38), y2 - 9 * Math.sin(angle + 0.38)); - ctx.closePath(); - ctx.fill(); -} - -function render() { - const W = canvasFill.clientWidth; - const H = canvasFill.clientHeight; - if (W === 0 || H === 0) return; - - const dpr = window.devicePixelRatio || 1; - canvas.width = W * dpr; - canvas.height = H * dpr; - canvas.style.width = `${W}px`; - canvas.style.height = `${H}px`; - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - - const cs = getComputedStyle(document.documentElement); - const bg = cs.getPropertyValue("--surface").trim(); - const border = cs.getPropertyValue("--border").trim(); - const green = cs.getPropertyValue("--green").trim(); - const amber = cs.getPropertyValue("--amber").trim(); - - const cx = W / 2; - const cy = H / 2; - - ctx.fillStyle = bg; - ctx.fillRect(0, 0, W, H); - - // Grid - ctx.strokeStyle = border; - ctx.lineWidth = 1; - for (let i = -Math.ceil(W / 2 / SCALE) - 1; i <= Math.ceil(W / 2 / SCALE) + 1; i++) { - ctx.beginPath(); - ctx.moveTo(cx + i * SCALE, 0); - ctx.lineTo(cx + i * SCALE, H); - ctx.stroke(); - } - for (let i = -Math.ceil(H / 2 / SCALE) - 1; i <= Math.ceil(H / 2 / SCALE) + 1; i++) { - ctx.beginPath(); - ctx.moveTo(0, cy + i * SCALE); - ctx.lineTo(W, cy + i * SCALE); - ctx.stroke(); - } - - // Axes - ctx.strokeStyle = "rgba(0,0,0,0.12)"; - ctx.lineWidth = 1.5; - ctx.beginPath(); ctx.moveTo(0, cy); ctx.lineTo(W, cy); ctx.stroke(); - ctx.beginPath(); ctx.moveTo(cx, 0); ctx.lineTo(cx, H); ctx.stroke(); - - const plane = getPlane(); - - // Point on plane closest to origin - const p0x = -plane.constant * plane.normal.x; - const p0z = -plane.constant * plane.normal.z; - // Tangent direction along the plane (perpendicular to normal in XZ) - const tdx = -plane.normal.z; - const tdz = plane.normal.x; - const ext = (Math.max(W, H) / SCALE) * 1.5; - - const [s1x, s1y] = w2c(p0x + tdx * ext, p0z + tdz * ext, cx, cy); - const [s2x, s2y] = w2c(p0x - tdx * ext, p0z - tdz * ext, cx, cy); - const [p0sx, p0sy] = w2c(p0x, p0z, cx, cy); - const [nex, ney] = w2c(p0x + plane.normal.x * 1.5, p0z + plane.normal.z * 1.5, cx, cy); - - // Plane line - ctx.strokeStyle = green; - ctx.lineWidth = 2; - ctx.setLineDash([]); - ctx.beginPath(); - ctx.moveTo(s1x, s1y); - ctx.lineTo(s2x, s2y); - ctx.stroke(); - - // Normal arrow - ctx.strokeStyle = green; - ctx.fillStyle = green; - ctx.lineWidth = 1.5; - arrow(ctx, p0sx, p0sy, nex, ney); - - // "n" label - ctx.font = `500 11px var(--font)`; - ctx.fillStyle = green; - ctx.fillText("n", nex + 7, ney - 3); - - // Signed-distance shading: tint positive side - const dist = plane.distanceTo(mousePt); - const proj = plane.projectPoint(mousePt); - - const [ptsx, ptsy] = w2c(mousePt.x, mousePt.z, cx, cy); - const [prsx, prsy] = w2c(proj.x, proj.z, cx, cy); - - // Dashed perpendicular to projection - ctx.strokeStyle = amber; - ctx.lineWidth = 1; - ctx.setLineDash([5, 4]); - ctx.beginPath(); - ctx.moveTo(ptsx, ptsy); - ctx.lineTo(prsx, prsy); - ctx.stroke(); - ctx.setLineDash([]); - - // Projected point - ctx.beginPath(); - ctx.arc(prsx, prsy, 4, 0, Math.PI * 2); - ctx.fillStyle = green; - ctx.fill(); - - // Mouse point - ctx.beginPath(); - ctx.arc(ptsx, ptsy, 5, 0, Math.PI * 2); - ctx.fillStyle = amber; - ctx.fill(); - - // Distance label near midpoint - ctx.font = `500 11px var(--font)`; - ctx.fillStyle = amber; - const lmx = (ptsx + prsx) / 2 + 8; - const lmy = (ptsy + prsy) / 2; - ctx.fillText(`d = ${dist.toFixed(3)}`, lmx, lmy); - - // Result panel - resultBox.textContent = [ - `point Vec3(${mousePt.x.toFixed(2)}, 0, ${mousePt.z.toFixed(2)})`, - ``, - `distanceTo(point)`, - ` ${dist.toFixed(4)}`, - ``, - `projectPoint(point)`, - ` Vec3(${proj.x.toFixed(3)}, 0, ${proj.z.toFixed(3)})`, - ].join("\n"); -} - -canvas.addEventListener("mousemove", (e) => { - const rect = canvas.getBoundingClientRect(); - const [wx, wz] = c2w( - e.clientX - rect.left, - e.clientY - rect.top, - canvas.clientWidth / 2, - canvas.clientHeight / 2 - ); - mousePt = new Vec3(wx, 0, wz); - render(); -}); - -function sync(slider: HTMLInputElement, num: HTMLInputElement, set: (v: number) => void) { - slider.addEventListener("input", () => { num.value = slider.value; set(parseFloat(slider.value)); render(); }); - num.addEventListener("change", () => { slider.value = num.value; set(parseFloat(num.value)); render(); }); -} - -sync(angleSlider, angleNum, (v) => (angleDeg = v)); -sync(constSlider, constNum, (v) => (constant = v)); - -window.addEventListener("resize", render); -render(); diff --git a/demos/ray.html b/demos/ray.html deleted file mode 100644 index c50eddd..0000000 --- a/demos/ray.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/demos/ray.pug b/demos/ray.pug deleted file mode 100644 index 1bfe2dd..0000000 --- a/demos/ray.pug +++ /dev/null @@ -1,113 +0,0 @@ -extends ./_layout - -block title - | wtc-math — Ray - -block head - style. - .result-box { - font-size: var(--fs-sm); - color: var(--amber); - background: var(--amber-dim); - border-left: 2px solid var(--amber-border); - padding: 6px 10px; - border-radius: 0 var(--r) var(--r) 0; - line-height: 1.8; - white-space: pre; - } - .legend-dot { - width: 10px; - height: 10px; - border-radius: 50%; - flex-shrink: 0; - } - .legend-row { - display: flex; - align-items: center; - gap: 8px; - font-size: var(--fs-sm); - color: var(--text-mid); - } - .canvas-fill { - flex: 1; - overflow: hidden; - position: relative; - background: var(--surface); - } - #ray-canvas { - display: block; - width: 100%; - height: 100%; - } - -block header-desc - p.header-desc - a(href="./index.html") demos - span.breadcrumb-sep › - span.breadcrumb-current Ray - -block main - main.demo-main - aside.demo-controls - - div.ctrl-section - h3 Origin - div.ctrl-row - span.ctrl-label x - input.ctrl-slider(type="range" id="oxSlider" min="-4" max="4" step="0.1" value="-3") - input.ctrl-num(type="number" id="oxNum" min="-4" max="4" step="0.1" value="-3") - div.ctrl-row - span.ctrl-label z - input.ctrl-slider(type="range" id="ozSlider" min="-4" max="4" step="0.1" value="0") - input.ctrl-num(type="number" id="ozNum" min="-4" max="4" step="0.1" value="0") - - div.ctrl-section - h3 Direction angle - div.ctrl-row - span.ctrl-label ° - input.ctrl-slider(type="range" id="dirSlider" min="-180" max="180" step="1" value="15") - input.ctrl-num(type="number" id="dirNum" min="-180" max="180" step="1" value="15") - - div.ctrl-section - h3 at(t) - div.ctrl-row - span.ctrl-label t - input.ctrl-slider(type="range" id="tSlider" min="0" max="12" step="0.1" value="3") - input.ctrl-num(type="number" id="tNum" min="0" max="12" step="0.1" value="3") - - div.ctrl-section - h3 Sphere radius - div.ctrl-row - span.ctrl-label r - input.ctrl-slider(type="range" id="srSlider" min="0.3" max="3" step="0.1" value="1.2") - input.ctrl-num(type="number" id="srNum" min="0.3" max="3" step="0.1" value="1.2") - - div.ctrl-section - h3 Intersections - pre.result-box#resultBox - - div.ctrl-section - div.legend-row - div.legend-dot(style="background:var(--green)") - span ray - div.legend-row - div.legend-dot(style="background:var(--red)") - span sphere (intersectSphere) - div.legend-row - div.legend-dot(style="background:var(--amber)") - span box (intersectBox) - div.legend-row - div.legend-dot(style="background:var(--purple)") - span plane (intersectPlane) - - div.canvas-fill#canvas-fill - canvas#ray-canvas - -block footer-links - a.footer-link(href="./index.html") demos - -block footer-right - span.footer-right Ray · at · intersectSphere · intersectBox · intersectPlane - -block scripts - script(type="module" src="./ray.ts") diff --git a/demos/ray.ts b/demos/ray.ts deleted file mode 100644 index 06ae4ee..0000000 --- a/demos/ray.ts +++ /dev/null @@ -1,211 +0,0 @@ -import { Vec3 } from "../src/Vec3"; -import { Ray } from "../src/Ray"; -import { Plane } from "../src/Plane"; - -const SCALE = 52; - -const canvasFill = document.getElementById("canvas-fill") as HTMLDivElement; -const canvas = document.getElementById("ray-canvas") as HTMLCanvasElement; -const resultBox = document.getElementById("resultBox") as HTMLPreElement; - -const gi = (id: string) => document.getElementById(id) as HTMLInputElement; -const oxSlider = gi("oxSlider"); const oxNum = gi("oxNum"); -const ozSlider = gi("ozSlider"); const ozNum = gi("ozNum"); -const dirSlider = gi("dirSlider"); const dirNum = gi("dirNum"); -const tSlider = gi("tSlider"); const tNum = gi("tNum"); -const srSlider = gi("srSlider"); const srNum = gi("srNum"); - -// Fixed scene objects -const SPHERE_CENTER = new Vec3(2, 0, 1); -const BOX_MIN = new Vec3(-1.2, -0.5, -0.8); -const BOX_MAX = new Vec3(1.2, 0.5, 0.8); -const SCENE_PLANE = new Plane(new Vec3(0, 0, 1), -3.5); - -function w2c(x: number, z: number, cx: number, cy: number): [number, number] { - return [cx + x * SCALE, cy - z * SCALE]; -} - -function getRay(): Ray { - const ox = parseFloat(oxSlider.value); - const oz = parseFloat(ozSlider.value); - const rad = (parseFloat(dirSlider.value) * Math.PI) / 180; - return new Ray(new Vec3(ox, 0, oz), new Vec3(Math.cos(rad), 0, Math.sin(rad))); -} - -function arrowHead( - ctx: CanvasRenderingContext2D, - x1: number, y1: number, - x2: number, y2: number, - size = 10 -) { - const angle = Math.atan2(y2 - y1, x2 - x1); - ctx.beginPath(); - ctx.moveTo(x2, y2); - ctx.lineTo(x2 - size * Math.cos(angle - 0.35), y2 - size * Math.sin(angle - 0.35)); - ctx.lineTo(x2 - size * Math.cos(angle + 0.35), y2 - size * Math.sin(angle + 0.35)); - ctx.closePath(); - ctx.fill(); -} - -function render() { - const W = canvasFill.clientWidth; - const H = canvasFill.clientHeight; - if (W === 0 || H === 0) return; - - const dpr = window.devicePixelRatio || 1; - canvas.width = W * dpr; - canvas.height = H * dpr; - canvas.style.width = `${W}px`; - canvas.style.height = `${H}px`; - const ctx = canvas.getContext("2d")!; - ctx.scale(dpr, dpr); - - const cs = getComputedStyle(document.documentElement); - const bg = cs.getPropertyValue("--surface").trim(); - const border = cs.getPropertyValue("--border").trim(); - const green = cs.getPropertyValue("--green").trim(); - const amber = cs.getPropertyValue("--amber").trim(); - const purple = cs.getPropertyValue("--purple").trim(); - const red = cs.getPropertyValue("--red").trim(); - - const cx = W / 2; - const cy = H / 2; - - ctx.fillStyle = bg; - ctx.fillRect(0, 0, W, H); - - // Grid - ctx.strokeStyle = border; - ctx.lineWidth = 1; - for (let i = -Math.ceil(W / 2 / SCALE) - 1; i <= Math.ceil(W / 2 / SCALE) + 1; i++) { - ctx.beginPath(); ctx.moveTo(cx + i * SCALE, 0); ctx.lineTo(cx + i * SCALE, H); ctx.stroke(); - } - for (let i = -Math.ceil(H / 2 / SCALE) - 1; i <= Math.ceil(H / 2 / SCALE) + 1; i++) { - ctx.beginPath(); ctx.moveTo(0, cy + i * SCALE); ctx.lineTo(W, cy + i * SCALE); ctx.stroke(); - } - ctx.strokeStyle = "rgba(0,0,0,0.12)"; - ctx.lineWidth = 1.5; - ctx.beginPath(); ctx.moveTo(0, cy); ctx.lineTo(W, cy); ctx.stroke(); - ctx.beginPath(); ctx.moveTo(cx, 0); ctx.lineTo(cx, H); ctx.stroke(); - - const ray = getRay(); - const t = parseFloat(tSlider.value); - const sphereR = parseFloat(srSlider.value); - - const hitSphere = ray.intersectSphere(SPHERE_CENTER, sphereR); - const hitBox = ray.intersectBox(BOX_MIN, BOX_MAX); - const hitPlane = ray.intersectPlane(SCENE_PLANE); - const atT = ray.at(t); - - // Draw plane - const ext = (Math.max(W, H) / SCALE) * 1.5; - const pnx = -SCENE_PLANE.constant * SCENE_PLANE.normal.x; - const pnz = -SCENE_PLANE.constant * SCENE_PLANE.normal.z; - const ptdx = -SCENE_PLANE.normal.z; - const ptdz = SCENE_PLANE.normal.x; - const [pl1x, pl1y] = w2c(pnx + ptdx * ext, pnz + ptdz * ext, cx, cy); - const [pl2x, pl2y] = w2c(pnx - ptdx * ext, pnz - ptdz * ext, cx, cy); - - ctx.strokeStyle = hitPlane ? purple : "rgba(136,102,255,0.25)"; - ctx.lineWidth = hitPlane ? 2 : 1.5; - ctx.setLineDash([6, 5]); - ctx.beginPath(); ctx.moveTo(pl1x, pl1y); ctx.lineTo(pl2x, pl2y); ctx.stroke(); - ctx.setLineDash([]); - - // Draw box - const [bx1, by1] = w2c(BOX_MIN.x, BOX_MIN.z, cx, cy); - const [bx2, by2] = w2c(BOX_MAX.x, BOX_MAX.z, cx, cy); - ctx.fillStyle = hitBox ? "rgba(255,201,64,0.08)" : "rgba(255,201,64,0.03)"; - ctx.strokeStyle = hitBox ? amber : "rgba(255,201,64,0.25)"; - ctx.lineWidth = hitBox ? 2 : 1.5; - ctx.beginPath(); - ctx.rect(bx1, by2, bx2 - bx1, by1 - by2); - ctx.fill(); - ctx.stroke(); - - // Draw sphere - const [scx, scy] = w2c(SPHERE_CENTER.x, SPHERE_CENTER.z, cx, cy); - ctx.fillStyle = hitSphere ? "rgba(255,85,102,0.08)" : "rgba(255,85,102,0.03)"; - ctx.strokeStyle = hitSphere ? red : "rgba(255,85,102,0.25)"; - ctx.lineWidth = hitSphere ? 2 : 1.5; - ctx.beginPath(); - ctx.arc(scx, scy, sphereR * SCALE, 0, Math.PI * 2); - ctx.fill(); - ctx.stroke(); - - // Ray line - const farPt = ray.at((Math.max(W, H) / SCALE) * 2); - const [rox, roy] = w2c(ray.origin.x, ray.origin.z, cx, cy); - const [rfx, rfy] = w2c(farPt.x, farPt.z, cx, cy); - - ctx.strokeStyle = green; - ctx.lineWidth = 2; - ctx.beginPath(); ctx.moveTo(rox, roy); ctx.lineTo(rfx, rfy); ctx.stroke(); - - // Arrow on ray - const arrowAt = ray.at(2); - const [arx, ary] = w2c(arrowAt.x, arrowAt.z, cx, cy); - ctx.fillStyle = green; - arrowHead(ctx, rox, roy, arx, ary); - - // Origin dot - ctx.beginPath(); - ctx.arc(rox, roy, 5, 0, Math.PI * 2); - ctx.fillStyle = green; - ctx.fill(); - - // at(t) marker - const [atx, aty] = w2c(atT.x, atT.z, cx, cy); - ctx.beginPath(); - ctx.arc(atx, aty, 4, 0, Math.PI * 2); - ctx.fillStyle = "rgba(255,255,255,0.85)"; - ctx.fill(); - ctx.strokeStyle = green; - ctx.lineWidth = 1.5; - ctx.stroke(); - ctx.font = `500 11px var(--font)`; - ctx.fillStyle = "rgba(0,0,0,0.55)"; - ctx.fillText(`t=${t}`, atx + 7, aty - 4); - - // Intersection dots - const hits: [Vec3 | null, string, string][] = [ - [hitSphere, red, "sphere"], - [hitBox, amber, "box"], - [hitPlane, purple, "plane"], - ]; - for (const [hit, col, label] of hits) { - if (!hit) continue; - const [hx, hy] = w2c(hit.x, hit.z, cx, cy); - ctx.beginPath(); - ctx.arc(hx, hy, 6, 0, Math.PI * 2); - ctx.fillStyle = col; - ctx.fill(); - ctx.font = `500 11px var(--font)`; - ctx.fillStyle = col; - ctx.fillText(label, hx + 9, hy + 4); - } - - // Result text - const fv = (v: Vec3 | null) => - v ? `Vec3(${v.x.toFixed(2)}, 0, ${v.z.toFixed(2)})` : "null"; - resultBox.textContent = [ - `at(${t.toFixed(1)}) ${fv(atT)}`, - `intersectSphere ${fv(hitSphere)}`, - `intersectBox ${fv(hitBox)}`, - `intersectPlane ${fv(hitPlane)}`, - ].join("\n"); -} - -function sync(slider: HTMLInputElement, num: HTMLInputElement) { - slider.addEventListener("input", () => { num.value = slider.value; render(); }); - num.addEventListener("change", () => { slider.value = num.value; render(); }); -} - -sync(oxSlider, oxNum); -sync(ozSlider, ozNum); -sync(dirSlider, dirNum); -sync(tSlider, tNum); -sync(srSlider, srNum); - -window.addEventListener("resize", render); -render(); diff --git a/demos/style.css b/demos/style.css deleted file mode 100644 index 1a6032e..0000000 --- a/demos/style.css +++ /dev/null @@ -1,810 +0,0 @@ -:root { - color-scheme: light; - - --bg: #f0f2f8; - --surface: #ffffff; - --surface-2: #e8eaf2; - --border: rgba(0, 0, 0, 0.08); - --border-hi: rgba(0, 0, 0, 0.15); - --text: #111827; - --text-mid: #4b5570; - --text-dim: #7880a0; - - --green: #0d8040; - --green-dim: rgba(13, 128, 64, 0.10); - --green-glow: rgba(13, 128, 64, 0.30); - --purple: #5533cc; - --purple-dim: rgba(85, 51, 204, 0.10); - --amber: #a07000; - --amber-dim: rgba(160, 112, 0, 0.10); - --red: #cc2233; - - --font: "IBM Plex Mono", monospace; - --r: 3px; - - --fs-xs: 11px; - --fs-sm: 12px; - --fs-md: 13px; - --fs-base: 15px; - --fs-lg: 18px; - - --header-h: 58px; - --nav-h: 40px; - --footer-h: 36px; - - --surface-hover: rgba(0, 0, 0, 0.04); - --surface-hover-dim: rgba(0, 0, 0, 0.02); - --focus-ring: rgba(13, 128, 64, 0.45); - --green-border: rgba(13, 128, 64, 0.35); - --amber-border: rgba(160, 112, 0, 0.40); - --label-bg: rgba(250, 251, 255, 0.88); - --dot-border: rgba(0, 0, 0, 0.12); -} - -*, -*::before, -*::after { - box-sizing: border-box; - margin: 0; - padding: 0; -} - -html, -body { - height: 100%; - overflow: hidden; - background: var(--bg); - color: var(--text); - font-family: var(--font); - font-size: var(--fs-base); - line-height: 1.5; - -webkit-font-smoothing: antialiased; -} - -/* Header */ - -header { - height: var(--header-h); - border-bottom: 1px solid var(--border); - display: flex; - align-items: center; - gap: 20px; - padding: 0 20px; - background: var(--bg); -} - -.wordmark { - font-size: var(--fs-lg); - font-weight: 600; - letter-spacing: -0.02em; - line-height: 1; - flex-shrink: 0; -} - -.w-lib { - color: var(--text); -} -.w-dot { - color: var(--text-dim); - margin: 0 1px; -} -.w-mod { - color: var(--green); -} - -.header-desc { - color: var(--text-mid); - /* font-size: 11px; */ - font-weight: 300; - flex: 1; -} - -.header-desc a { - color: var(--text-mid); - text-decoration: none; -} - -.breadcrumb-sep { - color: var(--text-dim); - margin: 0 4px; -} - -.breadcrumb-current { - color: var(--text); - font-weight: 500; -} - -.header-link { - /* font-size: 11px; */ - color: var(--text-mid); - text-decoration: none; - padding: 4px 10px; - border: 1px solid var(--border); - border-radius: var(--r); - transition: - color 0.12s, - border-color 0.12s; - white-space: nowrap; -} - -.header-link:hover { - color: var(--text); - border-color: var(--border-hi); -} - -/* Demos dropdown */ - -.nav-dropdown { - position: relative; -} - -.nav-dropdown > summary { - list-style: none; - cursor: pointer; - color: var(--text-mid); - padding: 4px 10px; - border: 1px solid var(--border); - border-radius: var(--r); - transition: color 0.12s, border-color 0.12s; - white-space: nowrap; - font-family: var(--font); - font-size: inherit; - user-select: none; -} - -.nav-dropdown > summary::-webkit-details-marker { display: none; } -.nav-dropdown > summary::marker { content: ''; } - -.nav-dropdown > summary::after { - content: ' ▾'; - font-size: 0.75em; - display: inline-block; - transition: transform 0.15s; - transform-origin: center 55%; -} - -.nav-dropdown[open] > summary::after { - transform: rotate(180deg); -} - -.nav-dropdown > summary:hover, -.nav-dropdown[open] > summary { - color: var(--text); - border-color: var(--border-hi); -} - -.dropdown-menu { - position: absolute; - top: calc(100% + 6px); - right: 0; - background: var(--surface); - border: 1px solid var(--border-hi); - border-radius: var(--r); - min-width: 200px; - z-index: 100; - overflow: hidden; - animation: dropIn 0.1s ease; -} - -@keyframes dropIn { - from { opacity: 0; transform: translateY(-4px); } - to { opacity: 1; transform: translateY(0); } -} - -.dropdown-item { - display: block; - padding: 8px 14px; - color: var(--text-mid); - text-decoration: none; - border-bottom: 1px solid var(--border); - transition: background 0.1s, color 0.1s; - white-space: nowrap; -} - -.dropdown-item:last-child { border-bottom: none; } - -.dropdown-item:hover { - background: var(--surface-hover); - color: var(--text); -} - -/* Tab Navigation */ - -.tab-nav { - height: var(--nav-h); - border-bottom: 1px solid var(--border); - display: flex; - align-items: stretch; - padding: 0 20px; - background: var(--bg); - gap: 2px; -} - -.tab-btn { - background: none; - border: none; - border-bottom: 2px solid transparent; - margin-bottom: -1px; - color: var(--text-mid); - font-family: var(--font); - /* font-size: 11px; */ - font-weight: 500; - letter-spacing: 0.06em; - text-transform: uppercase; - padding: 0 14px; - cursor: pointer; - transition: color 0.1s; - white-space: nowrap; -} - -.tab-btn:hover { - color: var(--text); -} - -.tab-btn.active { - color: var(--green); - border-bottom-color: var(--green); -} - -/* Main Layout */ - -.main { - display: grid; - grid-template-columns: 35vw 1fr; - height: calc(100vh - var(--header-h) - var(--nav-h) - var(--footer-h)); -} - -/* Left Column */ - -.col-left { - display: flex; - flex-direction: column; - border-right: 1px solid var(--border); - overflow: hidden; -} - -.tab-desc { - padding: 10px 20px; - border-bottom: 1px solid var(--border); - color: var(--text-mid); - /* font-size: 11px; */ - font-style: italic; - font-weight: 300; - flex-shrink: 0; -} - -/* Examples List */ - -.examples { - flex: 1; - overflow-y: auto; - overflow-x: hidden; - min-height: 0; -} - -.example-item { - border-bottom: 1px solid var(--border); -} - -.example-header { - display: flex; - align-items: center; - gap: 10px; - padding: 11px 20px; - cursor: pointer; - user-select: none; - transition: background 0.1s; -} - -.example-header:hover { - background: var(--surface-hover-dim); -} - -.example-item.active .example-header { - background: var(--green-dim); -} - -.example-num { - /* font-size: 10px; */ - color: var(--text-dim); - width: 16px; - flex-shrink: 0; -} - -.example-item.active .example-num { - color: var(--green); -} - -.example-meta { - flex: 1; - min-width: 0; -} - -.example-title { - /* font-size: 13px; */ - font-weight: 500; - color: var(--text); - line-height: 1.3; -} - -.example-item.active .example-title { - color: var(--green); -} - -.example-preview { - /* font-size: 10px; */ - color: var(--text-dim); - margin-top: 1px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; -} - -.example-item.active .example-preview { - color: var(--text-mid); -} - -.example-chevron { - /* font-size: 9px; */ - color: var(--text-dim); - flex-shrink: 0; - transition: transform 0.15s; -} - -.example-item.active .example-chevron { - transform: rotate(90deg); - color: var(--green); -} - -.example-body { - display: none; - padding: 0 20px 14px; - animation: fadeIn 0.12s ease; -} - -.example-item.active .example-body { - display: block; -} - -@keyframes fadeIn { - from { - opacity: 0; - transform: translateY(-4px); - } - to { - opacity: 1; - transform: translateY(0); - } -} - -.example-result { - /* font-size: 11px; */ - color: var(--amber); - background: var(--amber-dim); - border-left: 2px solid var(--amber-border); - padding: 5px 10px; - margin-bottom: 12px; - border-radius: 0 var(--r) var(--r) 0; - word-break: break-all; - font-weight: 500; - line-height: 1.5; -} - -.inputs-grid { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); - gap: 8px 12px; -} - -.input-group { - display: flex; - flex-direction: column; - gap: 5px; -} - -.input-label { - /* font-size: 10px; */ - color: var(--text-mid); - font-weight: 500; - letter-spacing: 0.04em; -} - -.input-row { - display: flex; - align-items: center; - gap: 6px; -} - -/* Range slider */ -.input-slider { - flex: 1; - -webkit-appearance: none; - appearance: none; - height: 2px; - background: var(--border-hi); - border-radius: 1px; - outline: none; - cursor: pointer; -} - -.input-slider::-webkit-slider-thumb { - -webkit-appearance: none; - width: 10px; - height: 10px; - border-radius: 50%; - background: var(--green); - cursor: pointer; - box-shadow: 0 0 8px var(--green-glow); - transition: box-shadow 0.1s; -} - -.input-slider::-webkit-slider-thumb:hover { - box-shadow: 0 0 12px var(--green-glow); -} - -.input-slider::-moz-range-thumb { - width: 10px; - height: 10px; - border-radius: 50%; - border: none; - background: var(--green); - cursor: pointer; -} - -/* Number input */ -.input-number { - width: 54px; - background: var(--surface-2); - border: 1px solid var(--border); - border-radius: var(--r); - color: var(--text); - font-family: var(--font); - /* font-size: 11px; */ - padding: 2px 5px; - text-align: right; - outline: none; - transition: border-color 0.1s; - flex-shrink: 0; -} - -.input-number:focus { - border-color: var(--focus-ring); -} - -/* Try It */ - -.tryit { - border-top: 1px solid var(--border); - padding: 12px 20px; - background: var(--surface); - flex-shrink: 0; -} - -.tryit-header { - display: flex; - align-items: center; - justify-content: space-between; - margin-bottom: 7px; -} - -.tryit-label { - /* font-size: 9px; */ - font-weight: 600; - letter-spacing: 0.12em; - text-transform: uppercase; - color: var(--text-mid); -} - -.tryit-hint { - /* font-size: 10px; */ - color: var(--text-dim); - font-style: italic; -} - -.tryit-input { - width: 100%; - background: var(--bg); - border: 1px solid var(--border); - border-radius: var(--r); - color: var(--text); - font-family: var(--font); - /* font-size: 12px; */ - line-height: 1.6; - padding: 7px 10px; - resize: none; - outline: none; - transition: border-color 0.1s; -} - -.tryit-input:focus { - border-color: var(--border-hi); -} - -.tryit-output { - display: flex; - gap: 8px; - align-items: flex-start; - margin-top: 6px; - min-height: 18px; -} - -.output-prompt { - color: var(--green); - /* font-size: 14px; */ - line-height: 1.3; - flex-shrink: 0; -} - -.output-value { - /* font-size: 12px; */ - color: var(--amber); - word-break: break-word; - line-height: 1.5; -} - -.output-value.err { - color: var(--red); -} - -/* Right Column / Canvas */ - -.col-right { - background: var(--surface); - display: flex; - flex-direction: column; - overflow: hidden; -} - -.canvas-wrap { - flex: 1; - display: flex; - align-items: center; - justify-content: center; - padding: 16px; - min-height: 0; -} - -#canvas { - display: block; - border-radius: var(--r); - border: 1px solid var(--border); -} - -.canvas-legend { - padding: 8px 14px; - border-top: 1px solid var(--border); - display: flex; - gap: 14px; - flex-wrap: wrap; - flex-shrink: 0; - min-height: 33px; -} - -.legend-item { - display: flex; - align-items: center; - gap: 6px; - /* font-size: 10px; */ - color: var(--text-mid); -} - -.legend-swatch { - width: 20px; - height: 2px; - border-radius: 1px; - flex-shrink: 0; -} - -/* Intro */ - -.intro { - padding: 12px 20px; - border-bottom: 1px solid var(--border); - flex-shrink: 0; -} - -.intro-text { - /* font-size: 11px; */ - color: var(--text-mid); - margin-bottom: 8px; - line-height: 1.7; - font-weight: 300; -} - -.intro-install { - margin-bottom: 8px; -} - -.install-cmd { - display: inline-block; - font-family: var(--font); - /* font-size: 11px; */ - color: var(--green); - background: var(--green-dim); - border-left: 2px solid var(--green-border); - padding: 4px 12px; - border-radius: 0 var(--r) var(--r) 0; - letter-spacing: 0.01em; -} - -.intro-links { - display: flex; - gap: 12px; -} - -.intro-link { - /* font-size: 10px; */ - color: var(--text-dim); - text-decoration: none; - letter-spacing: 0.04em; - transition: color 0.12s; -} - -.intro-link:hover { - color: var(--text-mid); -} - -/* Footer */ - -footer { - height: var(--footer-h); - border-top: 1px solid var(--border); - display: flex; - align-items: center; - gap: 10px; - padding: 0 20px; - background: var(--bg); - /* font-size: 10px; */ - color: var(--text-dim); - flex-shrink: 0; -} - -.footer-sep { - color: var(--text-dim); - opacity: 0.4; -} - -.footer-link { - color: var(--text-dim); - text-decoration: none; - transition: color 0.12s; -} - -.footer-link:hover { - color: var(--text-mid); -} - -.footer-right { - margin-left: auto; -} - -/* Demo pages */ - -.demo-main { - display: grid; - grid-template-columns: 35vw 1fr; - height: calc(100vh - var(--header-h) - var(--footer-h)); -} - -.demo-controls { - display: flex; - flex-direction: column; - border-right: 1px solid var(--border); - overflow-y: auto; - overflow-x: hidden; - padding: 14px 18px; - gap: 14px; -} - -.ctrl-section { - display: flex; - flex-direction: column; - gap: 8px; -} - -.ctrl-section h3 { - font-size: var(--fs-xs); - font-weight: 600; - letter-spacing: 0.10em; - text-transform: uppercase; - color: var(--text-mid); - padding-bottom: 5px; - border-bottom: 1px solid var(--border); -} - -.ctrl-row { - display: flex; - align-items: center; - gap: 7px; -} - -.ctrl-label { - color: var(--text-mid); - flex-shrink: 0; -} - -.ctrl-slider { - flex: 1; - -webkit-appearance: none; - appearance: none; - height: 2px; - background: var(--border-hi); - border-radius: 1px; - outline: none; - cursor: pointer; -} - -.ctrl-slider::-webkit-slider-thumb { - -webkit-appearance: none; - width: 10px; - height: 10px; - border-radius: 50%; - background: var(--green); - cursor: pointer; - box-shadow: 0 0 8px var(--green-glow); - transition: box-shadow 0.1s; -} - -.ctrl-slider::-webkit-slider-thumb:hover { - box-shadow: 0 0 12px var(--green-glow); -} - -.ctrl-slider::-moz-range-thumb { - width: 10px; - height: 10px; - border-radius: 50%; - border: none; - background: var(--green); - cursor: pointer; -} - -.ctrl-num { - width: 54px; - background: var(--surface-2); - border: 1px solid var(--border); - border-radius: var(--r); - color: var(--text); - font-family: var(--font); - padding: 2px 5px; - text-align: right; - outline: none; - flex-shrink: 0; - transition: border-color 0.1s; -} - -.ctrl-num:focus { - border-color: var(--focus-ring); -} - -.ctrl-section--fill { - flex: 1; - min-height: 0; -} - -.info-text { - font-size: var(--fs-sm); - color: var(--text-dim); - line-height: 1.7; - font-weight: 300; -} - -.info-text + .info-text { - margin-top: 8px; -} - -.txt-green { color: var(--green); } -.txt-amber { color: var(--amber); } -.txt-mid { color: var(--text-mid); } - -/* Scrollbar */ - -::-webkit-scrollbar { - width: 4px; -} -::-webkit-scrollbar-track { - background: transparent; -} -::-webkit-scrollbar-thumb { - background: var(--border-hi); - border-radius: 2px; -} diff --git a/deploy-docs.yml b/deploy-docs.yml deleted file mode 100644 index c94a577..0000000 --- a/deploy-docs.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Documentation - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [master] - pull_request: - branches: [master] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - runs-on: ubuntu-latest - steps: - - name: Checkout 🛎️ - uses: actions/checkout@v2.3.1 - - - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built. - run: | - npm install - npm run document - - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@4.1.4 - with: - branch: gh-pages # The branch the action should deploy to. - folder: documentation # The folder the action should deploy. diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts new file mode 100644 index 0000000..9069bfb --- /dev/null +++ b/docs/.vitepress/config.mts @@ -0,0 +1,142 @@ +import { readFileSync, existsSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { defineConfig, type DefaultTheme } from 'vitepress' + +const here = (path: string) => fileURLToPath(new URL(path, import.meta.url)) + +const pkg = JSON.parse(readFileSync(here('../../package.json'), 'utf8')) + +// The API sidebar is generated by TypeDoc (`npm run docs:api`) alongside the +// API pages. Missing before the first run, so read it leniently. +const apiSidebar = (): DefaultTheme.SidebarItem[] => { + const file = here('../api/typedoc-sidebar.json') + return existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : [] +} + +const guide: DefaultTheme.SidebarItem[] = [ + { + text: 'Getting started', + items: [ + { text: 'Introduction', link: '/' }, + { text: 'Installation', link: '/getting-started/installation' }, + { text: 'Conventions', link: '/getting-started/conventions' } + ] + }, + { + text: 'Vectors', + items: [ + { text: 'Vec2', link: '/vectors/vec2' }, + { text: 'Vec3', link: '/vectors/vec3' }, + { text: 'Vec4', link: '/vectors/vec4' }, + { text: 'Swizzling', link: '/vectors/swizzling' } + ] + }, + { + text: 'Matrices', + items: [ + { text: '2D transforms', link: '/matrices/2d-transforms' }, + { text: '3D transforms', link: '/matrices/3d-transforms' }, + { text: 'Cameras and projection', link: '/matrices/projection' } + ] + }, + { + text: 'Rotation', + items: [{ text: 'Quaternions', link: '/rotation/quaternions' }] + }, + { + text: 'Geometry', + items: [ + { text: 'Plane', link: '/geometry/plane' }, + { text: 'Ray', link: '/geometry/ray' } + ] + }, + { + text: 'Colour', + items: [ + { text: 'Color', link: '/colour/color' }, + { text: 'Colour spaces', link: '/colour/colour-spaces' }, + { text: 'Gradients', link: '/colour/gradients' } + ] + }, + { + text: 'Utilities', + items: [{ text: 'Scalar functions', link: '/utilities/scalars' }] + }, + { + text: 'Guides', + items: [{ text: 'With WebGL and wtc-gl', link: '/guides/webgl' }] + } +] + +const api: DefaultTheme.SidebarItem[] = [ + { + text: 'API', + items: [{ text: 'Overview', link: '/api/' }, ...apiSidebar()] + } +] + +export default defineConfig({ + title: 'wtc-math', + description: + 'Vectors, matrices, quaternions, colours and scalar helpers for graphics and creative coding in JavaScript and TypeScript.', + base: '/wtc-math/', + cleanUrls: true, + // The README is for people working on the docs + srcExclude: ['README.md'], + lastUpdated: false, + // The API pages link to sources on GitHub; everything else must resolve + ignoreDeadLinks: [/^https?:\/\//], + head: [['link', { rel: 'icon', href: '/wtc-math/favicon.svg' }]], + + markdown: { + // Code blocks are dark in both themes, as in the wtc-gl docs + theme: { light: 'github-dark', dark: 'github-dark' }, + lineNumbers: false + }, + + themeConfig: { + logo: { src: '/logo.svg', alt: '' }, + siteTitle: 'wtc-math', + nav: [ + { text: 'Docs', link: '/', activeMatch: '^/(?!api)' }, + { text: 'API', link: '/api/', activeMatch: '^/api/' }, + { + text: `v${pkg.version}`, + items: [ + { + text: 'Changelog', + link: 'https://github.com/wethegit/wtc-math/blob/master/CHANGELOG.md' + }, + { text: 'npm', link: 'https://www.npmjs.com/package/wtc-math' }, + { text: 'wtc-gl', link: 'https://wethegit.github.io/wtc-gl/docs/' } + ] + } + ], + sidebar: { + '/api/': api, + '/': guide + }, + outline: { level: [2, 3], label: 'On this page' }, + search: { provider: 'local' }, + socialLinks: [ + { icon: 'github', link: 'https://github.com/wethegit/wtc-math' } + ], + editLink: { + pattern: 'https://github.com/wethegit/wtc-math/edit/master/docs/:path', + text: 'Edit this page on GitHub' + }, + docFooter: { prev: 'Previous', next: 'Next' } + }, + + vite: { + resolve: { + // Examples run against the library's source, so they show unreleased changes + alias: [ + { find: /^wtc-math\/color$/, replacement: here('../../src/Color.ts') }, + { find: /^wtc-math\/plane$/, replacement: here('../../src/Plane.ts') }, + { find: /^wtc-math\/ray$/, replacement: here('../../src/Ray.ts') }, + { find: /^wtc-math$/, replacement: here('../../src/index.ts') } + ] + } + } +}) diff --git a/docs/.vitepress/theme/components/Example.vue b/docs/.vitepress/theme/components/Example.vue new file mode 100644 index 0000000..28f3f77 --- /dev/null +++ b/docs/.vitepress/theme/components/Example.vue @@ -0,0 +1,170 @@ + + + diff --git a/docs/.vitepress/theme/components/PageHeader.vue b/docs/.vitepress/theme/components/PageHeader.vue new file mode 100644 index 0000000..09f6f45 --- /dev/null +++ b/docs/.vitepress/theme/components/PageHeader.vue @@ -0,0 +1,42 @@ + + + diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css new file mode 100644 index 0000000..ec0fc20 --- /dev/null +++ b/docs/.vitepress/theme/custom.css @@ -0,0 +1,345 @@ +/* + * The wtc-gl docs theme, in green. A light restyle of + * VitePress's default theme after tailwindcss.com/docs: + * mono section labels, a ruled sidebar with the active page marked on the + * rule, a section name above each title with a lead paragraph under it, + * and dark code blocks in both themes. + */ +@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&display=swap'); + +:root { + --vp-font-family-mono: + 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace; + + --vp-c-brand-1: #0d8040; + --vp-c-brand-2: #11994d; + --vp-c-brand-3: #2fbf71; + --vp-c-brand-soft: rgb(13 128 64 / 0.1); + + --vp-c-text-1: #0b0d12; + --vp-c-text-2: #4b5563; + --vp-c-text-3: #6b7280; + --vp-c-divider: rgb(11 13 18 / 0.08); + --vp-c-gutter: rgb(11 13 18 / 0.05); + + --vp-code-block-bg: #0e1016; + --vp-code-block-divider-color: rgb(255 255 255 / 0.08); + --vp-code-copy-code-bg: rgb(255 255 255 / 0.06); + --vp-code-copy-code-hover-bg: rgb(255 255 255 / 0.1); + --vp-code-lang-color: rgb(255 255 255 / 0.4); + /* Code groups sit on the dark code background in both themes */ + --vp-code-tab-bg: var(--vp-code-block-bg); + --vp-code-tab-divider: rgb(255 255 255 / 0.08); + --vp-code-tab-text-color: rgb(255 255 255 / 0.5); + --vp-code-tab-hover-text-color: rgb(255 255 255 / 0.8); + --vp-code-tab-active-text-color: #fff; + --vp-code-tab-active-bar-color: var(--vp-c-brand-3); + --vp-code-color: var(--vp-c-text-1); + --vp-code-bg: rgb(11 13 18 / 0.05); + + --vp-layout-max-width: 1560px; + --vp-sidebar-width: 288px; + + --docs-ring: rgb(11 13 18 / 0.1); + --docs-stage-bg: #f3f4f6; + + /* Series colours for the live examples */ + --docs-c-1: #0d8040; + --docs-c-2: #5533cc; + --docs-c-3: #b07a00; +} + +.dark { + --vp-c-bg: #07070e; + --vp-c-bg-alt: #07070e; + --vp-c-bg-elv: #10111a; + --vp-c-bg-soft: #10111a; + + --vp-c-brand-1: #3ccf7e; + --vp-c-brand-2: #5fdb95; + --vp-c-brand-3: #1fa65a; + --vp-c-brand-soft: rgb(60 207 126 / 0.14); + + --vp-c-text-1: #eef0f7; + --vp-c-text-2: rgb(221 224 238 / 0.7); + --vp-c-text-3: rgb(221 224 238 / 0.5); + --vp-c-divider: rgb(255 255 255 / 0.08); + --vp-c-gutter: rgb(255 255 255 / 0.04); + + --vp-code-block-bg: #10111a; + --vp-code-color: var(--vp-c-text-1); + --vp-code-bg: rgb(255 255 255 / 0.07); + + --docs-ring: rgb(255 255 255 / 0.1); + --docs-stage-bg: #0c0d15; + + --docs-c-1: #3ccf7e; + --docs-c-2: #a08cff; + --docs-c-3: #f0b429; +} + +/* ── Top bar ─────────────────────────────────────────────────────────── */ + +.VPNavBar, +.VPNavBar.has-sidebar .content, +.VPNavBar:not(.home).top .content { + background: transparent !important; +} +.VPNav { + background: color-mix(in srgb, var(--vp-c-bg) 85%, transparent); + backdrop-filter: blur(12px); + border-bottom: 1px solid var(--vp-c-divider); +} +.VPNavBar .divider, +.VPNavBar.has-sidebar .divider-line { + display: none; +} +.VPNavBarTitle .title { + font-weight: 600; + letter-spacing: -0.01em; +} +.VPNavBarMenuLink, +.VPNavBarMenuGroup .button { + font-size: 14px; +} + +/* ── Sidebar: mono group labels, links on a rule ─────────────────────── */ + +.VPSidebar { + border-right: 1px solid var(--vp-c-divider); +} +.VPSidebarItem.level-0 { + padding-bottom: 20px; +} +.VPSidebarItem.level-0 > .item > .text, +.VPSidebarItem.level-0 > .item .text { + font-family: var(--vp-font-family-mono); + font-size: 12px; + font-weight: 500; + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--vp-c-text-3); +} +.VPSidebarItem.level-0 > .items { + margin-top: 6px; + border-left: 1px solid var(--vp-c-divider); +} +.VPSidebarItem.level-1 > .item, +.VPSidebarItem.level-2 > .item { + margin-left: -1px; + padding-left: 15px; + border-left: 1px solid transparent; +} +.VPSidebarItem.level-1 .text, +.VPSidebarItem.level-2 .text { + font-size: 14px; + font-weight: 400; + color: var(--vp-c-text-2); +} +.VPSidebarItem.level-1 > .item:hover, +.VPSidebarItem.level-2 > .item:hover { + border-left-color: var(--vp-c-text-3); +} +.VPSidebarItem.level-1 > .item:hover .text, +.VPSidebarItem.level-2 > .item:hover .text { + color: var(--vp-c-text-1); +} +.VPSidebarItem.is-active > .item { + border-left-color: var(--vp-c-brand-1); +} +.VPSidebarItem.is-active > .item .text { + color: var(--vp-c-text-1); + font-weight: 600; +} +.VPSidebarItem .indicator { + display: none; +} + +/* ── Page header: section, title, lead ───────────────────────────────── */ + +.page-section { + margin: 0 0 10px; + font-family: var(--vp-font-family-mono); + font-size: 13px; + font-weight: 500; + letter-spacing: 0.1em; + text-transform: uppercase; + color: var(--vp-c-brand-1); +} +.vp-doc h1 { + font-size: 36px; + line-height: 1.15; + font-weight: 600; + letter-spacing: -0.025em; +} +.vp-doc h2 { + border-top: none; + margin-top: 56px; + padding-top: 0; + font-size: 24px; + font-weight: 600; + letter-spacing: -0.015em; +} +.vp-doc h3 { + font-size: 18px; + font-weight: 600; +} +.vp-doc p.lead, +.vp-doc .lead { + margin-top: 12px; + font-size: 18px; + line-height: 1.65; + color: var(--vp-c-text-2); +} +.vp-doc h1 + p { + margin-top: 12px; +} + +/* ── Code ────────────────────────────────────────────────────────────── */ + +.vp-doc div[class*='language-'] { + border-radius: 12px; + box-shadow: 0 0 0 1px var(--docs-ring); +} +.dark .vp-doc div[class*='language-'] { + box-shadow: 0 0 0 1px var(--docs-ring); +} +.vp-doc :not(pre) > code { + font-weight: 500; + font-size: 0.875em; +} +.vp-code-group .tabs { + border-radius: 12px 12px 0 0; +} + +/* ── Tables: the option and property tables ──────────────────────────── */ + +.vp-doc table { + display: table; + width: 100%; + border-collapse: collapse; + font-size: 14px; +} +.vp-doc tr { + background: transparent !important; + border-top: none; +} +.vp-doc th, +.vp-doc td { + border: none; + border-bottom: 1px solid var(--vp-c-divider); + padding: 10px 16px 10px 0; + text-align: left; + vertical-align: top; + overflow-wrap: break-word; +} +/* Names on one line; types and descriptions wrap */ +.vp-doc td:first-child { + white-space: nowrap; +} +.vp-doc th { + font-family: var(--vp-font-family-mono); + font-size: 12px; + font-weight: 500; + letter-spacing: 0.05em; + text-transform: uppercase; + color: var(--vp-c-text-3); + background: transparent; +} +.vp-doc td:first-child code { + color: var(--vp-c-brand-1); + background: transparent; + padding: 0; +} + +/* ── Live examples ───────────────────────────────────────────────────── */ + +.example { + margin: 24px 0 0; + border-radius: 12px; + box-shadow: 0 0 0 1px var(--docs-ring); + overflow: hidden; + background: var(--docs-stage-bg); +} +.example__stage { + position: relative; + width: 100%; +} +.example__stage canvas { + display: block; + width: 100% !important; + height: 100% !important; +} +.example__message { + margin: 0 !important; + padding: 12px 16px; + font-size: 14px; + color: var(--vp-c-text-2); +} +.example__bar { + display: flex; + align-items: center; + gap: 16px; + padding: 8px 12px; + border-top: 1px solid var(--vp-c-divider); + background: var(--vp-c-bg); + font-size: 13px; +} +.example__button { + font-family: var(--vp-font-family-mono); + font-size: 12px; + font-weight: 500; + letter-spacing: 0.05em; + text-transform: uppercase; + color: var(--vp-c-text-2); +} +.example__button:hover { + color: var(--vp-c-text-1); +} +.example__link { + margin-left: auto; + font-weight: 500; + text-decoration: none !important; +} +/* The example's code sits straight under it, as one card */ +.example + div[class*='language-'], +.example + .vp-code-group { + margin-top: 0; +} +.example:has(+ div[class*='language-']), +.example:has(+ .vp-code-group) { + border-radius: 12px 12px 0 0; +} +.example + div[class*='language-'], +.example + .vp-code-group .tabs { + border-top-left-radius: 0; + border-top-right-radius: 0; +} + +/* ── Examples ────────────────────────────────────────────────────────── */ + +/* The gallery takes the outline's space; its prose keeps a reading width */ +.showcase-gallery .vp-doc > div > p { + max-width: 688px; +} +/* A walkthrough's screenshot, and the links under it */ +.vp-doc img.showcase-shot { + display: block; + width: 100%; + aspect-ratio: 16 / 9; + object-fit: cover; + border-radius: 12px; + box-shadow: 0 0 0 1px var(--docs-ring); + background: var(--docs-stage-bg); +} +.vp-doc p:has(> img.showcase-shot) { + margin: 32px 0 0; +} +.vp-doc .showcase-links { + margin-top: 12px; + font-size: 14px; + color: var(--vp-c-text-3); +} +.vp-doc .showcase-links a { + text-decoration: none; +} diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts new file mode 100644 index 0000000..3c8c0df --- /dev/null +++ b/docs/.vitepress/theme/index.ts @@ -0,0 +1,19 @@ +import { h } from 'vue' +import DefaultTheme from 'vitepress/theme' +import type { Theme } from 'vitepress' + +import Example from './components/Example.vue' +import PageHeader from './components/PageHeader.vue' +import './custom.css' + +export default { + extends: DefaultTheme, + Layout: () => + h(DefaultTheme.Layout, null, { + // The section name above each page's title, as on tailwindcss.com + 'doc-before': () => h(PageHeader) + }), + enhanceApp({ app }) { + app.component('Example', Example) + } +} satisfies Theme diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..c18f4eb --- /dev/null +++ b/docs/README.md @@ -0,0 +1,60 @@ +# wtc-math docs + +The documentation site, built with [VitePress](https://vitepress.dev) and published to GitHub Pages at [wethegit.github.io/wtc-math](https://wethegit.github.io/wtc-math/). It follows the [wtc-gl docs](https://github.com/wethegit/wtc-gl/tree/master/packages/docs). + +```sh +npm run docs:dev # API pages, then the dev server on port 5274 +npm run docs:build # API pages, then a static build in docs/.vitepress/dist +``` + +- Guides are Markdown pages in the section folders (`getting-started/`, `vectors/`, `matrices/` and so on). The sidebar is in `.vitepress/config.mts`. +- `api/` is generated from the TSDoc comments in `src/` by TypeDoc (`npm run docs:api`, configured in `typedoc.json`) and isn't committed. The build fails on an undocumented export or a broken `{@link}`, so document anything you export. +- `Color`, `Plane` and `Ray` are separate entry points; their `@module` comments name them `wtc-math/color` and so on in the API reference. +- Live examples are modules in `examples/`, shown with ``. Helpers they share are in `examples/lib/`. + +## Writing a page + +Each page starts with a title and a one-sentence lead, marked `{.lead}`: + +```md +# Quaternions + +A `Quat` holds a rotation in 3D. {.lead} +``` + +Then explain the idea in a paragraph or two, show it working, and work through what a reader actually reaches for, each under its own `##` heading. Finish with links to related pages and the API reference. + +- Write plainly, in British English (colour, normalise, centre), but keep code names as they are (`Color`, `Plane.normalize`). Short sentences; say what something does and why you'd use it. No "simply", "just", "easy" or "powerful". +- Code is complete enough to paste: imports, then the setup. Check names and behaviour against `src/` rather than memory, and say whether a method changes its object in place or returns a new one. +- Link to API pages by path, without the extension: `[Vec2](/api/wtc-math/classes/Vec2)`, `[Color](/api/wtc-math/color/classes/Color)`. Link to other guides the same way: `[Conventions](/getting-started/conventions)`. The build fails on dead links. +- Use `::: tip` and `::: warning` containers sparingly, for things that trip people up. + +## Live examples + +An example is a module in `examples/` whose default export takes the element to draw into and returns `{ frame(time, delta), resize(width, height), dispose() }`. Most use the `stage` helper, which makes a 2D canvas and returns that object for you: + +```js +import { Vec2 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { arrow } from './lib/draw.js' + +export default function (container) { + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const centre = new Vec2(width / 2, height / 2) + const tip = pointer ?? centre.addNew(new Vec2(80, 0).rotate(time)) + arrow(ctx, centre, tip, colours.one) + }) +} +``` + +The draw function runs every frame while the example plays, and again when the pointer moves or the canvas resizes, so interaction works while it's paused. It draws in CSS pixels on a cleared canvas. `pointer` is a `Vec2` or null, and `colours` follow the light and dark themes (`one`, `two`, `three` for series, plus `text`, `muted`, `grid` and `font`). + +Show it on a page with its source under it: + +```md + + +<<< @/examples/vec2-projection.js +``` + +`` makes the example when it nears the screen, only calls `frame` while it's visible, and disposes of it when it's far away. Keep examples small and focused on the page's idea, and don't add a render loop or window listeners of your own. Examples import `wtc-math` from `src/`, so they show unreleased changes. diff --git a/docs/colour/color.md b/docs/colour/color.md new file mode 100644 index 0000000..22d0468 --- /dev/null +++ b/docs/colour/color.md @@ -0,0 +1,74 @@ +# Color + +An RGBA colour, with each channel from 0 to 1, that converts to and from the formats you meet in CSS and design tools. {.lead} + +```js +import { Color } from 'wtc-math/color' + +const red = new Color(1, 0, 0) +const glass = new Color(0.6, 0.8, 1, 0.5) +``` + +`Color` has an entry point of its own, `wtc-math/color`. Its channels are `r`, `g`, `b` and `a`, read and written directly. They're sRGB values, the same as CSS uses, scaled to 0–1 rather than 0–255. Alpha defaults to 1. + +## Making colours + +From the formats you're most likely to have: + +```js +Color.fromHex('#ff8800') // or '#f80', or 'ff8800' +Color.fromRGB255(255, 136, 0) +Color.fromHSL(32, 1, 0.5) // hue in degrees, saturation and lightness 0–1 +Color.fromHSV(32, 1, 1) // hue in degrees, saturation and value 0–1 +Color.fromOklch(0.74, 0.18, 56) // see Colour spaces +``` + +`fromHex` reads 3- and 6-digit hex. It doesn't read alpha from 4- or 8-digit hex, and anything that isn't hex comes out black. + +`Color.interpolate(value)` accepts any of a `Color`, a hex string, an `[r, g, b, a?]` array or an `{ r, g, b, a? }` object, which is handy for options that take a colour in whatever form is to hand: + +```js +function setTint(tint) { + const colour = Color.interpolate(tint) // '#f80', [1, 0.5, 0], { r: 1, g: 0.5, b: 0 } +} +``` + +## Using them + +`toCSS()` gives a string for a canvas or a style, `rgb(…)` or `rgba(…)` depending on alpha, and `toString()` is the same. `toHex()` gives `#rrggbb`, dropping alpha. `array` gives `[r, g, b, a]`, ready for a shader uniform: + +```js +const orange = Color.fromHex('#ff8800') + +ctx.fillStyle = orange.toCSS() // 'rgb(255, 136, 0)' +element.style.color = `${orange}` +orange.toHex() // '#ff8800' +uniform.value = orange.array // [1, 0.533, 0, 1] +``` + +`toHSL()`, `toHSV()`, `toOklab()` and `toOklch()` give the colour in those spaces, as arrays of three numbers. Alpha is left out. + +```js +orange.toHSL() // [32, 1, 0.5] +``` + +`toHex` and `toCSS` don't clamp, so keep channels within 0–1 before formatting a colour you've done arithmetic on. + +## Arithmetic + +`add`, `multiply` and `multiplyScalar` change the colour in place; add `New` for a copy. `add` and `multiplyScalar` cap the channels at 1, and `multiplyScalar` leaves alpha alone: + +```js +const lit = baseColour.multiplyNew(lightColour) // tint by a light +const brighter = baseColour.multiplyScalarNew(1.2) +``` + +## Blending + +`lerp(c, t)` moves the colour `t` of the way towards `c`, and `Color.lerp(a, b, t)` returns the blend as a new colour. Both blend the sRGB channels directly, which is fast, but the midpoints of a blend can look muddy or too dark. For gradients, blend in OKLab or OKLCH instead; [Gradients](/colour/gradients) compares them. + +## Related + +- [Colour spaces](/colour/colour-spaces) +- [Gradients](/colour/gradients) +- API: [Color](/api/wtc-math/color/classes/Color), [ColorLike](/api/wtc-math/color/type-aliases/ColorLike) diff --git a/docs/colour/colour-spaces.md b/docs/colour/colour-spaces.md new file mode 100644 index 0000000..cc59634 --- /dev/null +++ b/docs/colour/colour-spaces.md @@ -0,0 +1,58 @@ +# Colour spaces + +`Color` converts between sRGB, HSL, HSV, OKLab and OKLCH. Which one you work in changes how predictable your colours are. {.lead} + +The channels a `Color` stores are sRGB, the space CSS and most images use. The other spaces are ways of describing the same colours that make some changes easier: rotating a hue, darkening, desaturating. + + + +<<< @/examples/colour-spaces.js + +## HSL and HSV + +HSL and HSV describe a colour by hue, an angle around the colour wheel in degrees, and two amounts from 0 to 1: saturation and lightness (HSL), or saturation and value (HSV, also called HSB). They're familiar from colour pickers and quick to compute. + +```js +import { Color } from 'wtc-math/color' + +const [h, s, l] = Color.fromHex('#3388ff').toHSL() +const complement = Color.fromHSL((h + 180) % 360, s, l) +``` + +Their weakness is that "lightness" doesn't match what you see. At the same HSL lightness, yellow looks far brighter than blue, as the top strips in the example show. Swap the hue in a palette built in HSL and its contrast changes with it. + +## OKLab and OKLCH + +[OKLab](https://bottosson.github.io/posts/oklab/) is a perceptual colour space: equal steps in it look like roughly equal changes. Its `L` is perceived lightness from 0 to 1, and `a` and `b` run from green to red and from blue to yellow. + +OKLCH is OKLab in polar form, the perceptual counterpart of HSL: + +- `L`, lightness, 0 to 1, +- `C`, chroma or colourfulness, from 0 for grey up to about 0.4 for the most vivid colours a screen can show, +- `H`, hue in degrees. + +```js +const [L, C, H] = Color.fromHex('#3388ff').toOklch() + +// The same lightness and chroma at other hues: a palette with even contrast +const palette = [0, 72, 144, 216, 288].map((offset) => + Color.fromOklch(L, C, (H + offset) % 360) +) +``` + +That's the bottom strip in the example: every hue at the same `L` and `C`, and the greys under it barely change. + +`Color.fromOklch` and `Color.fromOklab` clamp each channel to 0–1, because not every combination of `L`, `C` and `H` is a colour a screen can show. Very high chroma at very high or low lightness gets clipped and shifts in hue, so keep chroma moderate (0.1–0.2) for colours that hold their hue across the wheel. + +## Which to use + +- **sRGB** to store, format and send colours, and for arithmetic that models light, such as tinting. +- **HSL or HSV** to match a design tool or a colour picker. +- **OKLCH** to build palettes, adjust lightness or chroma predictably, or rotate hues without changing contrast. +- **OKLab or OKLCH** to [blend](/colour/gradients). + +## Related + +- [Color](/colour/color) +- [Gradients](/colour/gradients) +- API: [Color](/api/wtc-math/color/classes/Color) diff --git a/docs/colour/gradients.md b/docs/colour/gradients.md new file mode 100644 index 0000000..1982498 --- /dev/null +++ b/docs/colour/gradients.md @@ -0,0 +1,52 @@ +# Gradients + +Blend between colours with `Color.lerp`, `Color.lerpOklab` or `Color.lerpOklch`. They give quite different gradients from the same two colours. {.lead} + +Each takes two colours and an amount from 0 to 1, and returns a new colour. Alpha is blended linearly in all three. + + + +<<< @/examples/gradients.js + +## The three blends + +**`Color.lerp(a, b, t)`** blends the sRGB channels directly. It's the cheapest, and what CSS gradients have traditionally done, but colours far apart on the wheel pass through a dull, greyish middle: blue to yellow goes through grey. + +**`Color.lerpOklab(a, b, t)`** blends in OKLab. Lightness changes evenly along the gradient and the middle stays clean, but complementary colours still pass close to grey, because the straight line between them crosses the centre of the colour space. + +**`Color.lerpOklch(a, b, t)`** blends lightness, chroma and hue separately, turning the hue the shorter way around the wheel. The middle stays as colourful as the ends, passing through the hues between. When one end is grey it has no real hue, so the blend keeps the other end's hue rather than sweeping through unrelated colours. + +```js +import { Color } from 'wtc-math/color' + +const from = Color.fromHex('#1e3a8a') +const to = Color.fromHex('#fde047') + +const middle = Color.lerpOklch(from, to, 0.5) +``` + +## Choosing + +- `lerpOklch` for vivid gradients between different hues, and for animating a colour around the wheel. +- `lerpOklab` for gradients that should stay close to the two colours you chose, such as two shades of a brand colour, or a colour to grey. +- `lerp` when speed matters more than looks, or to match sRGB blending elsewhere, such as in a shader. + +## Several stops + +For a gradient with more than two colours, find the two stops either side of `t` and blend between them: + +```js +function gradient(stops, t) { + const scaled = Math.min(Math.max(t, 0), 1) * (stops.length - 1) + const i = Math.min(Math.floor(scaled), stops.length - 2) + return Color.lerpOklch(stops[i], stops[i + 1], scaled - i) +} + +const heat = ['#000004', '#7c1d6f', '#f2741f', '#fcfdbf'].map(Color.fromHex) +const colour = gradient(heat, 0.6) +``` + +## Related + +- [Colour spaces](/colour/colour-spaces) +- [Color](/colour/color) diff --git a/docs/examples/colour-spaces.js b/docs/examples/colour-spaces.js new file mode 100644 index 0000000..e1e01ce --- /dev/null +++ b/docs/examples/colour-spaces.js @@ -0,0 +1,36 @@ +import { Color } from 'wtc-math/color' +import { stage } from './lib/stage.js' +import { label } from './lib/draw.js' + +// A sweep around the hue circle in HSL, and in OKLCH. Under each, the same +// colours with only their perceived lightness (OKLab L) kept: HSL's swings +// from dark blue to bright yellow, OKLCH's stays even. +export default function (container) { + return stage(container, ({ ctx, width, height, time, colours }) => { + const pad = 16 + const rowHeight = (height - pad * 5) / 4 + const steps = 90 + const stepWidth = (width - pad * 2) / steps + const offset = time * 20 + + const rows = [ + { name: 'Color.fromHSL(h, 1, 0.5)', make: (h) => Color.fromHSL(h, 1, 0.5) }, + { name: 'Color.fromOklch(0.7, 0.13, h)', make: (h) => Color.fromOklch(0.7, 0.13, h) } + ] + rows.forEach(({ name, make }, row) => { + const y = pad + row * 2 * (rowHeight + pad) + for (let i = 0; i < steps; i++) { + const colour = make((i * 360) / steps + offset) + const x = pad + i * stepWidth + ctx.fillStyle = colour.toCSS() + ctx.fillRect(x, y, stepWidth + 0.5, rowHeight) + + // The perceived lightness, as a grey + const [L] = colour.toOklab() + ctx.fillStyle = Color.fromOklab(L, 0, 0).toCSS() + ctx.fillRect(x, y + rowHeight, stepWidth + 0.5, rowHeight) + } + label(ctx, name, { x: pad + 8, y: y + 14 }, '#000', colours.font) + }) + }) +} diff --git a/docs/examples/gradients.js b/docs/examples/gradients.js new file mode 100644 index 0000000..eab25fc --- /dev/null +++ b/docs/examples/gradients.js @@ -0,0 +1,31 @@ +import { Color } from 'wtc-math/color' +import { stage } from './lib/stage.js' +import { label } from './lib/draw.js' + +// The same two colours blended three ways. The ends drift around the hue +// circle so you can compare many pairs. +export default function (container) { + return stage(container, ({ ctx, width, height, time, colours }) => { + const pad = 16 + const rowHeight = (height - pad * 4) / 3 + const steps = 64 + const stepWidth = (width - pad * 2) / steps + + const from = Color.fromOklch(0.55, 0.2, 260 + time * 15) + const to = Color.fromOklch(0.9, 0.17, 100 + time * 15) + + const rows = [ + ['Color.lerp', Color.lerp], + ['Color.lerpOklab', Color.lerpOklab], + ['Color.lerpOklch', Color.lerpOklch] + ] + rows.forEach(([name, blend], row) => { + const y = pad + row * (rowHeight + pad) + for (let i = 0; i < steps; i++) { + ctx.fillStyle = blend(from, to, i / (steps - 1)).toCSS() + ctx.fillRect(pad + i * stepWidth, y, stepWidth + 0.5, rowHeight) + } + label(ctx, name, { x: pad + 8, y: y + 14 }, '#fff', colours.font) + }) + }) +} diff --git a/docs/examples/intro.js b/docs/examples/intro.js new file mode 100644 index 0000000..d19bbfa --- /dev/null +++ b/docs/examples/intro.js @@ -0,0 +1,40 @@ +import { Vec2 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { arrow, axes, dot, label, line } from './lib/draw.js' + +// Two vectors and their sum. Move the pointer to steer `b`. +export default function (container) { + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const origin = new Vec2(width / 2, height / 2) + axes(ctx, origin, width, height, colours) + + // y points down on a canvas, so flip it to draw maths the usual way up + const toScreen = (v) => new Vec2(origin.x + v.x, origin.y - v.y) + const fromScreen = (p) => new Vec2(p.x - origin.x, origin.y - p.y) + + const a = new Vec2(110, 0).rotate(time * 0.4) + const b = pointer ? fromScreen(pointer) : new Vec2(-40, 90) + const sum = a.addNew(b) + + // The parallelogram the sum completes + line(ctx, toScreen(a), toScreen(sum), colours.muted, 1, [4, 4]) + line(ctx, toScreen(b), toScreen(sum), colours.muted, 1, [4, 4]) + + arrow(ctx, origin, toScreen(a), colours.one) + arrow(ctx, origin, toScreen(b), colours.two) + arrow(ctx, origin, toScreen(sum), colours.three) + dot(ctx, origin, colours.text, 3) + + const angle = Vec2.getAngle(a, b) + label(ctx, 'a', toScreen(a.scaleNew(1.12)), colours.one, colours.font) + label(ctx, 'b', toScreen(b.scaleNew(1.12)), colours.two, colours.font) + label(ctx, 'a + b', toScreen(sum).addScalar(10), colours.three, colours.font) + label( + ctx, + `|a + b| = ${sum.length.toFixed(1)} angle(a, b) = ${((angle * 180) / Math.PI).toFixed(0)}°`, + new Vec2(16, height - 20), + colours.muted, + colours.font + ) + }) +} diff --git a/docs/examples/lib/draw.js b/docs/examples/lib/draw.js new file mode 100644 index 0000000..de4b67d --- /dev/null +++ b/docs/examples/lib/draw.js @@ -0,0 +1,109 @@ +/** + * Small canvas helpers shared by the examples. Points are anything with an + * x and a y, in CSS pixels. + */ + +/** A line from `a` to `b` with an arrowhead at `b`. */ +export function arrow(ctx, a, b, colour, width = 2) { + const angle = Math.atan2(b.y - a.y, b.x - a.x) + const head = 9 + ctx.strokeStyle = colour + ctx.fillStyle = colour + ctx.lineWidth = width + ctx.lineCap = 'round' + ctx.beginPath() + ctx.moveTo(a.x, a.y) + ctx.lineTo( + b.x - Math.cos(angle) * head * 0.6, + b.y - Math.sin(angle) * head * 0.6 + ) + ctx.stroke() + ctx.beginPath() + ctx.moveTo(b.x, b.y) + ctx.lineTo( + b.x - Math.cos(angle - 0.4) * head, + b.y - Math.sin(angle - 0.4) * head + ) + ctx.lineTo( + b.x - Math.cos(angle + 0.4) * head, + b.y - Math.sin(angle + 0.4) * head + ) + ctx.closePath() + ctx.fill() +} + +/** A line from `a` to `b`. */ +export function line(ctx, a, b, colour, width = 1, dash = []) { + ctx.strokeStyle = colour + ctx.lineWidth = width + ctx.setLineDash(dash) + ctx.beginPath() + ctx.moveTo(a.x, a.y) + ctx.lineTo(b.x, b.y) + ctx.stroke() + ctx.setLineDash([]) +} + +/** A filled circle. */ +export function dot(ctx, p, colour, radius = 4) { + ctx.fillStyle = colour + ctx.beginPath() + ctx.arc(p.x, p.y, radius, 0, Math.PI * 2) + ctx.fill() +} + +/** An outlined circle. */ +export function ring(ctx, p, colour, radius, width = 1, dash = []) { + ctx.strokeStyle = colour + ctx.lineWidth = width + ctx.setLineDash(dash) + ctx.beginPath() + ctx.arc(p.x, p.y, radius, 0, Math.PI * 2) + ctx.stroke() + ctx.setLineDash([]) +} + +/** Text in the docs' mono font. */ +export function label(ctx, text, p, colour, font, align = 'left') { + ctx.fillStyle = colour + ctx.font = `500 12px ${font}` + ctx.textAlign = align + ctx.textBaseline = 'middle' + ctx.fillText(text, p.x, p.y) +} + +/** Axes through `origin`, with a faint grid every `step` pixels. */ +export function axes(ctx, origin, width, height, colours, step = 40) { + ctx.strokeStyle = colours.grid + ctx.lineWidth = 1 + ctx.beginPath() + for (let x = origin.x % step; x < width; x += step) { + ctx.moveTo(x, 0) + ctx.lineTo(x, height) + } + for (let y = origin.y % step; y < height; y += step) { + ctx.moveTo(0, y) + ctx.lineTo(width, y) + } + ctx.stroke() + ctx.strokeStyle = colours.muted + ctx.globalAlpha = 0.5 + ctx.beginPath() + ctx.moveTo(0, origin.y) + ctx.lineTo(width, origin.y) + ctx.moveTo(origin.x, 0) + ctx.lineTo(origin.x, height) + ctx.stroke() + ctx.globalAlpha = 1 +} + +/** A polyline through `points`, closed if asked. */ +export function path(ctx, points, colour, width = 1.5, closed = false) { + ctx.strokeStyle = colour + ctx.lineWidth = width + ctx.lineJoin = 'round' + ctx.beginPath() + points.forEach((p, i) => (i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y))) + if (closed) ctx.closePath() + ctx.stroke() +} diff --git a/docs/examples/lib/stage.js b/docs/examples/lib/stage.js new file mode 100644 index 0000000..9d7fb1e --- /dev/null +++ b/docs/examples/lib/stage.js @@ -0,0 +1,123 @@ +import { Vec2 } from 'wtc-math' + +/** + * A 2D canvas for a live example. Give it the container `` passes + * in and a draw function, and return what it returns: + * + * export default function (container) { + * return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + * // draw a frame + * }) + * } + * + * `draw` is called every frame while the example plays, and again when the + * pointer moves or the canvas resizes, so interaction works while paused. + * The canvas is cleared first, and `ctx` is scaled so you draw in CSS + * pixels. `pointer` is a Vec2 in CSS pixels, or null when it's off the + * canvas. `colours` follow the docs' light and dark themes. + */ +export function stage(container, draw, { onPointerDown, onPointerUp } = {}) { + const canvas = document.createElement('canvas') + canvas.style.touchAction = 'none' + container.appendChild(canvas) + const ctx = canvas.getContext('2d') + + const state = { + ctx, + canvas, + width: 0, + height: 0, + time: 0, + delta: 0, + pointer: null, + down: false, + colours: readColours() + } + + const redraw = () => { + if (!state.width || !state.height) return + const dpr = Math.min(devicePixelRatio, 2) + ctx.setTransform(dpr, 0, 0, dpr, 0, 0) + ctx.clearRect(0, 0, state.width, state.height) + draw(state) + } + + const toLocal = (e) => { + const rect = canvas.getBoundingClientRect() + return new Vec2(e.clientX - rect.left, e.clientY - rect.top) + } + const move = (e) => { + state.pointer = toLocal(e) + redraw() + } + const down = (e) => { + state.down = true + state.pointer = toLocal(e) + canvas.setPointerCapture(e.pointerId) + onPointerDown?.(state) + redraw() + } + const up = () => { + state.down = false + onPointerUp?.(state) + redraw() + } + const leave = () => { + if (state.down) return + state.pointer = null + redraw() + } + canvas.addEventListener('pointermove', move) + canvas.addEventListener('pointerdown', down) + canvas.addEventListener('pointerup', up) + canvas.addEventListener('pointercancel', up) + canvas.addEventListener('pointerleave', leave) + + // The colours change when the docs switch between light and dark + const themeObserver = new MutationObserver(() => { + state.colours = readColours() + redraw() + }) + themeObserver.observe(document.documentElement, { + attributes: true, + attributeFilter: ['class'] + }) + + return { + state, + frame(time, delta) { + state.time = time + state.delta = delta + redraw() + }, + resize(width, height) { + const dpr = Math.min(devicePixelRatio, 2) + state.width = width + state.height = height + canvas.width = Math.round(width * dpr) + canvas.height = Math.round(height * dpr) + canvas.style.width = `${width}px` + canvas.style.height = `${height}px` + redraw() + }, + dispose() { + themeObserver.disconnect() + canvas.remove() + } + } +} + +/** The docs' theme colours, read from the CSS custom properties. */ +function readColours() { + const style = getComputedStyle(document.documentElement) + const get = (name) => style.getPropertyValue(name).trim() + return { + text: get('--vp-c-text-1'), + muted: get('--vp-c-text-3'), + grid: get('--vp-c-divider'), + one: get('--docs-c-1'), + two: get('--docs-c-2'), + three: get('--docs-c-3'), + font: get('--vp-font-family-mono') + } +} diff --git a/docs/examples/lib/wire.js b/docs/examples/lib/wire.js new file mode 100644 index 0000000..0253224 --- /dev/null +++ b/docs/examples/lib/wire.js @@ -0,0 +1,37 @@ +import { Vec2, Vec3 } from 'wtc-math' + +/** The corners of a cube from -1 to 1, and the pairs of corners its edges join. */ +export const cube = { + points: [ + [-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], + [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1] + ].map((p) => new Vec3(...p)), + edges: [ + [0, 1], [1, 2], [2, 3], [3, 0], + [4, 5], [5, 6], [6, 7], [7, 4], + [0, 4], [1, 5], [2, 6], [3, 7] + ] +} + +/** + * Take a point through a model-view-projection matrix to the canvas, from + * normalised device coordinates (-1 to 1, y up) to pixels (y down). + */ +export function toCanvas(point, matrix, width, height) { + const ndc = point.transformByMat4New(matrix) + return new Vec2((ndc.x + 1) * 0.5 * width, (1 - ndc.y) * 0.5 * height) +} + +/** Draw a wireframe through a matrix. */ +export function wireframe(ctx, shape, matrix, width, height, colour, lineWidth = 1.5) { + const screen = shape.points.map((p) => toCanvas(p, matrix, width, height)) + ctx.strokeStyle = colour + ctx.lineWidth = lineWidth + ctx.lineCap = 'round' + ctx.beginPath() + for (const [a, b] of shape.edges) { + ctx.moveTo(screen[a].x, screen[a].y) + ctx.lineTo(screen[b].x, screen[b].y) + } + ctx.stroke() +} diff --git a/docs/examples/mat3-transform.js b/docs/examples/mat3-transform.js new file mode 100644 index 0000000..fa7f06f --- /dev/null +++ b/docs/examples/mat3-transform.js @@ -0,0 +1,40 @@ +import { Vec2, Mat3 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { arrow, path } from './lib/draw.js' + +// One Mat3 places, turns and stretches a shape. The pointer moves it. +export default function (container) { + // A unit square around the origin, and an arrow along its local x axis + const square = [ + new Vec2(-1, -1), + new Vec2(1, -1), + new Vec2(1, 1), + new Vec2(-1, 1) + ] + + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const at = pointer ?? new Vec2(width / 2, height / 2) + const stretch = 1 + 0.5 * Math.sin(time * 1.3) + + // Read from the bottom up: stretch, then turn, then move. The last call + // is the first applied to each point. + const model = Mat3.identity() + .translate(at) + .rotate(time * 0.6) + .scaleByVec2([40 * stretch, 40]) + + const corners = square.map((p) => p.transformByMat3New(model)) + ctx.fillStyle = colours.one + ctx.globalAlpha = 0.15 + ctx.beginPath() + corners.forEach((p, i) => (i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y))) + ctx.fill() + ctx.globalAlpha = 1 + path(ctx, corners, colours.one, 1.5, true) + + // The shape's own axes, carried along by the same matrix + const centre = new Vec2(0, 0).transformByMat3(model) + arrow(ctx, centre, new Vec2(1.6, 0).transformByMat3(model), colours.two) + arrow(ctx, centre, new Vec2(0, 1.6).transformByMat3(model), colours.three) + }) +} diff --git a/docs/examples/mat4-hierarchy.js b/docs/examples/mat4-hierarchy.js new file mode 100644 index 0000000..00ff5f3 --- /dev/null +++ b/docs/examples/mat4-hierarchy.js @@ -0,0 +1,35 @@ +import { Vec3, Mat4 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { cube, wireframe, toCanvas } from './lib/wire.js' +import { arrow } from './lib/draw.js' + +// A moon on a planet: the moon's matrix is the planet's, times its own +// orbit. Moving the planet carries the moon with it. +export default function (container) { + return stage(container, ({ ctx, width, height, time, colours }) => { + const projection = Mat4.perspective(Math.PI / 4, width / height, 0.1, 100) + const view = Mat4.lookAt([0, 3, 8], [0, 0, 0], [0, 1, 0]) + const viewProjection = projection.multiply(view) + + // The planet circles the centre, spinning as it goes + const planet = new Mat4() + .rotate(time * 0.3, [0, 1, 0]) + .translate([3, 0, 0]) + .rotate(time, [0, 1, 0]) + + // The moon starts from the planet's matrix, then orbits and shrinks + const moon = planet + .clone() + .rotate(time * 1.5, [0, 0, 1]) + .translate([2, 0, 0]) + .scaleByVec3([0.35, 0.35, 0.35]) + + wireframe(ctx, cube, viewProjection.multiplyNew(planet), width, height, colours.one) + wireframe(ctx, cube, viewProjection.multiplyNew(moon), width, height, colours.two) + + // The planet's position is its matrix's translation + const centre = toCanvas(planet.translation, viewProjection, width, height) + const origin = toCanvas(new Vec3(), viewProjection, width, height) + arrow(ctx, origin, centre, colours.three, 1.5) + }) +} diff --git a/docs/examples/plane-distance.js b/docs/examples/plane-distance.js new file mode 100644 index 0000000..bc8e004 --- /dev/null +++ b/docs/examples/plane-distance.js @@ -0,0 +1,37 @@ +import { Vec2, Vec3 } from 'wtc-math' +import { Plane } from 'wtc-math/plane' +import { stage } from './lib/stage.js' +import { arrow, dot, label, line } from './lib/draw.js' + +// A plane seen edge-on, as a line. The pointer is a point: its signed +// distance from the plane, and where it lands when projected onto it. +export default function (container) { + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const centre = new Vec3(width / 2, height / 2, 0) + const facing = new Vec2(0, -1).rotate(Math.sin(time * 0.3) * 0.6) + const plane = Plane.fromNormalAndPoint([facing.x, facing.y, 0], centre) + + // Draw the plane as a long line through the centre + const across = new Vec2(-facing.y, facing.x).scale(Math.hypot(width, height)) + line(ctx, centre.xy.subtract(across), centre.xy.add(across), colours.muted, 1.5) + arrow(ctx, centre, centre.xy.add(facing.scaleNew(40)), colours.one) + label(ctx, 'normal', centre.xy.add(facing.scaleNew(56)), colours.one, colours.font, 'center') + + const point = pointer + ? new Vec3(pointer.x, pointer.y, 0) + : new Vec3(width * 0.3, height * 0.3 + Math.sin(time) * height * 0.25, 0) + const distance = plane.distanceTo(point) + const onPlane = plane.projectPoint(point) + + line(ctx, point, onPlane, colours.muted, 1, [4, 4]) + dot(ctx, onPlane, colours.three) + dot(ctx, point, distance >= 0 ? colours.one : colours.two, 5) + label( + ctx, + `distanceTo = ${distance.toFixed(0)} (${distance >= 0 ? 'in front' : 'behind'})`, + { x: 16, y: height - 20 }, + colours.muted, + colours.font + ) + }) +} diff --git a/docs/examples/projection.js b/docs/examples/projection.js new file mode 100644 index 0000000..2017011 --- /dev/null +++ b/docs/examples/projection.js @@ -0,0 +1,43 @@ +import { Vec3, Mat4 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { cube, wireframe } from './lib/wire.js' +import { label, line } from './lib/draw.js' + +// The same row of cubes through a perspective camera (left) and an +// orthographic one (right). The pointer moves the camera. +export default function (container) { + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const half = width / 2 + const aspect = half / height + + const angle = pointer ? (pointer.x / width - 0.5) * 2 : Math.sin(time * 0.4) + const eye = new Vec3(Math.sin(angle) * 14, 4, Math.cos(angle) * 14) + const view = Mat4.lookAt(eye, [0, 0, 0], [0, 1, 0]) + + const perspective = Mat4.perspective(Math.PI / 4, aspect, 0.1, 100) + // An orthographic box about as big as the perspective view at the centre + const size = 5.5 + const orthographic = Mat4.ortho(-size * aspect, size * aspect, -size, size, 0.1, 100) + + const panels = [ + { projection: perspective, x: 0, name: 'Mat4.perspective' }, + { projection: orthographic, x: half, name: 'Mat4.ortho' } + ] + for (const { projection, x, name } of panels) { + ctx.save() + ctx.translate(x, 0) + ctx.beginPath() + ctx.rect(0, 0, half, height) + ctx.clip() + const viewProjection = projection.multiplyNew(view) + for (let i = -2; i <= 2; i++) { + const model = new Mat4().translate([0, 0, i * 2.5]).scaleByVec3([0.8, 0.8, 0.8]) + const colour = i === 0 ? colours.one : colours.two + wireframe(ctx, cube, viewProjection.multiplyNew(model), half, height, colour) + } + label(ctx, name, { x: 16, y: height - 20 }, colours.muted, colours.font) + ctx.restore() + } + line(ctx, { x: half, y: 0 }, { x: half, y: height }, colours.grid) + }) +} diff --git a/docs/examples/quat-slerp.js b/docs/examples/quat-slerp.js new file mode 100644 index 0000000..39b8c26 --- /dev/null +++ b/docs/examples/quat-slerp.js @@ -0,0 +1,48 @@ +import { Vec3, Mat4, Quat, smootherstep } from 'wtc-math' +import { stage } from './lib/stage.js' +import { cube, wireframe, toCanvas } from './lib/wire.js' +import { arrow } from './lib/draw.js' + +// Turning smoothly from one orientation to the next with Quat.slerp. +export default function (container) { + // Random orientations to visit, each from a random axis and angle + const randomOrientation = () => + Quat.fromAxisAngle( + new Vec3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalise(), + Math.random() * Math.PI * 2 + ) + let from = Quat.identity() + let to = randomOrientation() + let leg = 0 + + return stage(container, ({ ctx, width, height, time, colours }) => { + // Two seconds a leg: turn for one and a half, then rest + const thisLeg = Math.floor(time / 2) + if (thisLeg !== leg) { + leg = thisLeg + from = to + to = randomOrientation() + } + const t = smootherstep(0, 1.5, time % 2) + const orientation = Quat.slerp(from, to, t) + + const projection = Mat4.perspective(Math.PI / 4, width / height, 0.1, 100) + const view = Mat4.lookAt([0, 0, 7], [0, 0, 0], [0, 1, 0]) + const viewProjection = projection.multiply(view) + const model = Mat4.fromQuat(orientation) + + wireframe(ctx, cube, viewProjection.multiplyNew(model), width, height, colours.muted, 1) + + // The object's own axes, turned by the quaternion + const origin = toCanvas(new Vec3(), viewProjection, width, height) + const axes = [ + [new Vec3(1.8, 0, 0), colours.one], + [new Vec3(0, 1.8, 0), colours.two], + [new Vec3(0, 0, 1.8), colours.three] + ] + for (const [axis, colour] of axes) { + const tip = axis.transformByQuat(orientation) + arrow(ctx, origin, toCanvas(tip, viewProjection, width, height), colour) + } + }) +} diff --git a/docs/examples/ray-cast.js b/docs/examples/ray-cast.js new file mode 100644 index 0000000..ed25fec --- /dev/null +++ b/docs/examples/ray-cast.js @@ -0,0 +1,60 @@ +import { Vec2, Vec3 } from 'wtc-math' +import { Ray } from 'wtc-math/ray' +import { Plane } from 'wtc-math/plane' +import { stage } from './lib/stage.js' +import { dot, line, ring, label } from './lib/draw.js' + +// Rays against spheres, a box and a plane, seen from the side: everything +// sits at z = 0, so the 3D shapes show as circles, a square and a line. The +// pointer aims the rays. +export default function (container) { + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const spheres = [ + { centre: new Vec3(width * 0.55, height * 0.3, 0), radius: 34 }, + { centre: new Vec3(width * 0.75, height * 0.62, 0), radius: 48 } + ] + const box = { + min: new Vec3(width * 0.4, height * 0.58, -30), + max: new Vec3(width * 0.5, height * 0.78, 30) + } + // The floor, facing up the screen (y points down on a canvas) + const floor = Plane.fromNormalAndPoint([0, -1, 0], [0, height - 24, 0]) + + ring(ctx, spheres[0].centre, colours.muted, spheres[0].radius) + ring(ctx, spheres[1].centre, colours.muted, spheres[1].radius) + ctx.strokeStyle = colours.muted + ctx.strokeRect(box.min.x, box.min.y, box.max.x - box.min.x, box.max.y - box.min.y) + line(ctx, { x: 0, y: height - 24 }, { x: width, y: height - 24 }, colours.muted) + + const origin = new Vec3(28, height * 0.4, 0) + const target = pointer + ? new Vec3(pointer.x, pointer.y, 0) + : new Vec3(width * 0.7, height * 0.5 + Math.sin(time * 0.6) * height * 0.4, 0) + + // A fan of rays around the aim + let hits = 0 + for (let i = -4; i <= 4; i++) { + const aim = new Vec2(target.x - origin.x, target.y - origin.y).rotate(i * 0.06) + const ray = new Ray(origin, [aim.x, aim.y, 0]) + + // The nearest of everything the ray hits + const candidates = [ + ...spheres.map((s) => ray.intersectSphere(s.centre, s.radius)), + ray.intersectBox(box.min, box.max), + ray.intersectPlane(floor) + ].filter(Boolean) + const hit = candidates.sort( + (a, b) => a.distance(origin) - b.distance(origin) + )[0] + + const end = hit ?? ray.at(Math.hypot(width, height)) + line(ctx, origin, end, i === 0 ? colours.one : colours.grid, i === 0 ? 2 : 1) + if (hit) { + dot(ctx, hit, colours.three, i === 0 ? 5 : 3) + hits++ + } + } + dot(ctx, origin, colours.one, 5) + label(ctx, `${hits} of 9 rays hit`, { x: 16, y: 20 }, colours.muted, colours.font) + }) +} diff --git a/docs/examples/scalars.js b/docs/examples/scalars.js new file mode 100644 index 0000000..d5330a8 --- /dev/null +++ b/docs/examples/scalars.js @@ -0,0 +1,43 @@ +import { Vec2, lerp, smoothstep, smootherstep, pingpong, map } from 'wtc-math' +import { stage } from './lib/stage.js' +import { dot, label, line, path } from './lib/draw.js' + +// The easing curves, plotted from 0 to 1, with a dot riding each one. +export default function (container) { + const curves = [ + ['t', (t) => t], + ['smoothstep(0, 1, t)', (t) => smoothstep(0, 1, t)], + ['smootherstep(0, 1, t)', (t) => smootherstep(0, 1, t)] + ] + + return stage(container, ({ ctx, width, height, time, colours }) => { + const pad = 32 + const size = Math.min(width * 0.55, height) - pad * 2 + const left = pad + const bottom = height - pad + // Graph space (0–1) to the canvas + const toCanvas = (x, y) => + new Vec2(map(x, 0, 1, left, left + size), map(y, 0, 1, bottom, bottom - size)) + + line(ctx, toCanvas(0, 0), toCanvas(1, 0), colours.muted) + line(ctx, toCanvas(0, 0), toCanvas(0, 1), colours.muted) + + // Back and forth along the x axis, once every two seconds + const t = pingpong(time * 0.5, 1) + const series = [colours.muted, colours.one, colours.two] + + curves.forEach(([name, curve], i) => { + const points = [] + for (let s = 0; s <= 60; s++) points.push(toCanvas(s / 60, curve(s / 60))) + path(ctx, points, series[i], i ? 2 : 1) + dot(ctx, toCanvas(t, curve(t)), series[i], 5) + + // The same value driving a position on the right + const x = lerp(left + size + pad * 2, width - pad, curve(t)) + const y = pad + 20 + i * 44 + line(ctx, { x: left + size + pad * 2, y }, { x: width - pad, y }, colours.grid) + dot(ctx, { x, y }, series[i], 7) + label(ctx, name, { x: left + size + pad * 2, y: y + 18 }, series[i], colours.font) + }) + }) +} diff --git a/docs/examples/vec2-projection.js b/docs/examples/vec2-projection.js new file mode 100644 index 0000000..bcb764a --- /dev/null +++ b/docs/examples/vec2-projection.js @@ -0,0 +1,47 @@ +import { Vec2 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { arrow, axes, dot, label, line } from './lib/draw.js' + +// Projecting one vector onto another with the dot product. The pointer +// moves `v`; the line turns slowly. +export default function (container) { + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + const origin = new Vec2(width / 2, height / 2) + axes(ctx, origin, width, height, colours) + const toScreen = (v) => new Vec2(origin.x + v.x, origin.y - v.y) + + // A unit vector along the line + const along = new Vec2(1, 0).rotate(time * 0.25) + const v = pointer + ? new Vec2(pointer.x - origin.x, origin.y - pointer.y) + : new Vec2(60, 100).rotate(time * -0.5) + + // How far v reaches along the line, and the point it lands on + const reach = v.dot(along) + const projected = along.scaleNew(reach) + + const extent = Math.hypot(width, height) + line( + ctx, + toScreen(along.scaleNew(-extent)), + toScreen(along.scaleNew(extent)), + colours.muted, + 1 + ) + line(ctx, toScreen(v), toScreen(projected), colours.muted, 1, [4, 4]) + arrow(ctx, origin, toScreen(projected), colours.three, 3) + arrow(ctx, origin, toScreen(v), colours.two) + arrow(ctx, origin, toScreen(along.scaleNew(50)), colours.one) + dot(ctx, toScreen(projected), colours.three) + + label(ctx, 'along', toScreen(along.scaleNew(64)), colours.one, colours.font) + label(ctx, 'v', toScreen(v.scaleNew(1.1)), colours.two, colours.font) + label( + ctx, + `v.dot(along) = ${reach.toFixed(1)}`, + new Vec2(16, height - 20), + colours.muted, + colours.font + ) + }) +} diff --git a/docs/examples/vec3-normal.js b/docs/examples/vec3-normal.js new file mode 100644 index 0000000..3237dfd --- /dev/null +++ b/docs/examples/vec3-normal.js @@ -0,0 +1,56 @@ +import { Vec2, Vec3, Mat4 } from 'wtc-math' +import { stage } from './lib/stage.js' +import { arrow, dot, label, path } from './lib/draw.js' + +// A triangle's normal from the cross product of two of its edges. The +// triangle tumbles; the pointer tilts the camera. +export default function (container) { + const corners = [new Vec3(-1, -0.7, 0), new Vec3(1, -0.7, 0), new Vec3(0, 1, 0)] + const centre = new Vec3() + + return stage(container, ({ ctx, width, height, time, pointer, colours }) => { + // A camera, and a matrix that takes a point to the screen + const tilt = pointer ? (pointer.y / height - 0.5) * 4 : 1 + const eye = new Vec3(0, tilt, 5) + const view = Mat4.lookAt(eye, [0, 0, 0], [0, 1, 0]) + const projection = Mat4.perspective(Math.PI / 4, width / height, 0.1, 100) + const viewProjection = projection.multiplyNew(view) + const toScreen = (p) => { + const ndc = p.transformByMat4New(viewProjection) + return new Vec2((ndc.x + 1) * 0.5 * width, (1 - ndc.y) * 0.5 * height) + } + + // Turn the corners around the centre + const points = corners.map((p) => + p.clone().rotateY(centre, time * 0.7).rotateX(centre, time * 0.3) + ) + + // Two edges from the first corner, crossed, give the face's normal + const [a, b, c] = points + const normal = b.subtractNew(a).cross(c.subtractNew(a)).normalise() + const mid = a.addNew(b).add(c).scale(1 / 3) + + // Facing the camera when the normal points back towards the eye + const facing = normal.dot(eye.subtractNew(mid)) > 0 + + const screen = points.map(toScreen) + ctx.globalAlpha = facing ? 0.18 : 0.06 + ctx.fillStyle = colours.one + ctx.beginPath() + screen.forEach((p, i) => (i ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y))) + ctx.fill() + ctx.globalAlpha = 1 + path(ctx, screen, colours.one, 1.5, true) + screen.forEach((p) => dot(ctx, p, colours.one, 3)) + + arrow(ctx, toScreen(mid), toScreen(mid.addNew(normal)), colours.three) + label(ctx, 'normal', toScreen(mid.addNew(normal.scaleNew(1.2))), colours.three, colours.font, 'center') + label( + ctx, + facing ? 'front face' : 'back face', + new Vec2(16, height - 20), + colours.muted, + colours.font + ) + }) +} diff --git a/docs/geometry/plane.md b/docs/geometry/plane.md new file mode 100644 index 0000000..7cc990a --- /dev/null +++ b/docs/geometry/plane.md @@ -0,0 +1,61 @@ +# Plane + +A `Plane` is a flat surface that goes on forever, given by the direction it faces and its distance from the origin. {.lead} + +```js +import { Plane } from 'wtc-math/plane' + +const ground = new Plane([0, 1, 0], 0) // the xz plane, facing up +``` + +`Plane` has an entry point of its own, `wtc-math/plane`. It has a `normal`, the `Vec3` it faces, and a `constant`. A point `p` is on the plane when `normal.dot(p) + constant` is 0, so for a unit normal the constant is the negative of the plane's distance from the origin along it. Without arguments the plane faces up through the origin. + + + +<<< @/examples/plane-distance.js + +## Making one + +Usually it's easier to make a plane from a point on it, or from three points: + +```js +// Facing up, 2 units above the origin +const floor = Plane.fromNormalAndPoint([0, 1, 0], [0, 2, 0]) // constant -2 + +// Through three points; the normal follows the right-hand rule a → b → c +const face = Plane.fromPoints(a, b, c) +``` + +Both normalise the normal for you. The constructor doesn't, so pass it a unit normal, or call `normalize()` afterwards, which scales the normal and the constant together. `negate()` flips the plane to face the other way. + +## Distance and projection + +`distanceTo(point)` gives the signed distance from the plane: positive on the side the normal points to, negative behind it, 0 on the plane. That makes it a test for which side of a wall something is on: + +```js +floor.distanceTo([0, 5, 0]) // 3 +floor.distanceTo([0, 0, 0]) // -2 +``` + +`projectPoint(point)` gives the nearest point on the plane, by moving the point along the normal: + +```js +floor.projectPoint([3, 5, 1]) // Vec3(3, 2, 1) +``` + +## Intersecting a line + +`intersectLine(start, end)` gives the point where the segment from `start` to `end` crosses the plane, or null if it doesn't reach it or runs parallel to it: + +```js +floor.intersectLine([0, 0, 0], [0, 4, 0]) // Vec3(0, 2, 0) +floor.intersectLine([0, 3, 0], [0, 4, 0]) // null: both ends are above +``` + +For a line that goes on forever, use [`Ray.intersectPlane`](/geometry/ray#intersections). + +## Related + +- [Ray](/geometry/ray) +- [Vec3](/vectors/vec3) +- API: [Plane](/api/wtc-math/plane/classes/Plane) diff --git a/docs/geometry/ray.md b/docs/geometry/ray.md new file mode 100644 index 0000000..f8a4f1b --- /dev/null +++ b/docs/geometry/ray.md @@ -0,0 +1,71 @@ +# Ray + +A `Ray` starts at a point and runs forever in one direction. Cast one to find what it hits. {.lead} + +```js +import { Ray } from 'wtc-math/ray' + +const ray = new Ray([0, 1, 5], [0, 0, -1]) +``` + +`Ray` has an entry point of its own, `wtc-math/ray`. It has an `origin` and a `direction`, both `Vec3`s. The direction is normalised when the ray is made, so distances along it are in world units. Without arguments a ray starts at the origin and points down -z. + + + +<<< @/examples/ray-cast.js + +## Points along a ray + +`at(t)` gives the point `t` units along the ray: + +```js +ray.at(2) // Vec3(0, 1, 3) +``` + +`closestPoint(p)` gives the point on the ray nearest to `p`, and `distanceTo(p)` the distance between them. Neither looks behind the origin: for a point behind it, the closest point is the origin itself. + +## Intersections + +Each intersection method returns the point where the ray first meets the shape, as a new `Vec3`, or null if it misses: + +- `intersectSphere(centre, radius)` hits a sphere. From inside the sphere it returns the point where the ray leaves. +- `intersectBox(min, max)` hits an axis-aligned box given by its opposite corners. It returns null when the ray starts inside the box. +- `intersectPlane(plane)` hits a [`Plane`](/geometry/plane). It returns null when the ray runs parallel to the plane or points away from it. + +```js +import { Ray } from 'wtc-math/ray' +import { Plane } from 'wtc-math/plane' + +const ray = new Ray([0, 0, 5], [0, 0, -1]) + +ray.intersectSphere([0, 0, 0], 1) // Vec3(0, 0, 1) +ray.intersectBox([-1, -1, -1], [1, 1, 1]) // Vec3(0, 0, 1) +ray.intersectPlane(new Plane([0, 0, 1], 0)) // Vec3(0, 0, 0) +ray.intersectSphere([5, 0, 0], 1) // null +``` + +To find the nearest of several hits, compare their distances from the origin, as the example does. + +## Picking with the pointer + +To find what's under the pointer in a 3D scene, cast a ray from the camera through the pointer. Take the pointer to normalised device coordinates, then back through the inverse of the view-projection matrix at the near and far planes: + +```js +import { Vec3 } from 'wtc-math' +import { Ray } from 'wtc-math/ray' + +function pointerRay(x, y, width, height, viewProjection) { + const ndcX = (x / width) * 2 - 1 + const ndcY = 1 - (y / height) * 2 + const inverse = viewProjection.invertNew() + const near = new Vec3(ndcX, ndcY, -1).transformByMat4(inverse) + const far = new Vec3(ndcX, ndcY, 1).transformByMat4(inverse) + return new Ray(near, far.subtract(near)) +} +``` + +## Related + +- [Plane](/geometry/plane) +- [Cameras and projection](/matrices/projection) +- API: [Ray](/api/wtc-math/ray/classes/Ray) diff --git a/docs/getting-started/conventions.md b/docs/getting-started/conventions.md new file mode 100644 index 0000000..833fdbd --- /dev/null +++ b/docs/getting-started/conventions.md @@ -0,0 +1,115 @@ +# Conventions + +A few rules hold across the whole library. Learn them once and every class reads the same way. {.lead} + +## In place, or new + +Most methods change the object they're called on and return it, so calls chain: + +```js +import { Vec2 } from 'wtc-math' + +const v = new Vec2(3, 4) +v.normalise().scale(10).rotate(Math.PI / 2) // v is now (-8, 6) +``` + +Each of those has a twin ending in `New` that leaves the original alone and returns a new object: + +```js +const a = new Vec2(1, 2) +const b = a.addNew(new Vec2(3, 4)) // b is (4, 6), a is still (1, 2) +``` + +Use the in-place methods in hot loops, where making a new object every frame adds up, and the `New` methods when you want to keep the original. `clone()` gives you a copy to change: + +```js +const next = position.clone().add(velocity.scaleNew(delta)) +``` + +::: warning +The in-place methods change the object everywhere it's referenced. If two things share one vector, changing it through one changes it for both. Clone a vector before keeping it if its owner might change it later. +::: + +Methods that compute a number, such as `dot`, `distance` or `length`, don't change anything. A few others return a new object without the `New` suffix too, notably `Vec3.cross` and the static helpers such as `Vec2.lerp`. + +## Static helpers + +Constructors that build an object from something else are static methods: `Mat4.perspective`, `Mat4.lookAt`, `Quat.fromAxisAngle`, `Quat.slerp`, `Color.fromHex`. They always return a new object. + +```js +import { Mat4, Quat, Vec3 } from 'wtc-math' + +const projection = Mat4.perspective(Math.PI / 3, 16 / 9, 0.1, 100) +const spin = Quat.fromAxisAngle(new Vec3(0, 1, 0), Math.PI) +``` + +## Angles + +Angles are in radians unless a name says otherwise. Methods that take degrees say so: `rotateDeg`, `rotateToDeg`, `angleInDegrees`. Convert with `degToRad` and `radToDeg`: + +```js +import { Vec2, degToRad } from 'wtc-math' + +new Vec2(1, 0).rotate(degToRad(90)) // (0, 1) +new Vec2(1, 0).rotateDeg(90) // the same +``` + +Positive angles turn counter-clockwise when y points up. On a canvas, where y points down, they turn clockwise on screen. + +## Column-major matrices + +Matrices store their elements column by column, as WebGL and GLSL do. Element names read `a` + column + row, so in a `Mat4`: + +- `a11`, `a12`, `a13`, `a14` are the first column, +- `a41`, `a42`, `a43` are the translation. + +`.array` gives the elements in that order, ready for `gl.uniformMatrix4fv` or a wtc-gl `Uniform`. + +`a.multiply(b)` gives `a × b`. Applied to a point, `b` happens first, then `a`. Methods such as `translate` and `rotate` multiply on the right in the same way, so the last one you call is the first applied to a point. [3D transforms](/matrices/3d-transforms#order) works through an example. + +## Like types + +Methods that read a value without keeping it usually accept a plain array or object as well as a class instance. These are the `…Like` types: + +| Type | Accepts | +| ------------------------- | -------------------------------------------------------- | +| `Vec2Like` | `Vec2`, `{ x, y }`, `[x, y]` | +| `Vec3Like` | `Vec3`, `{ x, y, z }`, `[x, y, z]` | +| `Vec4Like`, `QuatLike` | `Vec4`, `Quat`, `{ x, y, z, w }`, `[x, y, z, w]` | +| `Mat2Like` … `Mat4Like` | a matrix, or an array of its elements in column order | +| `ColorLike` | `Color`, `{ r, g, b, a? }`, `[r, g, b, a?]`, a hex string | + +```js +import { Mat4 } from 'wtc-math' + +const view = Mat4.lookAt([0, 2, 5], [0, 0, 0], [0, 1, 0]) +``` + +Arithmetic such as `add` and `multiply` takes an instance of the same class. To turn a loose value into one, use the static `interpolate`: + +```js +import { Vec2, Vec3 } from 'wtc-math' + +Vec2.interpolate([3, 4]) // Vec2(3, 4) +Vec2.interpolate({ x: 3, y: 4 }) // Vec2(3, 4) +Vec2.interpolate('3, 4') // Vec2(3, 4), handy for data attributes +Vec2.interpolate(5) // Vec2(5, 5) +Vec3.interpolate([1, 2, 3]) // Vec3(1, 2, 3) +``` + +## Arrays and destructuring + +Every vector and matrix has an `.array` getter with its components in order, and can be spread or destructured: + +```js +const v = new Vec3(1, 2, 3) + +v.array // [1, 2, 3] +const [x, y, z] = v +Math.max(...v) // 3 +ctx.lineTo(...new Vec2(10, 20)) +``` + +## Names + +The library writes British English in its docs but keeps established names in code. Vectors have `normalise`; `Plane` has `normalize`. The colour class is `Color`. diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md new file mode 100644 index 0000000..0e05be9 --- /dev/null +++ b/docs/getting-started/installation.md @@ -0,0 +1,63 @@ +# Installation + +Install wtc-math from npm and import what you need. {.lead} + +```sh +npm install wtc-math +``` + +wtc-math is an ES module with TypeScript declarations included. It has no dependencies. + +## Importing + +The vectors, matrices, quaternion and scalar functions come from the main entry point: + +```js +import { Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Quat } from 'wtc-math' +import { clamp, lerp, map, smoothstep, degToRad } from 'wtc-math' +``` + +`Color`, `Plane` and `Ray` have entry points of their own, so a project that doesn't use them doesn't bundle them: + +```js +import { Color } from 'wtc-math/color' +import { Plane } from 'wtc-math/plane' +import { Ray } from 'wtc-math/ray' +``` + +## Types + +The library is written in TypeScript. Alongside the classes it exports the `…Like` types that many methods accept, so your own functions can take the same inputs: + +```ts +import type { Vec2Like, Vec3Like, QuatLike, Mat4Like } from 'wtc-math' +import type { ColorLike } from 'wtc-math/color' + +function moveTo(target: Vec3Like) { + // [x, y, z] or { x, y, z } +} +``` + +[Conventions](/getting-started/conventions#like-types) explains where they're accepted. + +## With wtc-gl + +[wtc-gl](https://wethegit.github.io/wtc-gl/docs/) re-exports wtc-math, so in a wtc-gl project you can import the maths from either package: + +```js +import { Renderer, Vec2, Mat4 } from 'wtc-gl' +``` + +[With WebGL and wtc-gl](/guides/webgl) covers passing values to shaders. + +## From a CDN + +For a quick sketch without a bundler, import the module from a CDN that serves npm packages: + +```html + +``` diff --git a/docs/guides/webgl.md b/docs/guides/webgl.md new file mode 100644 index 0000000..2fcfd7a --- /dev/null +++ b/docs/guides/webgl.md @@ -0,0 +1,68 @@ +# With WebGL and wtc-gl + +wtc-math's vectors, matrices and colours are laid out the way WebGL expects, so they go straight into shader uniforms. {.lead} + +## Passing values to a shader + +Every vector, matrix and colour has an `.array` getter with its values in the order GLSL reads them. Matrices are column-major, so there's nothing to transpose: + +```js +import { Vec3, Mat4 } from 'wtc-math' +import { Color } from 'wtc-math/color' + +const projection = Mat4.perspective(Math.PI / 4, width / height, 0.1, 100) + +gl.uniformMatrix4fv(projectionLocation, false, projection.array) +gl.uniform3fv(lightLocation, new Vec3(1, 2, 3).normalise().array) +gl.uniform4fv(colourLocation, Color.fromHex('#ff8800').array) +``` + +`.array` returns a new array each time, so read it once per frame rather than once per draw if you're drawing many objects with the same value. + +## In wtc-gl + +[wtc-gl](https://wethegit.github.io/wtc-gl/docs/) re-exports wtc-math, so the same classes come from either import, and its cameras and objects use them for positions, rotations and matrices: + +```js +import { Camera, Uniform, Vec2, Vec3 } from 'wtc-gl' + +const camera = new Camera({ fov: 35 }) +camera.position.reset(0, 2, 6) +camera.lookAt(new Vec3(0, 0, 0)) +``` + +A wtc-gl `Uniform` takes plain values, so pass a vector's or matrix's `.array`: + +```js +const u_pointer = new Uniform({ + name: 'pointer', + value: new Vec2(0, 0).array, + kind: 'float_vec2' +}) + +addEventListener('pointermove', (e) => { + u_pointer.value = new Vec2(e.clientX / innerWidth, 1 - e.clientY / innerHeight).array +}) +``` + +wtc-gl's [uniforms guide](https://wethegit.github.io/wtc-gl/docs/core/uniforms) covers kinds, arrays and textures. + +## Matching GLSL + +Much of wtc-math has a GLSL counterpart, so maths you prototype on the CPU carries over to a shader: + +| wtc-math | GLSL | +| ----------------------------------------- | ---------------------------------------- | +| `a.dot(b)` | `dot(a, b)` | +| `a.cross(b)` on `Vec3` | `cross(a, b)` | +| `v.length`, `v.normaliseNew()` | `length(v)`, `normalize(v)` | +| `v.floorNew()`, `v.fractNew()` | `floor(v)`, `fract(v)` | +| `clamp`, `smoothstep`, `smootherstep` | `clamp`, `smoothstep`, and Perlin's curve | +| `lerp(a, b, t)`, `Vec3.lerp(a, b, t)` | `mix(a, b, t)` | +| `v.xy`, `v.zxy` and other swizzles | `v.xy`, `v.zxy` | +| `m.multiplyNew(n)` | `m * n` | +| `v.transformByMat4(m)` on `Vec4` | `m * v` | + +## Clip space + +`Mat4.perspective`, `Mat4.ortho` and `Mat4.frustum` map depth to -1 at the near plane and 1 at the far plane, as WebGL does. [Cameras and projection](/matrices/projection) covers them, and `Mat3.fromProjection` does the same job for 2D drawing in pixels: see [2D transforms](/matrices/2d-transforms#pixels-to-clip-space). diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..ff12977 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,49 @@ +--- +title: Introduction +--- + +# Introduction + +wtc-math is a small maths library for graphics and creative coding: vectors, matrices, quaternions, colours, and the scalar helpers you reach for in every sketch. {.lead} + +It has no dependencies and works anywhere JavaScript does. The vectors and matrices are laid out the way WebGL expects, so a value goes straight into a shader uniform, and [wtc-gl](https://wethegit.github.io/wtc-gl/docs/) re-exports the whole library. + + + +<<< @/examples/intro.js + +## What's in it + +- **Vectors.** [`Vec2`](/vectors/vec2), [`Vec3`](/vectors/vec3) and [`Vec4`](/vectors/vec4), with arithmetic, length and angle, dot and cross products, rotation, interpolation and [swizzling](/vectors/swizzling). +- **Matrices.** `Mat2`, `Mat3` and `Mat4`, column-major, for [2D](/matrices/2d-transforms) and [3D](/matrices/3d-transforms) transforms, and [cameras and projection](/matrices/projection). +- **Rotation.** [`Quat`](/rotation/quaternions) for rotations without gimbal lock, from an axis and angle or Euler angles, with spherical interpolation. +- **Geometry.** [`Plane`](/geometry/plane) and [`Ray`](/geometry/ray), for distances, projections and intersections. +- **Colour.** [`Color`](/colour/color), an RGBA colour with conversions to and from hex, HSL, HSV, [OKLab and OKLCH](/colour/colour-spaces), and [perceptual gradients](/colour/gradients). +- **Utilities.** [`clamp`, `lerp`, `map`, `smoothstep`](/utilities/scalars) and friends. + +## A first look + +```js +import { Vec2, Vec3, Mat4, Quat, lerp } from 'wtc-math' + +// Vectors change in place and return themselves, so calls chain +const velocity = new Vec2(3, 4) +velocity.normalise().scale(10) // Vec2(6, 8) + +// Methods ending in New leave the vector alone and return a new one +const position = new Vec2(0, 0) +const next = position.addNew(velocity) // position is still (0, 0) + +// Build a model matrix from a rotation, translation and scale +const rotation = Quat.fromAxisAngle(new Vec3(0, 1, 0), Math.PI / 4) +const model = Mat4.fromRotationTranslationScale( + rotation, + [0, 1, 0], + [2, 2, 2] +) + +// And transform a point by it +const point = new Vec3(1, 0, 0).transformByMat4(model) +``` + +Start with [installation](/getting-started/installation), then read the [conventions](/getting-started/conventions) the whole library follows. diff --git a/docs/matrices/2d-transforms.md b/docs/matrices/2d-transforms.md new file mode 100644 index 0000000..1b9358b --- /dev/null +++ b/docs/matrices/2d-transforms.md @@ -0,0 +1,86 @@ +# 2D transforms + +Move, turn and stretch points on a plane with `Mat2` and `Mat3`. {.lead} + +A `Mat2` holds a rotation, scale or shear: anything that keeps the origin where it is. A `Mat3` adds a translation, so one matrix can place a shape anywhere. Both are column-major, like every matrix in wtc-math (see [conventions](/getting-started/conventions#column-major-matrices)). + + + +<<< @/examples/mat3-transform.js + +## Making a matrix + +`new Mat3()` and `Mat3.identity()` both give the identity, which leaves points where they are. To set the elements yourself, pass them a column at a time: + +```js +import { Mat2, Mat3 } from 'wtc-math' + +// Scale x by 2 and y by 3 +const scaling = new Mat2( + 2, 0, // first column + 0, 3 // second column +) + +// The same, with a translation of (10, 20) in the third column +const placed = new Mat3( + 2, 0, 0, + 0, 3, 0, + 10, 20, 1 +) +``` + +## Building up a transform + +`translate(v)`, `rotate(radians)` and `scaleByVec2(v)` change the matrix in place and return it, so they chain: + +```js +import { Vec2, Mat3 } from 'wtc-math' + +const model = Mat3.identity() + .translate(new Vec2(200, 120)) + .rotate(Math.PI / 4) +``` + +Each call multiplies on the right, so it happens *before* the ones you called earlier when the matrix is applied to a point. Read the chain from the bottom up: this matrix turns a point by 45° around the origin, then moves it to (200, 120). Swap the calls and the point is moved first, then swung around the origin. + +`multiply(m)` works the same way: `a.multiply(b)` gives `a × b`, which applies `b` first. + +::: tip +`scale(n)` multiplies every element by `n`, translation included, so it isn't a scaling transform. Use `scaleByVec2([sx, sy])` to stretch a shape along its own axes. +::: + +## Applying it + +Transform a `Vec2` with `transformByMat3`, which treats it as a point so the translation applies, or `transformByMat2` for a `Mat2`: + +```js +const corner = new Vec2(1, 1).transformByMat3(model) +const turned = new Vec2(1, 0).transformByMat2(Mat2.identity().rotate(Math.PI / 2)) // (0, 1) +``` + +## Inverting + +`invert()` undoes a transform. With the inverse of a shape's matrix you can take a point from the screen into the shape's own space, to test whether the pointer is inside it: + +```js +const local = pointer.transformByMat3New(model.invertNew()) +const inside = Math.abs(local.x) <= 1 && Math.abs(local.y) <= 1 +``` + +`determinant` tells you whether a matrix can be inverted (anything but 0) and whether it mirrors (negative). `transpose`, `adjoint`, `add`, `subtract` and `multiplyScalar` are there too, each with a `New` form. + +## Pixels to clip space + +`Mat3.fromProjection(width, height)` maps pixel coordinates, with the origin at the top left and y pointing down, to WebGL's clip space from -1 to 1 with y pointing up. Multiply it on the left of a 2D model matrix to draw in pixels in a shader: + +```js +const projection = Mat3.fromProjection(canvas.width, canvas.height) +const matrix = projection.multiplyNew(model) +// In the vertex shader: gl_Position = vec4((u_matrix * vec3(a_position, 1)).xy, 0, 1); +``` + +## Related + +- [3D transforms](/matrices/3d-transforms) +- [Vec2](/vectors/vec2) +- API: [Mat2](/api/wtc-math/classes/Mat2), [Mat3](/api/wtc-math/classes/Mat3) diff --git a/docs/matrices/3d-transforms.md b/docs/matrices/3d-transforms.md new file mode 100644 index 0000000..df03867 --- /dev/null +++ b/docs/matrices/3d-transforms.md @@ -0,0 +1,103 @@ +# 3D transforms + +Place, turn and scale things in 3D with `Mat4`. {.lead} + +A `Mat4` holds a whole transform: rotation, scale and translation in one matrix. Multiplying matrices combines transforms, so an object's matrix can start from its parent's, and anything you do to the parent carries the child along: + + + +<<< @/examples/mat4-hierarchy.js + +`new Mat4()` is the identity. Like every matrix in wtc-math it's column-major: `a11`–`a14` are the first column, and `a41`, `a42` and `a43` are the translation. + +## Building up a transform + +`translate`, `rotate` and `scaleByVec3` change the matrix in place and chain: + +```js +import { Mat4 } from 'wtc-math' + +const model = new Mat4() + .translate([0, 1, -5]) + .rotate(Math.PI / 4, [0, 1, 0]) + .scaleByVec3([2, 2, 2]) +``` + +- `translate(v)` moves along the matrix's own axes, so after a rotation it moves in the rotated directions. +- `rotate(radians, axis)` turns around an axis through the matrix's origin. Normalise the axis. +- `scaleByVec3(v)` stretches along the matrix's own axes and leaves the translation alone. + +`transform(v)` adds to the translation in world space instead, ignoring any rotation, and `transformTo(v)` sets it outright. + +::: tip +`scale(n)` multiplies every element by `n`, including the translation and the bottom-right 1, so it isn't a scaling transform. Use `scaleByVec3`. +::: + +## Order + +Each of those calls multiplies on the right. Applied to a point, the last call happens first. The example above scales the point by 2, turns it 45° around y, then moves it to (0, 1, -5): read the chain from the bottom up. + +`multiply` works the same way: `a.multiply(b)` gives `a × b`, which applies `b` first, then `a`. That's why a child's matrix is its parent's times its own, and why a model-view-projection matrix is written in this order: + +```js +const mvp = projection.multiplyNew(view).multiply(model) +``` + +## From parts + +When you already have a position, rotation and scale, build the matrix in one step: + +```js +import { Mat4, Quat, Vec3 } from 'wtc-math' + +const rotation = Quat.fromAxisAngle(new Vec3(0, 1, 0), Math.PI / 2) +const model = Mat4.fromRotationTranslationScale(rotation, [1, 2, 3], [2, 2, 2]) +``` + +`fromRotationTranslationScaleOrigin(q, v, s, origin)` does the same, rotating and scaling around `origin` instead of the matrix's own origin. `fromQuat(q)` is a rotation alone, and `fromXRotation`, `fromYRotation`, `fromZRotation` and `fromRotation(radians, axis)` turn around one axis. + +## Taking a matrix apart + +`translation` gives the position as a `Vec3`, `scaling` the scale on each axis, and `rotation` the rotation as a [`Quat`](/rotation/quaternions): + +```js +model.translation // Vec3(1, 2, 3) +model.scaling // Vec3(2, 2, 2) +model.rotation // Quat +``` + +`rotation` is only exact when the scale is the same on every axis. For Euler angles, use [`Vec3.fromRotationMatrix`](/vectors/vec3#euler-angles-from-a-matrix). + +## Applying it + +`Vec3.transformByMat4` transforms a point, translation included: + +```js +import { Vec3 } from 'wtc-math' + +const world = new Vec3(1, 0, 0).transformByMat4(model) +``` + +For a direction or a normal, which shouldn't move with the translation, use the upper 3×3. `Mat3.fromMat4(m)` gives the normal matrix, the inverse transpose of that 3×3, which keeps normals at right angles to their surfaces when a model is scaled unevenly: + +```js +import { Mat3 } from 'wtc-math' + +const normalMatrix = Mat3.fromMat4(model) // null if model can't be inverted +const normal = new Vec3(0, 1, 0).transformByMat3(normalMatrix).normalise() +``` + +## Inverting + +`invert()` gives the transform that undoes this one, for example to take a world-space point into an object's local space, or to turn a camera's matrix into a view matrix. A matrix that can't be inverted (its `determinant` is 0) is left as it is. + +```js +const local = worldPoint.transformByMat4New(model.invertNew()) +``` + +## Related + +- [Cameras and projection](/matrices/projection) +- [Quaternions](/rotation/quaternions) +- [2D transforms](/matrices/2d-transforms) +- API: [Mat4](/api/wtc-math/classes/Mat4), [Mat3](/api/wtc-math/classes/Mat3) diff --git a/docs/matrices/projection.md b/docs/matrices/projection.md new file mode 100644 index 0000000..002d04a --- /dev/null +++ b/docs/matrices/projection.md @@ -0,0 +1,80 @@ +# Cameras and projection + +Turn a 3D scene into a 2D picture with a view matrix and a projection matrix. {.lead} + +Drawing a point takes three matrices. The **model** matrix places an object in the world, the **view** matrix moves the world so the camera is at the origin looking down -z, and the **projection** matrix squashes what the camera sees into WebGL's clip space, from -1 to 1 on every axis. + +```js +import { Mat4 } from 'wtc-math' + +const model = new Mat4().translate([0, 0.5, 0]) +const view = Mat4.lookAt([0, 2, 6], [0, 0, 0], [0, 1, 0]) +const projection = Mat4.perspective(Math.PI / 4, width / height, 0.1, 100) + +const mvp = projection.multiplyNew(view).multiply(model) +``` + +The projection is on the left because it's applied last. See [order](/matrices/3d-transforms#order). + + + +<<< @/examples/projection.js + +## The view matrix + +`Mat4.lookAt(eye, center, up)` makes a view matrix for a camera at `eye`, looking at `center`, with `up` as the rough up direction. It's the inverse of the camera's own transform. + +```js +const view = Mat4.lookAt([0, 2, 6], [0, 0, 0], [0, 1, 0]) +``` + +To point an *object* at something, rather than set up a camera, use `Mat4.targetTo(eye, target, up)`. It places the object at `eye` with its -z axis facing `target`, and is the inverse of `lookAt`: + +```js +const turret = Mat4.targetTo(turretPosition, enemyPosition, [0, 1, 0]) +``` + +If the camera already has a transform, its inverse is the view matrix: `cameraMatrix.invertNew()`. + +## Perspective + +`Mat4.perspective(fovy, aspect, near, far)` makes distant things smaller, as an eye or a lens does. + +- `fovy` is the vertical field of view in radians. `Math.PI / 4` (45°) is a common choice. +- `aspect` is the viewport's width divided by its height. Update it when the canvas resizes. +- `near` and `far` bound what's drawn. Keep `near` as large as you can, since depth precision is spread between them unevenly. Pass `Infinity` for `far` to draw everything beyond `near`. + +`Mat4.frustum(left, right, bottom, top, near, far)` makes the same kind of matrix from the edges of the near plane, for off-centre projections. + +## Orthographic + +`Mat4.ortho(left, right, bottom, top, near, far)` keeps parallel lines parallel and sizes the same at every distance, which suits 2D scenes, isometric views, shadow maps and UI: + +```js +// One unit per CSS pixel, with the origin at the top left +const projection = Mat4.ortho(0, width, height, 0, -1, 1) +``` + +## Clip space and the screen + +All the projections are right-handed and map depth as WebGL expects, from -1 at the near plane to 1 at the far plane. + +`Vec3.transformByMat4` divides by w, so transforming a point by the model-view-projection matrix gives normalised device coordinates directly. From there to the canvas is a scale and a flip of y: + +```js +import { Vec2, Vec3 } from 'wtc-math' + +function toScreen(point, mvp, width, height) { + const ndc = point.transformByMat4New(mvp) + return new Vec2((ndc.x + 1) * 0.5 * width, (1 - ndc.y) * 0.5 * height) +} +``` + +A point with an NDC z outside -1 to 1 is in front of the near plane or past the far one, and wouldn't be drawn. + +## Related + +- [3D transforms](/matrices/3d-transforms) +- [With WebGL and wtc-gl](/guides/webgl) +- [Ray](/geometry/ray), for picking with the pointer +- API: [Mat4](/api/wtc-math/classes/Mat4) diff --git a/docs/public/favicon.svg b/docs/public/favicon.svg new file mode 100644 index 0000000..acd5fdc --- /dev/null +++ b/docs/public/favicon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/docs/public/logo.svg b/docs/public/logo.svg new file mode 100644 index 0000000..acd5fdc --- /dev/null +++ b/docs/public/logo.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/docs/rotation/quaternions.md b/docs/rotation/quaternions.md new file mode 100644 index 0000000..9b4abae --- /dev/null +++ b/docs/rotation/quaternions.md @@ -0,0 +1,95 @@ +# Quaternions + +A `Quat` holds a rotation in 3D. Quaternions combine and interpolate cleanly, and don't suffer from gimbal lock. {.lead} + +You rarely need to know what's inside one. Make a quaternion from an axis and an angle, or from Euler angles, combine it with others, and turn vectors or build matrices with it: + + + +<<< @/examples/quat-slerp.js + +`Quat` extends [`Vec4`](/vectors/vec4), with the rotation in `x`, `y`, `z` and `w`. `new Quat()` and `Quat.identity()` are both no rotation, `(0, 0, 0, 1)`. + +## Making one + +`Quat.fromAxisAngle(axis, radians)` turns around an axis by an angle. The axis must be normalised: + +```js +import { Quat, Vec3 } from 'wtc-math' + +const quarterTurn = Quat.fromAxisAngle(new Vec3(0, 1, 0), Math.PI / 2) +const tilt = Quat.fromAxisAngle(new Vec3(1, 1, 0).normalise(), 0.3) +``` + +`Quat.fromEuler(angles, order)` takes one angle per axis, in radians, as a `Vec3` or an array. The order says how they're combined, as in three.js, and defaults to `'YXZ'`, which suits a camera: heading around y, then pitch around the new x, then roll: + +```js +const look = Quat.fromEuler([pitch, yaw, 0]) // YXZ +const other = Quat.fromEuler([0.1, 0.2, 0.3], 'XYZ') +``` + +The orders are `'XYZ'`, `'YXZ'`, `'ZXY'`, `'ZYX'`, `'YZX'` and `'XZY'`. + +To read a rotation out of a matrix, use `Mat4`'s [`rotation`](/matrices/3d-transforms#taking-a-matrix-apart) getter. + +## Turning things + +`Vec3.transformByQuat(q)` rotates a vector: + +```js +new Vec3(0, 0, 1).transformByQuat(quarterTurn) // (1, 0, 0) +``` + +`Mat4.fromQuat(q)` makes a rotation matrix, and `Mat4.fromRotationTranslationScale(q, position, scale)` a full model matrix: + +```js +import { Mat4 } from 'wtc-math' + +const model = Mat4.fromRotationTranslationScale(orientation, position, [1, 1, 1]) +``` + +## Combining + +`a.multiply(b)` combines two rotations into one that applies `b` first, then `a`, in the same order as [matrices](/matrices/3d-transforms#order). It changes `a` in place; `multiplyNew` leaves it alone. + +```js +const yaw = Quat.fromAxisAngle(new Vec3(0, 1, 0), heading) +const pitch = Quat.fromAxisAngle(new Vec3(1, 0, 0), tilt) + +// Pitch the object, then turn it to its heading +const orientation = yaw.multiplyNew(pitch) +``` + +Turning an orientation by a small amount every frame is one multiply. Normalise it now and then so rounding errors don't build up: + +```js +const step = Quat.fromAxisAngle(axis, speed * delta) +orientation.multiply(step).normalise() +``` + +`conjugate()` reverses a unit quaternion's rotation, and `invert()` does the same for any quaternion. Use them to undo a rotation, or to find the rotation from one orientation to another: + +```js +// The rotation that takes `from` to `to` +const difference = to.multiplyNew(from.invertNew()) +``` + +::: warning +`inverse()`, inherited from `Vec4`, takes `1 / x` of each component. It isn't the inverse rotation; that's `invert()`. +::: + +## Interpolating + +`Quat.slerp(a, b, t)` returns a new rotation `t` of the way from `a` to `b`, turning at a steady speed along the shortest path. Ease `t` for natural starts and stops, as the example does with [`smootherstep`](/utilities/scalars). + +```js +const halfway = Quat.slerp(from, to, 0.5) +``` + +Don't interpolate quaternions with `Vec4.lerp`; it doesn't keep a steady speed or a unit length. + +## Related + +- [3D transforms](/matrices/3d-transforms) +- [Vec3](/vectors/vec3#rotation) +- API: [Quat](/api/wtc-math/classes/Quat), [QuatLike](/api/wtc-math/type-aliases/QuatLike) diff --git a/docs/typedoc.json b/docs/typedoc.json new file mode 100644 index 0000000..dfc751c --- /dev/null +++ b/docs/typedoc.json @@ -0,0 +1,71 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "plugin": [ + "typedoc-plugin-markdown", + "typedoc-vitepress-theme" + ], + "name": "wtc-math", + "entryPoints": [ + "../src/index.ts", + "../src/Color.ts", + "../src/Plane.ts", + "../src/Ray.ts" + ], + "tsconfig": "../tsconfig.json", + "out": "./api", + "docsRoot": "./", + "readme": "none", + "excludeExternals": true, + "excludePrivate": true, + "excludeInternal": true, + "disableSources": false, + "gitRevision": "master", + "sourceLinkTemplate": "https://github.com/wethegit/wtc-math/blob/{gitRevision}/{path}#L{line}", + "outputFileStrategy": "members", + "entryFileName": "index", + "hidePageHeader": true, + "hideBreadcrumbs": true, + "useCodeBlocks": true, + "parametersFormat": "table", + "interfacePropertiesFormat": "table", + "classPropertiesFormat": "table", + "typeDeclarationFormat": "table", + "enumMembersFormat": "table", + "propertyMembersFormat": "table", + "categorizeByGroup": false, + "navigation": { + "includeCategories": true, + "includeGroups": false + }, + "sidebar": { + "autoConfiguration": true, + "format": "vitepress", + "pretty": true, + "collapsed": true + }, + "tableColumnSettings": { + "hideSources": true, + "leftAlignHeaders": true + }, + "pageTitleTemplates": { + "member": "{name}" + }, + "validation": { + "notExported": true, + "invalidLink": true, + "notDocumented": true + }, + "treatValidationWarningsAsErrors": true, + "defaultCategory": "Other", + "intentionallyNotExported": [ + "V4Q", + "Mat3DeterminantFunction", + "Mat4DeterminantFunction", + "src/Mat3.ts:Mat4" + ], + "excludeTags": [ + "@author", + "@version", + "@created" + ] +} diff --git a/docs/utilities/scalars.md b/docs/utilities/scalars.md new file mode 100644 index 0000000..3efc5a5 --- /dev/null +++ b/docs/utilities/scalars.md @@ -0,0 +1,87 @@ +# Scalar functions + +Small functions on plain numbers, for the clamping, blending, remapping and easing that turn up in every sketch. {.lead} + +```js +import { clamp, lerp, map, pingpong } from 'wtc-math' +import { smoothstep, smootherstep, degToRad, radToDeg } from 'wtc-math' +``` + + + +<<< @/examples/scalars.js + +## clamp + +`clamp(v, min, max)` keeps a value within a range: + +```js +clamp(1.4, 0, 1) // 1 +clamp(-3, 0, 1) // 0 +``` + +## lerp + +`lerp(a, b, t)` returns the value `t` of the way from `a` to `b`. `t` isn't clamped, so values outside 0–1 carry on past the ends: + +```js +lerp(10, 20, 0.25) // 12.5 + +// Ease towards a target a tenth of the way each frame +x = lerp(x, target, 0.1) +``` + +`Vec2.lerp`, `Vec3.lerp` and `Color.lerp` do the same for vectors and colours. + +## map + +`map(v, inMin, inMax, outMin, outMax)` remaps a value from one range to another. It doesn't clamp, so wrap it in `clamp` if the input can leave its range: + +```js +map(5, 0, 10, 100, 200) // 150 + +// Scroll position to a 0–1 progress through a section +const progress = clamp(map(scrollY, start, end, 0, 1), 0, 1) +``` + +Make sure `inMin` and `inMax` differ, or it divides by zero. + +## smoothstep and smootherstep + +`smoothstep(edge0, edge1, x)` is 0 below `edge0`, 1 above `edge1`, and eases smoothly between them, with no sudden change of speed at either end. `smootherstep` is Ken Perlin's variant, flatter at the ends. Both match the GLSL functions of the same name, so the same easing works on the CPU and in a shader. + +```js +smoothstep(0, 1, 0.25) // 0.15625 + +// Fade in as an element scrolls through the middle of the screen +const opacity = smoothstep(0.3, 0.7, progress) +``` + +Use them to ease an animation's `t`, to soften a threshold, or to fade something in over a range. + +## pingpong + +`pingpong(t, length)` runs from 0 up to `length` and back down again as `t` grows, for things that go back and forth: + +```js +pingpong(0.5, 2) // 0.5 +pingpong(3, 2) // 1, on the way back down + +const swing = pingpong(time, 1) // 0 → 1 → 0 → 1 … +``` + +It's meant for `t` of 0 or more. + +## degToRad and radToDeg + +Every angle in wtc-math is in radians unless its name says otherwise. Convert with: + +```js +degToRad(180) // Math.PI +radToDeg(Math.PI / 2) // 90 +``` + +## Related + +- [Conventions](/getting-started/conventions#angles) +- API: [clamp](/api/wtc-math/functions/clamp), [lerp](/api/wtc-math/functions/lerp), [map](/api/wtc-math/functions/map), [smoothstep](/api/wtc-math/functions/smoothstep), [smootherstep](/api/wtc-math/functions/smootherstep), [pingpong](/api/wtc-math/functions/pingpong), [degToRad](/api/wtc-math/functions/degToRad), [radToDeg](/api/wtc-math/functions/radToDeg) diff --git a/docs/vectors/swizzling.md b/docs/vectors/swizzling.md new file mode 100644 index 0000000..6bf5437 --- /dev/null +++ b/docs/vectors/swizzling.md @@ -0,0 +1,72 @@ +# Swizzling + +Read a vector's components in a different order, or a few of them at once, as you would in GLSL. {.lead} + +Each vector has getters named after combinations of its components. They return a new vector with those components in that order: + +```js +import { Vec2, Vec3, Vec4 } from 'wtc-math' + +new Vec2(1, 2).yx // Vec2(2, 1) + +const v = new Vec3(1, 2, 3) +v.xy // Vec2(1, 2) +v.zx // Vec2(3, 1) +v.zxy // Vec3(3, 1, 2) + +const q = new Vec4(1, 2, 3, 4) +q.xyz // Vec3(1, 2, 3) +q.wxyz // Vec4(4, 1, 2, 3) +``` + +The result is a copy, so changing it doesn't change the original. + +## Which swizzles there are + +| Class | Two components | Three | Four | +| ------ | -------------------------------------------------------- | --------------------- | --------------------------- | +| `Vec2` | `xy`, `yx`, `xx`, `yy` | | | +| `Vec3` | `xy`, `yz`, `zx`, `yx`, `zy`, `xx`, `yy`, `zz` | `xyz`, `yzx`, `zxy` | | +| `Vec4` | every pair of `x`, `y`, `z` and `w`, such as `xz`, `zw` | `xyz`, `yzx`, `zxy` | `xyzw`, `yzwx`, `zwxy`, `wxyz` | + +This is a useful subset, not every combination GLSL allows. + +## Setting + +Assigning to a swizzle writes into those components, from a vector or an array: + +```js +const v = new Vec3(1, 2, 3) + +v.xy = [9, 8] // Vec3(9, 8, 3) +v.yz = new Vec2(0, 0) // Vec3(9, 0, 0) + +const p = new Vec4(1, 2, 3, 4) +p.xyz = [7, 8, 9] // Vec4(7, 8, 9, 4) +``` + +Stick to the pairs in order (`xy`, `yz`, `zw` and so on), `yx`, `zx`, and the in-order `xyz` and `xyzw`, whose setters write the components in the order the name gives. + +## Where it's useful + +Drawing a 3D point on a 2D canvas, ignoring depth: + +```js +ctx.lineTo(...position.xy) +``` + +Swapping a 2D direction's components, then flipping one, to get a perpendicular, a quarter turn counter-clockwise: + +```js +const perpendicular = direction.yx.multiply(new Vec2(-1, 1)) +``` + +Dropping `w` after a perspective divide: + +```js +const ndc = clip.xyz.scale(1 / clip.w) +``` + +## Related + +- [Vec2](/vectors/vec2), [Vec3](/vectors/vec3), [Vec4](/vectors/vec4) diff --git a/docs/vectors/vec2.md b/docs/vectors/vec2.md new file mode 100644 index 0000000..6a91b2b --- /dev/null +++ b/docs/vectors/vec2.md @@ -0,0 +1,106 @@ +# Vec2 + +A two-dimensional vector, for positions, directions, sizes and velocities on a plane. {.lead} + +Make one with an x and a y. Both default to 0: + +```js +import { Vec2 } from 'wtc-math' + +const position = new Vec2(120, 80) +const origin = new Vec2() // (0, 0) +``` + +`x` and `y` are read and written directly. `width` and `height` are the same two values under other names, for when a `Vec2` holds a size, and `area` is their product. + +## Arithmetic + +`add`, `subtract`, `multiply` and `divide` work component by component with another `Vec2`. Each has a `Scalar` form that applies one number to both components. `scale(n)` is the same as `multiplyScalar(n)`. + +```js +const a = new Vec2(1, 2) + +a.add(new Vec2(3, 4)) // (4, 6) +a.multiplyScalar(2) // (8, 12) +a.divide(new Vec2(4, 0)) // (2, 0): dividing by 0 gives 0, not Infinity +``` + +All of these change `a` in place. Add `New` for a copy: `a.addNew(b)`. See [in place, or new](/getting-started/conventions#in-place-or-new). + +`negate` flips the direction, and `inverse` takes `1 / x` and `1 / y`. `floor`, `ceil`, `round` and `fract` apply to both components, and `mod(v)` takes the remainder by another vector, which suits wrapping a position around the edges of a canvas: + +```js +position.add(velocity).mod(new Vec2(width, height)) +``` + +## Length and direction + +`length` is the vector's magnitude. Set it to change the magnitude while keeping the direction: + +```js +const v = new Vec2(3, 4) +v.length // 5 + +v.length = 10 // (6, 8) +v.normalise() // (0.6, 0.8), length 1 +``` + +`normalise` keeps the direction and sets the length to 1. A zero vector stays zero. `lengthSquared` skips the square root, so use it to compare lengths: + +```js +if (a.subtractNew(b).lengthSquared < radius * radius) { + // a is within radius of b +} +``` + +`distance(v)` gives the distance to another point, and `distanceX` and `distanceY` the distance along each axis. + +## Angles and rotation + +`angle` is the direction the vector points, in radians, from `Math.atan2(y, x)`. `angleInDegrees` is the same in degrees. Setting either turns the vector to face that way, keeping its length. + +`rotate(radians)` turns the vector by an angle, and `rotateTo(radians)` turns it to face one. Both have degree forms, `rotateDeg` and `rotateToDeg`: + +```js +const v = new Vec2(1, 0) + +v.rotate(Math.PI / 2) // (0, 1) +v.rotateToDeg(180) // (-1, 0) +``` + +Positive angles turn counter-clockwise with y up, which is clockwise on a canvas where y points down. + +`Vec2.getAngle(a, b)` gives the angle between two vectors, from 0 to π, whatever their lengths. + +## Dot and cross products + +`dot(v)` multiplies the vectors' lengths by the cosine of the angle between them. With a unit vector, it gives how far the other vector reaches in that direction, which is how you project one vector onto another: + + + +<<< @/examples/vec2-projection.js + +The dot product is positive when the vectors point the same way, zero when they're at right angles and negative when they point apart, which makes it a quick test for whether something is in front of or behind you. + +`cross(v)` gives the 2D cross product, a single number: positive when `v` is counter-clockwise of this vector, negative when it's clockwise. `det(v)` is the same value. + +## Interpolation + +`Vec2.lerp(a, b, t)` returns a new vector `t` of the way from `a` to `b`: + +```js +const halfway = Vec2.lerp(start, end, 0.5) + +// Ease towards a target each frame +position = Vec2.lerp(position, target, 0.1) +``` + +## Matrices + +`transformByMat2(m)` multiplies the vector by a 2×2 matrix, and `transformByMat3(m)` by a 3×3 matrix, treating the vector as a point so the matrix's translation applies. See [2D transforms](/matrices/2d-transforms). + +## Related + +- [Vec3](/vectors/vec3), [Swizzling](/vectors/swizzling) +- [Conventions](/getting-started/conventions) +- API: [Vec2](/api/wtc-math/classes/Vec2), [Vec2Like](/api/wtc-math/type-aliases/Vec2Like) diff --git a/docs/vectors/vec3.md b/docs/vectors/vec3.md new file mode 100644 index 0000000..035d1ab --- /dev/null +++ b/docs/vectors/vec3.md @@ -0,0 +1,95 @@ +# Vec3 + +A three-dimensional vector, for positions, directions, normals and scales in 3D. {.lead} + +`Vec3` works like [`Vec2`](/vectors/vec2) with a third component: the same arithmetic, `length`, `normalise`, `distance`, `dot`, `lerp` and in-place and `New` forms. This page covers what's different in 3D. + +```js +import { Vec3 } from 'wtc-math' + +const position = new Vec3(0, 1.5, -4) +const up = new Vec3(0, 1, 0) +``` + +`width`, `height` and `depth` are other names for `x`, `y` and `z`, for when a `Vec3` holds a size, and `area` is their product, the volume. + +## Cross product + +`cross(v)` returns a new vector at right angles to both, with a length equal to the area of the parallelogram they make. Its direction follows the right-hand rule: `x` cross `y` is `z`. + +```js +new Vec3(1, 0, 0).cross(new Vec3(0, 1, 0)) // (0, 0, 1) +``` + +::: warning +Unlike most methods, `cross` doesn't change the vector it's called on. It returns a new vector, as `crossNew` does. +::: + +Crossing two edges of a triangle gives its normal, the direction the face points. The dot product of the normal with the direction to the camera tells you which side of the face you're looking at: + + + +<<< @/examples/vec3-normal.js + +## Rotation + +`rotateX`, `rotateY` and `rotateZ` turn the vector around an axis through a point. Pass the point first, then the angle in radians: + +```js +const centre = new Vec3(0, 0, 0) +const p = new Vec3(1, 0, 0) + +p.rotateY(centre, Math.PI / 2) // (0, 0, -1) +``` + +Rotating a position around a point other than the origin orbits it around that point: `new Vec3(2, 0, 0).rotateY(new Vec3(1, 0, 0), Math.PI / 2)` gives `(1, 0, -1)`. + +For an arbitrary axis, or to combine rotations, use a [quaternion](/rotation/quaternions) and `transformByQuat`: + +```js +import { Vec3, Quat } from 'wtc-math' + +const spin = Quat.fromAxisAngle(new Vec3(1, 1, 0).normalise(), Math.PI / 3) +const turned = new Vec3(0, 0, 1).transformByQuat(spin) +``` + +## Matrices + +`transformByMat4(m)` treats the vector as a point and transforms it by a 4×4 matrix, including the translation. It divides by the resulting w, so a projection matrix takes a point straight to normalised device coordinates, from -1 to 1 on each axis: + +```js +const ndc = worldPosition.transformByMat4New(viewProjection) +const screenX = (ndc.x + 1) * 0.5 * width +const screenY = (1 - ndc.y) * 0.5 * height +``` + +`transformByMat3(m)` multiplies by a 3×3 matrix with no translation, which suits directions and normals. [3D transforms](/matrices/3d-transforms) has more. + +## Euler angles from a matrix + +`Vec3.fromRotationMatrix(m, order)` reads the rotation out of a `Mat4` as Euler angles in radians, one per axis. The order defaults to `'YXZ'`, as in three.js, and can be any of `'XYZ'`, `'YXZ'`, `'ZXY'`, `'ZYX'`, `'YZX'` and `'XZY'`: + +```js +import { Vec3, Mat4 } from 'wtc-math' + +Vec3.fromRotationMatrix(Mat4.fromYRotation(0.5)) // (0, 0.5, 0) +``` + +## Spherical names + +`radius`, `phi` and `theta` are other names for `x`, `y` and `z`, for a `Vec3` that holds spherical coordinates. They don't convert anything, so you do the trigonometry: + +```js +const s = new Vec3(5, Math.PI / 3, Math.PI / 4) // radius, phi, theta +const p = new Vec3( + s.radius * Math.sin(s.phi) * Math.cos(s.theta), + s.radius * Math.cos(s.phi), + s.radius * Math.sin(s.phi) * Math.sin(s.theta) +) +``` + +## Related + +- [Vec2](/vectors/vec2), [Vec4](/vectors/vec4), [Swizzling](/vectors/swizzling) +- [Quaternions](/rotation/quaternions), [3D transforms](/matrices/3d-transforms) +- API: [Vec3](/api/wtc-math/classes/Vec3), [Vec3Like](/api/wtc-math/type-aliases/Vec3Like) diff --git a/docs/vectors/vec4.md b/docs/vectors/vec4.md new file mode 100644 index 0000000..38792b3 --- /dev/null +++ b/docs/vectors/vec4.md @@ -0,0 +1,52 @@ +# Vec4 + +A four-dimensional vector, for homogeneous coordinates, RGBA values and anything else that comes in fours. {.lead} + +`Vec4` has the same arithmetic, `length`, `normalise`, `dot` and in-place and `New` methods as [`Vec2`](/vectors/vec2) and [`Vec3`](/vectors/vec3), with a fourth component, `w`. + +```js +import { Vec4 } from 'wtc-math' + +const point = new Vec4(1, 2, 3, 1) // w = 1: a position +const direction = new Vec4(0, 0, -1, 0) // w = 0: a direction +``` + +## Homogeneous coordinates + +In 3D graphics, a point is often written as four numbers with `w` set to 1, and a direction with `w` set to 0. A 4×4 matrix then moves points but only turns directions, since the translation is multiplied by `w`. + +`transformByMat4(m)` multiplies the vector by a column-major 4×4 matrix. Unlike `Vec3.transformByMat4`, it doesn't divide by `w` afterwards, so after a projection you get clip coordinates and do the divide yourself: + +```js +import { Vec4, Mat4 } from 'wtc-math' + +const clip = new Vec4(0, 0, -5, 1).transformByMat4(viewProjection) +const ndc = clip.xyz.scale(1 / clip.w) +``` + +`transformByQuat(q)` rotates the x, y and z components by a quaternion. + +## Size + +`width`, `height` and `depth` are other names for `x`, `y` and `z`. `area` is the product of all four components. + +## Getting smaller vectors out + +The [swizzle](/vectors/swizzling) getters return smaller vectors: `xyz` gives a `Vec3`, and `xy`, `zw` and the rest give a `Vec2`. + +```js +const v = new Vec4(1, 2, 3, 4) + +v.xyz // Vec3(1, 2, 3) +v.zw // Vec2(3, 4) +``` + +## Quaternions + +[`Quat`](/rotation/quaternions) extends `Vec4`, so it has all of these methods too. Some don't mean much for a rotation; the quaternion page covers the ones that do. + +## Related + +- [Vec3](/vectors/vec3), [Swizzling](/vectors/swizzling) +- [Quaternions](/rotation/quaternions) +- API: [Vec4](/api/wtc-math/classes/Vec4), [Vec4Like](/api/wtc-math/type-aliases/Vec4Like) diff --git a/package-lock.json b/package-lock.json index fff6c79..0eab142 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,21 +14,280 @@ "devDependencies": { "@changesets/changelog-github": "^1.0.1", "@changesets/cli": "^3.0.3", - "@types/markdown-it": "~14.1.1", "@types/node": "^25.7.0", - "@types/pug": "^2.0.10", "husky": "^9.0.11", - "pug": "^3.0.4", "typedoc": "^0.28.19", + "typedoc-plugin-markdown": "^4.14.1", + "typedoc-vitepress-theme": "^1.1.4", "vite": "^8.0.13", "vite-plugin-dts": "^5.0.0", - "vitest": "^5.0.4" + "vitepress": "1.6.4", + "vitest": "^5.0.4", + "vue": "^3.5.46" + } + }, + "node_modules/@algolia/abtesting": { + "version": "1.31.0", + "resolved": "https://registry.npmjs.org/@algolia/abtesting/-/abtesting-1.31.0.tgz", + "integrity": "sha512-6ii6y4Anj91i/O9RqHndwgAXzE7XPn9VJt7JhW5fM0u3DSKFzP8vX02GR5m41BIojGmItF3w9kDbqorLPl5gwQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/autocomplete-core": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-core/-/autocomplete-core-1.17.7.tgz", + "integrity": "sha512-BjiPOW6ks90UKl7TwMv7oNQMnzU+t/wk9mgIDi6b1tXpUek7MW0lbNOUHpvam9pe3lVCf4xPFT+lK7s+e+fs7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/autocomplete-plugin-algolia-insights": "1.17.7", + "@algolia/autocomplete-shared": "1.17.7" + } + }, + "node_modules/@algolia/autocomplete-plugin-algolia-insights": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-plugin-algolia-insights/-/autocomplete-plugin-algolia-insights-1.17.7.tgz", + "integrity": "sha512-Jca5Ude6yUOuyzjnz57og7Et3aXjbwCSDf/8onLHSQgw1qW3ALl9mrMWaXb5FmPVkV3EtkD2F/+NkT6VHyPu9A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/autocomplete-shared": "1.17.7" + }, + "peerDependencies": { + "search-insights": ">= 1 < 3" + } + }, + "node_modules/@algolia/autocomplete-preset-algolia": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.17.7.tgz", + "integrity": "sha512-ggOQ950+nwbWROq2MOCIL71RE0DdQZsceqrg32UqnhDz8FlO9rL8ONHNsI2R1MH0tkgVIDKI/D0sMiUchsFdWA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/autocomplete-shared": "1.17.7" + }, + "peerDependencies": { + "@algolia/client-search": ">= 4.9.1 < 6", + "algoliasearch": ">= 4.9.1 < 6" + } + }, + "node_modules/@algolia/autocomplete-shared": { + "version": "1.17.7", + "resolved": "https://registry.npmjs.org/@algolia/autocomplete-shared/-/autocomplete-shared-1.17.7.tgz", + "integrity": "sha512-o/1Vurr42U/qskRSuhBH+VKxMvkkUVTLU6WZQr+L5lGZZLYWyhdzWjW0iGXY7EkwRTjBqvN2EsR81yCTGV/kmg==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@algolia/client-search": ">= 4.9.1 < 6", + "algoliasearch": ">= 4.9.1 < 6" + } + }, + "node_modules/@algolia/client-abtesting": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-abtesting/-/client-abtesting-5.65.0.tgz", + "integrity": "sha512-oucECT3zn6/dg8IaUlB/VtLemCC5WEYQSe1c8epFu2CCXluAaDOXop0tHTCVzA11UReSy2/HST4+0ImW4KjNMA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/client-analytics": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-analytics/-/client-analytics-5.65.0.tgz", + "integrity": "sha512-xtCoO8qPX0vEjHLtvHBX5H/eGemWi4pd25nHvxyvE0lJW6UAXsMulTmYR6LQDRe11P7TehYNRxQyNGRfsl9sUw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/client-common": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-common/-/client-common-5.65.0.tgz", + "integrity": "sha512-HKsPz1ez+iCQPvCnp/LAc6tvHDOZbgYqmEBBIzT/ypqcVxuSiVjefS49dtdUCIBLFQx82G952YwuQRer3FkT8g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/client-insights": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-insights/-/client-insights-5.65.0.tgz", + "integrity": "sha512-sK60DDwXgMBxSmwouWtO+7+kiZBLeR3p7HYpua19GvD5SjhUaT//NhV2zBYv+nEyMAWkZz2WwnJP1hrh2Byzfg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/client-personalization": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-personalization/-/client-personalization-5.65.0.tgz", + "integrity": "sha512-AFNZWZ8sxNIXJX24se0zQQIGtdlv1NzLDL8VBd7UG4MWyxVdG01ltekAliZhuoauUaKpCEMR+ZnMlFSbEYnvJA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/client-query-suggestions": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-query-suggestions/-/client-query-suggestions-5.65.0.tgz", + "integrity": "sha512-szXK38E7vTF5cI7BtgK1wSQVHuZ9o2ZF0AwEDAcHVr92m+g1Gwk7QkpbtV4pat6k5Ea8iTZNi6xk91se7tD+Ew==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/client-search": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/client-search/-/client-search-5.65.0.tgz", + "integrity": "sha512-ve+54en+XDMy7pwpdsN70aeMBwKvVyglJPYTuWnhN8RTvskxRPwPMllBiFSApP+QKzzHAuFZGRujzGO+mAhzXQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/ingestion": { + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@algolia/ingestion/-/ingestion-1.65.0.tgz", + "integrity": "sha512-exDdxCEGZHyMH/dOEkJZVx8KVvU7MITUl9CNcyYI4cqfgDo37b8Xzcvcsp3k/aHcZxTwwtroIZgp45VlEBMzKQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/monitoring": { + "version": "1.65.0", + "resolved": "https://registry.npmjs.org/@algolia/monitoring/-/monitoring-1.65.0.tgz", + "integrity": "sha512-kDxmwvY7sHf/xNP9ztXJ3UdQLDW+24zh0lDS5ZQOUxA0xOknt0ayYI3rS4RHKqWzUDl284WBCRreMhbpY387Wg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/recommend": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/recommend/-/recommend-5.65.0.tgz", + "integrity": "sha512-AOjncjDyAl82z9Hb7+4moiNH/222YpX/X1OU5ShsXVX4gVxFZFK9ro+d+ArxmiAsRhPyH0xc+P8CHZGgs2S11w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/requester-browser-xhr": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/requester-browser-xhr/-/requester-browser-xhr-5.65.0.tgz", + "integrity": "sha512-57OdxaUZ3GS/NbdMIkDB93qy019zz2sZ+Awet+zNe9wo5/b/tObR9Seq/hsieFHYLxpjvpPF4pmctr9l3mAQJg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/requester-fetch": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/requester-fetch/-/requester-fetch-5.65.0.tgz", + "integrity": "sha512-x5jvVRt44N25elrCBDTFG8+iM0/pFxE9Z/sjg1eCeSjXb1SwhLhkqTVpG+yqkPoDOFRjD02S0WtmeQkiGX/LQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/@algolia/requester-node-http": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/@algolia/requester-node-http/-/requester-node-http-5.65.0.tgz", + "integrity": "sha512-+3RUs4gm83CAuBmQZO3oSSc6dCywiOpb83W7NTKW+Ex6dIAfHp/XtUFMmsPU33OsT+2sZ/SpCNQwvDAOdPBprw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/client-common": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.27.1", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.27.1.tgz", - "integrity": "sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==", + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.15.tgz", + "integrity": "sha512-C2FuapQ2Kh1OnVHAoLi5rD3GBJ8COb9Q609T6HEpLqaBAo560PDP5OxBE5dCI/h951MBO/+bCUYU5SZ+8ZlV+w==", "dev": true, "license": "MIT", "engines": { @@ -36,9 +295,9 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.28.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.28.5.tgz", - "integrity": "sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==", + "version": "7.29.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", + "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", "dev": true, "license": "MIT", "engines": { @@ -46,13 +305,13 @@ } }, "node_modules/@babel/parser": { - "version": "7.29.3", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.3.tgz", - "integrity": "sha512-b3ctpQwp+PROvU/cttc4OYl4MzfJUWy6FZg+PMXfzmt/+39iHVF0sDfqay8TQM3JA2EUOyKcFZt75jWriQijsA==", + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.15.tgz", + "integrity": "sha512-RpKWyisHoP81twtSCgmE02iU0RnPcq1DN5bBEbpUePrjA9Q3wXhufnCJrrayPpoZieqFh3zyZQqwtSK0gGccRA==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.29.0" + "@babel/types": "^7.29.15" }, "bin": { "parser": "bin/babel-parser.js" @@ -62,14 +321,14 @@ } }, "node_modules/@babel/types": { - "version": "7.29.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.0.tgz", - "integrity": "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A==", + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.15.tgz", + "integrity": "sha512-/XKpKDakL//LZ66bq1XsZOswuqeI5MZqPLDu18o3XdkU1fNJ7bdPtzgnc4ZNS+bBGHV0FJG8jjb8SwcC3nNVQQ==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.27.1", - "@babel/helper-validator-identifier": "^7.28.5" + "@babel/helper-string-parser": "^7.29.15", + "@babel/helper-validator-identifier": "^7.29.7" }, "engines": { "node": ">=6.9.0" @@ -375,6 +634,57 @@ "node": ">= 20.12.0" } }, + "node_modules/@docsearch/css": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/@docsearch/css/-/css-3.8.2.tgz", + "integrity": "sha512-y05ayQFyUmCXze79+56v/4HpycYF3uFqB78pLPrSV5ZKAlDuIAAJNhaRi8tTdRNXh05yxX/TyNnzD6LwSM89vQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@docsearch/js": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/@docsearch/js/-/js-3.8.2.tgz", + "integrity": "sha512-Q5wY66qHn0SwA7Taa0aDbHiJvaFJLOJyHmooQ7y8hlwwQLQ/5WwCcoX0g7ii04Qi2DJlHsd0XXzJ8Ypw9+9YmQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@docsearch/react": "3.8.2", + "preact": "^10.0.0" + } + }, + "node_modules/@docsearch/react": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/@docsearch/react/-/react-3.8.2.tgz", + "integrity": "sha512-xCRrJQlTt8N9GU0DG4ptwHRkfnSnD/YpdeaXe02iKfqs97TkZJv60yE+1eq/tjPcVnTW8dP5qLP7itifFVV5eg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/autocomplete-core": "1.17.7", + "@algolia/autocomplete-preset-algolia": "1.17.7", + "@docsearch/css": "3.8.2", + "algoliasearch": "^5.14.2" + }, + "peerDependencies": { + "@types/react": ">= 16.8.0 < 19.0.0", + "react": ">= 16.8.0 < 19.0.0", + "react-dom": ">= 16.8.0 < 19.0.0", + "search-insights": ">= 1 < 3" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "react": { + "optional": true + }, + "react-dom": { + "optional": true + }, + "search-insights": { + "optional": true + } + } + }, "node_modules/@emnapi/core": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.1.tgz", @@ -409,158 +719,172 @@ "tslib": "^2.4.0" } }, - "node_modules/@gerrit0/mini-shiki": { - "version": "3.23.0", - "resolved": "https://registry.npmjs.org/@gerrit0/mini-shiki/-/mini-shiki-3.23.0.tgz", - "integrity": "sha512-bEMORlG0cqdjVyCEuU0cDQbORWX+kYCeo0kV1lbxF5bt4r7SID2l9bqsxJEM0zndaxpOUT7riCyIVEuqq/Ynxg==", + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", + "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", + "cpu": [ + "ppc64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@shikijs/engine-oniguruma": "^3.23.0", - "@shikijs/langs": "^3.23.0", - "@shikijs/themes": "^3.23.0", - "@shikijs/types": "^3.23.0", - "@shikijs/vscode-textmate": "^10.0.2" + "optional": true, + "os": [ + "aix" + ], + "peer": true, + "engines": { + "node": ">=18" } }, - "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.13", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", - "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", + "node_modules/@esbuild/android-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", + "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", + "cpu": [ + "arm" + ], "dev": true, "license": "MIT", - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.5.0", - "@jridgewell/trace-mapping": "^0.3.24" + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">=18" } }, - "node_modules/@jridgewell/remapping": { - "version": "2.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", - "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", + "node_modules/@esbuild/android-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", + "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@jridgewell/gen-mapping": "^0.3.5", - "@jridgewell/trace-mapping": "^0.3.24" + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">=18" } }, - "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", - "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "node_modules/@esbuild/android-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", + "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, "engines": { - "node": ">=6.0.0" + "node": ">=18" } }, - "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", - "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.31", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", - "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", + "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@jridgewell/resolve-uri": "^3.1.0", - "@jridgewell/sourcemap-codec": "^1.4.14" + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">=18" } }, - "node_modules/@manypkg/find-root": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@manypkg/find-root/-/find-root-3.1.0.tgz", - "integrity": "sha512-BcSqCyKhBVZ5YkSzOiheMCV41kqAFptW6xGqYSTjkVTl9XQpr+pqHhwgGCOHQtjDCv7Is6EFyA14Sm5GVbVABA==", + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", + "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@manypkg/tools": "^2.1.0" - }, + "optional": true, + "os": [ + "darwin" + ], + "peer": true, "engines": { - "node": ">=20.0.0" + "node": ">=18" } }, - "node_modules/@manypkg/get-packages": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@manypkg/get-packages/-/get-packages-3.1.0.tgz", - "integrity": "sha512-0TbBVyvPrP7xGYBI/cP8UP+yl/z+HtbTttAD7FMAJgn/kXOTwh5/60TsqP9ZYY710forNfyV0N8P/IE/ujGZJg==", + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", + "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@manypkg/find-root": "^3.1.0", - "@manypkg/tools": "^2.1.0" - }, + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, "engines": { - "node": ">=20.0.0" + "node": ">=18" } }, - "node_modules/@manypkg/tools": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@manypkg/tools/-/tools-2.1.2.tgz", - "integrity": "sha512-6QEf6yqFbETdwGITKq57aYoPfX/3K8XFNwsAlx0C1M7o8cb79sv1M3w+tWuWvIcSbNqrLF7OD7YpZMVVz335hQ==", + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", + "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "jju": "^1.4.0", - "tinyglobby": "^0.2.13", - "yaml": "^2.9.0" - }, + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, "engines": { - "node": ">=20.0.0" + "node": ">=18" } }, - "node_modules/@napi-rs/wasm-runtime": { - "version": "1.1.6", - "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.6.tgz", - "integrity": "sha512-ZLv/JdUfkvOy9eCnnBaGfiO+XimbjebAeO+MRQqD/B+FR1tnRN0tpKSJHRbE8sFfS6aqsXZ67TQjfwfsxULVbg==", + "node_modules/@esbuild/linux-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", + "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", + "cpu": [ + "arm" + ], "dev": true, "license": "MIT", "optional": true, - "dependencies": { - "@tybys/wasm-util": "^0.10.3" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/Brooooooklyn" - }, - "peerDependencies": { - "@emnapi/core": "^1.7.1", - "@emnapi/runtime": "^1.7.1" - } - }, - "node_modules/@oxc-project/types": { - "version": "0.138.0", - "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.138.0.tgz", - "integrity": "sha512-1a7ZKmrRTCoN1XMZ4L0PyyqrMnrNlLyPuOkdSX2MZg7IiIGRUyurNhAm73ptDOraoBcIordsIGKNPKUzy3ZmfA==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/Boshen" - } - }, - "node_modules/@pnpm/deps.graph-sequencer": { - "version": "1100.0.1", - "resolved": "https://registry.npmjs.org/@pnpm/deps.graph-sequencer/-/deps.graph-sequencer-1100.0.1.tgz", - "integrity": "sha512-pOr5+q1fLYKwFN3LAJuGZEnfXDcQ73zqgDHMtGy+K+uIoUqyY+6MeDCWFwfu+4EFuq76I5EPFofoNAI+Bmmq4A==", - "dev": true, - "license": "MIT", + "os": [ + "linux" + ], + "peer": true, "engines": { - "node": ">=22.13" - }, - "funding": { - "url": "https://opencollective.com/pnpm" + "node": ">=18" } }, - "node_modules/@rolldown/binding-android-arm64": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.1.4.tgz", - "integrity": "sha512-EZLpf/8y7GXkkra90ML47kzik/GMP3EMcE9bPyHmRfxLC6z9+aW5A8poCsoxjrT5GfEcNAAvWwUHjvP1pUQkfw==", + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", + "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", "cpu": [ "arm64" ], @@ -568,69 +892,73 @@ "license": "MIT", "optional": true, "os": [ - "android" + "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-darwin-arm64": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.1.4.tgz", - "integrity": "sha512-aUi+HBvmYb7j8krl1+qJgkG8C17fO79gk3c+jPw4S8glRFc1DTija9S3EyaTSQUm5GJXYKDAsugBEhFHH2vYiQ==", + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", + "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", "cpu": [ - "arm64" + "ia32" ], "dev": true, "license": "MIT", "optional": true, "os": [ - "darwin" + "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-darwin-x64": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.1.4.tgz", - "integrity": "sha512-F7hHC3gwY11+vByKPRWqwGbeXWVgKmL+pTGCinaEhdihzBV2aQ0fvZOch9cXYUOKuKKq429HeYXOqQLc7wFCEg==", + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", + "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", "cpu": [ - "x64" + "loong64" ], "dev": true, "license": "MIT", "optional": true, "os": [ - "darwin" + "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-freebsd-x64": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.1.4.tgz", - "integrity": "sha512-sI5yw+7s92SK6odiEhD5lKCBlWcpjHS5qyqpVQbZAJ0fIzEUXrmbl3DH2ybR3PZogulNJF+COLtmA8hUfvkCCQ==", + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", + "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", "cpu": [ - "x64" + "mips64el" ], "dev": true, "license": "MIT", "optional": true, "os": [ - "freebsd" + "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-arm-gnueabihf": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.1.4.tgz", - "integrity": "sha512-mCi0OKgEieFircrtVYmQAFGszRtMnZ6fpZAXrxanXAu7lqZcsK1E1RAaZNG0uKAnxox3B1f4EyQNnoyMfN1vAA==", + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", + "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", "cpu": [ - "arm" + "ppc64" ], "dev": true, "license": "MIT", @@ -638,134 +966,141 @@ "os": [ "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-arm64-gnu": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.1.4.tgz", - "integrity": "sha512-B9Ial3Kv5sh0SHnB1g/QWcUQCEvCF6QKGAl4zXypYj65mVI+B4AhFBwPtSN7pDrJeIx8Z7zdy4ntx+wQABom7w==", + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", + "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", "cpu": [ - "arm64" + "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-arm64-musl": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.1.4.tgz", - "integrity": "sha512-lZVym0PuHE1KZ22gmFTC15lAkrg9iTszR617oYRB/iPY1A56ywoJzVKOJBKaot5RiikCObmur6pogpse3gRcng==", + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", + "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", "cpu": [ - "arm64" + "s390x" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-ppc64-gnu": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.1.4.tgz", - "integrity": "sha512-t2DNiLJWNTbnEHyUzTumldML6ET4/g16467LZoDDJ3tSxGvguL5/NyC2lCsNKuyRycg9XeDQF5SSv+TNOhQEXg==", + "node_modules/@esbuild/linux-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", + "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", "cpu": [ - "ppc64" + "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-s390x-gnu": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.1.4.tgz", - "integrity": "sha512-0WIRnL1Uw4BvTZRLQt+PVgo6ZKTJadlC2btP+/EOXv2f/DWbY0rEgl+y834mIVwP1FkTlWVTrGGJXf12lru7EQ==", + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", + "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", "cpu": [ - "s390x" + "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ - "linux" + "netbsd" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-x64-gnu": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.1.4.tgz", - "integrity": "sha512-JWtGshGfX+oENAKonoNkqEJX+7hC8yfhi9GUyPX1VX4mdh1y5r+ZiJLR5XzAB0aoP6s/PcILsGjKq8O0mm24bw==", + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", + "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", "cpu": [ "x64" ], "dev": true, - "libc": [ - "glibc" + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", + "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", + "cpu": [ + "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ - "linux" + "openbsd" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-linux-x64-musl": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.1.4.tgz", - "integrity": "sha512-rT6yQcxUuXs4CnbofqwHRRV0iem349rLMYpTjkgQGLjrY4ado/eDzwPZPTCgTOlF6Nkp8NEv70yLMTn6qkWxsQ==", + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", + "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", "cpu": [ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ - "linux" + "openbsd" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-openharmony-arm64": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.1.4.tgz", - "integrity": "sha512-KXMGoboq5cyaCQjDA4GLuRiOwBQ0EyFnJoVViLeZ45/3rFItRODEr+NdsBcVpll40hhNArlm/speWGRvj08LzA==", + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", + "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", "cpu": [ "arm64" ], @@ -775,33 +1110,33 @@ "os": [ "openharmony" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-wasm32-wasi": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.1.4.tgz", - "integrity": "sha512-5K83rb36oJiY7BCyE9zLZtGcPV4g5wvq+xwdO0XPIwDVZI8cyB/AUjkNXGb92/rnmezEkjMOpgY61rtwjQtFwg==", + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", + "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", "cpu": [ - "wasm32" + "x64" ], "dev": true, "license": "MIT", "optional": true, - "dependencies": { - "@emnapi/core": "1.11.1", - "@emnapi/runtime": "1.11.1", - "@napi-rs/wasm-runtime": "^1.1.6" - }, + "os": [ + "sunos" + ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-win32-arm64-msvc": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.1.4.tgz", - "integrity": "sha512-PnWBtw3TV5KOg69HQQDR0mnQuyCmSGR2pAB4DC1rPF808fgKeTUMj2EOEyKATpgiuxuR5APQmiDO7PDgEjTFSA==", + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", + "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", "cpu": [ "arm64" ], @@ -811,16 +1146,17 @@ "os": [ "win32" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/binding-win32-x64-msvc": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.1.4.tgz", - "integrity": "sha512-M1lpniBePobTfsa7Ks9a199e1akxsXn+GYBUKsEzv3YFzOm1HJAMNwKI3qr0Zq+mxwx9gOZoTdP1yXRYsZUocQ==", + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", + "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", "cpu": [ - "x64" + "ia32" ], "dev": true, "license": "MIT", @@ -828,1907 +1164,3894 @@ "os": [ "win32" ], + "peer": true, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": ">=18" } }, - "node_modules/@rolldown/pluginutils": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", - "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@rollup/pluginutils": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.3.0.tgz", - "integrity": "sha512-5EdhGZtnu3V88ces7s53hhfK5KSASnJZv8Lulpc04cWO3REESroJXg73DFsOmgbU2BhwV0E20bu2IDZb3VKW4Q==", + "node_modules/@esbuild/win32-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", + "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@types/estree": "^1.0.0", - "estree-walker": "^2.0.2", - "picomatch": "^4.0.2" - }, + "optional": true, + "os": [ + "win32" + ], + "peer": true, "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - } + "node": ">=18" } }, - "node_modules/@shikijs/engine-oniguruma": { + "node_modules/@gerrit0/mini-shiki": { "version": "3.23.0", - "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.23.0.tgz", - "integrity": "sha512-1nWINwKXxKKLqPibT5f4pAFLej9oZzQTsby8942OTlsJzOBZ0MWKiwzMsd+jhzu8YPCHAswGnnN1YtQfirL35g==", + "resolved": "https://registry.npmjs.org/@gerrit0/mini-shiki/-/mini-shiki-3.23.0.tgz", + "integrity": "sha512-bEMORlG0cqdjVyCEuU0cDQbORWX+kYCeo0kV1lbxF5bt4r7SID2l9bqsxJEM0zndaxpOUT7riCyIVEuqq/Ynxg==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/types": "3.23.0", + "@shikijs/engine-oniguruma": "^3.23.0", + "@shikijs/langs": "^3.23.0", + "@shikijs/themes": "^3.23.0", + "@shikijs/types": "^3.23.0", "@shikijs/vscode-textmate": "^10.0.2" } }, - "node_modules/@shikijs/langs": { - "version": "3.23.0", - "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.23.0.tgz", - "integrity": "sha512-2Ep4W3Re5aB1/62RSYQInK9mM3HsLeB91cHqznAJMuylqjzNVAVCMnNWRHFtcNHXsoNRayP9z1qj4Sq3nMqYXg==", + "node_modules/@iconify-json/simple-icons": { + "version": "1.2.103", + "resolved": "https://registry.npmjs.org/@iconify-json/simple-icons/-/simple-icons-1.2.103.tgz", + "integrity": "sha512-FMn+aVTsqQdYOwf5reCXXtfWapb+4ijI6WrU8ej1spWXWfA+d41TBXcKagHFwiHZyqt7kP7F04AiG1dYj2R06w==", "dev": true, - "license": "MIT", + "license": "CC0-1.0", "dependencies": { - "@shikijs/types": "3.23.0" + "@iconify/types": "*" } }, - "node_modules/@shikijs/themes": { - "version": "3.23.0", - "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.23.0.tgz", - "integrity": "sha512-5qySYa1ZgAT18HR/ypENL9cUSGOeI2x+4IvYJu4JgVJdizn6kG4ia5Q1jDEOi7gTbN4RbuYtmHh0W3eccOrjMA==", + "node_modules/@iconify/types": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz", + "integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==", "dev": true, - "license": "MIT", - "dependencies": { - "@shikijs/types": "3.23.0" - } + "license": "MIT" }, - "node_modules/@shikijs/types": { - "version": "3.23.0", - "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.23.0.tgz", - "integrity": "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ==", + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.13", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", + "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", "dev": true, "license": "MIT", "dependencies": { - "@shikijs/vscode-textmate": "^10.0.2", - "@types/hast": "^3.0.4" + "@jridgewell/sourcemap-codec": "^1.5.0", + "@jridgewell/trace-mapping": "^0.3.24" } }, - "node_modules/@shikijs/vscode-textmate": { - "version": "10.0.2", - "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz", - "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tybys/wasm-util": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.3.tgz", - "integrity": "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==", + "node_modules/@jridgewell/remapping": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", + "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", "dev": true, "license": "MIT", - "optional": true, "dependencies": { - "tslib": "^2.4.0" + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" } }, - "node_modules/@types/chai": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", - "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", "dev": true, "license": "MIT", - "dependencies": { - "@types/deep-eql": "*", - "assertion-error": "^2.0.1" + "engines": { + "node": ">=6.0.0" } }, - "node_modules/@types/deep-eql": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", - "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/estree": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", - "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==", + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", "dev": true, "license": "MIT" }, - "node_modules/@types/hast": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz", - "integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==", + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", "dev": true, "license": "MIT", "dependencies": { - "@types/unist": "*" + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@types/linkify-it": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==", - "dev": true - }, - "node_modules/@types/markdown-it": { - "version": "14.1.2", - "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz", - "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==", + "node_modules/@manypkg/find-root": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@manypkg/find-root/-/find-root-3.1.0.tgz", + "integrity": "sha512-BcSqCyKhBVZ5YkSzOiheMCV41kqAFptW6xGqYSTjkVTl9XQpr+pqHhwgGCOHQtjDCv7Is6EFyA14Sm5GVbVABA==", "dev": true, + "license": "MIT", "dependencies": { - "@types/linkify-it": "^5", - "@types/mdurl": "^2" + "@manypkg/tools": "^2.1.0" + }, + "engines": { + "node": ">=20.0.0" } }, - "node_modules/@types/mdurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==", - "dev": true - }, - "node_modules/@types/node": { - "version": "25.7.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.7.0.tgz", - "integrity": "sha512-z+pdZyxE+RTQE9AcboAZCb4otwcrvgHD+GlBpPgn0emDVt0ohrTMhAwlr2Wd9nZ+nihhYFxO2pThz3C5qSu2Eg==", + "node_modules/@manypkg/get-packages": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@manypkg/get-packages/-/get-packages-3.1.0.tgz", + "integrity": "sha512-0TbBVyvPrP7xGYBI/cP8UP+yl/z+HtbTttAD7FMAJgn/kXOTwh5/60TsqP9ZYY710forNfyV0N8P/IE/ujGZJg==", "dev": true, "license": "MIT", "dependencies": { - "undici-types": "~7.21.0" + "@manypkg/find-root": "^3.1.0", + "@manypkg/tools": "^2.1.0" + }, + "engines": { + "node": ">=20.0.0" } }, - "node_modules/@types/pug": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.10.tgz", - "integrity": "sha512-Sk/uYFOBAB7mb74XcpizmH0KOR2Pv3D2Hmrh1Dmy5BmK3MpdSa5kqZcg6EKBdklU0bFXX9gCfzvpnyUehrPIuA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@types/unist": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", - "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==", + "node_modules/@manypkg/tools": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@manypkg/tools/-/tools-2.1.2.tgz", + "integrity": "sha512-6QEf6yqFbETdwGITKq57aYoPfX/3K8XFNwsAlx0C1M7o8cb79sv1M3w+tWuWvIcSbNqrLF7OD7YpZMVVz335hQ==", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "jju": "^1.4.0", + "tinyglobby": "^0.2.13", + "yaml": "^2.9.0" + }, + "engines": { + "node": ">=20.0.0" + } }, - "node_modules/@vitest/mocker": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.0.4.tgz", - "integrity": "sha512-tqAlrYWce4iUxhr3ncNohejtCTOcHeE8XWrSNZY3OhPoDn01yeGv+gnaBy64ATp7o6pb03eIbBAjzmibpc9vIQ==", + "node_modules/@napi-rs/wasm-runtime": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.6.tgz", + "integrity": "sha512-ZLv/JdUfkvOy9eCnnBaGfiO+XimbjebAeO+MRQqD/B+FR1tnRN0tpKSJHRbE8sFfS6aqsXZ67TQjfwfsxULVbg==", "dev": true, "license": "MIT", + "optional": true, "dependencies": { - "@jridgewell/trace-mapping": "0.3.31", - "@vitest/spy": "5.0.4", - "estree-walker": "^3.0.3", - "magic-string": "^1.4.3" + "@tybys/wasm-util": "^0.10.3" }, "funding": { - "url": "https://opencollective.com/vitest" + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" }, "peerDependencies": { - "msw": "^2.4.9 || ^3.0.0", - "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "msw": { - "optional": true - }, - "vite": { - "optional": true - } + "@emnapi/core": "^1.7.1", + "@emnapi/runtime": "^1.7.1" } }, - "node_modules/@vitest/mocker/node_modules/estree-walker": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", - "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "node_modules/@oxc-project/types": { + "version": "0.138.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.138.0.tgz", + "integrity": "sha512-1a7ZKmrRTCoN1XMZ4L0PyyqrMnrNlLyPuOkdSX2MZg7IiIGRUyurNhAm73ptDOraoBcIordsIGKNPKUzy3ZmfA==", "dev": true, "license": "MIT", - "dependencies": { - "@types/estree": "^1.0.0" + "funding": { + "url": "https://github.com/sponsors/Boshen" } }, - "node_modules/@vitest/mocker/node_modules/magic-string": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.3.tgz", - "integrity": "sha512-z12OxmaPGE0F4xlpGdjuAUckipLpQlTAuAmyGhNoD7ODpYUzvDfvtxUbjM/jwznyP178oju/KDdyi220wNJ0RQ==", + "node_modules/@pnpm/deps.graph-sequencer": { + "version": "1100.0.1", + "resolved": "https://registry.npmjs.org/@pnpm/deps.graph-sequencer/-/deps.graph-sequencer-1100.0.1.tgz", + "integrity": "sha512-pOr5+q1fLYKwFN3LAJuGZEnfXDcQ73zqgDHMtGy+K+uIoUqyY+6MeDCWFwfu+4EFuq76I5EPFofoNAI+Bmmq4A==", "dev": true, "license": "MIT", - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.6.0" + "engines": { + "node": ">=22.13" + }, + "funding": { + "url": "https://opencollective.com/pnpm" } }, - "node_modules/@vitest/spy": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.0.4.tgz", - "integrity": "sha512-MZKk/gSkm2q+ICobMxCpH1mA+cCAWm8WV7UhxlqGjq/sJ3AGc1BqFOs5CRVXxH78wQtme9q/NAAgBquj4AcyMw==", + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.1.4.tgz", + "integrity": "sha512-EZLpf/8y7GXkkra90ML47kzik/GMP3EMcE9bPyHmRfxLC6z9+aW5A8poCsoxjrT5GfEcNAAvWwUHjvP1pUQkfw==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "funding": { - "url": "https://opencollective.com/vitest" + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/@volar/language-core": { - "version": "2.4.28", - "resolved": "https://registry.npmjs.org/@volar/language-core/-/language-core-2.4.28.tgz", - "integrity": "sha512-w4qhIJ8ZSitgLAkVay6AbcnC7gP3glYM3fYwKV3srj8m494E3xtrCv6E+bWviiK/8hs6e6t1ij1s2Endql7vzQ==", + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.1.4.tgz", + "integrity": "sha512-aUi+HBvmYb7j8krl1+qJgkG8C17fO79gk3c+jPw4S8glRFc1DTija9S3EyaTSQUm5GJXYKDAsugBEhFHH2vYiQ==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@volar/source-map": "2.4.28" + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/@volar/source-map": { - "version": "2.4.28", - "resolved": "https://registry.npmjs.org/@volar/source-map/-/source-map-2.4.28.tgz", - "integrity": "sha512-yX2BDBqJkRXfKw8my8VarTyjv48QwxdJtvRgUpNE5erCsgEUdI2DsLbpa+rOQVAJYshY99szEcRDmyHbF10ggQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/@volar/typescript": { - "version": "2.4.28", - "resolved": "https://registry.npmjs.org/@volar/typescript/-/typescript-2.4.28.tgz", - "integrity": "sha512-Ja6yvWrbis2QtN4ClAKreeUZPVYMARDYZl9LMEv1iQ1QdepB6wn0jTRxA9MftYmYa4DQ4k/DaSZpFPUfxl8giw==", + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.1.4.tgz", + "integrity": "sha512-F7hHC3gwY11+vByKPRWqwGbeXWVgKmL+pTGCinaEhdihzBV2aQ0fvZOch9cXYUOKuKKq429HeYXOqQLc7wFCEg==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@volar/language-core": "2.4.28", - "path-browserify": "^1.0.1", - "vscode-uri": "^3.0.8" + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/acorn": { - "version": "8.16.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", - "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.1.4.tgz", + "integrity": "sha512-sI5yw+7s92SK6odiEhD5lKCBlWcpjHS5qyqpVQbZAJ0fIzEUXrmbl3DH2ybR3PZogulNJF+COLtmA8hUfvkCCQ==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "bin": { - "acorn": "bin/acorn" - }, + "optional": true, + "os": [ + "freebsd" + ], "engines": { - "node": ">=0.4.0" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, - "node_modules/asap": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.1.4.tgz", + "integrity": "sha512-mCi0OKgEieFircrtVYmQAFGszRtMnZ6fpZAXrxanXAu7lqZcsK1E1RAaZNG0uKAnxox3B1f4EyQNnoyMfN1vAA==", + "cpu": [ + "arm" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } }, - "node_modules/assert-never": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/assert-never/-/assert-never-1.4.0.tgz", - "integrity": "sha512-5oJg84os6NMQNl27T9LnZkvvqzvAnHu03ShCnoj6bsJwS7L8AO4lf+C/XjK/nvzEqQB744moC6V128RucQd1jA==", + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.1.4.tgz", + "integrity": "sha512-B9Ial3Kv5sh0SHnB1g/QWcUQCEvCF6QKGAl4zXypYj65mVI+B4AhFBwPtSN7pDrJeIx8Z7zdy4ntx+wQABom7w==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } }, - "node_modules/assertion-error": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", - "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.1.4.tgz", + "integrity": "sha512-lZVym0PuHE1KZ22gmFTC15lAkrg9iTszR617oYRB/iPY1A56ywoJzVKOJBKaot5RiikCObmur6pogpse3gRcng==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=12" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/babel-walk": { - "version": "3.0.0-canary-5", - "resolved": "https://registry.npmjs.org/babel-walk/-/babel-walk-3.0.0-canary-5.tgz", - "integrity": "sha512-GAwkz0AihzY5bkwIY5QDR+LvsRQgB/B+1foMPvi0FZPMl5fjD7ICiznUiBdLYMH1QYe6vqu4gWYytZOccLouFw==", + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.1.4.tgz", + "integrity": "sha512-t2DNiLJWNTbnEHyUzTumldML6ET4/g16467LZoDDJ3tSxGvguL5/NyC2lCsNKuyRycg9XeDQF5SSv+TNOhQEXg==", + "cpu": [ + "ppc64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@babel/types": "^7.9.6" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">= 10.0.0" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/cac": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/cac/-/cac-7.1.0.tgz", - "integrity": "sha512-LMDU/U2yA4IPIY8KT0NsNPWEYZvAMkbgyspxJ6btJaYV+WMDOHAZCmB0lsTObiHaRS1V/ztKAl7+TSkTqXyeoA==", + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.1.4.tgz", + "integrity": "sha512-0WIRnL1Uw4BvTZRLQt+PVgo6ZKTJadlC2btP+/EOXv2f/DWbY0rEgl+y834mIVwP1FkTlWVTrGGJXf12lru7EQ==", + "cpu": [ + "s390x" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=20.19.0" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/call-bind-apply-helpers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", - "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.1.4.tgz", + "integrity": "sha512-JWtGshGfX+oENAKonoNkqEJX+7hC8yfhi9GUyPX1VX4mdh1y5r+ZiJLR5XzAB0aoP6s/PcILsGjKq8O0mm24bw==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">= 0.4" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/call-bound": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", - "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.1.4.tgz", + "integrity": "sha512-rT6yQcxUuXs4CnbofqwHRRV0iem349rLMYpTjkgQGLjrY4ado/eDzwPZPTCgTOlF6Nkp8NEv70yLMTn6qkWxsQ==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "get-intrinsic": "^1.3.0" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/chai": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", - "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.1.4.tgz", + "integrity": "sha512-KXMGoboq5cyaCQjDA4GLuRiOwBQ0EyFnJoVViLeZ45/3rFItRODEr+NdsBcVpll40hhNArlm/speWGRvj08LzA==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], "engines": { - "node": ">=18" + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/character-parser": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz", - "integrity": "sha512-+UqJQjFEFaTAs3bNsF2j2kEN1baG/zghZbdqoYEDxGZtJo9LBzl1A+m0D4n3qKx8N2FNv8/Xp6yV9mQmBuptaw==", + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.1.4.tgz", + "integrity": "sha512-5K83rb36oJiY7BCyE9zLZtGcPV4g5wvq+xwdO0XPIwDVZI8cyB/AUjkNXGb92/rnmezEkjMOpgY61rtwjQtFwg==", + "cpu": [ + "wasm32" + ], "dev": true, "license": "MIT", + "optional": true, "dependencies": { - "is-regex": "^1.0.3" + "@emnapi/core": "1.11.1", + "@emnapi/runtime": "1.11.1", + "@napi-rs/wasm-runtime": "^1.1.6" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/compare-versions": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-6.1.1.tgz", - "integrity": "sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg==", - "dev": true, - "license": "MIT" - }, - "node_modules/confbox": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.2.4.tgz", - "integrity": "sha512-ysOGlgTFbN2/Y6Cg3Iye8YKulHw+R2fNXHrgSmXISQdMnomY6eNDprVdW9R5xBguEqI954+S6709UyiO7B+6OQ==", + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.1.4.tgz", + "integrity": "sha512-PnWBtw3TV5KOg69HQQDR0mnQuyCmSGR2pAB4DC1rPF808fgKeTUMj2EOEyKATpgiuxuR5APQmiDO7PDgEjTFSA==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" + } }, - "node_modules/constantinople": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/constantinople/-/constantinople-4.0.1.tgz", - "integrity": "sha512-vCrqcSIq4//Gx74TXXCGnHpulY1dskqLTFGDmhrGxzeXL8lF8kvXv6mpNWlJj1uD4DW23D4ljAqbY4RRaaUZIw==", + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.1.4.tgz", + "integrity": "sha512-M1lpniBePobTfsa7Ks9a199e1akxsXn+GYBUKsEzv3YFzOm1HJAMNwKI3qr0Zq+mxwx9gOZoTdP1yXRYsZUocQ==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@babel/parser": "^7.6.0", - "@babel/types": "^7.6.1" + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^20.19.0 || >=22.12.0" } }, - "node_modules/dataloader": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/dataloader/-/dataloader-2.2.3.tgz", - "integrity": "sha512-y2krtASINtPFS1rSDjacrFgn1dcUuoREVabwlOGOe4SdxenREqwjwjElAdwvbGM7kgZz9a3KVicWR7vcz8rnzA==", + "node_modules/@rolldown/pluginutils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz", + "integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==", "dev": true, "license": "MIT" }, - "node_modules/debug": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", - "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "node_modules/@rollup/pluginutils": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.3.0.tgz", + "integrity": "sha512-5EdhGZtnu3V88ces7s53hhfK5KSASnJZv8Lulpc04cWO3REESroJXg73DFsOmgbU2BhwV0E20bu2IDZb3VKW4Q==", "dev": true, "license": "MIT", "dependencies": { - "ms": "^2.1.3" + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^4.0.2" }, "engines": { - "node": ">=6.0" + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" }, "peerDependenciesMeta": { - "supports-color": { + "rollup": { "optional": true } } }, - "node_modules/detect-libc": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", - "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.68.8.tgz", + "integrity": "sha512-7l9FdeCGjhmMTVePgndK4t9u5tLR+VuTTMoyc0PscqZDdYjS07ZsQ0vQYsWsODu/ZZYPG7WVJwbUZ77n1hVT+w==", + "cpu": [ + "arm" + ], "dev": true, - "license": "Apache-2.0", - "engines": { - "node": ">=8" - } - }, - "node_modules/doctypes": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz", - "integrity": "sha512-LLBi6pEqS6Do3EKQ3J0NqHWV5hhb78Pi8vvESYwyOy2c31ZEZVdtitdzsQsKb7878PEERhzUk0ftqGhG6Mz+pQ==", - "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "android" + ] }, - "node_modules/dunder-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", - "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.68.8.tgz", + "integrity": "sha512-kXkkIiJujBjArHwEToz99BQqIqibn4xdV6SjsoaxuZzvLUCVEzoHQ1Lp62m7xOhpLRpWpCtxL2ZUy/ADKuz9/g==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "es-errors": "^1.3.0", - "gopd": "^1.2.0" - }, - "engines": { - "node": ">= 0.4" - } + "optional": true, + "os": [ + "android" + ] }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "node_modules/@rollup/rollup-android-x64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-x64/-/rollup-android-x64-4.68.8.tgz", + "integrity": "sha512-KYoBygnHs3zUOLR0z7SaqhMnUrSF9pbuTOJT/uHK3PrgCXdv/xaMubZD8jCpg6NTo46deasLgZRq38xFTyu8uw==", + "cpu": [ + "x64" + ], "dev": true, - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } + "license": "MIT", + "optional": true, + "os": [ + "android" + ] }, - "node_modules/es-define-property": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", - "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.68.8.tgz", + "integrity": "sha512-YmBUNjgm5bsjOByO+H1TFbuGZe+ZnHcYtPXYj9+L1cwTu/BG8zjuUzO2PH9KwS85P0UH+WJDSb+mQ2hqjp5uBQ==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "engines": { - "node": ">= 0.4" - } + "optional": true, + "os": [ + "darwin" + ] }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.68.8.tgz", + "integrity": "sha512-XMX5ybuOmkwiM13KJtsBxakZ69pyaR9thRYU2fMejhaB0VuzLMIkIc+9TBsu2rv34eEf6XaSMOaLOyEgHGWHTQ==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "engines": { - "node": ">= 0.4" - } + "optional": true, + "os": [ + "darwin" + ] }, - "node_modules/es-module-lexer": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", - "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.68.8.tgz", + "integrity": "sha512-WuBXScWJDaqPJKwVrotUe1sM9DHWMN937C23RClt0MVHVt7A1rBy285ZfZTLccPEVMxmGJMt2jvdHMOI33lrKA==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] }, - "node_modules/es-object-atoms": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", - "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.68.8.tgz", + "integrity": "sha512-kegwGqP3rMenEMaKo8OzMBb5WvLW2h2jrQ3iKuYptTTF8C/yuxz+hinjBPrtYuIPLJDwxHc/hv2e4u5pmrqo9A==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - } + "optional": true, + "os": [ + "freebsd" + ] }, - "node_modules/estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.68.8.tgz", + "integrity": "sha512-Qct0oLM1zGNbvqs1udQnuchg+Q9uHbkMcQqCfs3M7foNn7HvEkUypfFn9o5fklimUI5OF3A2nMknd4/vrEyeVg==", + "cpu": [ + "arm" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/expect-type": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", - "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.68.8.tgz", + "integrity": "sha512-xTH5vD+lW/5MU3kL/Op8RSSG/O9fxUQZuJcSBmmBeYem9uXYvCq6PDHx/oDSNeyLD/p4pGujG2PVI0R8MjAhSw==", + "cpu": [ + "arm" + ], "dev": true, - "license": "Apache-2.0", - "engines": { - "node": ">=12.0.0" - } + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/exsolve": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/exsolve/-/exsolve-1.0.8.tgz", - "integrity": "sha512-LmDxfWXwcTArk8fUEnOfSZpHOJ6zOMUJKOtFLFqJLoKJetuQG874Uc7/Kki7zFLzYybmZhp1M7+98pfMqeX8yA==", + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.68.8.tgz", + "integrity": "sha512-lPPStmynSHvwWpSrAsuemPFB+EWFObXjwz44EK4Hph47U6SBAk1Kehq5MkI7i8EYVjrXddaAV7YkJH8mX8QSZQ==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/fast-string-truncated-width": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/fast-string-truncated-width/-/fast-string-truncated-width-3.0.3.tgz", - "integrity": "sha512-0jjjIEL6+0jag3l2XWWizO64/aZVtpiGE3t0Zgqxv0DPuxiMjvB3M24fCyhZUO4KomJQPj3LTSUnDP3GpdwC0g==", + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.68.8.tgz", + "integrity": "sha512-kZkvIYAihM6l6M+giSUHayDDf/JL+TYR5bYWiAX7/jUFWvMkMmysA4GV2F0HOsXQNEyctW3x1xLjww1GqW7Q1w==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/fast-string-width": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/fast-string-width/-/fast-string-width-3.0.2.tgz", - "integrity": "sha512-gX8LrtNEI5hq8DVUfRQMbr5lpaS4nMIWV+7XEbXk2b8kiQIizgnlr12B4dA3ZEx3308ze0O4Q1R+cHts8kyUJg==", + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.68.8.tgz", + "integrity": "sha512-XZKLEIY977OJr6zUtK6nlQcLXme34c8HqVp3+WmKQxKVN6Nj+b9qE3ZHWIDHXznHJsGl2AsaMOgB0GL0fkZGUg==", + "cpu": [ + "loong64" + ], "dev": true, "license": "MIT", - "dependencies": { - "fast-string-truncated-width": "^3.0.2" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/fast-wrap-ansi": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/fast-wrap-ansi/-/fast-wrap-ansi-0.2.2.tgz", - "integrity": "sha512-7F2Fl+TjRSenLqlU3UjSH0iyqopqoZIu7eZVpEirP2g1GtWa2G/ecEmBdgz31+Mxr+ELclgg6sokpSFIQiZ02Q==", + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.68.8.tgz", + "integrity": "sha512-+sN+Fj6F9suk8SkL6boIfXDmj9iJwSKPCTeCy8/pfTOHuzNX+duhTb9uyj6154oVK8Odl5zgL4DXRZzXjsRKcw==", + "cpu": [ + "loong64" + ], "dev": true, "license": "MIT", - "dependencies": { - "fast-string-width": "^3.0.2" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/fdir": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", - "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.68.8.tgz", + "integrity": "sha512-EBCu3uDFaGwSodUl+XR8yubvVFUkSo6QK9YAIOV1vljqntzTF2/mXLM6utgLaSGf/8oM+qEe8Ai0Jd4+tyMoIQ==", + "cpu": [ + "ppc64" + ], "dev": true, "license": "MIT", - "engines": { - "node": ">=12.0.0" - }, - "peerDependencies": { - "picomatch": "^3 || ^4" - }, - "peerDependenciesMeta": { - "picomatch": { - "optional": true - } - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.68.8.tgz", + "integrity": "sha512-hRC0jWdsLBckCijx2wiUfk7zW1SqEW47yMsCNoDGmQfoqq0AjW+9UYZqxg3LTmG76PyHNdNGBSuspB3CqrhGIA==", + "cpu": [ + "ppc64" + ], "dev": true, - "hasInstallScript": true, "license": "MIT", "optional": true, "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } + "linux" + ] }, - "node_modules/function-bind": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", - "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.68.8.tgz", + "integrity": "sha512-OZKrTRWyGnLITUTipbeXDdtb2dxQPyFk/Fbw9qER8pIvd2Ja9hHELkY0Fv5p9yYYkimqtzVhApKKXGv0cWGQGw==", + "cpu": [ + "riscv64" + ], "dev": true, "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/get-intrinsic": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", - "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.68.8.tgz", + "integrity": "sha512-HmhSRSQ+dOeOntPfmYux4rCpOQLtsGbcGLQu4nm8ig3tuVqe/bKfDHorg36LKAqYq4X/nwFr79ImtaFHHsn4ug==", + "cpu": [ + "riscv64" + ], "dev": true, "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "es-define-property": "^1.0.1", - "es-errors": "^1.3.0", - "es-object-atoms": "^1.1.1", - "function-bind": "^1.1.2", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-symbols": "^1.1.0", - "hasown": "^2.0.2", - "math-intrinsics": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/get-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", - "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.68.8.tgz", + "integrity": "sha512-wk1Ci1hsMREaBELoKPSnzRAh1oUULI+8kfb2F5vVmTD2IcfR9AKMskCusizZhIAvojOtPZihPj4OdKy6ifZwhQ==", + "cpu": [ + "s390x" + ], "dev": true, "license": "MIT", - "dependencies": { - "dunder-proto": "^1.0.1", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/gopd": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", - "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.68.8.tgz", + "integrity": "sha512-mDufoUJ6fnKZnCyjV3sGEDvXQQkM6j1UmINHheGX4Emau3TZWJzX3sCVmbzkNB+W2G84BiFQdDCcF09lv0i0VA==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/has-symbols": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", - "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.68.8.tgz", + "integrity": "sha512-7EGVL9rYRYQZe3UC8JQzfBN9rxk484Rfs4u/yGWumTYKUdJt6tmdP+0Y3qHvAvzJCQ+JQM5rSqZbVyrJARlGpA==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } + "optional": true, + "os": [ + "linux" + ] }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.68.8.tgz", + "integrity": "sha512-Umklz+QSGwKWQVlVrsMJrwFx1oNRYHgrxSGiZM8pJCMpzWnMDMinDhPILf0BvRXfA1QOArsDcs+AE7Jd6dQxvA==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.68.8.tgz", + "integrity": "sha512-BlRp6uzQDK5rczAdaXQ8dlSIRFRlkDRBqpb8GGtv8iwZxQdOjoigdFU5t5dcxpnpU0caMoT9mH27MyAl4dWwKw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.68.8.tgz", + "integrity": "sha512-Sc8Mkf/fVfcV0hBJNDRIM82BjS4kJn2Of0jP8dgQ+TodquxtCZ/5D6FgSsY3uN5IBmNi8Zrb/OHd60IEYKaw+Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.68.8.tgz", + "integrity": "sha512-XPTFXclN+I+Cfu3ONWDsw+uvgSZjTJa1B2u2EvtdKlSdgNU6mrOZdgeaMkvN+2T2KPTEXn6fnRY8IODlRg3/Tg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.68.8.tgz", + "integrity": "sha512-63dWiHgvpWcienfdr465lT3SIn4u3535vbDfaLKhSn0F2KJ06bbcUsewDGJZUPZCbJ67qESrPDhb85UnWdb5ew==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.68.8.tgz", + "integrity": "sha512-/W1LBsMeQAdiCuH3Z2gkRspl3mlxL+butknhq4vXjmxO45vuT08BqhehxDoE4YS+m6s9lhpq6M9/PjTEAg8PYw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@shikijs/core": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-2.5.0.tgz", + "integrity": "sha512-uu/8RExTKtavlpH7XqnVYBrfBkUc20ngXiX9NSrBhOVZYv/7XQRKUyhtkeflY5QsxC0GbJThCerruZfsUaSldg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/engine-javascript": "2.5.0", + "@shikijs/engine-oniguruma": "2.5.0", + "@shikijs/types": "2.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4", + "hast-util-to-html": "^9.0.4" } }, - "node_modules/hasown": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.3.tgz", - "integrity": "sha512-ej4AhfhfL2Q2zpMmLo7U1Uv9+PyhIZpgQLGT1F9miIGmiCJIoCgSmczFdrc97mWT4kVY72KA+WnnhJ5pghSvSg==", + "node_modules/@shikijs/core/node_modules/@shikijs/engine-oniguruma": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-2.5.0.tgz", + "integrity": "sha512-pGd1wRATzbo/uatrCIILlAdFVKdxImWJGQ5rFiB5VZi2ve5xj3Ax9jny8QvkaV93btQEwR/rSz5ERFpC5mKNIw==", "dev": true, "license": "MIT", "dependencies": { - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" + "@shikijs/types": "2.5.0", + "@shikijs/vscode-textmate": "^10.0.2" } }, - "node_modules/human-id": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/human-id/-/human-id-4.2.2.tgz", - "integrity": "sha512-Z+8unD6em/MJwyrkWQ2M3wygRGI1+MztbutiNwk1DCuEPXOZRWGjtcMPZYP1exY9iNZMhd7ZOSMQSo9WYtiQRw==", + "node_modules/@shikijs/core/node_modules/@shikijs/types": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-2.5.0.tgz", + "integrity": "sha512-ygl5yhxki9ZLNuNpPitBWvcy9fsSKKaRuO4BAlMyagszQidxcpLAr0qiW/q43DtSIDxO6hEbtYLiFZNXO/hdGw==", "dev": true, "license": "MIT", - "bin": { - "human-id": "dist/cli.js" + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" } }, - "node_modules/husky": { - "version": "9.1.7", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", - "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "node_modules/@shikijs/engine-javascript": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-javascript/-/engine-javascript-2.5.0.tgz", + "integrity": "sha512-VjnOpnQf8WuCEZtNUdjjwGUbtAVKuZkVQ/5cHy/tojVVRIRtlWMYVjyWhxOmIq05AlSOv72z7hRNRGVBgQOl0w==", "dev": true, - "bin": { - "husky": "bin.js" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" + "license": "MIT", + "dependencies": { + "@shikijs/types": "2.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "oniguruma-to-es": "^3.1.0" } }, - "node_modules/import-meta-resolve": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.2.0.tgz", - "integrity": "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg==", + "node_modules/@shikijs/engine-javascript/node_modules/@shikijs/types": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-2.5.0.tgz", + "integrity": "sha512-ygl5yhxki9ZLNuNpPitBWvcy9fsSKKaRuO4BAlMyagszQidxcpLAr0qiW/q43DtSIDxO6hEbtYLiFZNXO/hdGw==", "dev": true, "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/wooorm" + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" } }, - "node_modules/is-core-module": { - "version": "2.16.2", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz", - "integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==", + "node_modules/@shikijs/engine-oniguruma": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-3.23.0.tgz", + "integrity": "sha512-1nWINwKXxKKLqPibT5f4pAFLej9oZzQTsby8942OTlsJzOBZ0MWKiwzMsd+jhzu8YPCHAswGnnN1YtQfirL35g==", "dev": true, "license": "MIT", "dependencies": { - "hasown": "^2.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "@shikijs/types": "3.23.0", + "@shikijs/vscode-textmate": "^10.0.2" } }, - "node_modules/is-expression": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-expression/-/is-expression-4.0.0.tgz", - "integrity": "sha512-zMIXX63sxzG3XrkHkrAPvm/OVZVSCPNkwMHU8oTX7/U3AL78I0QXCEICXUM13BIa8TYGZ68PiTKfQz3yaTNr4A==", + "node_modules/@shikijs/langs": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-3.23.0.tgz", + "integrity": "sha512-2Ep4W3Re5aB1/62RSYQInK9mM3HsLeB91cHqznAJMuylqjzNVAVCMnNWRHFtcNHXsoNRayP9z1qj4Sq3nMqYXg==", "dev": true, "license": "MIT", "dependencies": { - "acorn": "^7.1.1", - "object-assign": "^4.1.1" + "@shikijs/types": "3.23.0" } }, - "node_modules/is-expression/node_modules/acorn": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", - "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", + "node_modules/@shikijs/themes": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-3.23.0.tgz", + "integrity": "sha512-5qySYa1ZgAT18HR/ypENL9cUSGOeI2x+4IvYJu4JgVJdizn6kG4ia5Q1jDEOi7gTbN4RbuYtmHh0W3eccOrjMA==", "dev": true, "license": "MIT", - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" + "dependencies": { + "@shikijs/types": "3.23.0" } }, - "node_modules/is-promise": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.2.2.tgz", - "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==", + "node_modules/@shikijs/transformers": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/transformers/-/transformers-2.5.0.tgz", + "integrity": "sha512-SI494W5X60CaUwgi8u4q4m4s3YAFSxln3tzNjOSYqq54wlVgz0/NbbXEb3mdLbqMBztcmS7bVTaEd2w0qMmfeg==", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "@shikijs/core": "2.5.0", + "@shikijs/types": "2.5.0" + } }, - "node_modules/is-regex": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", - "integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==", + "node_modules/@shikijs/transformers/node_modules/@shikijs/types": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-2.5.0.tgz", + "integrity": "sha512-ygl5yhxki9ZLNuNpPitBWvcy9fsSKKaRuO4BAlMyagszQidxcpLAr0qiW/q43DtSIDxO6hEbtYLiFZNXO/hdGw==", "dev": true, "license": "MIT", "dependencies": { - "call-bound": "^1.0.2", - "gopd": "^1.2.0", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" } }, - "node_modules/jju": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", - "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==", + "node_modules/@shikijs/types": { + "version": "3.23.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-3.23.0.tgz", + "integrity": "sha512-3JZ5HXOZfYjsYSk0yPwBrkupyYSLpAE26Qc0HLghhZNGTZg/SKxXIIgoxOpmmeQP0RRSDJTk1/vPfw9tbw+jSQ==", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" + } }, - "node_modules/js-stringify": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz", - "integrity": "sha512-rtS5ATOo2Q5k1G+DADISilDA6lv79zIiwFd6CcjuIxGKLFm5C+RLImRscVap9k55i+MOZwgliw+NejvkLuGD5g==", + "node_modules/@shikijs/vscode-textmate": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@shikijs/vscode-textmate/-/vscode-textmate-10.0.2.tgz", + "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==", "dev": true, "license": "MIT" }, - "node_modules/jsonc-parser": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", - "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "node_modules/@tybys/wasm-util": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.3.tgz", + "integrity": "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==", "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } }, - "node_modules/jstransformer": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/jstransformer/-/jstransformer-1.0.0.tgz", - "integrity": "sha512-C9YK3Rf8q6VAPDCCU9fnqo3mAfOH6vUGnMcP4AQAYIEpWtfGLpwOTmZ+igtdK5y+VvI2n3CyYSzy4Qh34eq24A==", + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", "dev": true, "license": "MIT", "dependencies": { - "is-promise": "^2.0.0", - "promise": "^7.0.1" + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" } }, - "node_modules/kolorist": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/kolorist/-/kolorist-1.8.0.tgz", - "integrity": "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==", + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", "dev": true, "license": "MIT" }, - "node_modules/launch-editor": { - "version": "2.14.2", - "resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.14.2.tgz", - "integrity": "sha512-NHJEb30MGBCkmZXLZwz25t37QR4aY03ZzPYUJXOJaOa92uWwExI9SBQUuIznBYc1xkD7cJNGX7oc3Nl3sq2kQQ==", + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/hast": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz", + "integrity": "sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==", "dev": true, "license": "MIT", "dependencies": { - "picocolors": "^1.1.1", - "shell-quote": "^1.10.0" + "@types/unist": "*" } }, - "node_modules/lightningcss": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz", - "integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==", + "node_modules/@types/linkify-it": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", + "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==", + "dev": true + }, + "node_modules/@types/markdown-it": { + "version": "14.1.2", + "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz", + "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==", "dev": true, - "license": "MPL-2.0", "dependencies": { - "detect-libc": "^2.0.3" - }, - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - }, - "optionalDependencies": { - "lightningcss-android-arm64": "1.32.0", - "lightningcss-darwin-arm64": "1.32.0", - "lightningcss-darwin-x64": "1.32.0", - "lightningcss-freebsd-x64": "1.32.0", - "lightningcss-linux-arm-gnueabihf": "1.32.0", - "lightningcss-linux-arm64-gnu": "1.32.0", - "lightningcss-linux-arm64-musl": "1.32.0", - "lightningcss-linux-x64-gnu": "1.32.0", - "lightningcss-linux-x64-musl": "1.32.0", - "lightningcss-win32-arm64-msvc": "1.32.0", - "lightningcss-win32-x64-msvc": "1.32.0" + "@types/linkify-it": "^5", + "@types/mdurl": "^2" } }, - "node_modules/lightningcss-android-arm64": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz", - "integrity": "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==", - "cpu": [ - "arm64" - ], + "node_modules/@types/mdast": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", + "integrity": "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" - } + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, + "node_modules/@types/mdurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz", + "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==", + "dev": true + }, + "node_modules/@types/node": { + "version": "25.7.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.7.0.tgz", + "integrity": "sha512-z+pdZyxE+RTQE9AcboAZCb4otwcrvgHD+GlBpPgn0emDVt0ohrTMhAwlr2Wd9nZ+nihhYFxO2pThz3C5qSu2Eg==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~7.21.0" + } + }, + "node_modules/@types/unist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.3.tgz", + "integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/web-bluetooth": { + "version": "0.0.21", + "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.21.tgz", + "integrity": "sha512-oIQLCGWtcFZy2JW77j9k8nHzAOpqMHLQejDA48XXMWH6tjCQHz5RCFz1bzsmROyL6PUm+LLnUiI4BCn221inxA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@ungap/structured-clone": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.4.0.tgz", + "integrity": "sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/@vitest/mocker": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.0.4.tgz", + "integrity": "sha512-tqAlrYWce4iUxhr3ncNohejtCTOcHeE8XWrSNZY3OhPoDn01yeGv+gnaBy64ATp7o6pb03eIbBAjzmibpc9vIQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.31", + "@vitest/spy": "5.0.4", + "estree-walker": "^3.0.3", + "magic-string": "^1.4.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9 || ^3.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker/node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/@vitest/mocker/node_modules/magic-string": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.3.tgz", + "integrity": "sha512-z12OxmaPGE0F4xlpGdjuAUckipLpQlTAuAmyGhNoD7ODpYUzvDfvtxUbjM/jwznyP178oju/KDdyi220wNJ0RQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/@vitest/spy": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.0.4.tgz", + "integrity": "sha512-MZKk/gSkm2q+ICobMxCpH1mA+cCAWm8WV7UhxlqGjq/sJ3AGc1BqFOs5CRVXxH78wQtme9q/NAAgBquj4AcyMw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@volar/language-core": { + "version": "2.4.28", + "resolved": "https://registry.npmjs.org/@volar/language-core/-/language-core-2.4.28.tgz", + "integrity": "sha512-w4qhIJ8ZSitgLAkVay6AbcnC7gP3glYM3fYwKV3srj8m494E3xtrCv6E+bWviiK/8hs6e6t1ij1s2Endql7vzQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@volar/source-map": "2.4.28" + } + }, + "node_modules/@volar/source-map": { + "version": "2.4.28", + "resolved": "https://registry.npmjs.org/@volar/source-map/-/source-map-2.4.28.tgz", + "integrity": "sha512-yX2BDBqJkRXfKw8my8VarTyjv48QwxdJtvRgUpNE5erCsgEUdI2DsLbpa+rOQVAJYshY99szEcRDmyHbF10ggQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@volar/typescript": { + "version": "2.4.28", + "resolved": "https://registry.npmjs.org/@volar/typescript/-/typescript-2.4.28.tgz", + "integrity": "sha512-Ja6yvWrbis2QtN4ClAKreeUZPVYMARDYZl9LMEv1iQ1QdepB6wn0jTRxA9MftYmYa4DQ4k/DaSZpFPUfxl8giw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@volar/language-core": "2.4.28", + "path-browserify": "^1.0.1", + "vscode-uri": "^3.0.8" + } + }, + "node_modules/@vue/compiler-core": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.5.46.tgz", + "integrity": "sha512-yb+N8/mgBcoeqCJPVyJI/D3OphLrSMXnB3ZQUNmRLU/1fsMW4bFfdJWNi9oIj7+EA3ULKKkP7b/VCpcYQYeiuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.12", + "@vue/shared": "3.5.46", + "entities": "^7.0.1", + "estree-walker": "^2.0.2", + "source-map-js": "^1.2.3" + } + }, + "node_modules/@vue/compiler-core/node_modules/entities": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz", + "integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/@vue/compiler-dom": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.5.46.tgz", + "integrity": "sha512-Bj3lCSw3DQnDRDxw115XqdLDd0+18Nftlgd8OXSGG+ud74hxJIE17eYrM+VWgQrTMsvJbLh9Hzf2MkwAzru36Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/compiler-core": "3.5.46", + "@vue/shared": "3.5.46" + } + }, + "node_modules/@vue/compiler-sfc": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.5.46.tgz", + "integrity": "sha512-hjUvMxGh+QIgegwksfp6BRBYleE/a8veZHvTR6sa+o+bM4HU+WnrUZlhN0X+pDcsl8Lhwmbu72xPvLMk3XUwog==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/parser": "^7.29.12", + "@vue/compiler-core": "3.5.46", + "@vue/compiler-dom": "3.5.46", + "@vue/compiler-ssr": "3.5.46", + "@vue/shared": "3.5.46", + "estree-walker": "^2.0.2", + "magic-string": "^0.30.21", + "postcss": "^8.5.32", + "source-map-js": "^1.2.3" + } + }, + "node_modules/@vue/compiler-ssr": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/compiler-ssr/-/compiler-ssr-3.5.46.tgz", + "integrity": "sha512-qebChL3aP0m1k+TlSf+fZWvOwAf3flBCi5o+n01ykR3DX4mTIWheFltmoiQ12+z66/4cGeXqbB2P7sPWkGhQNQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/compiler-dom": "3.5.46", + "@vue/shared": "3.5.46" + } + }, + "node_modules/@vue/devtools-api": { + "version": "7.7.10", + "resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-7.7.10.tgz", + "integrity": "sha512-KxtEpUOOpFz/qOGRrAwA36QF7DqIA+FXgCYit9mk9wjbaZt0sXOFz81ElOZtKA4HbWHUdwNjZHBFsFFyp5BZiA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/devtools-kit": "^7.7.10" + } + }, + "node_modules/@vue/devtools-kit": { + "version": "7.7.10", + "resolved": "https://registry.npmjs.org/@vue/devtools-kit/-/devtools-kit-7.7.10.tgz", + "integrity": "sha512-3WNi2Kq4tbpVbmhml7RiphmAt0279oh3fKNeWMQIrltfX8Q91b4i5PL8DtyNKdwmcsGrV4fg+erwWOmD05CLIw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/devtools-shared": "^7.7.10", + "birpc": "^2.3.0", + "hookable": "^5.5.3", + "mitt": "^3.0.1", + "perfect-debounce": "^1.0.0", + "speakingurl": "^14.0.1", + "superjson": "^2.2.2" + } + }, + "node_modules/@vue/devtools-shared": { + "version": "7.7.10", + "resolved": "https://registry.npmjs.org/@vue/devtools-shared/-/devtools-shared-7.7.10.tgz", + "integrity": "sha512-wOPslzB8vTvpxwdaOcR2qAbwmuSP0L+rhpoC6Cf56V3Jip+HWb7PQQXOUPgBNQARpXsbQX/+mvi8kKucmBGRwQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "rfdc": "^1.4.1" + } + }, + "node_modules/@vue/reactivity": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.5.46.tgz", + "integrity": "sha512-+FHtYTvGxgFoX3oRs7soz6JHizGv50Q26WJN6PWtXuTLXRfkfUpDUTRuoTA/kiZVVt8NMeMpsPQLh9h++ReUjQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/shared": "3.5.46" + } + }, + "node_modules/@vue/runtime-core": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/runtime-core/-/runtime-core-3.5.46.tgz", + "integrity": "sha512-eJUzKAUaHAmtnys/l9qduPzUnBrYMkmsCU7TN+vbSOSpm8kcETT7nacKxIO4MBej/XiOraVzq+lSeZv7o1//jQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/reactivity": "3.5.46", + "@vue/shared": "3.5.46" + } + }, + "node_modules/@vue/runtime-dom": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/runtime-dom/-/runtime-dom-3.5.46.tgz", + "integrity": "sha512-6L7lbBvXTYBFFjIt25a0pgdpmn3Ns8RqUnNVibRzF4bgyiWJvqOhKEV5MXYWKlCttZE3aGeJN8mveo+6IrIKXA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/reactivity": "3.5.46", + "@vue/runtime-core": "3.5.46", + "@vue/shared": "3.5.46", + "csstype": "^3.2.4" + } + }, + "node_modules/@vue/server-renderer": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/server-renderer/-/server-renderer-3.5.46.tgz", + "integrity": "sha512-4mc0YWREc6OZ5pDCigvKPDzIUV+aciiH92yvyTS6xaHHxW/80rMceQQn11pYe7OEEBt2YQgYWR9zF8QF30GJUQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/compiler-ssr": "3.5.46", + "@vue/runtime-dom": "3.5.46", + "@vue/shared": "3.5.46" + } + }, + "node_modules/@vue/shared": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.5.46.tgz", + "integrity": "sha512-P1WePbdzHrcIciWtmY2Im9EFhdakd3rZxYqvalOa3SfoxtF35Q8Uhmj1tKn6bWP4utcOpN8ao6BoJUItq0Uf+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/@vueuse/core": { + "version": "12.8.2", + "resolved": "https://registry.npmjs.org/@vueuse/core/-/core-12.8.2.tgz", + "integrity": "sha512-HbvCmZdzAu3VGi/pWYm5Ut+Kd9mn1ZHnn4L5G8kOQTPs/IwIAmJoBrmYk2ckLArgMXZj0AW3n5CAejLUO+PhdQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/web-bluetooth": "^0.0.21", + "@vueuse/metadata": "12.8.2", + "@vueuse/shared": "12.8.2", + "vue": "^3.5.13" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/@vueuse/integrations": { + "version": "12.8.2", + "resolved": "https://registry.npmjs.org/@vueuse/integrations/-/integrations-12.8.2.tgz", + "integrity": "sha512-fbGYivgK5uBTRt7p5F3zy6VrETlV9RtZjBqd1/HxGdjdckBgBM4ugP8LHpjolqTj14TXTxSK1ZfgPbHYyGuH7g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vueuse/core": "12.8.2", + "@vueuse/shared": "12.8.2", + "vue": "^3.5.13" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + }, + "peerDependencies": { + "async-validator": "^4", + "axios": "^1", + "change-case": "^5", + "drauu": "^0.4", + "focus-trap": "^7", + "fuse.js": "^7", + "idb-keyval": "^6", + "jwt-decode": "^4", + "nprogress": "^0.2", + "qrcode": "^1.5", + "sortablejs": "^1", + "universal-cookie": "^7" + }, + "peerDependenciesMeta": { + "async-validator": { + "optional": true + }, + "axios": { + "optional": true + }, + "change-case": { + "optional": true + }, + "drauu": { + "optional": true + }, + "focus-trap": { + "optional": true + }, + "fuse.js": { + "optional": true + }, + "idb-keyval": { + "optional": true + }, + "jwt-decode": { + "optional": true + }, + "nprogress": { + "optional": true + }, + "qrcode": { + "optional": true + }, + "sortablejs": { + "optional": true + }, + "universal-cookie": { + "optional": true + } + } + }, + "node_modules/@vueuse/metadata": { + "version": "12.8.2", + "resolved": "https://registry.npmjs.org/@vueuse/metadata/-/metadata-12.8.2.tgz", + "integrity": "sha512-rAyLGEuoBJ/Il5AmFHiziCPdQzRt88VxR+Y/A/QhJ1EWtWqPBBAxTAFaSkviwEuOEZNtW8pvkPgoCZQ+HxqW1A==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/@vueuse/shared": { + "version": "12.8.2", + "resolved": "https://registry.npmjs.org/@vueuse/shared/-/shared-12.8.2.tgz", + "integrity": "sha512-dznP38YzxZoNloI0qpEfpkms8knDtaoQ6Y/sfS0L7Yki4zh40LFHEhur0odJC6xTHG5dxWVPiUWBXn+wCG2s5w==", + "dev": true, + "license": "MIT", + "dependencies": { + "vue": "^3.5.13" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/acorn": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", + "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/algoliasearch": { + "version": "5.65.0", + "resolved": "https://registry.npmjs.org/algoliasearch/-/algoliasearch-5.65.0.tgz", + "integrity": "sha512-W6pp+0u2lJ6/4XeGGmtjLgHBxd+pKEGW0IcAyhBlk42y+nZLdsPM0w80R83zt6FZCdPLIjdTVxBn24E727wM+Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@algolia/abtesting": "1.31.0", + "@algolia/client-abtesting": "5.65.0", + "@algolia/client-analytics": "5.65.0", + "@algolia/client-common": "5.65.0", + "@algolia/client-insights": "5.65.0", + "@algolia/client-personalization": "5.65.0", + "@algolia/client-query-suggestions": "5.65.0", + "@algolia/client-search": "5.65.0", + "@algolia/ingestion": "1.65.0", + "@algolia/monitoring": "1.65.0", + "@algolia/recommend": "5.65.0", + "@algolia/requester-browser-xhr": "5.65.0", + "@algolia/requester-fetch": "5.65.0", + "@algolia/requester-node-http": "5.65.0" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/birpc": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/birpc/-/birpc-2.9.0.tgz", + "integrity": "sha512-KrayHS5pBi69Xi9JmvoqrIgYGDkD6mcSe/i6YKi3w5kekCLzrX4+nawcXqrj2tIp50Kw/mT/s3p+GVK0A0sKxw==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/cac": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/cac/-/cac-7.1.0.tgz", + "integrity": "sha512-LMDU/U2yA4IPIY8KT0NsNPWEYZvAMkbgyspxJ6btJaYV+WMDOHAZCmB0lsTObiHaRS1V/ztKAl7+TSkTqXyeoA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.19.0" + } + }, + "node_modules/ccount": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz", + "integrity": "sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/character-entities-html4": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/character-entities-html4/-/character-entities-html4-2.1.0.tgz", + "integrity": "sha512-1v7fgQRj6hnSwFpq1Eu0ynr/CDEw0rXo2B61qXrLNdHZmPKgb7fqS1a2JwF0rISo9q77jDI8VMEHoApn8qDoZA==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/character-entities-legacy": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/character-entities-legacy/-/character-entities-legacy-3.0.0.tgz", + "integrity": "sha512-RpPp0asT/6ufRm//AJVwpViZbGM/MkjQFxJccQRHmISF/22NBtsHqAWmL+/pmkPWoIUJdWyeVleTl1wydHATVQ==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/comma-separated-tokens": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz", + "integrity": "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/compare-versions": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-6.1.1.tgz", + "integrity": "sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg==", + "dev": true, + "license": "MIT" + }, + "node_modules/confbox": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.2.4.tgz", + "integrity": "sha512-ysOGlgTFbN2/Y6Cg3Iye8YKulHw+R2fNXHrgSmXISQdMnomY6eNDprVdW9R5xBguEqI954+S6709UyiO7B+6OQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/copy-anything": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-4.1.5.tgz", + "integrity": "sha512-vePst2VLTSqPglW7Q98VwFpGiGpOHTyXIo81MO5VyLecA5zMbZw/P/V1vmwD1jksa2iJpn/YkDrJ3XhTfzUyhQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/mesqueeb" + } + }, + "node_modules/csstype": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.4.tgz", + "integrity": "sha512-PoKaoPzQapnEoqUSnHx1u6W6ku8CVEgKsnpmmzU3m1nwkidpPBQ8V/Zq2+bWNrsOKoKLwTGdbx6xF7BXP1zLVQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/dataloader": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/dataloader/-/dataloader-2.2.3.tgz", + "integrity": "sha512-y2krtASINtPFS1rSDjacrFgn1dcUuoREVabwlOGOe4SdxenREqwjwjElAdwvbGM7kgZz9a3KVicWR7vcz8rnzA==", + "dev": true, + "license": "MIT" + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/devlop": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz", + "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==", + "dev": true, + "license": "MIT", + "dependencies": { + "dequal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/emoji-regex-xs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex-xs/-/emoji-regex-xs-1.0.0.tgz", + "integrity": "sha512-LRlerrMYoIDrT6jgpeZ2YYl/L8EulRTt5hQcYjy5AInh7HWXKimpqx68aknBFpGL2+/IcogTcaydJEgaTmOpDg==", + "dev": true, + "license": "MIT" + }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "dev": true, + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", + "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "peer": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true, + "license": "MIT" + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/exsolve": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/exsolve/-/exsolve-1.0.8.tgz", + "integrity": "sha512-LmDxfWXwcTArk8fUEnOfSZpHOJ6zOMUJKOtFLFqJLoKJetuQG874Uc7/Kki7zFLzYybmZhp1M7+98pfMqeX8yA==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-string-truncated-width": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/fast-string-truncated-width/-/fast-string-truncated-width-3.0.3.tgz", + "integrity": "sha512-0jjjIEL6+0jag3l2XWWizO64/aZVtpiGE3t0Zgqxv0DPuxiMjvB3M24fCyhZUO4KomJQPj3LTSUnDP3GpdwC0g==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-string-width": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/fast-string-width/-/fast-string-width-3.0.2.tgz", + "integrity": "sha512-gX8LrtNEI5hq8DVUfRQMbr5lpaS4nMIWV+7XEbXk2b8kiQIizgnlr12B4dA3ZEx3308ze0O4Q1R+cHts8kyUJg==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-string-truncated-width": "^3.0.2" + } + }, + "node_modules/fast-wrap-ansi": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/fast-wrap-ansi/-/fast-wrap-ansi-0.2.2.tgz", + "integrity": "sha512-7F2Fl+TjRSenLqlU3UjSH0iyqopqoZIu7eZVpEirP2g1GtWa2G/ecEmBdgz31+Mxr+ELclgg6sokpSFIQiZ02Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-string-width": "^3.0.2" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/focus-trap": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-7.8.0.tgz", + "integrity": "sha512-/yNdlIkpWbM0ptxno3ONTuf+2g318kh2ez3KSeZN5dZ8YC6AAmgeWz+GasYYiBJPFaYcSAPeu4GfhUaChzIJXA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tabbable": "^6.4.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/hast-util-to-html": { + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/hast-util-to-html/-/hast-util-to-html-9.0.7.tgz", + "integrity": "sha512-HYNDA3qdnzUPitY/LcQm1nWs8z0cWFNH1Nz09jdI/tXifAqF7h3+jrLl4S/b9Mi4VSjn0Dsn54ctuTV6zhBthA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/unist": "^3.0.0", + "ccount": "^2.0.0", + "comma-separated-tokens": "^2.0.0", + "hast-util-whitespace": "^3.0.0", + "html-void-elements": "^3.0.0", + "mdast-util-to-hast": "^13.0.0", + "property-information": "^7.0.0", + "space-separated-tokens": "^2.0.0", + "stringify-entities": "^4.0.0", + "zwitch": "^2.0.4" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hast-util-whitespace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/hast-util-whitespace/-/hast-util-whitespace-3.0.0.tgz", + "integrity": "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/hookable": { + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/hookable/-/hookable-5.5.3.tgz", + "integrity": "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/html-void-elements": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/html-void-elements/-/html-void-elements-3.0.0.tgz", + "integrity": "sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/human-id": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/human-id/-/human-id-4.2.2.tgz", + "integrity": "sha512-Z+8unD6em/MJwyrkWQ2M3wygRGI1+MztbutiNwk1DCuEPXOZRWGjtcMPZYP1exY9iNZMhd7ZOSMQSo9WYtiQRw==", + "dev": true, + "license": "MIT", + "bin": { + "human-id": "dist/cli.js" + } + }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, + "node_modules/import-meta-resolve": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.2.0.tgz", + "integrity": "sha512-Iqv2fzaTQN28s/FwZAoFq0ZSs/7hMAHJVX+w8PZl3cY19Pxk6jFFalxQoIfW2826i/fDLXv8IiEZRIT0lDuWcg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/jju": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", + "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==", + "dev": true, + "license": "MIT" + }, + "node_modules/jsonc-parser": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/kolorist": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/kolorist/-/kolorist-1.8.0.tgz", + "integrity": "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/launch-editor": { + "version": "2.14.2", + "resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.14.2.tgz", + "integrity": "sha512-NHJEb30MGBCkmZXLZwz25t37QR4aY03ZzPYUJXOJaOa92uWwExI9SBQUuIznBYc1xkD7cJNGX7oc3Nl3sq2kQQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "picocolors": "^1.1.1", + "shell-quote": "^1.10.0" + } + }, + "node_modules/lightningcss": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz", + "integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.32.0", + "lightningcss-darwin-arm64": "1.32.0", + "lightningcss-darwin-x64": "1.32.0", + "lightningcss-freebsd-x64": "1.32.0", + "lightningcss-linux-arm-gnueabihf": "1.32.0", + "lightningcss-linux-arm64-gnu": "1.32.0", + "lightningcss-linux-arm64-musl": "1.32.0", + "lightningcss-linux-x64-gnu": "1.32.0", + "lightningcss-linux-x64-musl": "1.32.0", + "lightningcss-win32-arm64-msvc": "1.32.0", + "lightningcss-win32-x64-msvc": "1.32.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz", + "integrity": "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz", + "integrity": "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz", + "integrity": "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz", + "integrity": "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz", + "integrity": "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz", + "integrity": "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz", + "integrity": "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz", + "integrity": "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz", + "integrity": "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz", + "integrity": "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.32.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz", + "integrity": "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/linkify-it": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", + "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", + "dev": true, + "dependencies": { + "uc.micro": "^2.0.0" + } + }, + "node_modules/local-pkg": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-1.1.2.tgz", + "integrity": "sha512-arhlxbFRmoQHl33a0Zkle/YWlmNwoyt6QNZEIJcqNbdrsix5Lvc4HyyI3EnwxTYlZYc32EbYrQ8SzEZ7dqgg9A==", + "dev": true, + "license": "MIT", + "dependencies": { + "mlly": "^1.7.4", + "pkg-types": "^2.3.0", + "quansync": "^0.2.11" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/lunr": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", + "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", + "dev": true + }, + "node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/mark.js": { + "version": "8.11.1", + "resolved": "https://registry.npmjs.org/mark.js/-/mark.js-8.11.1.tgz", + "integrity": "sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/mdast-util-to-hast": { + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/mdast-util-to-hast/-/mdast-util-to-hast-13.2.2.tgz", + "integrity": "sha512-l2pnmOuqs+SGLVpTVXnRLQu5v1AzvDe181404fbXzzqObVxrAnnVxapAP27pUwzLBL/ABIkgUhGlPVU7QSvIFg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "@types/mdast": "^4.0.0", + "@ungap/structured-clone": "^1.0.0", + "devlop": "^1.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "trim-lines": "^3.0.0", + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0", + "vfile": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, + "node_modules/mdurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", + "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", + "dev": true + }, + "node_modules/micromark-util-character": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.1.1.tgz", + "integrity": "sha512-wv8tdUTJ3thSFFFJKtpYKOYiGP2+v96Hvk4Tu8KpCAsTMs6yi+nVmGh1syvSCsaxz45J6Jbw+9DD6g97+NV67Q==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-util-encode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-encode/-/micromark-util-encode-2.0.1.tgz", + "integrity": "sha512-c3cVx2y4KqUnwopcO9b/SCdo2O67LwJJ/UyqGfbigahfegL9myoEFoDYZgkT7f36T0bLrM9hZTAaAyH+PCAXjw==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-sanitize-uri": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-sanitize-uri/-/micromark-util-sanitize-uri-2.0.1.tgz", + "integrity": "sha512-9N9IomZ/YuGGZZmQec1MbgxtlgougxTodVwDzzEouPKo3qFWvymFHWcnDi2vzV1ff6kas9ucW+o3yzJK9YB1AQ==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT", + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-encode": "^2.0.0", + "micromark-util-symbol": "^2.0.0" + } + }, + "node_modules/micromark-util-symbol": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.1.tgz", + "integrity": "sha512-vs5t8Apaud9N28kgCrRUdEed4UJ+wWNvicHLPxCa9ENlYuAY31M0ETy5y1vA33YoNPDFTghEbnh6efaE8h4x0Q==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/micromark-util-types": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.3.tgz", + "integrity": "sha512-oxB2Ik03hI0gv+VNn9tnh1t1YEe9MDPptViAEgfdf3YQHsn0pzGTgCdlSCJXcwhqm8phaEuM7zeEu3QQzVBrPg==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "license": "MIT" + }, + "node_modules/minisearch": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/minisearch/-/minisearch-7.2.0.tgz", + "integrity": "sha512-dqT2XBYUOZOiC5t2HRnwADjhNS2cecp9u+TJRiJ1Qp/f5qjkeT5APcGPjHw+bz89Ms8Jp+cG4AlE+QZ/QnDglg==", + "dev": true, + "license": "MIT" + }, + "node_modules/mitt": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz", + "integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==", + "dev": true, + "license": "MIT" + }, + "node_modules/mlly": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.8.2.tgz", + "integrity": "sha512-d+ObxMQFmbt10sretNDytwt85VrbkhhUA/JBGm1MPaWJ65Cl4wOgLaB1NYvJSZ0Ef03MMEU/0xpPMXUIQ29UfA==", + "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.16.0", + "pathe": "^2.0.3", + "pkg-types": "^1.3.1", + "ufo": "^1.6.3" + } + }, + "node_modules/mlly/node_modules/confbox": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.8.tgz", + "integrity": "sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==", + "dev": true, + "license": "MIT" + }, + "node_modules/mlly/node_modules/pkg-types": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.3.1.tgz", + "integrity": "sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "confbox": "^0.1.8", + "mlly": "^1.7.4", + "pathe": "^2.0.1" + } }, - "node_modules/lightningcss-darwin-arm64": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz", - "integrity": "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==", - "cpu": [ - "arm64" + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/oniguruma-to-es": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/oniguruma-to-es/-/oniguruma-to-es-3.1.1.tgz", + "integrity": "sha512-bUH8SDvPkH3ho3dvwJwfonjlQ4R80vjyvrU8YpxuROddv55vAEJrTuCuCVUhhsHbtlD9tGGbaNApGQckXhS8iQ==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "darwin" + "license": "MIT", + "dependencies": { + "emoji-regex-xs": "^1.0.0", + "regex": "^6.0.1", + "regex-recursion": "^6.0.2" + } + }, + "node_modules/package-manager-detector": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/package-manager-detector/-/package-manager-detector-1.9.0.tgz", + "integrity": "sha512-zAMfbta9nPA8AKkA4WdmNAT8R8s6Dk0/xwPsqNnRidMFcLo1YkLuPDTgs2f64XdzS8vbLNnoJ+uUIkgbz7oRHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true, + "license": "MIT" + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/perfect-debounce": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/perfect-debounce/-/perfect-debounce-1.0.0.tgz", + "integrity": "sha512-xCy9V055GLEqoFaHoC1SoLIaLmWctgCUaBaWxDZ7/Zx4CTyX7cJQLJOok/orfjZAh9kEYpjJa4d0KcJmCbctZA==", + "dev": true, + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pkg-types": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-2.3.1.tgz", + "integrity": "sha512-y+ichcgc2LrADuhLNAx8DFjVfgz91pRxfZdI3UDhxHvcVEZsenLO+7XaU5vOp0u/7V/wZ+plyuQxtrDlZJ+yeg==", + "dev": true, + "license": "MIT", + "dependencies": { + "confbox": "^0.2.4", + "exsolve": "^1.0.8", + "pathe": "^2.0.3" + } + }, + "node_modules/postcss": { + "version": "8.5.33", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/preact": { + "version": "10.29.8", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.29.8.tgz", + "integrity": "sha512-ej2aVZ+vZ8WO7tvlQWRM9N63A0KzF9q4mWJfDUHgYaIofWY9hu74QdnQrjoPMmZi2/nZ5gN0bJCQF49xQqx09Q==", + "dev": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + }, + "peerDependencies": { + "preact-render-to-string": ">=5" + }, + "peerDependenciesMeta": { + "preact-render-to-string": { + "optional": true + } + } + }, + "node_modules/property-information": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/property-information/-/property-information-7.2.0.tgz", + "integrity": "sha512-IAtzIB6sUiWaJYrX9smp3V46pBGbBeLFRGdh25kg1334VcBlD8HzhPeNIWQH9zhGmo2itIe25EHt9dQP7G5hmg==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, + "node_modules/punycode.js": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", + "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/quansync": { + "version": "0.2.11", + "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz", + "integrity": "sha512-AifT7QEbW9Nri4tAwR5M/uzpBuqfZf+zwaEM/QkzEjj7NBuFD2rBuy0K3dE+8wltbezDV7JMA0WfnCPYRSYbXA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/antfu" + }, + { + "type": "individual", + "url": "https://github.com/sponsors/sxzz" + } ], + "license": "MIT" + }, + "node_modules/regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/regex/-/regex-6.1.0.tgz", + "integrity": "sha512-6VwtthbV4o/7+OaAF9I5L5V3llLEsoPyq9P1JVXkedTP33c7MfCG0/5NOPcSJn0TzXcG9YUrR0gQSWioew3LDg==", + "dev": true, + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-recursion": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/regex-recursion/-/regex-recursion-6.0.2.tgz", + "integrity": "sha512-0YCaSCq2VRIebiaUviZNs0cBz1kg5kVS2UKUfNIx8YVs1cN3AV7NTctO5FOKBA+UT2BPJIWZauYHPqJODG50cg==", + "dev": true, + "license": "MIT", + "dependencies": { + "regex-utilities": "^2.3.0" + } + }, + "node_modules/regex-utilities": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/regex-utilities/-/regex-utilities-2.3.0.tgz", + "integrity": "sha512-8VhliFJAWRaUiVvREIiW2NXXTmHs4vMNnSzuJVhscgmGav3g9VDxLrQndI3dZZVVdp0ZO/5v0xmX516/7M9cng==", + "dev": true, + "license": "MIT" + }, + "node_modules/rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "dev": true, + "license": "MIT" + }, + "node_modules/rolldown": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.1.4.tgz", + "integrity": "sha512-IjZYiLxZwpnhwhdBH2ugdTGVSdhCQUmLxLoqyjiL0JxYjyRst+5a0P3xfrTxJ5F638j4Mvvw5FAX5XE6eHpXbA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@oxc-project/types": "=0.138.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm64": "1.1.4", + "@rolldown/binding-darwin-arm64": "1.1.4", + "@rolldown/binding-darwin-x64": "1.1.4", + "@rolldown/binding-freebsd-x64": "1.1.4", + "@rolldown/binding-linux-arm-gnueabihf": "1.1.4", + "@rolldown/binding-linux-arm64-gnu": "1.1.4", + "@rolldown/binding-linux-arm64-musl": "1.1.4", + "@rolldown/binding-linux-ppc64-gnu": "1.1.4", + "@rolldown/binding-linux-s390x-gnu": "1.1.4", + "@rolldown/binding-linux-x64-gnu": "1.1.4", + "@rolldown/binding-linux-x64-musl": "1.1.4", + "@rolldown/binding-openharmony-arm64": "1.1.4", + "@rolldown/binding-wasm32-wasi": "1.1.4", + "@rolldown/binding-win32-arm64-msvc": "1.1.4", + "@rolldown/binding-win32-x64-msvc": "1.1.4" + } + }, + "node_modules/rollup": { + "version": "4.68.8", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.68.8.tgz", + "integrity": "sha512-IHx4DeeTGhoAPke6p1Wlg0JEQFyQoZQQjEe1iD+nhEERk7eoeHK9zyOpVJiGc54Z1MCgI96rN1tD7Ttub8XyPA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.10" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.68.8", + "@rollup/rollup-android-arm64": "4.68.8", + "@rollup/rollup-android-x64": "4.68.8", + "@rollup/rollup-darwin-arm64": "4.68.8", + "@rollup/rollup-darwin-x64": "4.68.8", + "@rollup/rollup-freebsd-arm64": "4.68.8", + "@rollup/rollup-freebsd-x64": "4.68.8", + "@rollup/rollup-linux-arm-gnueabihf": "4.68.8", + "@rollup/rollup-linux-arm-musleabihf": "4.68.8", + "@rollup/rollup-linux-arm64-gnu": "4.68.8", + "@rollup/rollup-linux-arm64-musl": "4.68.8", + "@rollup/rollup-linux-loong64-gnu": "4.68.8", + "@rollup/rollup-linux-loong64-musl": "4.68.8", + "@rollup/rollup-linux-ppc64-gnu": "4.68.8", + "@rollup/rollup-linux-ppc64-musl": "4.68.8", + "@rollup/rollup-linux-riscv64-gnu": "4.68.8", + "@rollup/rollup-linux-riscv64-musl": "4.68.8", + "@rollup/rollup-linux-s390x-gnu": "4.68.8", + "@rollup/rollup-linux-x64-gnu": "4.68.8", + "@rollup/rollup-linux-x64-musl": "4.68.8", + "@rollup/rollup-openbsd-x64": "4.68.8", + "@rollup/rollup-openharmony-arm64": "4.68.8", + "@rollup/rollup-win32-arm64-msvc": "4.68.8", + "@rollup/rollup-win32-ia32-msvc": "4.68.8", + "@rollup/rollup-win32-x64-gnu": "4.68.8", + "@rollup/rollup-win32-x64-msvc": "4.68.8", + "fsevents": "~2.3.2" + } + }, + "node_modules/search-insights": { + "version": "2.17.3", + "resolved": "https://registry.npmjs.org/search-insights/-/search-insights-2.17.3.tgz", + "integrity": "sha512-RQPdCYTa8A68uM2jwxoY842xDhvx3E5LFL1LxvxCNMev4o5mLuokczhzjAgGwUZBAmOKZknArSxLKmXtIi2AxQ==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shell-quote": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.12.0.tgz", + "integrity": "sha512-PcByqNyT/38F2kDNi006HAMRJaULuBzq/FOsw3qdZvX/GA9W/jamDaRskgHjubHiftXK5sIFxLNkvrXUwcof6Q==", + "dev": true, + "license": "MIT", "engines": { - "node": ">= 12.0.0" + "node": ">= 0.4" }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/lightningcss-darwin-x64": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz", - "integrity": "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==", - "cpu": [ - "x64" - ], + "node_modules/shiki": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-2.5.0.tgz", + "integrity": "sha512-mI//trrsaiCIPsja5CNfsyNOqgAZUb6VpJA+340toL42UpzQlXpwRV9nch69X6gaUxrr9kaOOa6e3y3uAkGFxQ==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "license": "MIT", + "dependencies": { + "@shikijs/core": "2.5.0", + "@shikijs/engine-javascript": "2.5.0", + "@shikijs/engine-oniguruma": "2.5.0", + "@shikijs/langs": "2.5.0", + "@shikijs/themes": "2.5.0", + "@shikijs/types": "2.5.0", + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" } }, - "node_modules/lightningcss-freebsd-x64": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz", - "integrity": "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==", - "cpu": [ - "x64" - ], + "node_modules/shiki/node_modules/@shikijs/engine-oniguruma": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/engine-oniguruma/-/engine-oniguruma-2.5.0.tgz", + "integrity": "sha512-pGd1wRATzbo/uatrCIILlAdFVKdxImWJGQ5rFiB5VZi2ve5xj3Ax9jny8QvkaV93btQEwR/rSz5ERFpC5mKNIw==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "license": "MIT", + "dependencies": { + "@shikijs/types": "2.5.0", + "@shikijs/vscode-textmate": "^10.0.2" } }, - "node_modules/lightningcss-linux-arm-gnueabihf": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz", - "integrity": "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==", - "cpu": [ - "arm" - ], + "node_modules/shiki/node_modules/@shikijs/langs": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/langs/-/langs-2.5.0.tgz", + "integrity": "sha512-Qfrrt5OsNH5R+5tJ/3uYBBZv3SuGmnRPejV9IlIbFH3HTGLDlkqgHymAlzklVmKBjAaVmkPkyikAV/sQ1wSL+w==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], + "license": "MIT", + "dependencies": { + "@shikijs/types": "2.5.0" + } + }, + "node_modules/shiki/node_modules/@shikijs/themes": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/themes/-/themes-2.5.0.tgz", + "integrity": "sha512-wGrk+R8tJnO0VMzmUExHR+QdSaPUl/NKs+a4cQQRWyoc3YFbUzuLEi/KWK1hj+8BfHRKm2jNhhJck1dfstJpiw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/types": "2.5.0" + } + }, + "node_modules/shiki/node_modules/@shikijs/types": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-2.5.0.tgz", + "integrity": "sha512-ygl5yhxki9ZLNuNpPitBWvcy9fsSKKaRuO4BAlMyagszQidxcpLAr0qiW/q43DtSIDxO6hEbtYLiFZNXO/hdGw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" + } + }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true, + "license": "MIT" + }, + "node_modules/source-map-js": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", + "dev": true, + "license": "BSD-3-Clause", "engines": { - "node": ">= 12.0.0" - }, + "node": ">=6.0.0" + } + }, + "node_modules/space-separated-tokens": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz", + "integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==", + "dev": true, + "license": "MIT", "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "type": "github", + "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/lightningcss-linux-arm64-gnu": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz", - "integrity": "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==", - "cpu": [ - "arm64" - ], + "node_modules/speakingurl": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/speakingurl/-/speakingurl-14.0.1.tgz", + "integrity": "sha512-1POYv7uv2gXoyGFpBCmpDVSNV74IfsWlDW216UPjbWufNf+bSU6GdbDsxdcxtfwb4xlI3yxzOTKClUosxARYrQ==", "dev": true, - "libc": [ - "glibc" - ], - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], + "license": "BSD-3-Clause", "engines": { - "node": ">= 12.0.0" + "node": ">=0.10.0" + } + }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, + "node_modules/stringify-entities": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.5.tgz", + "integrity": "sha512-jNuI2fNNw5ecxrWmgm90R3iH0Kc/94AQwoQWoSUYphWzvmUA2pjFG34H56Z7Z3FkvH3FpYwwewKAa97oQnPFhw==", + "dev": true, + "license": "MIT", + "dependencies": { + "character-entities-html4": "^2.0.0", + "character-entities-legacy": "^3.0.0" }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "type": "github", + "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/lightningcss-linux-arm64-musl": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz", - "integrity": "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==", - "cpu": [ - "arm64" - ], + "node_modules/superjson": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/superjson/-/superjson-2.2.7.tgz", + "integrity": "sha512-QK/H+tosbovdRvIuGqcWn8g3IxPZY7B8ZPowCAmWsV8bPvCk+bGMlZt90C4AxZjnzMO2WBRDacr1+0i1AOy/5g==", "dev": true, - "libc": [ - "musl" - ], - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 12.0.0" + "license": "MIT", + "dependencies": { + "copy-anything": "^4" }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "engines": { + "node": ">=16" } }, - "node_modules/lightningcss-linux-x64-gnu": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz", - "integrity": "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==", - "cpu": [ - "x64" - ], + "node_modules/tabbable": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.5.2.tgz", + "integrity": "sha512-XgdnB1nGU6KU4VgMnZPaZCx7M1hBrLyEiZYau2G2gq9UT0d7d4FUBlNX7vvPlm/B1vk1PjrzJBx9Lbv4fsqS9g==", "dev": true, - "libc": [ - "glibc" - ], - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], + "license": "MIT" + }, + "node_modules/tinybench": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.2.tgz", + "integrity": "sha512-nIZ2N2dFpjBsg2hgitKu7mA+FvsIJuGJOwysRngmVRRmWgR/UyPjwJj8c/fT/dhm8EkHnF5EOogRf+0Z2qrimA==", + "dev": true, + "license": "MIT", "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "node": ">=20.0.0" } }, - "node_modules/lightningcss-linux-x64-musl": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz", - "integrity": "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==", - "cpu": [ - "x64" - ], + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", "dev": true, - "libc": [ - "musl" - ], - "license": "MPL-2.0", - "optional": true, - "os": [ - "linux" - ], + "license": "MIT", "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "node": ">=18" } }, - "node_modules/lightningcss-win32-arm64-msvc": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz", - "integrity": "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==", - "cpu": [ - "arm64" - ], + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "win32" - ], + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, "engines": { - "node": ">= 12.0.0" + "node": ">=12.0.0" }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "url": "https://github.com/sponsors/SuperchupuDev" } }, - "node_modules/lightningcss-win32-x64-msvc": { - "version": "1.32.0", - "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz", - "integrity": "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==", - "cpu": [ - "x64" - ], + "node_modules/trim-lines": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", + "integrity": "sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==", "dev": true, - "license": "MPL-2.0", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 12.0.0" - }, + "license": "MIT", "funding": { - "type": "opencollective", - "url": "https://opencollective.com/parcel" + "type": "github", + "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/linkify-it": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "dev": true, - "dependencies": { - "uc.micro": "^2.0.0" - } + "license": "0BSD", + "optional": true }, - "node_modules/local-pkg": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-1.1.2.tgz", - "integrity": "sha512-arhlxbFRmoQHl33a0Zkle/YWlmNwoyt6QNZEIJcqNbdrsix5Lvc4HyyI3EnwxTYlZYc32EbYrQ8SzEZ7dqgg9A==", + "node_modules/typedoc": { + "version": "0.28.19", + "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.28.19.tgz", + "integrity": "sha512-wKh+lhdmMFivMlc6vRRcMGXeGEHGU2g8a2CkPTJjJlwRf1iXbimWIPcFolCqe4E0d/FRtGszpIrsp3WLpDB8Pw==", "dev": true, - "license": "MIT", + "license": "Apache-2.0", "dependencies": { - "mlly": "^1.7.4", - "pkg-types": "^2.3.0", - "quansync": "^0.2.11" + "@gerrit0/mini-shiki": "^3.23.0", + "lunr": "^2.3.9", + "markdown-it": "^14.1.1", + "minimatch": "^10.2.5", + "yaml": "^2.8.3" + }, + "bin": { + "typedoc": "bin/typedoc" }, "engines": { - "node": ">=14" + "node": ">= 18", + "pnpm": ">= 10" }, - "funding": { - "url": "https://github.com/sponsors/antfu" + "peerDependencies": { + "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x || 6.0.x" } }, - "node_modules/lunr": { - "version": "2.3.9", - "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", - "integrity": "sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==", - "dev": true - }, - "node_modules/magic-string": { - "version": "0.30.21", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", - "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "node_modules/typedoc-plugin-markdown": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/typedoc-plugin-markdown/-/typedoc-plugin-markdown-4.14.1.tgz", + "integrity": "sha512-24XX0oqyBsjBIBNoSH4wbgQkouci/CmgmO1ZBSaVkrcflqXFL2PQ5zFOpkz+Ewow5xQ3q2You+wrcmilNepRKg==", "dev": true, "license": "MIT", - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.5.5" + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "typedoc": "0.28.x" } }, - "node_modules/math-intrinsics": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", - "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "node_modules/typedoc-vitepress-theme": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/typedoc-vitepress-theme/-/typedoc-vitepress-theme-1.1.4.tgz", + "integrity": "sha512-RDFWSuFUYgHv8UYZnHRaTaep53+Tl/4dsl5EN+6laSdTFKp920KHdDNovHD1OKGqnJr47kXNwOM7LFj3IWMrtw==", "dev": true, "license": "MIT", "engines": { - "node": ">= 0.4" + "node": ">= 18" + }, + "peerDependencies": { + "typedoc": "0.28.x", + "typedoc-plugin-markdown": ">=4.11.0" } }, - "node_modules/mdurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", - "dev": true - }, - "node_modules/mlly": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.8.2.tgz", - "integrity": "sha512-d+ObxMQFmbt10sretNDytwt85VrbkhhUA/JBGm1MPaWJ65Cl4wOgLaB1NYvJSZ0Ef03MMEU/0xpPMXUIQ29UfA==", + "node_modules/typedoc/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true, "license": "MIT", - "dependencies": { - "acorn": "^8.16.0", - "pathe": "^2.0.3", - "pkg-types": "^1.3.1", - "ufo": "^1.6.3" + "engines": { + "node": "18 || 20 || >=22" } }, - "node_modules/mlly/node_modules/confbox": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.8.tgz", - "integrity": "sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w==", - "dev": true, - "license": "MIT" - }, - "node_modules/mlly/node_modules/pkg-types": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.3.1.tgz", - "integrity": "sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ==", + "node_modules/typedoc/node_modules/brace-expansion": { + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", + "integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==", "dev": true, "license": "MIT", "dependencies": { - "confbox": "^0.1.8", - "mlly": "^1.7.4", - "pathe": "^2.0.1" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, - "node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, - "license": "MIT" - }, - "node_modules/nanoid": { - "version": "3.3.15", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.15.tgz", - "integrity": "sha512-y7Wygv/7mEOvxTuEQDB8StXdMRBWf1kR/tlhAzBRUFkB2jfcLOAxO/SHmOO2zgz1pVgK29/kyupn059/bCHdjA==", + "node_modules/typedoc/node_modules/markdown-it": { + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz", + "integrity": "sha512-BuU2qnTti9YKgK5N+IeMubp14ZUKUUw7yeJbkjtosvHiP0AZ5c8IAgEMk79D0eC8F23r4Ac/q8cAIFdm2FtyoA==", "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], "license": "MIT", - "bin": { - "nanoid": "bin/nanoid.cjs" + "dependencies": { + "argparse": "^2.0.1", + "entities": "^4.4.0", + "linkify-it": "^5.0.0", + "mdurl": "^2.0.0", + "punycode.js": "^2.3.1", + "uc.micro": "^2.1.0" }, - "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + "bin": { + "markdown-it": "bin/markdown-it.mjs" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "node_modules/typedoc/node_modules/minimatch": { + "version": "10.2.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.5.tgz", + "integrity": "sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==", "dev": true, - "license": "MIT", + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.5" + }, "engines": { - "node": ">=0.10.0" + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/obug": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", - "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", - "dev": true, - "funding": [ - "https://github.com/sponsors/sxzz", - "https://opencollective.com/debug" - ], - "license": "MIT", + "node_modules/typescript": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, "engines": { - "node": ">=12.20.0" + "node": ">=14.17" } }, - "node_modules/package-manager-detector": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/package-manager-detector/-/package-manager-detector-1.9.0.tgz", - "integrity": "sha512-zAMfbta9nPA8AKkA4WdmNAT8R8s6Dk0/xwPsqNnRidMFcLo1YkLuPDTgs2f64XdzS8vbLNnoJ+uUIkgbz7oRHA==", + "node_modules/uc.micro": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", + "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", + "dev": true + }, + "node_modules/ufo": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.4.tgz", + "integrity": "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==", "dev": true, "license": "MIT" }, - "node_modules/path-browserify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", - "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "node_modules/undici-types": { + "version": "7.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.21.0.tgz", + "integrity": "sha512-w9IMgQrz4O0YN1LtB7K5P63vhlIOvC7opSmouCJ+ZywlPAlO9gIkJ+otk6LvGpAs2wg4econaCz3TvQ9xPoyuQ==", "dev": true, "license": "MIT" }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "node_modules/unist-util-is": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", + "integrity": "sha512-LsiILbtBETkDz8I9p1dQ0uyRUWuaQzd/cuEeS1hoRSyW5E5XGmTzlwY1OrNzzakGowI9Dr/I8HVaw4hTtnxy8g==", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } }, - "node_modules/pathe": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", - "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "node_modules/unist-util-position": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/unist-util-position/-/unist-util-position-5.0.0.tgz", + "integrity": "sha512-fucsC7HjXvkB5R3kTCO7kUjRdrS0BJt3M/FPxmHMBOm8JQi2BsHAHFsy27E0EolP8rp0NzXsJ+jNPyDWvOJZPA==", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } }, - "node_modules/picocolors": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", - "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "node_modules/unist-util-stringify-position": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", + "integrity": "sha512-0ASV06AAoKCDkS2+xw5RXJywruurpbC4JZSm7nr7MOt1ojAzvyyaO+UxZf18j8FCF6kmzCZKcAgN/yu2gm2XgQ==", "dev": true, - "license": "ISC" + "license": "MIT", + "dependencies": { + "@types/unist": "^3.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } }, - "node_modules/picomatch": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", - "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "node_modules/unist-util-visit": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.2.0.tgz", + "integrity": "sha512-fpsYs/VVoZxfGY9/j3FQpZmN8wdLJaV1Pt38AaJNZu9uKIHcFU3halCdBveEq1HGKO1OEfJY65w1zvoFV1b3qQ==", "dev": true, "license": "MIT", - "engines": { - "node": ">=12" + "dependencies": { + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0", + "unist-util-visit-parents": "^6.1.0" }, "funding": { - "url": "https://github.com/sponsors/jonschlinkert" + "type": "opencollective", + "url": "https://opencollective.com/unified" } }, - "node_modules/pkg-types": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-2.3.1.tgz", - "integrity": "sha512-y+ichcgc2LrADuhLNAx8DFjVfgz91pRxfZdI3UDhxHvcVEZsenLO+7XaU5vOp0u/7V/wZ+plyuQxtrDlZJ+yeg==", + "node_modules/unist-util-visit-parents": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.1.0.tgz", + "integrity": "sha512-vKXxz6O38sKDj1mtx/k2cWvkkFBuYGx6uGrlzBkVeWCRF/F8sdI0j3Wbkz/5rVNRRuVc8UrgRdbCxNhmYXgP3w==", "dev": true, "license": "MIT", "dependencies": { - "confbox": "^0.2.4", - "exsolve": "^1.0.8", - "pathe": "^2.0.3" + "@types/unist": "^3.0.0", + "unist-util-is": "^6.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" } }, - "node_modules/postcss": { - "version": "8.5.16", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.16.tgz", - "integrity": "sha512-vuwillviilfKZsg0VGj5R/YwwcHx4SLsIOI/7K6mQkWx+l5cUHTjj5g0AasTBcyXsbfTgrwsUNmVUb5xVwyPwg==", + "node_modules/unplugin": { + "version": "2.3.11", + "resolved": "https://registry.npmjs.org/unplugin/-/unplugin-2.3.11.tgz", + "integrity": "sha512-5uKD0nqiYVzlmCRs01Fhs2BdkEgBS3SAVP6ndrBsuK42iC2+JHyxM05Rm9G8+5mkmRtzMZGY8Ct5+mliZxU/Ww==", "dev": true, - "funding": [ - { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/funding/github/npm/postcss" - }, - { - "type": "github", - "url": "https://github.com/sponsors/ai" - } - ], "license": "MIT", "dependencies": { - "nanoid": "^3.3.12", - "picocolors": "^1.1.1", - "source-map-js": "^1.2.1" + "@jridgewell/remapping": "^2.3.5", + "acorn": "^8.15.0", + "picomatch": "^4.0.3", + "webpack-virtual-modules": "^0.6.2" }, "engines": { - "node": "^10 || ^12 || >=14" + "node": ">=18.12.0" } }, - "node_modules/promise": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", - "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", + "node_modules/unplugin-dts": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unplugin-dts/-/unplugin-dts-1.0.0.tgz", + "integrity": "sha512-qz+U1lCscwq+t8Mkaxy5Esa7IQ5wWV18b4mnioOXSdnPaNiJ0+qgE3I+KL6UkXYZWxxGo2qdGone8LEQ52Sfkw==", "dev": true, "license": "MIT", "dependencies": { - "asap": "~2.0.3" + "@rollup/pluginutils": "^5.1.4", + "@volar/typescript": "^2.4.26", + "compare-versions": "^6.1.1", + "debug": "^4.4.0", + "kolorist": "^1.8.0", + "local-pkg": "^1.1.1", + "magic-string": "^0.30.17", + "unplugin": "^2.3.2" + }, + "peerDependencies": { + "@microsoft/api-extractor": ">=7", + "@rspack/core": "^1", + "@vue/language-core": "~3.1.5", + "esbuild": "*", + "rolldown": "*", + "rollup": ">=3", + "typescript": ">=4", + "vite": ">=3", + "webpack": "^4 || ^5" + }, + "peerDependenciesMeta": { + "@microsoft/api-extractor": { + "optional": true + }, + "@rspack/core": { + "optional": true + }, + "@vue/language-core": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "rolldown": { + "optional": true + }, + "rollup": { + "optional": true + }, + "vite": { + "optional": true + }, + "webpack": { + "optional": true + } } }, - "node_modules/pug": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/pug/-/pug-3.0.4.tgz", - "integrity": "sha512-kFfq5mMzrS7+wrl5pLJzZEzemx34OQ0w4SARfhy/3yxTlhbstsudDwJzhf1hP02yHzbjoVMSXUj/Sz6RNfMyXg==", + "node_modules/vfile": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", + "integrity": "sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==", "dev": true, "license": "MIT", "dependencies": { - "pug-code-gen": "^3.0.4", - "pug-filters": "^4.0.0", - "pug-lexer": "^5.0.1", - "pug-linker": "^4.0.0", - "pug-load": "^3.0.0", - "pug-parser": "^6.0.0", - "pug-runtime": "^3.0.1", - "pug-strip-comments": "^2.0.0" + "@types/unist": "^3.0.0", + "vfile-message": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" } }, - "node_modules/pug-attrs": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pug-attrs/-/pug-attrs-3.0.0.tgz", - "integrity": "sha512-azINV9dUtzPMFQktvTXciNAfAuVh/L/JCl0vtPCwvOA21uZrC08K/UnmrL+SXGEVc1FwzjW62+xw5S/uaLj6cA==", + "node_modules/vfile-message": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-4.0.4.tgz", + "integrity": "sha512-66ycRswIkNmHH9PHku7ADtv5RVwgIrOcuv3J8Svz6h4qgGRrKVa+9/neuKyJZUXyOpYwLTvS+whZ4R2urHHgQg==", "dev": true, "license": "MIT", "dependencies": { - "constantinople": "^4.0.1", - "js-stringify": "^1.0.2", - "pug-runtime": "^3.0.0" + "@types/unist": "^3.0.0", + "unist-util-stringify-position": "^4.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" } }, - "node_modules/pug-code-gen": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/pug-code-gen/-/pug-code-gen-3.0.4.tgz", - "integrity": "sha512-6okWYIKdasTyXICyEtvobmTZAVX57JkzgzIi4iRJlin8kmhG+Xry2dsus+Mun/nGCn6F2U49haHI5mkELXB14g==", + "node_modules/vite": { + "version": "8.1.3", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.1.3.tgz", + "integrity": "sha512-Ds+gBRbj0lwRO2Y5hwnUBdxSwlAve9LeRyU4sNnAr0ewW0gWF0n5bgXgUzbgZ49MV9BVUAQUFYVcDUcilUExMA==", "dev": true, "license": "MIT", "dependencies": { - "constantinople": "^4.0.1", - "doctypes": "^1.1.0", - "js-stringify": "^1.0.2", - "pug-attrs": "^3.0.0", - "pug-error": "^2.1.0", - "pug-runtime": "^3.0.1", - "void-elements": "^3.1.0", - "with": "^7.0.0" + "lightningcss": "^1.32.0", + "picomatch": "^4.0.4", + "postcss": "^8.5.16", + "rolldown": "~1.1.3", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.3.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } } }, - "node_modules/pug-error": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/pug-error/-/pug-error-2.1.0.tgz", - "integrity": "sha512-lv7sU9e5Jk8IeUheHata6/UThZ7RK2jnaaNztxfPYUY+VxZyk/ePVaNZ/vwmH8WqGvDz3LrNYt/+gA55NDg6Pg==", - "dev": true, - "license": "MIT" - }, - "node_modules/pug-filters": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/pug-filters/-/pug-filters-4.0.0.tgz", - "integrity": "sha512-yeNFtq5Yxmfz0f9z2rMXGw/8/4i1cCFecw/Q7+D0V2DdtII5UvqE12VaZ2AY7ri6o5RNXiweGH79OCq+2RQU4A==", + "node_modules/vite-plugin-dts": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/vite-plugin-dts/-/vite-plugin-dts-5.0.0.tgz", + "integrity": "sha512-VLNAUttBq7pLxxL/m/ztjd5zj5yiviiC7ijfPFVLK5c45FLcibvieBsdjSka3a4ag1qdrAF9K3OysH4/lW+rPQ==", "dev": true, "license": "MIT", "dependencies": { - "constantinople": "^4.0.1", - "jstransformer": "1.0.0", - "pug-error": "^2.0.0", - "pug-walk": "^2.0.0", - "resolve": "^1.15.1" + "unplugin-dts": "1.0.0" + }, + "peerDependencies": { + "@microsoft/api-extractor": ">=7", + "rollup": ">=3", + "vite": ">=3" + }, + "peerDependenciesMeta": { + "@microsoft/api-extractor": { + "optional": true + }, + "rollup": { + "optional": true + }, + "vite": { + "optional": true + } } }, - "node_modules/pug-lexer": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/pug-lexer/-/pug-lexer-5.0.1.tgz", - "integrity": "sha512-0I6C62+keXlZPZkOJeVam9aBLVP2EnbeDw3An+k0/QlqdwH6rv8284nko14Na7c0TtqtogfWXcRoFE4O4Ff20w==", + "node_modules/vitepress": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/vitepress/-/vitepress-1.6.4.tgz", + "integrity": "sha512-+2ym1/+0VVrbhNyRoFFesVvBvHAVMZMK0rw60E3X/5349M1GuVdKeazuksqopEdvkKwKGs21Q729jX81/bkBJg==", "dev": true, "license": "MIT", "dependencies": { - "character-parser": "^2.2.0", - "is-expression": "^4.0.0", - "pug-error": "^2.0.0" + "@docsearch/css": "3.8.2", + "@docsearch/js": "3.8.2", + "@iconify-json/simple-icons": "^1.2.21", + "@shikijs/core": "^2.1.0", + "@shikijs/transformers": "^2.1.0", + "@shikijs/types": "^2.1.0", + "@types/markdown-it": "^14.1.2", + "@vitejs/plugin-vue": "^5.2.1", + "@vue/devtools-api": "^7.7.0", + "@vue/shared": "^3.5.13", + "@vueuse/core": "^12.4.0", + "@vueuse/integrations": "^12.4.0", + "focus-trap": "^7.6.4", + "mark.js": "8.11.1", + "minisearch": "^7.1.1", + "shiki": "^2.1.0", + "vite": "^5.4.14", + "vue": "^3.5.13" + }, + "bin": { + "vitepress": "bin/vitepress.js" + }, + "peerDependencies": { + "markdown-it-mathjax3": "^4", + "postcss": "^8" + }, + "peerDependenciesMeta": { + "markdown-it-mathjax3": { + "optional": true + }, + "postcss": { + "optional": true + } } }, - "node_modules/pug-linker": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/pug-linker/-/pug-linker-4.0.0.tgz", - "integrity": "sha512-gjD1yzp0yxbQqnzBAdlhbgoJL5qIFJw78juN1NpTLt/mfPJ5VgC4BvkoD3G23qKzJtIIXBbcCt6FioLSFLOHdw==", + "node_modules/vitepress/node_modules/@esbuild/aix-ppc64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", + "integrity": "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==", + "cpu": [ + "ppc64" + ], "dev": true, "license": "MIT", - "dependencies": { - "pug-error": "^2.0.0", - "pug-walk": "^2.0.0" + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=12" } }, - "node_modules/pug-load": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pug-load/-/pug-load-3.0.0.tgz", - "integrity": "sha512-OCjTEnhLWZBvS4zni/WUMjH2YSUosnsmjGBB1An7CsKQarYSWQ0GCVyd4eQPMFJqZ8w9xgs01QdiZXKVjk92EQ==", + "node_modules/vitepress/node_modules/@esbuild/android-arm": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.21.5.tgz", + "integrity": "sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==", + "cpu": [ + "arm" + ], "dev": true, "license": "MIT", - "dependencies": { - "object-assign": "^4.1.1", - "pug-walk": "^2.0.0" + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" } }, - "node_modules/pug-parser": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/pug-parser/-/pug-parser-6.0.0.tgz", - "integrity": "sha512-ukiYM/9cH6Cml+AOl5kETtM9NR3WulyVP2y4HOU45DyMim1IeP/OOiyEWRr6qk5I5klpsBnbuHpwKmTx6WURnw==", + "node_modules/vitepress/node_modules/@esbuild/android-arm64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.21.5.tgz", + "integrity": "sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "pug-error": "^2.0.0", - "token-stream": "1.0.0" + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" } }, - "node_modules/pug-runtime": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/pug-runtime/-/pug-runtime-3.0.1.tgz", - "integrity": "sha512-L50zbvrQ35TkpHwv0G6aLSuueDRwc/97XdY8kL3tOT0FmhgG7UypU3VztfV/LATAvmUfYi4wNxSajhSAeNN+Kg==", - "dev": true, - "license": "MIT" - }, - "node_modules/pug-strip-comments": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/pug-strip-comments/-/pug-strip-comments-2.0.0.tgz", - "integrity": "sha512-zo8DsDpH7eTkPHCXFeAk1xZXJbyoTfdPlNR0bK7rpOMuhBYb0f5qUVCO1xlsitYd3w5FQTK7zpNVKb3rZoUrrQ==", + "node_modules/vitepress/node_modules/@esbuild/android-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.21.5.tgz", + "integrity": "sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "pug-error": "^2.0.0" + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" } }, - "node_modules/pug-walk": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/pug-walk/-/pug-walk-2.0.0.tgz", - "integrity": "sha512-yYELe9Q5q9IQhuvqsZNwA5hfPkMJ8u92bQLIMcsMxf/VADjNtEYptU+inlufAFYcWdHlwNfZOEnOOQrZrcyJCQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/punycode.js": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", - "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "node_modules/vitepress/node_modules/@esbuild/darwin-arm64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz", + "integrity": "sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==", + "cpu": [ + "arm64" + ], "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], "engines": { - "node": ">=6" + "node": ">=12" } }, - "node_modules/quansync": { - "version": "0.2.11", - "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz", - "integrity": "sha512-AifT7QEbW9Nri4tAwR5M/uzpBuqfZf+zwaEM/QkzEjj7NBuFD2rBuy0K3dE+8wltbezDV7JMA0WfnCPYRSYbXA==", + "node_modules/vitepress/node_modules/@esbuild/darwin-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.21.5.tgz", + "integrity": "sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==", + "cpu": [ + "x64" + ], "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/antfu" - }, - { - "type": "individual", - "url": "https://github.com/sponsors/sxzz" - } + "license": "MIT", + "optional": true, + "os": [ + "darwin" ], - "license": "MIT" + "engines": { + "node": ">=12" + } }, - "node_modules/resolve": { - "version": "1.22.12", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz", - "integrity": "sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==", + "node_modules/vitepress/node_modules/@esbuild/freebsd-arm64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.5.tgz", + "integrity": "sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "is-core-module": "^2.16.1", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, + "optional": true, + "os": [ + "freebsd" + ], "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=12" } }, - "node_modules/rolldown": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.1.4.tgz", - "integrity": "sha512-IjZYiLxZwpnhwhdBH2ugdTGVSdhCQUmLxLoqyjiL0JxYjyRst+5a0P3xfrTxJ5F638j4Mvvw5FAX5XE6eHpXbA==", + "node_modules/vitepress/node_modules/@esbuild/freebsd-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.21.5.tgz", + "integrity": "sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "@oxc-project/types": "=0.138.0", - "@rolldown/pluginutils": "^1.0.0" - }, - "bin": { - "rolldown": "bin/cli.mjs" - }, + "optional": true, + "os": [ + "freebsd" + ], "engines": { - "node": "^20.19.0 || >=22.12.0" - }, - "optionalDependencies": { - "@rolldown/binding-android-arm64": "1.1.4", - "@rolldown/binding-darwin-arm64": "1.1.4", - "@rolldown/binding-darwin-x64": "1.1.4", - "@rolldown/binding-freebsd-x64": "1.1.4", - "@rolldown/binding-linux-arm-gnueabihf": "1.1.4", - "@rolldown/binding-linux-arm64-gnu": "1.1.4", - "@rolldown/binding-linux-arm64-musl": "1.1.4", - "@rolldown/binding-linux-ppc64-gnu": "1.1.4", - "@rolldown/binding-linux-s390x-gnu": "1.1.4", - "@rolldown/binding-linux-x64-gnu": "1.1.4", - "@rolldown/binding-linux-x64-musl": "1.1.4", - "@rolldown/binding-openharmony-arm64": "1.1.4", - "@rolldown/binding-wasm32-wasi": "1.1.4", - "@rolldown/binding-win32-arm64-msvc": "1.1.4", - "@rolldown/binding-win32-x64-msvc": "1.1.4" + "node": ">=12" } }, - "node_modules/semver": { - "version": "7.8.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", - "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "node_modules/vitepress/node_modules/@esbuild/linux-arm": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.21.5.tgz", + "integrity": "sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==", + "cpu": [ + "arm" + ], "dev": true, - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=10" + "node": ">=12" } }, - "node_modules/shell-quote": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.12.0.tgz", - "integrity": "sha512-PcByqNyT/38F2kDNi006HAMRJaULuBzq/FOsw3qdZvX/GA9W/jamDaRskgHjubHiftXK5sIFxLNkvrXUwcof6Q==", + "node_modules/vitepress/node_modules/@esbuild/linux-arm64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.21.5.tgz", + "integrity": "sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=12" } }, - "node_modules/sisteransi": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", - "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "node_modules/vitepress/node_modules/@esbuild/linux-ia32": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.21.5.tgz", + "integrity": "sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==", + "cpu": [ + "ia32" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } }, - "node_modules/source-map-js": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", - "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "node_modules/vitepress/node_modules/@esbuild/linux-loong64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.21.5.tgz", + "integrity": "sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==", + "cpu": [ + "loong64" + ], "dev": true, - "license": "BSD-3-Clause", + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=0.10.0" + "node": ">=12" } }, - "node_modules/std-env": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", - "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "node_modules/vitepress/node_modules/@esbuild/linux-mips64el": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.21.5.tgz", + "integrity": "sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==", + "cpu": [ + "mips64el" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "node_modules/vitepress/node_modules/@esbuild/linux-ppc64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.21.5.tgz", + "integrity": "sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==", + "cpu": [ + "ppc64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=12" } }, - "node_modules/tinybench": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.2.tgz", - "integrity": "sha512-nIZ2N2dFpjBsg2hgitKu7mA+FvsIJuGJOwysRngmVRRmWgR/UyPjwJj8c/fT/dhm8EkHnF5EOogRf+0Z2qrimA==", + "node_modules/vitepress/node_modules/@esbuild/linux-riscv64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.21.5.tgz", + "integrity": "sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==", + "cpu": [ + "riscv64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=20.0.0" + "node": ">=12" } }, - "node_modules/tinyexec": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", - "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "node_modules/vitepress/node_modules/@esbuild/linux-s390x": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.21.5.tgz", + "integrity": "sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==", + "cpu": [ + "s390x" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=18" + "node": ">=12" } }, - "node_modules/tinyglobby": { - "version": "0.2.17", - "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", - "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "node_modules/vitepress/node_modules/@esbuild/linux-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz", + "integrity": "sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "fdir": "^6.5.0", - "picomatch": "^4.0.4" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=12.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/SuperchupuDev" + "node": ">=12" } }, - "node_modules/token-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/token-stream/-/token-stream-1.0.0.tgz", - "integrity": "sha512-VSsyNPPW74RpHwR8Fc21uubwHY7wMDeJLys2IX5zJNih+OnAnaifKHo+1LHT7DAdloQ7apeaaWg8l7qnf/TnEg==", + "node_modules/vitepress/node_modules/@esbuild/netbsd-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz", + "integrity": "sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } }, - "node_modules/tslib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", - "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "node_modules/vitepress/node_modules/@esbuild/openbsd-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz", + "integrity": "sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==", + "cpu": [ + "x64" + ], "dev": true, - "license": "0BSD", - "optional": true + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } }, - "node_modules/typedoc": { - "version": "0.28.19", - "resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.28.19.tgz", - "integrity": "sha512-wKh+lhdmMFivMlc6vRRcMGXeGEHGU2g8a2CkPTJjJlwRf1iXbimWIPcFolCqe4E0d/FRtGszpIrsp3WLpDB8Pw==", + "node_modules/vitepress/node_modules/@esbuild/sunos-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz", + "integrity": "sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==", + "cpu": [ + "x64" + ], "dev": true, - "license": "Apache-2.0", - "dependencies": { - "@gerrit0/mini-shiki": "^3.23.0", - "lunr": "^2.3.9", - "markdown-it": "^14.1.1", - "minimatch": "^10.2.5", - "yaml": "^2.8.3" - }, - "bin": { - "typedoc": "bin/typedoc" - }, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], "engines": { - "node": ">= 18", - "pnpm": ">= 10" - }, - "peerDependencies": { - "typescript": "5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x || 5.8.x || 5.9.x || 6.0.x" + "node": ">=12" } }, - "node_modules/typedoc/node_modules/balanced-match": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", - "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "node_modules/vitepress/node_modules/@esbuild/win32-arm64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.21.5.tgz", + "integrity": "sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==", + "cpu": [ + "arm64" + ], "dev": true, "license": "MIT", + "optional": true, + "os": [ + "win32" + ], "engines": { - "node": "18 || 20 || >=22" + "node": ">=12" } }, - "node_modules/typedoc/node_modules/brace-expansion": { - "version": "5.0.6", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.6.tgz", - "integrity": "sha512-kLpxurY4Z4r9sgMsyG0Z9uzsBlgiU/EFKhj/h91/8yHu0edo7XuixOIH3VcJ8kkxs6/jPzoI6U9Vj3WqbMQ94g==", + "node_modules/vitepress/node_modules/@esbuild/win32-ia32": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.21.5.tgz", + "integrity": "sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==", + "cpu": [ + "ia32" + ], "dev": true, "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, + "optional": true, + "os": [ + "win32" + ], "engines": { - "node": "18 || 20 || >=22" + "node": ">=12" } }, - "node_modules/typedoc/node_modules/markdown-it": { - "version": "14.1.1", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz", - "integrity": "sha512-BuU2qnTti9YKgK5N+IeMubp14ZUKUUw7yeJbkjtosvHiP0AZ5c8IAgEMk79D0eC8F23r4Ac/q8cAIFdm2FtyoA==", + "node_modules/vitepress/node_modules/@esbuild/win32-x64": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz", + "integrity": "sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "argparse": "^2.0.1", - "entities": "^4.4.0", - "linkify-it": "^5.0.0", - "mdurl": "^2.0.0", - "punycode.js": "^2.3.1", - "uc.micro": "^2.1.0" - }, - "bin": { - "markdown-it": "bin/markdown-it.mjs" + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" } }, - "node_modules/typedoc/node_modules/minimatch": { - "version": "10.2.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.5.tgz", - "integrity": "sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==", + "node_modules/vitepress/node_modules/@shikijs/types": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@shikijs/types/-/types-2.5.0.tgz", + "integrity": "sha512-ygl5yhxki9ZLNuNpPitBWvcy9fsSKKaRuO4BAlMyagszQidxcpLAr0qiW/q43DtSIDxO6hEbtYLiFZNXO/hdGw==", "dev": true, - "license": "BlueOak-1.0.0", + "license": "MIT", "dependencies": { - "brace-expansion": "^5.0.5" - }, - "engines": { - "node": "18 || 20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/typescript": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", - "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" + "@shikijs/vscode-textmate": "^10.0.2", + "@types/hast": "^3.0.4" } }, - "node_modules/uc.micro": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", - "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", - "dev": true - }, - "node_modules/ufo": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.4.tgz", - "integrity": "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==", - "dev": true, - "license": "MIT" - }, - "node_modules/undici-types": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.21.0.tgz", - "integrity": "sha512-w9IMgQrz4O0YN1LtB7K5P63vhlIOvC7opSmouCJ+ZywlPAlO9gIkJ+otk6LvGpAs2wg4econaCz3TvQ9xPoyuQ==", - "dev": true, - "license": "MIT" - }, - "node_modules/unplugin": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/unplugin/-/unplugin-2.3.11.tgz", - "integrity": "sha512-5uKD0nqiYVzlmCRs01Fhs2BdkEgBS3SAVP6ndrBsuK42iC2+JHyxM05Rm9G8+5mkmRtzMZGY8Ct5+mliZxU/Ww==", + "node_modules/vitepress/node_modules/@vitejs/plugin-vue": { + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.4.tgz", + "integrity": "sha512-7Yx/SXSOcQq5HiiV3orevHUFn+pmMB4cgbEkDYgnkUWb0WfeQ/wa2yFv6D5ICiCQOVpjA7vYDXrC7AGO8yjDHA==", "dev": true, "license": "MIT", - "dependencies": { - "@jridgewell/remapping": "^2.3.5", - "acorn": "^8.15.0", - "picomatch": "^4.0.3", - "webpack-virtual-modules": "^0.6.2" - }, "engines": { - "node": ">=18.12.0" + "node": "^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "vite": "^5.0.0 || ^6.0.0", + "vue": "^3.2.25" } }, - "node_modules/unplugin-dts": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unplugin-dts/-/unplugin-dts-1.0.0.tgz", - "integrity": "sha512-qz+U1lCscwq+t8Mkaxy5Esa7IQ5wWV18b4mnioOXSdnPaNiJ0+qgE3I+KL6UkXYZWxxGo2qdGone8LEQ52Sfkw==", + "node_modules/vitepress/node_modules/esbuild": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", + "integrity": "sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==", "dev": true, + "hasInstallScript": true, "license": "MIT", - "dependencies": { - "@rollup/pluginutils": "^5.1.4", - "@volar/typescript": "^2.4.26", - "compare-versions": "^6.1.1", - "debug": "^4.4.0", - "kolorist": "^1.8.0", - "local-pkg": "^1.1.1", - "magic-string": "^0.30.17", - "unplugin": "^2.3.2" + "bin": { + "esbuild": "bin/esbuild" }, - "peerDependencies": { - "@microsoft/api-extractor": ">=7", - "@rspack/core": "^1", - "@vue/language-core": "~3.1.5", - "esbuild": "*", - "rolldown": "*", - "rollup": ">=3", - "typescript": ">=4", - "vite": ">=3", - "webpack": "^4 || ^5" + "engines": { + "node": ">=12" }, - "peerDependenciesMeta": { - "@microsoft/api-extractor": { - "optional": true - }, - "@rspack/core": { - "optional": true - }, - "@vue/language-core": { - "optional": true - }, - "esbuild": { - "optional": true - }, - "rolldown": { - "optional": true - }, - "rollup": { - "optional": true - }, - "vite": { - "optional": true - }, - "webpack": { - "optional": true - } - } - }, - "node_modules/vite": { - "version": "8.1.3", - "resolved": "https://registry.npmjs.org/vite/-/vite-8.1.3.tgz", - "integrity": "sha512-Ds+gBRbj0lwRO2Y5hwnUBdxSwlAve9LeRyU4sNnAr0ewW0gWF0n5bgXgUzbgZ49MV9BVUAQUFYVcDUcilUExMA==", + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.21.5", + "@esbuild/android-arm": "0.21.5", + "@esbuild/android-arm64": "0.21.5", + "@esbuild/android-x64": "0.21.5", + "@esbuild/darwin-arm64": "0.21.5", + "@esbuild/darwin-x64": "0.21.5", + "@esbuild/freebsd-arm64": "0.21.5", + "@esbuild/freebsd-x64": "0.21.5", + "@esbuild/linux-arm": "0.21.5", + "@esbuild/linux-arm64": "0.21.5", + "@esbuild/linux-ia32": "0.21.5", + "@esbuild/linux-loong64": "0.21.5", + "@esbuild/linux-mips64el": "0.21.5", + "@esbuild/linux-ppc64": "0.21.5", + "@esbuild/linux-riscv64": "0.21.5", + "@esbuild/linux-s390x": "0.21.5", + "@esbuild/linux-x64": "0.21.5", + "@esbuild/netbsd-x64": "0.21.5", + "@esbuild/openbsd-x64": "0.21.5", + "@esbuild/sunos-x64": "0.21.5", + "@esbuild/win32-arm64": "0.21.5", + "@esbuild/win32-ia32": "0.21.5", + "@esbuild/win32-x64": "0.21.5" + } + }, + "node_modules/vitepress/node_modules/vite": { + "version": "5.4.21", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.21.tgz", + "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", "dependencies": { - "lightningcss": "^1.32.0", - "picomatch": "^4.0.4", - "postcss": "^8.5.16", - "rolldown": "~1.1.3", - "tinyglobby": "^0.2.17" + "esbuild": "^0.21.3", + "postcss": "^8.4.43", + "rollup": "^4.20.0" }, "bin": { "vite": "bin/vite.js" }, "engines": { - "node": "^20.19.0 || >=22.12.0" + "node": "^18.0.0 || >=20.0.0" }, "funding": { "url": "https://github.com/vitejs/vite?sponsor=1" @@ -2737,33 +5060,23 @@ "fsevents": "~2.3.3" }, "peerDependencies": { - "@types/node": "^20.19.0 || >=22.12.0", - "@vitejs/devtools": "^0.3.0", - "esbuild": "^0.27.0 || ^0.28.0", - "jiti": ">=1.21.0", - "less": "^4.0.0", - "sass": "^1.70.0", - "sass-embedded": "^1.70.0", - "stylus": ">=0.54.8", - "sugarss": "^5.0.0", - "terser": "^5.16.0", - "tsx": "^4.8.1", - "yaml": "^2.4.2" + "@types/node": "^18.0.0 || >=20.0.0", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "sass-embedded": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.4.0" }, "peerDependenciesMeta": { "@types/node": { "optional": true }, - "@vitejs/devtools": { - "optional": true - }, - "esbuild": { - "optional": true - }, - "jiti": { + "less": { "optional": true }, - "less": { + "lightningcss": { "optional": true }, "sass": { @@ -2780,38 +5093,6 @@ }, "terser": { "optional": true - }, - "tsx": { - "optional": true - }, - "yaml": { - "optional": true - } - } - }, - "node_modules/vite-plugin-dts": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/vite-plugin-dts/-/vite-plugin-dts-5.0.0.tgz", - "integrity": "sha512-VLNAUttBq7pLxxL/m/ztjd5zj5yiviiC7ijfPFVLK5c45FLcibvieBsdjSka3a4ag1qdrAF9K3OysH4/lW+rPQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "unplugin-dts": "1.0.0" - }, - "peerDependencies": { - "@microsoft/api-extractor": ">=7", - "rollup": ">=3", - "vite": ">=3" - }, - "peerDependenciesMeta": { - "@microsoft/api-extractor": { - "optional": true - }, - "rollup": { - "optional": true - }, - "vite": { - "optional": true } } }, @@ -2908,16 +5189,6 @@ "@jridgewell/sourcemap-codec": "^1.6.0" } }, - "node_modules/void-elements": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz", - "integrity": "sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/vscode-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.1.0.tgz", @@ -2925,6 +5196,28 @@ "dev": true, "license": "MIT" }, + "node_modules/vue": { + "version": "3.5.46", + "resolved": "https://registry.npmjs.org/vue/-/vue-3.5.46.tgz", + "integrity": "sha512-0kW5CgfjMPBqmH158049SaE1muufp+K/ZyrwvSEwrwYky6QB7zL2y8kXfruneKb9O12eh0xAJL6CVSpzb9o0Kg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vue/compiler-dom": "3.5.46", + "@vue/compiler-sfc": "3.5.46", + "@vue/runtime-dom": "3.5.46", + "@vue/server-renderer": "3.5.46", + "@vue/shared": "3.5.46" + }, + "peerDependencies": { + "typescript": "*" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/webpack-virtual-modules": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/webpack-virtual-modules/-/webpack-virtual-modules-0.6.2.tgz", @@ -2945,22 +5238,6 @@ "node": ">=20.11" } }, - "node_modules/with": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/with/-/with-7.0.2.tgz", - "integrity": "sha512-RNGKj82nUPg3g5ygxkQl0R937xLyho1J24ItRCBTr/m1YnZkzJy1hUiHUJrc/VlsDQzsCnInEGSg3bci0Lmd4w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@babel/parser": "^7.9.6", - "@babel/types": "^7.9.6", - "assert-never": "^1.2.1", - "babel-walk": "3.0.0-canary-5" - }, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/yaml": { "version": "2.9.1", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", @@ -2976,6 +5253,17 @@ "funding": { "url": "https://github.com/sponsors/eemeli" } + }, + "node_modules/zwitch": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", + "integrity": "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==", + "dev": true, + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } } } } diff --git a/package.json b/package.json index 40ea3af..d72de4f 100644 --- a/package.json +++ b/package.json @@ -50,11 +50,11 @@ ], "scripts": { "build": "rm -rf dist && vite build", - "build:site": "npm run document && vite build --config vite.site.config.ts && cp -r documentation dist-site/docs", - "dev": "vite --config vite.site.config.ts", - "preview": "vite preview --config vite.site.config.ts", + "docs:api": "typedoc --options docs/typedoc.json", + "docs:dev": "npm run docs:api && vitepress dev docs --port 5274 --strictPort", + "docs:build": "npm run docs:api && vitepress build docs", + "docs:preview": "vitepress preview docs", "prepare": "husky install; npm run build", - "document": "npx typedoc src/index.ts", "test": "vitest run", "check": "tsc --noEmit -p tsconfig.json && npm test && npm run build", "changeset": "changeset", @@ -64,15 +64,16 @@ "devDependencies": { "@changesets/changelog-github": "^1.0.1", "@changesets/cli": "^3.0.3", - "@types/markdown-it": "~14.1.1", "@types/node": "^25.7.0", - "@types/pug": "^2.0.10", "husky": "^9.0.11", - "pug": "^3.0.4", "typedoc": "^0.28.19", + "typedoc-plugin-markdown": "^4.14.1", + "typedoc-vitepress-theme": "^1.1.4", "vite": "^8.0.13", "vite-plugin-dts": "^5.0.0", - "vitest": "^5.0.4" + "vitepress": "1.6.4", + "vitest": "^5.0.4", + "vue": "^3.5.46" }, "dependencies": { "typescript": "^6.0.3" diff --git a/src/Color.ts b/src/Color.ts index 6379122..5d8e3b5 100644 --- a/src/Color.ts +++ b/src/Color.ts @@ -1,5 +1,31 @@ +/** + * An RGBA colour in 0–1 space, with conversions to and from hex, HSL, HSV, + * OKLab and OKLCH. Imported separately from the rest of wtc-math: + * + * ```ts + * import { Color } from 'wtc-math/color' + * ``` + * + * @module wtc-math/color + */ + +/** + * Anything {@link Color.interpolate} can turn into a {@link Color}: an object + * with 0–1 `r`, `g`, `b` and optional `a`, an `[r, g, b, a?]` array in 0–1, + * or a hex string (`"#rgb"` or `"#rrggbb"`, `#` optional). Alpha defaults + * to 1. + */ export type ColorLike = - | { r: number; g: number; b: number; a?: number } + | { + /** Red, 0–1. */ + r: number; + /** Green, 0–1. */ + g: number; + /** Blue, 0–1. */ + b: number; + /** Alpha, 0–1. Defaults to 1. */ + a?: number; + } | [number, number, number, number?] | string; @@ -43,12 +69,35 @@ function oklabToColor(L: number, a: number, b: number, alpha: number): Color { ); } +/** + * An RGBA colour with each channel in 0–1. Channels are gamma-encoded sRGB, + * as used by CSS. + * + * Methods without the `New` suffix modify the colour and return it; the + * `New` variants return a new colour and leave this one unchanged. The + * constructor does not clamp, so channels can hold values outside 0–1. + * + * For perceptually even blends use {@link Color.lerpOklab} or + * {@link Color.lerpOklch} instead of {@link Color.lerp}. + */ class Color { + /** Red, 0–1. */ r: number; + /** Green, 0–1. */ g: number; + /** Blue, 0–1. */ b: number; + /** Alpha (opacity), 0–1. */ a: number; + /** + * Creates a colour from 0–1 channels. Values are stored as given. + * + * @param r Red, 0–1. Defaults to 0. + * @param g Green, 0–1. Defaults to 0. + * @param b Blue, 0–1. Defaults to 0. + * @param a Alpha, 0–1. Defaults to 1. + */ constructor(r = 0, g = 0, b = 0, a = 1) { this.r = r; this.g = g; @@ -56,10 +105,22 @@ class Color { this.a = a; } + /** + * Copies this colour. + * + * @returns A new colour with the same channels. + */ clone(): Color { return new Color(this.r, this.g, this.b, this.a); } + /** + * Adds another colour channel by channel, including alpha, capping each + * channel at 1. Modifies this colour. + * + * @param c The colour to add. + * @returns This colour. + */ add(c: Color): Color { this.r = Math.min(1, this.r + c.r); this.g = Math.min(1, this.g + c.g); @@ -68,10 +129,24 @@ class Color { return this; } + /** + * Adds another colour channel by channel, as {@link Color.add}, without + * modifying this one. + * + * @param c The colour to add. + * @returns A new colour. + */ addNew(c: Color): Color { return this.clone().add(c); } + /** + * Multiplies by another colour channel by channel, including alpha. + * Modifies this colour. + * + * @param c The colour to multiply by. + * @returns This colour. + */ multiply(c: Color): Color { this.r *= c.r; this.g *= c.g; @@ -80,10 +155,24 @@ class Color { return this; } + /** + * Multiplies by another colour channel by channel, as + * {@link Color.multiply}, without modifying this one. + * + * @param c The colour to multiply by. + * @returns A new colour. + */ multiplyNew(c: Color): Color { return this.clone().multiply(c); } + /** + * Scales red, green and blue by a number, capping each at 1. Alpha is left + * unchanged. Modifies this colour. + * + * @param s The scale factor. + * @returns This colour. + */ multiplyScalar(s: number): Color { this.r = Math.min(1, this.r * s); this.g = Math.min(1, this.g * s); @@ -91,10 +180,25 @@ class Color { return this; } + /** + * Scales red, green and blue by a number, as {@link Color.multiplyScalar}, + * without modifying this colour. + * + * @param s The scale factor. + * @returns A new colour. + */ multiplyScalarNew(s: number): Color { return this.clone().multiplyScalar(s); } + /** + * Linearly interpolates every channel, including alpha, towards another + * colour in sRGB space. `t` is not clamped. Modifies this colour. + * + * @param c The target colour. + * @param t The interpolation factor: 0 keeps this colour, 1 gives `c`. + * @returns This colour. + */ lerp(c: Color, t: number): Color { this.r += (c.r - this.r) * t; this.g += (c.g - this.g) * t; @@ -103,10 +207,25 @@ class Color { return this; } + /** + * Linearly interpolates towards another colour, as {@link Color.lerp}, + * without modifying this one. + * + * @param c The target colour. + * @param t The interpolation factor: 0 gives this colour, 1 gives `c`. + * @returns A new colour. + */ lerpNew(c: Color, t: number): Color { return this.clone().lerp(c, t); } + /** + * Formats the colour as a CSS colour string, with red, green and blue + * rounded to 0–255. + * + * @returns `"rgb(r, g, b)"` when alpha is exactly 1, otherwise + * `"rgba(r, g, b, a)"`. + */ toCSS(): string { const r = Math.round(this.r * 255); const g = Math.round(this.g * 255); @@ -115,11 +234,22 @@ class Color { return `rgba(${r}, ${g}, ${b}, ${this.a})`; } + /** + * Formats the colour as a 6-digit lowercase hex string. Alpha is dropped. + * + * @returns A string such as `"#ff8000"`. + */ toHex(): string { const ch = (v: number) => Math.round(v * 255).toString(16).padStart(2, "0"); return `#${ch(this.r)}${ch(this.g)}${ch(this.b)}`; } + /** + * Converts to HSL. Alpha is ignored. + * + * @returns `[h, s, l]` with hue in degrees (0–360) and saturation and + * lightness in 0–1. Greys have a hue of 0. + */ toHSL(): [number, number, number] { const { r, g, b } = this; const max = Math.max(r, g, b); @@ -135,7 +265,12 @@ class Color { return [h * 360, s, l]; } - // h: 0–360, s: 0–1, v: 0–1 + /** + * Converts to HSV (also called HSB). Alpha is ignored. + * + * @returns `[h, s, v]` with hue in degrees (0–360) and saturation and + * value in 0–1. Greys have a hue of 0. + */ toHSV(): [number, number, number] { const { r, g, b } = this; const max = Math.max(r, g, b); @@ -150,12 +285,22 @@ class Color { return [h * 360, s, max]; } - // L: 0–1, a/b: approx –0.5–0.5 + /** + * Converts to OKLab, a perceptual colour space. Alpha is ignored. + * + * @returns `[L, a, b]` with lightness in 0–1 and `a` and `b` roughly + * between −0.5 and 0.5. + */ toOklab(): [number, number, number] { return colorToOklab(this.r, this.g, this.b); } - // L: 0–1, C: 0–0.4 approx, H: 0–360° + /** + * Converts to OKLCH, the polar form of OKLab. Alpha is ignored. + * + * @returns `[L, C, H]` with lightness in 0–1, chroma roughly 0–0.4 and hue + * in degrees (0–360). The hue of a grey is not meaningful. + */ toOklch(): [number, number, number] { const [L, a, b] = colorToOklab(this.r, this.g, this.b); const C = Math.sqrt(a * a + b * b); @@ -163,14 +308,31 @@ class Color { return [L, C, H]; } + /** + * The channels as an array. + * + * @returns A new `[r, g, b, a]` array. + */ get array(): [number, number, number, number] { return [this.r, this.g, this.b, this.a]; } + /** + * Formats the colour as a CSS string, the same as {@link Color.toCSS}. + * + * @returns `"rgb(…)"` or `"rgba(…)"`. + */ toString(): string { return this.toCSS(); } + /** + * Creates a colour from a 3- or 6-digit hex string, with or without a + * leading `#` (`"#f80"`, `"ff8800"`). Alpha is always 1. + * + * @param hex The hex string. + * @returns A new colour. + */ static fromHex(hex: string): Color { const clean = hex.replace("#", ""); const full = @@ -188,6 +350,15 @@ class Color { ); } + /** + * Creates a colour from HSL values. + * + * @param h Hue in degrees (0–360). + * @param s Saturation, 0–1. + * @param l Lightness, 0–1. + * @param a Alpha, 0–1. Defaults to 1. + * @returns A new colour. + */ static fromHSL(h: number, s: number, l: number, a = 1): Color { const hNorm = h / 360; if (s === 0) return new Color(l, l, l, a); @@ -209,11 +380,28 @@ class Color { ); } + /** + * Creates a colour from 0–255 channels, dividing each by 255. + * + * @param r Red, 0–255. + * @param g Green, 0–255. + * @param b Blue, 0–255. + * @param a Alpha, 0–255. Defaults to 255. + * @returns A new colour. + */ static fromRGB255(r: number, g: number, b: number, a = 255): Color { return new Color(r / 255, g / 255, b / 255, a / 255); } - // h: 0–360, s: 0–1, v: 0–1 + /** + * Creates a colour from HSV (HSB) values. + * + * @param h Hue in degrees, 0 or more (0–360). + * @param s Saturation, 0–1. + * @param v Value (brightness), 0–1. + * @param a Alpha, 0–1. Defaults to 1. + * @returns A new colour. + */ static fromHSV(h: number, s: number, v: number, a = 1): Color { const i = Math.floor((h / 360) * 6); const f = (h / 360) * 6 - i; @@ -228,20 +416,57 @@ class Color { return new Color(r, g, b, a); } + /** + * Creates a colour from OKLab values. Results outside the sRGB gamut are + * clamped to 0–1 per channel. + * + * @param L Lightness, 0–1. + * @param a Green–red axis, roughly −0.5 to 0.5. + * @param b Blue–yellow axis, roughly −0.5 to 0.5. + * @param alpha Alpha, 0–1. Defaults to 1. + * @returns A new colour. + */ static fromOklab(L: number, a: number, b: number, alpha = 1): Color { return oklabToColor(L, a, b, alpha); } - // H in degrees (0–360) + /** + * Creates a colour from OKLCH values. Results outside the sRGB gamut are + * clamped to 0–1 per channel. + * + * @param L Lightness, 0–1. + * @param C Chroma, roughly 0–0.4. + * @param H Hue in degrees (0–360). + * @param alpha Alpha, 0–1. Defaults to 1. + * @returns A new colour. + */ static fromOklch(L: number, C: number, H: number, alpha = 1): Color { const hRad = (H * Math.PI) / 180; return oklabToColor(L, C * Math.cos(hRad), C * Math.sin(hRad), alpha); } + /** + * Linearly interpolates every channel, including alpha, between two colours + * in sRGB space. `t` is not clamped. + * + * @param c1 The colour at `t = 0`. + * @param c2 The colour at `t = 1`. + * @param t The interpolation factor. + * @returns A new colour. + */ static lerp(c1: Color, c2: Color, t: number): Color { return c1.clone().lerp(c2, t); } + /** + * Interpolates between two colours in OKLab space, which gives more even + * perceived steps than {@link Color.lerp}. Alpha is interpolated linearly. + * + * @param c1 The colour at `t = 0`. + * @param c2 The colour at `t = 1`. + * @param t The interpolation factor. + * @returns A new colour, clamped to 0–1 per channel. + */ static lerpOklab(c1: Color, c2: Color, t: number): Color { const [L1, a1, b1] = colorToOklab(c1.r, c1.g, c1.b); const [L2, a2, b2] = colorToOklab(c2.r, c2.g, c2.b); @@ -253,6 +478,17 @@ class Color { ); } + /** + * Interpolates between two colours in OKLCH space, taking the shorter way + * round the hue circle. If one end is grey, the other end's hue is used + * throughout so the blend does not pass through unrelated hues. Alpha is + * interpolated linearly. + * + * @param c1 The colour at `t = 0`. + * @param c2 The colour at `t = 1`. + * @param t The interpolation factor. + * @returns A new colour, clamped to 0–1 per channel. + */ static lerpOklch(c1: Color, c2: Color, t: number): Color { const [L1, C1, h1] = c1.toOklch(); const [L2, C2, h2] = c2.toOklch(); @@ -271,6 +507,14 @@ class Color { ); } + /** + * Creates a colour from any {@link ColorLike}: a hex string (see + * {@link Color.fromHex}), an `[r, g, b, a?]` array or an `{ r, g, b, a? }` + * object, both in 0–1. Missing alpha defaults to 1. + * + * @param v The value to convert. + * @returns A new colour. + */ static interpolate(v: ColorLike): Color { if (typeof v === "string") return Color.fromHex(v); if (Array.isArray(v)) return new Color(v[0], v[1], v[2], v[3] ?? 1); diff --git a/src/Mat2.ts b/src/Mat2.ts index fd32053..ce7efa5 100644 --- a/src/Mat2.ts +++ b/src/Mat2.ts @@ -10,12 +10,40 @@ const orDefault = function (v: any, ident: string): number { return isNaN(v) ? identity[identToIndex(ident)] : Number(v); }; +/** + * A 2×2 matrix, stored column-major as WebGL expects. + * + * Elements are named `aCR`, column first: `a11` and `a12` are rows 1 and 2 of + * the first column, `a21` and `a22` rows 1 and 2 of the second. The + * constructor, {@link Mat2.reset} and {@link Mat2.array} all use this order, + * so `array` can be passed straight to `uniformMatrix2fv`. + * + * Most operations come in two forms: `multiply` changes this matrix in place + * and returns it, while `multiplyNew` returns a new matrix and leaves this one + * unchanged. + */ class Mat2 { + /** + * Create a matrix from up to four elements in column-major order + * (`a11`, `a12`, `a21`, `a22`). Missing or non-numeric elements take their + * identity value, so `new Mat2()` is the identity matrix. + * + * @param args The elements, in column-major order. + */ constructor(...args: number[]) { const [a11, a12, a21, a22] = args; this.reset(a11, a12, a21, a22); } + /** + * Set every element, in place. Any element that is missing or not a number + * takes its identity value. Returns this matrix, for chaining. + * + * @param a11 Column 1, row 1. + * @param a12 Column 1, row 2. + * @param a21 Column 2, row 1. + * @param a22 Column 2, row 2. + */ reset(a11: number, a12: number, a21: number, a22: number): Mat2 { this.a11 = orDefault(a11, "a11"); this.a12 = orDefault(a12, "a12"); @@ -24,6 +52,12 @@ class Mat2 { return this; } + /** + * Copy every element of `m` into this matrix, in place. Returns this matrix, + * for chaining. + * + * @param m The matrix to copy from. + */ resetToMat2(m: Mat2): Mat2 { this.a11 = m.a11; this.a12 = m.a12; @@ -32,10 +66,15 @@ class Mat2 { return this; } + /** Returns a new matrix with the same elements as this one. */ clone(): Mat2 { return new Mat2(this.a11, this.a12, this.a21, this.a22); } + /** + * Transpose this matrix (swap rows and columns), in place. Returns this + * matrix, for chaining. + */ transpose(): Mat2 { const a12 = this.a12; this.a12 = this.a21; @@ -43,10 +82,20 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.transpose}, but returns a new matrix and leaves this one + * unchanged. + */ transposeNew(): Mat2 { return this.clone().transpose(); } + /** + * Add `m` to this matrix element by element, in place. Returns this matrix, + * for chaining. + * + * @param m The matrix to add. + */ add(m: Mat2): Mat2 { this.a11 += m.a11; this.a12 += m.a12; @@ -55,12 +104,24 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.add}, but returns a new matrix and leaves this one + * unchanged. + * + * @param m The matrix to add. + */ addNew(m: Mat2): Mat2 { return this.clone().add(m); } // @TODO: We might want to generalise this and allow any sort of matrix on these operations + /** + * Subtract `m` from this matrix element by element, in place. Returns this + * matrix, for chaining. + * + * @param m The matrix to subtract. + */ subtract(m: Mat2): Mat2 { this.a11 -= m.a11; this.a12 -= m.a12; @@ -69,10 +130,22 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.subtract}, but returns a new matrix and leaves this one + * unchanged. + * + * @param m The matrix to subtract. + */ subtractNew(m: Mat2): Mat2 { return this.clone().subtract(m); } + /** + * Multiply this matrix by `m` (this × m), in place, so `m` is applied to a + * vector first. Returns this matrix, for chaining. + * + * @param m The matrix to multiply by, on the right. + */ multiply(m: Mat2): Mat2 { const o = this.clone(); this.a11 = o.a11 * m.a11 + o.a21 * m.a12; @@ -82,10 +155,22 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.multiply}, but returns a new matrix and leaves this one + * unchanged. + * + * @param m The matrix to multiply by, on the right. + */ multiplyNew(m: Mat2): Mat2 { return this.clone().multiply(m); } + /** + * Multiply every element by `s`, in place. Returns this matrix, for + * chaining. + * + * @param s The scalar to multiply by. + */ multiplyScalar(s: number): Mat2 { this.a11 *= s; this.a12 *= s; @@ -94,18 +179,43 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.multiplyScalar}, but returns a new matrix and leaves this + * one unchanged. + * + * @param s The scalar to multiply by. + */ multiplyScalarNew(s: number): Mat2 { return this.clone().multiplyScalar(s); } + /** + * Multiply every element by `s`, in place. The same as + * {@link Mat2.multiplyScalar}. Returns this matrix, for chaining. + * + * @param s The scalar to multiply by. + */ scale(s: number): Mat2 { return this.multiplyScalar(s); } + /** + * Like {@link Mat2.scale}, but returns a new matrix and leaves this one + * unchanged. + * + * @param s The scalar to multiply by. + */ scaleNew(s: number): Mat2 { return this.multiplyScalarNew(s); } + /** + * Scale the first column by `v.x` and the second by `v.y`, in place. This + * is this × a scaling matrix, so the scale is applied to a vector before + * this matrix. Returns this matrix, for chaining. + * + * @param v The x and y scale factors, as a vector or `[x, y]` array. + */ scaleByVec2(v: Vec2Like): Mat2 { const arr: [number, number] = Array.isArray(v) ? v : [v.x, v.y]; this.a11 *= arr[0]; @@ -115,10 +225,23 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.scaleByVec2}, but returns a new matrix and leaves this + * one unchanged. + * + * @param v The x and y scale factors, as a vector or `[x, y]` array. + */ scaleByVec2New(v: Vec2Like): Mat2 { return this.clone().scaleByVec2(v); } + /** + * Rotate this matrix anticlockwise by `r` radians, in place. This is + * this × a rotation matrix, so the rotation is applied to a vector before + * this matrix. Returns this matrix, for chaining. + * + * @param r The angle, in radians. + */ rotate(r: number): Mat2 { const o = this.clone(); const s = Math.sin(r); @@ -130,10 +253,21 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.rotate}, but returns a new matrix and leaves this one + * unchanged. + * + * @param r The angle, in radians. + */ rotateNew(r: number): Mat2 { return this.clone().rotate(r); } + /** + * Invert this matrix, in place. If the matrix is singular (its determinant + * is 0) it is left unchanged; this method never returns null. Returns this + * matrix, for chaining. + */ invert(): Mat2 { const c = this.clone(); @@ -152,14 +286,17 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.invert}, but returns a new matrix and leaves this one + * unchanged. A singular matrix gives an unchanged copy. + */ invertNew(): Mat2 { return this.clone().invert(); } /** - * Calculates the adjugate of a mat2 - * - * @returns {mat2} out + * Replace this matrix with its adjugate, in place. Returns this matrix, for + * chaining. */ adjoint(): Mat2 { const a11 = this.a11; @@ -171,10 +308,15 @@ class Mat2 { return this; } + /** + * Like {@link Mat2.adjoint}, but returns a new matrix and leaves this one + * unchanged. + */ adjointNew(): Mat2 { return this.clone().adjoint(); } + /** Returns the elements as a string, one column per line. */ toString(): string { return ` ${this.a11}, ${this.a12}, @@ -182,17 +324,13 @@ class Mat2 { `; } - /** - * Getters and setters - */ + // Getters and setters + #a11: number = 0; /** - * (getter/setter) The a11 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 1, row 1. Throws a `TypeError` if `v` is not a + * number. */ - #a11: number = 0; set a11(v) { if (typeof v == "number") { this.#a11 = v; @@ -200,17 +338,20 @@ class Mat2 { throw new TypeError("a11 should be a number"); } } + /** + * The element at column 1, row 1. A stored `NaN` reads as 0. + * + * @default 1 + */ get a11() { return this.#a11 || 0; } + #a12: number = 0; /** - * (getter/setter) The a12 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 1, row 2. Throws a `TypeError` if `v` is not a + * number. */ - #a12: number = 0; set a12(v) { if (typeof v == "number") { this.#a12 = v; @@ -218,17 +359,20 @@ class Mat2 { throw new TypeError("a12 should be a number"); } } + /** + * The element at column 1, row 2. A stored `NaN` reads as 0. + * + * @default 0 + */ get a12() { return this.#a12 || 0; } + #a21: number = 0; /** - * (getter/setter) The a21 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 2, row 1. Throws a `TypeError` if `v` is not a + * number. */ - #a21: number = 0; set a21(v) { if (typeof v == "number") { this.#a21 = v; @@ -236,17 +380,20 @@ class Mat2 { throw new TypeError("a21 should be a number"); } } + /** + * The element at column 2, row 1. A stored `NaN` reads as 0. + * + * @default 0 + */ get a21() { return this.#a21 || 0; } + #a22: number = 0; /** - * (getter/setter) The a22 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 2, row 2. Throws a `TypeError` if `v` is not a + * number. */ - #a22: number = 0; set a22(v) { if (typeof v == "number") { this.#a22 = v; @@ -254,35 +401,47 @@ class Mat2 { throw new TypeError("a22 should be a number"); } } + /** + * The element at column 2, row 2. A stored `NaN` reads as 0. + * + * @default 1 + */ get a22() { return this.#a22 || 0; } + /** The determinant of the matrix. */ get determinant(): number { return this.a11 * this.a22 - this.a12 * this.a21; } /** - * (getter) Returns the basic array representation of this matrix. - * @readonly - * - * @type {array} + * A new array of the elements in column-major order + * (`[a11, a12, a21, a22]`), ready for `uniformMatrix2fv`. */ get array(): number[] { return [this.a11, this.a12, this.a21, this.a22]; } /** - * (getter) Returns the basic array representation of this matrix. - * this returns the array in column-major form. - * @readonly - * - * @type {array} + * A new array of the elements in row-major order (`[a11, a21, a12, a22]`), + * which is the transpose of {@link Mat2.array}. Despite the name, this is + * not the column-major order WebGL expects; use `array` for that. */ get columnArray(): number[] { return [this.a11, this.a21, this.a12, this.a22]; } + /** + * Create a rotation matrix from an angle in radians. + * + * Note: the result is `[cos r, -sin r, sin r, cos r]` in column-major + * order, which rotates clockwise by `r`. This is the opposite direction to + * {@link Mat2.rotate}, so `Mat2.fromAngle(r)` equals + * `Mat2.identity().rotate(-r)`. + * + * @param r The angle, in radians. + */ static fromAngle(r: number): Mat2 { let s = Math.sin(r); let c = Math.cos(r); @@ -290,32 +449,24 @@ class Mat2 { return new Mat2(c, -s, s, c); } + /** + * Create a scaling matrix, with `v.x` and `v.y` on the diagonal. + * + * @param v The x and y scale factors, as a vector or `[x, y]` array. + */ static fromScalingVec2(v: Vec2Like): Mat2 { const arr: [number, number] = Array.isArray(v) ? v : [v.x, v.y]; return new Mat2(arr[0], 0, 0, arr[1]); } + /** Returns a new identity matrix. */ static identity(): Mat2 { return new Mat2(...identity); } - - /** - * Adds iteration to the object, allowing it - * to be destructured and iterated upon in - * various useful ways. - */ - [Symbol.iterator]() { - let values = this.array; - let index = 0; - return { - next() { - if (index < values.length) { - let value = values[index]; - index++; - return { value, done: false }; - } else return { done: true } - } - } + + /** Iterate over the elements in column-major order, so the matrix can be spread: `[...m]`. */ + [Symbol.iterator](): Iterator { + return this.array[Symbol.iterator](); } } diff --git a/src/Mat3.ts b/src/Mat3.ts index 3f89611..b5ad675 100644 --- a/src/Mat3.ts +++ b/src/Mat3.ts @@ -3,9 +3,7 @@ import type { Vec2Like, QuatLike } from "./types.js"; const identity = [1, 0, 0, 0, 1, 0, 0, 0, 1]; -/** TO DO - * Move these functions to a types file - */ +// TO DO: Move these types to a types file type Mat3DeterminantFunction = { f: { b01: number; @@ -73,11 +71,39 @@ const orDefault = function (v: any, ident: string): number { return isNaN(v) ? identity[identToIndex(ident)] : Number(v); }; +/** + * A 3×3 matrix, stored column-major as WebGL expects. Used for 2D affine + * transforms (rotation, scale and translation) and for normal matrices. + * + * Elements are named `aCR`, column first: `a11`, `a12`, `a13` are rows 1 to 3 + * of the first column, `a21`, `a22`, `a23` the second column, and `a31`, + * `a32`, `a33` the third. In a 2D transform the translation sits in `a31` and + * `a32`. The constructor, {@link Mat3.reset} and {@link Mat3.array} all use + * this order, so `array` can be passed straight to `uniformMatrix3fv`. + * + * Most operations come in two forms: `multiply` changes this matrix in place + * and returns it, while `multiplyNew` returns a new matrix and leaves this one + * unchanged. + */ class Mat3 { + /** + * Create a matrix from up to nine elements in column-major order + * (`a11`, `a12`, `a13`, `a21`, …, `a33`). Missing or non-numeric elements + * take their identity value, so `new Mat3()` is the identity matrix. + * + * @param args The elements, in column-major order. + */ constructor(...args: number[]) { this.reset(...args); } + /** + * Set every element from up to nine values in column-major order, in place. + * Any element that is missing or not a number takes its identity value. + * Returns this matrix, for chaining. + * + * @param args The elements, in column-major order. + */ reset(...args: number[]): Mat3 { const [a11, a12, a13, a21, a22, a23, a31, a32, a33] = args; this.a11 = orDefault(a11, "a11"); @@ -94,6 +120,12 @@ class Mat3 { return this; } + /** + * Copy every element of `m` into this matrix, in place. Returns this matrix, + * for chaining. + * + * @param m The matrix to copy from. + */ resetToMat3(m: Mat3): Mat3 { this.a11 = m.a11; this.a12 = m.a12; @@ -107,6 +139,7 @@ class Mat3 { return this; } + /** Returns a new matrix with the same elements as this one. */ clone(): Mat3 { return new Mat3( this.a11, @@ -121,6 +154,10 @@ class Mat3 { ); } + /** + * Transpose this matrix (swap rows and columns), in place. Returns this + * matrix, for chaining. + */ transpose(): Mat3 { const a12 = this.a12, a13 = this.a13, @@ -136,10 +173,18 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.transpose}, but returns a new matrix and leaves this one + * unchanged. + */ transposeNew(): Mat3 { return this.clone().transpose(); } + /** + * Replace this matrix with its adjugate, in place. Returns this matrix, for + * chaining. + */ adjoint(): Mat3 { const o = this.clone(); @@ -158,10 +203,20 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.adjoint}, but returns a new matrix and leaves this one + * unchanged. + */ adjointNew(): Mat3 { return this.clone().adjoint(); } + /** + * Add `m` to this matrix element by element, in place. Returns this matrix, + * for chaining. + * + * @param m The matrix to add. + */ add(m: Mat3): Mat3 { this.a11 += m.a11; this.a12 += m.a12; @@ -175,12 +230,24 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.add}, but returns a new matrix and leaves this one + * unchanged. + * + * @param m The matrix to add. + */ addNew(m: Mat3): Mat3 { return this.clone().add(m); } // @TODO: We might want to generalise this and allow any sort of matrix on these operations + /** + * Subtract `m` from this matrix element by element, in place. Returns this + * matrix, for chaining. + * + * @param m The matrix to subtract. + */ subtract(m: Mat3): Mat3 { this.a11 -= m.a11; this.a12 -= m.a12; @@ -194,10 +261,22 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.subtract}, but returns a new matrix and leaves this one + * unchanged. + * + * @param m The matrix to subtract. + */ subtractNew(m: Mat3): Mat3 { return this.clone().subtract(m); } + /** + * Multiply this matrix by `m` (this × m), in place, so `m` is applied to a + * vector first. Returns this matrix, for chaining. + * + * @param m The matrix to multiply by, on the right. + */ multiply(m: Mat3): Mat3 { const o = this.clone(); this.a11 = m.a11 * o.a11 + m.a12 * o.a21 + m.a13 * o.a31; @@ -214,10 +293,22 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.multiply}, but returns a new matrix and leaves this one + * unchanged. + * + * @param m The matrix to multiply by, on the right. + */ multiplyNew(m: Mat3): Mat3 { return this.clone().multiply(m); } + /** + * Multiply every element by `s`, in place. Returns this matrix, for + * chaining. + * + * @param s The scalar to multiply by. + */ multiplyScalar(s: number): Mat3 { this.a11 *= s; this.a12 *= s; @@ -231,18 +322,45 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.multiplyScalar}, but returns a new matrix and leaves this + * one unchanged. + * + * @param s The scalar to multiply by. + */ multiplyScalarNew(s: number): Mat3 { return this.clone().multiplyScalar(s); } + /** + * Multiply every element by `s`, in place. The same as + * {@link Mat3.multiplyScalar}, so it also scales the translation and the + * bottom-right element; use {@link Mat3.scaleByVec2} for a 2D scale. + * Returns this matrix, for chaining. + * + * @param s The scalar to multiply by. + */ scale(s: number): Mat3 { return this.multiplyScalar(s); } + /** + * Like {@link Mat3.scale}, but returns a new matrix and leaves this one + * unchanged. + * + * @param s The scalar to multiply by. + */ scaleNew(s: number): Mat3 { return this.multiplyScalarNew(s); } + /** + * Apply a 2D scale, in place: the first column is multiplied by `v.x` and + * the second by `v.y`. This is this × a scaling matrix, so the scale is + * applied to a vector before this matrix. Returns this matrix, for chaining. + * + * @param v The x and y scale factors, as a vector or `[x, y]` array. + */ scaleByVec2(v: Vec2Like): Mat3 { const arr: [number, number] = Array.isArray(v) ? v : [v.x, v.y]; this.a11 *= arr[0]; @@ -254,10 +372,23 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.scaleByVec2}, but returns a new matrix and leaves this + * one unchanged. + * + * @param v The x and y scale factors, as a vector or `[x, y]` array. + */ scaleByVec2New(v: Vec2Like): Mat3 { return this.clone().scaleByVec2(v); } + /** + * Apply a 2D translation, in place. This is this × a translation matrix, so + * the translation is applied to a vector before this matrix. Returns this + * matrix, for chaining. + * + * @param v The x and y offsets. + */ translate(v: Vec2): Mat3 { this.a31 += v.x * this.a11 + v.y * this.a21; this.a32 += v.x * this.a12 + v.y * this.a22; @@ -265,6 +396,14 @@ class Mat3 { return this; } + /** + * Apply a 2D rotation of `r` radians anticlockwise (about the z axis), in + * place. This is this × a rotation matrix, so the rotation is applied to a + * vector before this matrix. The third column is unchanged. Returns this + * matrix, for chaining. + * + * @param r The angle, in radians. + */ rotate(r: number): Mat3 { const o = this.clone(); const s = Math.sin(r); @@ -281,10 +420,21 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.rotate}, but returns a new matrix and leaves this one + * unchanged. + * + * @param r The angle, in radians. + */ rotateNew(r: number): Mat3 { return this.clone().rotate(r); } + /** + * Invert this matrix, in place. If the matrix is singular (its determinant + * is 0) it is left unchanged; this method never returns null. Returns this + * matrix, for chaining. + */ invert(): Mat3 { const o = this.clone(); @@ -313,10 +463,15 @@ class Mat3 { return this; } + /** + * Like {@link Mat3.invert}, but returns a new matrix and leaves this one + * unchanged. A singular matrix gives an unchanged copy. + */ invertNew(): Mat3 { return this.clone().invert(); } + /** Returns the elements as a string, one column per line. */ toString(): string { return ` ${this.a11}, ${this.a12}, ${this.a13}, @@ -325,17 +480,13 @@ class Mat3 { `; } - /** - * Getters and setters - */ + // Getters and setters + #a11: number = 0; /** - * (getter/setter) The a11 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 1, row 1. Throws a `TypeError` if `v` is not a + * number. */ - #a11: number = 0; set a11(v) { if (typeof v == "number") { this.#a11 = v; @@ -343,17 +494,20 @@ class Mat3 { throw new TypeError("a11 should be a number"); } } + /** + * The element at column 1, row 1. A stored `NaN` reads as 0. + * + * @default 1 + */ get a11() { return this.#a11 || 0; } + #a12: number = 0; /** - * (getter/setter) The a12 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 1, row 2. Throws a `TypeError` if `v` is not a + * number. */ - #a12: number = 0; set a12(v) { if (typeof v == "number") { this.#a12 = v; @@ -361,17 +515,20 @@ class Mat3 { throw new TypeError("a12 should be a number"); } } + /** + * The element at column 1, row 2. A stored `NaN` reads as 0. + * + * @default 0 + */ get a12() { return this.#a12 || 0; } + #a13: number = 0; /** - * (getter/setter) The a13 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 1, row 3. Throws a `TypeError` if `v` is not a + * number. */ - #a13: number = 0; set a13(v) { if (typeof v == "number") { this.#a13 = v; @@ -379,17 +536,20 @@ class Mat3 { throw new TypeError("a13 should be a number"); } } + /** + * The element at column 1, row 3. A stored `NaN` reads as 0. + * + * @default 0 + */ get a13() { return this.#a13 || 0; } + #a21: number = 0; /** - * (getter/setter) The a21 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 2, row 1. Throws a `TypeError` if `v` is not a + * number. */ - #a21: number = 0; set a21(v) { if (typeof v == "number") { this.#a21 = v; @@ -397,17 +557,20 @@ class Mat3 { throw new TypeError("a21 should be a number"); } } + /** + * The element at column 2, row 1. A stored `NaN` reads as 0. + * + * @default 0 + */ get a21() { return this.#a21 || 0; } + #a22: number = 0; /** - * (getter/setter) The a22 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 2, row 2. Throws a `TypeError` if `v` is not a + * number. */ - #a22: number = 0; set a22(v) { if (typeof v == "number") { this.#a22 = v; @@ -415,17 +578,20 @@ class Mat3 { throw new TypeError("a22 should be a number"); } } + /** + * The element at column 2, row 2. A stored `NaN` reads as 0. + * + * @default 1 + */ get a22() { return this.#a22 || 0; } + #a23: number = 0; /** - * (getter/setter) The a23 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 2, row 3. Throws a `TypeError` if `v` is not a + * number. */ - #a23: number = 0; set a23(v) { if (typeof v == "number") { this.#a23 = v; @@ -433,17 +599,20 @@ class Mat3 { throw new TypeError("a23 should be a number"); } } + /** + * The element at column 2, row 3. A stored `NaN` reads as 0. + * + * @default 0 + */ get a23() { return this.#a23 || 0; } + #a31: number = 0; /** - * (getter/setter) The a31 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 3, row 1 (the x translation in a 2D transform). + * Throws a `TypeError` if `v` is not a number. */ - #a31: number = 0; set a31(v) { if (typeof v == "number") { this.#a31 = v; @@ -451,17 +620,21 @@ class Mat3 { throw new TypeError("a31 should be a number"); } } + /** + * The element at column 3, row 1 (the x translation in a 2D transform). A + * stored `NaN` reads as 0. + * + * @default 0 + */ get a31() { return this.#a31 || 0; } + #a32: number = 0; /** - * (getter/setter) The a32 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 3, row 2 (the y translation in a 2D transform). + * Throws a `TypeError` if `v` is not a number. */ - #a32: number = 0; set a32(v) { if (typeof v == "number") { this.#a32 = v; @@ -469,17 +642,21 @@ class Mat3 { throw new TypeError("a32 should be a number"); } } + /** + * The element at column 3, row 2 (the y translation in a 2D transform). A + * stored `NaN` reads as 0. + * + * @default 0 + */ get a32() { return this.#a32 || 0; } + #a33: number = 0; /** - * (getter/setter) The a33 value of the matrix. - * - * @type {number} - * @default 0 + * Set the element at column 3, row 3. Throws a `TypeError` if `v` is not a + * number. */ - #a33: number = 0; set a33(v) { if (typeof v == "number") { this.#a33 = v; @@ -487,19 +664,26 @@ class Mat3 { throw new TypeError("a33 should be a number"); } } + /** + * The element at column 3, row 3. A stored `NaN` reads as 0. + * + * @default 1 + */ get a33() { return this.#a33 || 0; } + /** + * The Frobenius norm of the matrix: the square root of the sum of the + * squares of all nine elements. + */ get frobeniusnorm(): number { return Math.hypot(...this.array); } /** - * (getter) Returns the basic array representation of this matrix. - * @readonly - * - * @type {array} + * A new array of the elements in column-major order + * (`[a11, a12, a13, a21, …, a33]`), ready for `uniformMatrix3fv`. */ get array(): number[] { return [ @@ -516,11 +700,10 @@ class Mat3 { } /** - * (getter) Returns the basic array representation of this matrix. - * this returns the array in column-major form. - * @readonly - * - * @type {array} + * A new array of the elements in row-major order + * (`[a11, a21, a31, a12, …, a33]`), which is the transpose of + * {@link Mat3.array}. Despite the name, this is not the column-major order + * WebGL expects; use `array` for that. */ get columnArray(): number[] { return [ @@ -536,6 +719,12 @@ class Mat3 { ]; } + /** + * The determinant of the matrix, along with the three cofactors + * (`f.b01`, `f.b11`, `f.b21`) that {@link Mat3.invert} reuses. Computed + * afresh on each read. Use {@link Mat3.determinant} if you only need the + * number. + */ get determinantFunction(): Mat3DeterminantFunction { let b01 = this.a33 * this.a22 - this.a23 * this.a32; let b11 = -this.a33 * this.a21 + this.a23 * this.a31; @@ -547,15 +736,21 @@ class Mat3 { }; } - /** - * Calculates the determinant of the mat3 - * - * @returns {Number} determinant of a - */ + /** The determinant of the matrix. */ get determinant(): number { return this.determinantFunction.determinant; } + /** + * Create a 2D rotation matrix from an angle in radians. + * + * Note: the upper-left 2×2 is `[cos r, -sin r, sin r, cos r]` in + * column-major order, which rotates clockwise by `r`. This is the opposite + * direction to {@link Mat3.rotate}, so `Mat3.fromAngle(r)` equals + * `Mat3.identity().rotate(-r)`. + * + * @param r The angle, in radians. + */ static fromAngle(r: number): Mat3 { let s = Math.sin(r); let c = Math.cos(r); @@ -563,11 +758,26 @@ class Mat3 { return new Mat3(c, -s, 0, s, c, 0, 0, 0, 1); } + /** + * Create a 2D scaling matrix, with `v.x`, `v.y` and 1 on the diagonal. + * + * @param v The x and y scale factors, as a vector or `[x, y]` array. + */ static fromScalingVec2(v: Vec2Like): Mat3 { const arr: [number, number] = Array.isArray(v) ? v : [v.x, v.y]; return new Mat3(arr[0], 0, 0, 0, arr[1], 0, 0, 0, 1); } + /** + * Create a rotation matrix from a quaternion. The quaternion is assumed to + * be normalised. + * + * Note: the result is the transpose of the usual column-major rotation + * matrix (the one `Mat4.fromQuat` builds), so it rotates by the inverse of + * `q`. + * + * @param q The quaternion, as an object or `[x, y, z, w]` array. + */ static fromQuat(q: QuatLike): Mat3 { const qa = Array.isArray(q) ? q : [q.x, q.y, q.z, q.w]; const [x, y, z, w] = qa; @@ -597,11 +807,12 @@ class Mat3 { } /** - * Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix + * Create a normal matrix from a 4×4 matrix: the inverse transpose of its + * upper-left 3×3. Use it to transform normals by a model or model-view + * matrix. * - * @param {mat4} a Mat4 to derive the normal matrix from - * - * @returns {mat3} + * @param a The 4×4 matrix, such as a `Mat4`. + * @returns A new matrix, or null if `a` can't be inverted. */ static fromMat4(a: Mat4): Mat3 | null { const { @@ -628,37 +839,25 @@ class Mat3 { } /** - * Generates a 2D projection matrix with the given bounds + * Create a 2D projection matrix that maps pixel coordinates to clip space: + * (0, 0) at the top left becomes (-1, 1) and (width, height) at the bottom + * right becomes (1, -1), so y points down. * - * @param {number} width Width of your gl context - * @param {number} height Height of gl context - * @returns {mat3} out + * @param width The width of the canvas or viewport, in pixels. + * @param height The height of the canvas or viewport, in pixels. */ static fromProjection(width: number, height: number): Mat3 { return new Mat3(2 / width, 0, 0, 0, -2 / height, 0, -1, 1, 1); } + /** Returns a new identity matrix. */ static identity(): Mat3 { return new Mat3(...identity); } - - /** - * Adds iteration to the object, allowing it - * to be destructured and iterated upon in - * various useful ways. - */ - [Symbol.iterator]() { - let values = this.array; - let index = 0; - return { - next() { - if (index < values.length) { - let value = values[index]; - index++; - return { value, done: false }; - } else return { done: true } - } - } + + /** Iterate over the elements in column-major order, so the matrix can be spread: `[...m]`. */ + [Symbol.iterator](): Iterator { + return this.array[Symbol.iterator](); } } diff --git a/src/Mat4.ts b/src/Mat4.ts index 8a127b0..65db72d 100644 --- a/src/Mat4.ts +++ b/src/Mat4.ts @@ -49,11 +49,33 @@ const orDefault = function (v: any, ident: string): number { return isNaN(v) ? identity[identToIndex(ident)] : Number(v); }; +/** + * A 4×4 matrix, used for 3D transforms, camera views and projections. + * + * Elements are stored column-major, as WebGL expects. Each element is named + * `aCR`, for column C and row R: `a11`–`a14` are the first column and + * `a41`–`a43` hold the translation. {@link Mat4.array} returns the elements in + * that order, ready to pass to `uniformMatrix4fv`. + * + * Most operations change the matrix in place and return it, for chaining. Each + * has a `…New` variant that returns a new matrix and leaves this one unchanged. + */ class Mat4 { + /** + * Create a matrix. With no arguments, this is the identity matrix. + * + * @param args Up to 16 elements in column-major order. Any missing or `NaN` element takes its value from the identity matrix. + */ constructor(...args: number[]) { this.reset(...args); } + /** + * Set every element in place. Any missing or `NaN` element takes its value from the identity matrix, so `reset()` with no arguments sets this to the identity. + * + * @param args Up to 16 elements in column-major order. + * @returns This matrix, for chaining. + */ reset(...args: number[]): Mat4 { const [ a11, @@ -95,6 +117,12 @@ class Mat4 { return this; } + /** + * Copy every element of another matrix into this one. + * + * @param m The matrix to copy. + * @returns This matrix, for chaining. + */ resetToMat4(m: Mat4): Mat4 { this.a11 = m.a11; this.a12 = m.a12; @@ -119,6 +147,11 @@ class Mat4 { return this; } + /** + * Create a copy of this matrix. + * + * @returns A new matrix with the same elements. + */ clone(): Mat4 { return new Mat4( this.a11, @@ -140,6 +173,11 @@ class Mat4 { ); } + /** + * Transpose the matrix in place, swapping rows and columns. + * + * @returns This matrix, for chaining. + */ transpose(): Mat4 { const a12 = this.a12, a13 = this.a13, @@ -167,10 +205,21 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.transpose}, but returns a new matrix and leaves this one unchanged. + * + * @returns A new, transposed matrix. + */ transposeNew(): Mat4 { return this.clone().transpose(); } + /** + * Add another matrix to this one in place, element by element. + * + * @param m The matrix to add. + * @returns This matrix, for chaining. + */ add(m: Mat4): Mat4 { this.a11 += m.a11; this.a12 += m.a12; @@ -194,12 +243,24 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.add}, but returns a new matrix and leaves this one unchanged. + * + * @param m The matrix to add. + * @returns A new matrix holding the sum. + */ addNew(m: Mat4): Mat4 { return this.clone().add(m); } // @TODO: We might want to generalise this and allow any sort of matrix on these operations + /** + * Subtract another matrix from this one in place, element by element. + * + * @param m The matrix to subtract. + * @returns This matrix, for chaining. + */ subtract(m: Mat4): Mat4 { this.a11 -= m.a11; this.a12 -= m.a12; @@ -223,10 +284,24 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.subtract}, but returns a new matrix and leaves this one unchanged. + * + * @param m The matrix to subtract. + * @returns A new matrix holding the difference. + */ subtractNew(m: Mat4): Mat4 { return this.clone().subtract(m); } + /** + * Multiply this matrix by another in place, so this becomes `this × m`. + * Applied to a vector, the result transforms by `m` first, then by the + * original matrix. + * + * @param m The matrix to multiply by, on the right. + * @returns This matrix, for chaining. + */ multiply(m: Mat4): Mat4 { const o = this.clone(); @@ -252,10 +327,22 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.multiply}, but returns a new matrix and leaves this one unchanged. + * + * @param m The matrix to multiply by, on the right. + * @returns A new matrix holding `this × m`. + */ multiplyNew(m: Mat4): Mat4 { return this.clone().multiply(m); } + /** + * Multiply every element, including the translation and `a44`, by a number in place. + * + * @param s The number to multiply by. + * @returns This matrix, for chaining. + */ multiplyScalar(s: number): Mat4 { this.a11 *= s; this.a12 *= s; @@ -280,18 +367,46 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.multiplyScalar}, but returns a new matrix and leaves this one unchanged. + * + * @param s The number to multiply by. + * @returns A new, scaled matrix. + */ multiplyScalarNew(s: number): Mat4 { return this.clone().multiplyScalar(s); } + /** + * An alias of {@link Mat4.multiplyScalar}: multiplies all 16 elements in + * place. This is not a uniform scale transform, since it also scales the + * translation and `a44`; use {@link Mat4.scaleByVec3} for that. + * + * @param s The number to multiply by. + * @returns This matrix, for chaining. + */ scale(s: number): Mat4 { return this.multiplyScalar(s); } + /** + * Like {@link Mat4.scale}, but returns a new matrix and leaves this one unchanged. + * + * @param s The number to multiply by. + * @returns A new, scaled matrix. + */ scaleNew(s: number): Mat4 { return this.multiplyScalarNew(s); } + /** + * Scale the matrix in place by a per-axis amount, multiplying the first, + * second and third columns by `x`, `y` and `z`. This is `this × S`, so the + * scale applies in the matrix's local space. The translation is unchanged. + * + * @param v The x, y and z scale factors. + * @returns This matrix, for chaining. + */ scaleByVec3(v: Vec3Like): Mat4 { const va = Array.isArray(v) ? v : [v.x, v.y, v.z]; const [x, y, z] = va; @@ -314,15 +429,22 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.scaleByVec3}, but returns a new matrix and leaves this one unchanged. + * + * @param v The x, y and z scale factors. + * @returns A new, scaled matrix. + */ scaleByVec3New(v: Vec3Like): Mat4 { return this.clone().scaleByVec3(v); } /** - * Transforms the mat4 by a given amount + * Add a vector to the translation (`a41`–`a43`) in place. Unlike + * {@link Mat4.translate}, the offset is not rotated or scaled by the matrix. * - * @param {Vec3} v The amount to add to the matrixes transformation properties - * @returns {mat4} output + * @param v The amount to add to the translation. + * @returns This matrix, for chaining. */ transform(v: Vec3Like): Mat4 { const va = Array.isArray(v) ? v : [v.x, v.y, v.z]; @@ -334,15 +456,21 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.transform}, but returns a new matrix and leaves this one unchanged. + * + * @param v The amount to add to the translation. + * @returns A new matrix with the offset translation. + */ transformNew(v: Vec3Like): Mat4 { return this.clone().transform(v); } /** - * Transforms the mat4 to a given position + * Set the translation (`a41`–`a43`) in place, leaving the other elements unchanged. * - * @param {Vec3} v The position to set on the matrix - * @returns {mat4} output + * @param v The new translation. + * @returns This matrix, for chaining. */ transformTo(v: Vec3Like): Mat4 { const va = Array.isArray(v) ? v : [v.x, v.y, v.z]; @@ -353,15 +481,25 @@ class Mat4 { return this; } + /** + * Meant to be like {@link Mat4.transformTo}, returning a new matrix and + * leaving this one unchanged. It currently calls {@link Mat4.transform}, so + * it adds `v` to the translation rather than setting it. + * + * @param v The translation. + * @returns A new matrix. + */ transformToNew(v: Vec3Like): Mat4 { return this.clone().transform(v); } /** - * Translates the mat4 to a given position + * Translate the matrix in place by `v` in its local space, so this becomes + * `this × T(v)`. The offset is rotated and scaled by the existing matrix; + * use {@link Mat4.transform} to offset in world space instead. * - * @param {Vec3} v The amount to add to the matrixes translation properties - * @returns {mat4} output + * @param v The amount to translate by. + * @returns This matrix, for chaining. */ translate(v: Vec3Like): Mat4 { const va = Array.isArray(v) ? v : [v.x, v.y, v.z]; @@ -396,16 +534,24 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.translate}, but returns a new matrix and leaves this one unchanged. + * + * @param v The amount to translate by. + * @returns A new, translated matrix. + */ translateNew(v: Vec3Like): Mat4 { return this.clone().translate(v); } /** - * Rotates a mat4 by the given angle around the given axis + * Rotate the matrix in place around an axis, so this becomes `this × R`. The + * rotation is right-handed (counter-clockwise when looking down the axis + * towards the origin) and the translation is unchanged. * - * @param {Number} r the angle to rotate the matrix by - * @param {vec3} axis the axis to rotate around - * @returns {mat4} output + * @param r The angle, in radians. + * @param axis The axis to rotate around. It is normalised for you; if its length is close to zero the matrix is left unchanged. + * @returns This matrix, for chaining. */ rotate(r: number, axis: Vec3Like): Mat4 { const aa = Array.isArray(axis) ? axis : [axis.x, axis.y, axis.z]; @@ -454,10 +600,23 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.rotate}, but returns a new matrix and leaves this one unchanged. + * + * @param r The angle, in radians. + * @param axis The axis to rotate around. + * @returns A new, rotated matrix. + */ rotateNew(r: number, axis: Vec3Like): Mat4 { return this.clone().rotate(r, axis); } + /** + * Invert the matrix in place. If the matrix is singular (its determinant is + * 0) it cannot be inverted, and is left unchanged; this never returns `null`. + * + * @returns This matrix, for chaining. + */ invert(): Mat4 { const c = this.clone(); @@ -491,10 +650,22 @@ class Mat4 { return this; } + /** + * Like {@link Mat4.invert}, but returns a new matrix and leaves this one + * unchanged. A singular matrix gives an unchanged copy. + * + * @returns A new, inverted matrix. + */ invertNew(): Mat4 { return this.clone().invert(); } + /** + * A readable string of the elements, one column per line in column-major + * order, with surrounding newlines and indentation. + * + * @returns The elements as a string. + */ toString(): string { return ` ${this.a11}, ${this.a12}, ${this.a13}, ${this.a14}, @@ -504,17 +675,10 @@ class Mat4 { `; } - /** - * Getters and setters - */ + // Element accessors. aCR is column C, row R. - /** - * (getter/setter) The a11 value of the matrix. - * - * @type {number} - * @default 0 - */ #a11: number = 0; + /** Set the element in column 1, row 1. Throws a `TypeError` if `v` is not a number. */ set a11(v: number) { if (typeof v == "number") { this.#a11 = v; @@ -522,17 +686,13 @@ class Mat4 { throw new TypeError("a11 should be a number"); } } + /** The element in column 1, row 1. Reads as 0 if the stored value is `NaN`. */ get a11() { return this.#a11 || 0; } - /** - * (getter/setter) The a12 value of the matrix. - * - * @type {number} - * @default 0 - */ #a12: number = 0; + /** Set the element in column 1, row 2. Throws a `TypeError` if `v` is not a number. */ set a12(v: number) { if (typeof v == "number") { this.#a12 = v; @@ -540,17 +700,13 @@ class Mat4 { throw new TypeError("a12 should be a number"); } } + /** The element in column 1, row 2. Reads as 0 if the stored value is `NaN`. */ get a12() { return this.#a12 || 0; } - /** - * (getter/setter) The a13 value of the matrix. - * - * @type {number} - * @default 0 - */ #a13: number = 0; + /** Set the element in column 1, row 3. Throws a `TypeError` if `v` is not a number. */ set a13(v: number) { if (typeof v == "number") { this.#a13 = v; @@ -558,17 +714,13 @@ class Mat4 { throw new TypeError("a13 should be a number"); } } + /** The element in column 1, row 3. Reads as 0 if the stored value is `NaN`. */ get a13() { return this.#a13 || 0; } - /** - * (getter/setter) The a14 value of the matrix. - * - * @type {number} - * @default 0 - */ #a14: number = 0; + /** Set the element in column 1, row 4. Throws a `TypeError` if `v` is not a number. */ set a14(v: number) { if (typeof v == "number") { this.#a14 = v; @@ -576,17 +728,13 @@ class Mat4 { throw new TypeError("a14 should be a number"); } } + /** The element in column 1, row 4. Reads as 0 if the stored value is `NaN`. */ get a14() { return this.#a14 || 0; } - /** - * (getter/setter) The a21 value of the matrix. - * - * @type {number} - * @default 0 - */ #a21: number = 0; + /** Set the element in column 2, row 1. Throws a `TypeError` if `v` is not a number. */ set a21(v: number) { if (typeof v == "number") { this.#a21 = v; @@ -594,17 +742,13 @@ class Mat4 { throw new TypeError("a21 should be a number"); } } + /** The element in column 2, row 1. Reads as 0 if the stored value is `NaN`. */ get a21() { return this.#a21 || 0; } - /** - * (getter/setter) The a22 value of the matrix. - * - * @type {number} - * @default 0 - */ #a22: number = 0; + /** Set the element in column 2, row 2. Throws a `TypeError` if `v` is not a number. */ set a22(v: number) { if (typeof v == "number") { this.#a22 = v; @@ -612,17 +756,13 @@ class Mat4 { throw new TypeError("a22 should be a number"); } } + /** The element in column 2, row 2. Reads as 0 if the stored value is `NaN`. */ get a22() { return this.#a22 || 0; } - /** - * (getter/setter) The a23 value of the matrix. - * - * @type {number} - * @default 0 - */ #a23: number = 0; + /** Set the element in column 2, row 3. Throws a `TypeError` if `v` is not a number. */ set a23(v: number) { if (typeof v == "number") { this.#a23 = v; @@ -630,17 +770,13 @@ class Mat4 { throw new TypeError("a23 should be a number"); } } + /** The element in column 2, row 3. Reads as 0 if the stored value is `NaN`. */ get a23() { return this.#a23 || 0; } - /** - * (getter/setter) The a24 value of the matrix. - * - * @type {number} - * @default 0 - */ #a24: number = 0; + /** Set the element in column 2, row 4. Throws a `TypeError` if `v` is not a number. */ set a24(v: number) { if (typeof v == "number") { this.#a24 = v; @@ -648,17 +784,13 @@ class Mat4 { throw new TypeError("a24 should be a number"); } } + /** The element in column 2, row 4. Reads as 0 if the stored value is `NaN`. */ get a24() { return this.#a24 || 0; } - /** - * (getter/setter) The a31 value of the matrix. - * - * @type {number} - * @default 0 - */ #a31: number = 0; + /** Set the element in column 3, row 1. Throws a `TypeError` if `v` is not a number. */ set a31(v: number) { if (typeof v == "number") { this.#a31 = v; @@ -666,17 +798,13 @@ class Mat4 { throw new TypeError("a31 should be a number"); } } + /** The element in column 3, row 1. Reads as 0 if the stored value is `NaN`. */ get a31() { return this.#a31 || 0; } - /** - * (getter/setter) The a32 value of the matrix. - * - * @type {number} - * @default 0 - */ #a32: number = 0; + /** Set the element in column 3, row 2. Throws a `TypeError` if `v` is not a number. */ set a32(v: number) { if (typeof v == "number") { this.#a32 = v; @@ -684,17 +812,13 @@ class Mat4 { throw new TypeError("a32 should be a number"); } } + /** The element in column 3, row 2. Reads as 0 if the stored value is `NaN`. */ get a32() { return this.#a32 || 0; } - /** - * (getter/setter) The a33 value of the matrix. - * - * @type {number} - * @default 0 - */ #a33: number = 0; + /** Set the element in column 3, row 3. Throws a `TypeError` if `v` is not a number. */ set a33(v: number) { if (typeof v == "number") { this.#a33 = v; @@ -702,17 +826,13 @@ class Mat4 { throw new TypeError("a33 should be a number"); } } + /** The element in column 3, row 3. Reads as 0 if the stored value is `NaN`. */ get a33() { return this.#a33 || 0; } - /** - * (getter/setter) The a34 value of the matrix. - * - * @type {number} - * @default 0 - */ #a34: number = 0; + /** Set the element in column 3, row 4. Throws a `TypeError` if `v` is not a number. */ set a34(v: number) { if (typeof v == "number") { this.#a34 = v; @@ -720,17 +840,13 @@ class Mat4 { throw new TypeError("a34 should be a number"); } } + /** The element in column 3, row 4. Reads as 0 if the stored value is `NaN`. */ get a34() { return this.#a34 || 0; } - /** - * (getter/setter) The a41 value of the matrix. - * - * @type {number} - * @default 0 - */ #a41: number = 0; + /** Set the element in column 4, row 1. The x translation. Throws a `TypeError` if `v` is not a number. */ set a41(v: number) { if (typeof v == "number") { this.#a41 = v; @@ -738,17 +854,13 @@ class Mat4 { throw new TypeError("a41 should be a number"); } } + /** The element in column 4, row 1. The x translation. Reads as 0 if the stored value is `NaN`. */ get a41() { return this.#a41 || 0; } - /** - * (getter/setter) The a42 value of the matrix. - * - * @type {number} - * @default 0 - */ #a42: number = 0; + /** Set the element in column 4, row 2. The y translation. Throws a `TypeError` if `v` is not a number. */ set a42(v: number) { if (typeof v == "number") { this.#a42 = v; @@ -756,17 +868,13 @@ class Mat4 { throw new TypeError("a42 should be a number"); } } + /** The element in column 4, row 2. The y translation. Reads as 0 if the stored value is `NaN`. */ get a42() { return this.#a42 || 0; } - /** - * (getter/setter) The a43 value of the matrix. - * - * @type {number} - * @default 0 - */ #a43: number = 0; + /** Set the element in column 4, row 3. The z translation. Throws a `TypeError` if `v` is not a number. */ set a43(v: number) { if (typeof v == "number") { this.#a43 = v; @@ -774,17 +882,13 @@ class Mat4 { throw new TypeError("a43 should be a number"); } } + /** The element in column 4, row 3. The z translation. Reads as 0 if the stored value is `NaN`. */ get a43() { return this.#a43 || 0; } - /** - * (getter/setter) The a44 value of the matrix. - * - * @type {number} - * @default 0 - */ #a44: number = 0; + /** Set the element in column 4, row 4. Throws a `TypeError` if `v` is not a number. */ set a44(v: number) { if (typeof v == "number") { this.#a44 = v; @@ -792,18 +896,26 @@ class Mat4 { throw new TypeError("a44 should be a number"); } } + /** The element in column 4, row 4. Reads as 0 if the stored value is `NaN`. */ get a44() { return this.#a44 || 0; } + /** The Frobenius norm: the square root of the sum of the squares of all 16 elements. */ get frobeniusnorm(): number { return Math.hypot(...this.array); } + /** The translation (`a41`, `a42`, `a43`), as a new {@link Vec3}. */ get translation(): Vec3 { return new Vec3(this.a41, this.a42, this.a43); } + /** + * The scale along each axis, as a new {@link Vec3}: the lengths of the first, + * second and third columns. Assumes there is no shear; values are always + * positive, so a negative scale (a mirror) is not recovered. + */ get scaling(): Vec3 { return new Vec3( Math.hypot(this.a11, this.a12, this.a13), @@ -812,6 +924,10 @@ class Mat4 { ); } + /** + * The rotation, as a new {@link Quat}, found by removing {@link Mat4.scaling} + * from the upper 3×3 part. Only reliable when the scale is uniform. + */ get rotation(): Quat { const scale = this.scaling.inverse(); @@ -866,9 +982,9 @@ class Mat4 { } /** - * Calculates the determinant function the mat4 - * - * @returns {Number} determinant of a + * The determinant of the matrix, along with the twelve 2×2 sub-determinants + * (`b00`–`b11`) that {@link Mat4.invert} reuses. Prefer {@link Mat4.determinant} + * unless you need the intermediate values. */ get determinantFunction(): Mat4DeterminantFunction { let b00 = this.a11 * this.a22 - this.a12 * this.a21; @@ -891,21 +1007,12 @@ class Mat4 { }; } - /** - * Calculates the determinant of the mat4 - * - * @returns {Number} determinant of a - */ + /** The determinant of the matrix. */ get determinant(): number { return this.determinantFunction.determinant; } - /** - * (getter) Returns the basic array representation of this matrix. - * @readonly - * - * @type {array} - */ + /** The 16 elements as a new array, in column-major order, ready to pass to WebGL. */ get array(): number[] { return [ this.a11, @@ -927,10 +1034,23 @@ class Mat4 { ]; } + /** + * Create a rotation matrix around an axis. See {@link Mat4.rotate}. + * + * @param r The angle, in radians. + * @param axis The axis to rotate around, as a {@link Vec3Like}. It is normalised for you; if its length is close to zero you get the identity matrix. + * @returns A new matrix. + */ static fromRotation(r: number, axis: any) { return new Mat4().rotate(r, axis); } + /** + * Create a matrix that rotates around the x axis (right-handed). + * + * @param r The angle, in radians. + * @returns A new matrix. + */ static fromXRotation(r: number) { const s = Math.sin(r), c = Math.cos(r); @@ -938,6 +1058,12 @@ class Mat4 { return new Mat4(1, 0, 0, 0, 0, c, s, 0, 0, -s, c, 0, 0, 0, 0, 1); } + /** + * Create a matrix that rotates around the y axis (right-handed). + * + * @param r The angle, in radians. + * @returns A new matrix. + */ static fromYRotation(r: number) { const s = Math.sin(r), c = Math.cos(r); @@ -945,6 +1071,12 @@ class Mat4 { return new Mat4(c, 0, -s, 0, 0, 1, 0, 0, s, 0, c, 0, 0, 0, 0, 1); } + /** + * Create a matrix that rotates around the z axis (right-handed). + * + * @param r The angle, in radians. + * @returns A new matrix. + */ static fromZRotation(r: number) { const s = Math.sin(r), c = Math.cos(r); @@ -952,22 +1084,34 @@ class Mat4 { return new Mat4(c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); } + /** + * Create a scale matrix. + * + * @param v The x, y and z scale factors. + * @returns A new matrix. + */ static fromScalingVec3(v: Vec3Like): Mat4 { const va = Array.isArray(v) ? v : [v.x, v.y, v.z]; return new Mat4(va[0], 0, 0, 0, 0, va[1], 0, 0, 0, 0, va[2], 0, 0, 0, 0, 1); } + /** + * Create a translation matrix. + * + * @param v The translation. + * @returns A new matrix. + */ static fromTranslatingVec3(v: Vec3Like): Mat4 { const va = Array.isArray(v) ? v : [v.x, v.y, v.z]; return new Mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, va[0], va[1], va[2], 1); } /** - * Calculates a 4x4 matrix from the given quaternion - * - * @param {quat} q Quaternion to create matrix from + * Create a rotation matrix from a quaternion. The quaternion should be + * normalised; it is not normalised for you. * - * @returns {mat4} out + * @param q The rotation, ordered x, y, z, w. + * @returns A new matrix. */ static fromQuat(q: QuatLike): Mat4 { const qa = Array.isArray(q) ? q : [q.x, q.y, q.z, q.w]; @@ -1005,20 +1149,20 @@ class Mat4 { } /** - * Creates a matrix from a quaternion rotation, vector translation and vector scale - * This is equivalent to (but much faster than): + * Create a matrix from a rotation, translation and scale. The result is + * `T × R × S`: points are scaled, then rotated, then translated. It gives the + * same result as the following, but faster: * - * mat4.identity(dest); - * mat4.translate(dest, vec); - * let quatMat = mat4.create(); - * quat4.toMat4(quat, quatMat); - * mat4.multiply(dest, quatMat); - * mat4.scale(dest, scale) + * ```ts + * Mat4.fromTranslatingVec3(v) + * .multiply(Mat4.fromQuat(q)) + * .scaleByVec3(s); + * ``` * - * @param {quat4} q Rotation quaternion - * @param {vec3} v Translation vector - * @param {vec3} s Scaling vector - * @returns {mat4} out + * @param q The rotation, as a normalised quaternion ordered x, y, z, w. + * @param v The translation. + * @param s The x, y and z scale factors. + * @returns A new matrix. */ static fromRotationTranslationScale(q: QuatLike, v: Vec3Like, s: Vec3Like): Mat4 { const qa = Array.isArray(q) ? q : [q.x, q.y, q.z, q.w]; @@ -1063,23 +1207,15 @@ class Mat4 { } /** - * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin - * This is equivalent to (but much faster than): + * Like {@link Mat4.fromRotationTranslationScale}, but rotates and scales + * around the point `o` rather than the origin. The result is + * `T(v) × T(o) × R × S × T(-o)`. * - * mat4.identity(dest); - * mat4.translate(dest, vec); - * mat4.translate(dest, origin); - * let quatMat = mat4.create(); - * quat4.toMat4(quat, quatMat); - * mat4.multiply(dest, quatMat); - * mat4.scale(dest, scale) - * mat4.translate(dest, negativeOrigin); - * - * @param {quat4} q Rotation quaternion - * @param {vec3} v Translation vector - * @param {vec3} s Scaling vector - * @param {vec3} o The origin vector around which to scale and rotate - * @returns {mat4} out + * @param q The rotation, as a normalised quaternion ordered x, y, z, w. + * @param v The translation. + * @param s The x, y and z scale factors. + * @param o The point to rotate and scale around. + * @returns A new matrix. */ static fromRotationTranslationScaleOrigin(q: QuatLike, v: Vec3Like, s: Vec3Like, o: Vec3Like): Mat4 { const qa = Array.isArray(q) ? q : [q.x, q.y, q.z, q.w]; @@ -1138,15 +1274,17 @@ class Mat4 { } /** - * Generates a frustum matrix with the given bounds + * Create a perspective projection matrix from the bounds of a frustum, as + * `glFrustum` does. Right-handed: the camera looks down -z. Maps depth to + * WebGL clip space, where z runs from -1 (near) to 1 (far). * - * @param {Number} left Left bound of the frustum - * @param {Number} right Right bound of the frustum - * @param {Number} bottom Bottom bound of the frustum - * @param {Number} top Top bound of the frustum - * @param {Number} near Near bound of the frustum - * @param {Number} far Far bound of the frustum - * @returns {mat4} out + * @param left The left edge of the near plane. + * @param right The right edge of the near plane. + * @param bottom The bottom edge of the near plane. + * @param top The top edge of the near plane. + * @param near The distance to the near plane. Must be positive. + * @param far The distance to the far plane. + * @returns A new matrix. */ static frustum(left: number, right: number, bottom: number, top: number, near: number, far: number) { const rl = 1 / (right - left), @@ -1177,14 +1315,15 @@ class Mat4 { } /** - * Generates a perspective projection matrix with the given bounds. - * Passing null/undefined/no value for far will generate infinite projection matrix. + * Create a perspective projection matrix. Right-handed: the camera looks + * down -z. Maps depth to WebGL clip space, where z runs from -1 (near) to + * 1 (far). * - * @param {number} fovy Vertical field of view in radians - * @param {number} aspect Aspect ratio. typically viewport width/height - * @param {number} near Near bound of the frustum - * @param {number} far Far bound of the frustum, can be null or Infinity - * @returns {mat4} out + * @param fovy The vertical field of view, in radians. + * @param aspect The aspect ratio, usually the viewport width divided by its height. + * @param near The distance to the near plane. Must be positive. + * @param far The distance to the far plane. Pass `Infinity` for an infinite far plane. + * @returns A new matrix. */ static perspective(fovy: number, aspect: number, near: number, far: number) { const f = 1.0 / Math.tan(fovy / 2); @@ -1226,15 +1365,17 @@ class Mat4 { } /** - * Generates a orthogonal projection matrix with the given bounds + * Create an orthographic projection matrix, as `glOrtho` does. Right-handed: + * the camera looks down -z. Maps the box to WebGL clip space, where x, y and + * z all run from -1 to 1. * - * @param {number} left Left bound of the frustum - * @param {number} right Right bound of the frustum - * @param {number} bottom Bottom bound of the frustum - * @param {number} top Top bound of the frustum - * @param {number} near Near bound of the frustum - * @param {number} far Far bound of the frustum - * @returns {mat4} out + * @param left The left edge of the view box. + * @param right The right edge of the view box. + * @param bottom The bottom edge of the view box. + * @param top The top edge of the view box. + * @param near The distance to the near plane. + * @param far The distance to the far plane. + * @returns A new matrix. */ static ortho(left: number, right: number, bottom: number, top: number, near: number, far: number) { const lr = 1 / (left - right), @@ -1265,13 +1406,19 @@ class Mat4 { } /** - * Generates a look-at matrix with the given eye position, focal point, and up axis. - * If you want a matrix that actually makes an object look at another object, you should use targetTo instead. + * Create a view matrix for a camera at `eye` looking at `center`. This is + * the inverse of the camera's world transform, for use as a view matrix; + * the camera looks down its -z axis. To point an object at a target, use + * {@link Mat4.targetTo} instead. + * + * If `eye` and `center` are (almost) the same point, returns the identity + * matrix. If `up` is parallel to the view direction, the x and y axes of the + * result are zero. * - * @param {vec3} eye Position of the viewer - * @param {vec3} center Point the viewer is looking at - * @param {vec3} up vec3 pointing up - * @returns {mat4} out + * @param eye The position of the camera. + * @param center The point the camera looks at. + * @param up The up direction. Does not need to be normalised. + * @returns A new matrix. */ static lookAt(eye: Vec3Like, center: Vec3Like, up: Vec3Like) { const ea = Array.isArray(eye) ? eye : [eye.x, eye.y, eye.z]; @@ -1349,12 +1496,18 @@ class Mat4 { } /** - * Generates a matrix that makes something look at something else. + * Create a world transform that places an object at `eye` with its -z axis + * pointing at `target` and its y axis towards `up`. This is the inverse of + * {@link Mat4.lookAt}. * - * @param {vec3} eye Position of the viewer - * @param {vec3} target Point the viewer is looking at - * @param {vec3} up vec3 pointing up - * @returns {mat4} out + * If `eye` and `target` are the same point, the object faces down -z. If + * `up` is parallel to the view direction, it is nudged slightly so the + * result is still valid. + * + * @param eye The position of the object. + * @param target The point the object faces. + * @param up The up direction. Does not need to be normalised. + * @returns A new matrix. */ static targetTo(eye: Vec3Like, target: Vec3Like, up: Vec3Like) { const ea = Array.isArray(eye) ? eye : [eye.x, eye.y, eye.z]; @@ -1420,24 +1573,10 @@ class Mat4 { 1 ); } - - /** - * Adds iteration to the object, allowing it - * to be destructured and iterated upon in - * various useful ways. - */ - [Symbol.iterator]() { - let values = this.array; - let index = 0; - return { - next() { - if (index < values.length) { - let value = values[index]; - index++; - return { value, done: false }; - } else return { done: true } - } - } + + /** Iterate over the elements in column-major order, so the matrix can be spread: `[...m]`. */ + [Symbol.iterator](): Iterator { + return this.array[Symbol.iterator](); } } diff --git a/src/Plane.ts b/src/Plane.ts index 0645b92..a9f7fa7 100644 --- a/src/Plane.ts +++ b/src/Plane.ts @@ -1,19 +1,57 @@ +/** + * An infinite plane in 3D space, stored as a normal and a constant so that + * points on the plane satisfy `normal · p + constant = 0`. Imported + * separately from the rest of wtc-math: + * + * ```ts + * import { Plane } from 'wtc-math/plane' + * ``` + * + * @module wtc-math/plane + */ import { Vec3 } from "./Vec3.js"; import type { Vec3Like } from "./types.js"; +/** + * An infinite plane defined by `normal · p + constant = 0`. + * + * Distances are only true distances when `normal` is unit length. The + * constructor does not normalise it; {@link Plane.fromNormalAndPoint} and + * {@link Plane.fromPoints} do, and {@link Plane.normalize} fixes an existing + * plane. + */ class Plane { + /** The plane's normal. Points on its side have a positive signed distance. */ normal: Vec3; + /** The plane constant: the signed distance from the plane to the world origin, for a unit normal. */ constant: number; + /** + * Creates a plane from a normal and constant. Neither is normalised. + * + * @param normal The plane normal. Defaults to `(0, 1, 0)`. + * @param constant The plane constant. Defaults to `0`, a plane through the origin. + */ constructor(normal: Vec3Like = new Vec3(0, 1, 0), constant = 0) { this.normal = Vec3.interpolate(normal); this.constant = constant; } + /** + * Copies this plane. + * + * @returns A new plane with a copy of the normal and the same constant. + */ clone(): Plane { return new Plane(this.normal.clone(), this.constant); } + /** + * Scales the normal to unit length and the constant by the same factor, so + * the plane stays in place. Modifies this plane. + * + * @returns This plane. + */ normalize(): Plane { const inv = 1 / this.normal.length; this.normal.multiplyScalar(inv); @@ -21,25 +59,52 @@ class Plane { return this; } + /** + * Flips the plane to face the other way by negating the normal and the + * constant. Modifies this plane. + * + * @returns This plane. + */ negate(): Plane { this.normal.negate(); this.constant = -this.constant; return this; } - // Signed distance — positive on the normal side, negative on the other + /** + * Signed distance from the plane to a point: positive on the normal side, + * negative on the other, zero on the plane. Scaled by the normal's length if + * it is not unit length. + * + * @param point The point to measure. + * @returns `normal · point + constant`. + */ distanceTo(point: Vec3Like): number { const p = Vec3.interpolate(point); return this.normal.dot(p) + this.constant; } - // Projects a point onto the plane surface + /** + * Projects a point onto the plane surface along the normal. Assumes a unit + * normal. + * + * @param point The point to project. + * @returns A new {@link Vec3} on the plane. + */ projectPoint(point: Vec3Like): Vec3 { const p = Vec3.interpolate(point); return p.subtractNew(this.normal.multiplyScalarNew(this.distanceTo(p))); } - // Returns intersection point along the line segment [start, end], or null if none + /** + * Finds where the line segment from `start` to `end` crosses the plane. + * Only hits within the segment count. + * + * @param start The start of the segment. + * @param end The end of the segment. + * @returns A new {@link Vec3} at the crossing, or `null` if the segment does + * not reach the plane or runs parallel to it. + */ intersectLine(start: Vec3Like, end: Vec3Like): Vec3 | null { const s = Vec3.interpolate(start); const e = Vec3.interpolate(end); @@ -51,12 +116,30 @@ class Plane { return s.addNew(d.multiplyScalar(t)); } + /** + * Creates a plane with the given normal passing through a point. The normal + * is normalised. + * + * @param normal The plane normal. + * @param point Any point on the plane. + * @returns A new plane. + */ static fromNormalAndPoint(normal: Vec3Like, point: Vec3Like): Plane { const n = Vec3.interpolate(normal).normalise(); const p = Vec3.interpolate(point); return new Plane(n, -n.dot(p)); } + /** + * Creates the plane through three points. The unit normal is + * `(b − a) × (c − a)`, so it faces the side from which `a`, `b`, `c` run + * anticlockwise. + * + * @param a The first point. + * @param b The second point. + * @param c The third point. + * @returns A new plane. + */ static fromPoints(a: Vec3Like, b: Vec3Like, c: Vec3Like): Plane { const va = Vec3.interpolate(a); const vb = Vec3.interpolate(b); diff --git a/src/Quat.ts b/src/Quat.ts index 8227f71..d5058a6 100644 --- a/src/Quat.ts +++ b/src/Quat.ts @@ -13,12 +13,35 @@ const orDefault = function (v: any, ident: string): number { return isNaN(v) ? identity[identToIndex(ident)] : Number(v); }; +/** + * A quaternion for representing 3D rotations, stored as x, y, z and w where + * w is the scalar (real) part. + * + * Quat extends {@link Vec4}, so it inherits the component-wise vector methods + * (`add`, `scale`, `normalise`, swizzles and so on). Multiplication, the axis + * rotations, `dot`, `clone` and `reset` are overridden with quaternion + * behaviour. Note that the inherited `inverse` is the component-wise + * reciprocal; use {@link Quat.invert} for the quaternion inverse. + */ class Quat extends Vec4 implements V4Q { + /** + * Create a new quaternion. Missing or `NaN` components default to the + * identity quaternion `(0, 0, 0, 1)`, so `new Quat()` is the identity. + * + * @param args The x, y, z and w components, in that order. + */ constructor(...args: number[]) { super(...args); this.reset(...args); } + /** + * Set the components in place. Missing or `NaN` components are taken from + * the identity quaternion: x, y and z become 0 and w becomes 1. + * + * @param args The x, y, z and w components, in that order. + * @returns This quaternion, for chaining. + */ reset(...args: number[]): V4Q { let [x, y, z, w] = args; this.x = orDefault(x, "x"); @@ -29,6 +52,13 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Copy the x, y, z and w components of another quaternion or vector into + * this one, in place. + * + * @param q The quaternion to copy from. + * @returns This quaternion, for chaining. + */ resetToQuat(q: V4Q): Quat { this.x = q.x; this.y = q.y; @@ -38,14 +68,31 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Create a copy of this quaternion. + * + * @returns A new Quat with the same components. + */ clone(): V4Q { return new Quat(this.x, this.y, this.z, this.w); } + /** + * The components as a comma-separated string. + * + * @returns A string in the form `"x, y, z, w"`. + */ toString() { return `${this.x}, ${this.y}, ${this.z}, ${this.w}`; } + /** + * Multiply this quaternion by another (the Hamilton product `this × q`), + * in place. The result applies the rotation `q` first, then this one. + * + * @param q The quaternion to multiply by, on the right. + * @returns This quaternion, for chaining. + */ multiply(q: V4Q): V4Q { const a = this.clone(); @@ -57,10 +104,25 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Like `multiply`, but returns a new quaternion and leaves this one + * unchanged. + * + * @param q The quaternion to multiply by, on the right. + * @returns A new Quat holding `this × q`. + */ multiplyNew(q: V4Q): V4Q { return this.clone().multiply(q); } + /** + * Rotate this quaternion around its local X axis, in place. Equivalent to + * multiplying on the right by a quaternion of `rad` radians about X. + * + * @param origin Ignored. Present to match the {@link Vec4.rotateX} signature. + * @param rad The angle in radians. + * @returns This quaternion, for chaining. + */ rotateX(origin: V4Q, rad: number): V4Q { rad *= 0.5; @@ -76,6 +138,14 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Rotate this quaternion around its local Y axis, in place. Equivalent to + * multiplying on the right by a quaternion of `rad` radians about Y. + * + * @param origin Ignored. Present to match the {@link Vec4.rotateY} signature. + * @param rad The angle in radians. + * @returns This quaternion, for chaining. + */ rotateY(origin: V4Q, rad: number): V4Q { rad *= 0.5; @@ -91,6 +161,14 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Rotate this quaternion around its local Z axis, in place. Equivalent to + * multiplying on the right by a quaternion of `rad` radians about Z. + * + * @param origin Ignored. Present to match the {@link Vec4.rotateZ} signature. + * @param rad The angle in radians. + * @returns This quaternion, for chaining. + */ rotateZ(origin: V4Q, rad: number): V4Q { rad *= 0.5; @@ -106,10 +184,24 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * The dot product of this quaternion and another. For unit quaternions this + * is the cosine of half the angle between the two rotations; its sign shows + * whether they lie in the same hemisphere. + * + * @param q The other quaternion. + * @returns The sum of the products of the matching components. + */ dot(q: V4Q): number { return this.x * q.x + this.y * q.y + this.z * q.z + this.w * q.w; } + /** + * Conjugate the quaternion in place by negating x, y and z. For a unit + * quaternion this is the inverse rotation. + * + * @returns This quaternion, for chaining. + */ conjugate(): Quat { this.x = -this.x; this.y = -this.y; @@ -117,10 +209,23 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Like `conjugate`, but returns a new quaternion and leaves this one + * unchanged. + * + * @returns A new, conjugated Quat. + */ conjugateNew(): Quat { return (this.clone() as Quat).conjugate(); } + /** + * Invert the quaternion in place: the conjugate divided by the squared + * length. Works for quaternions that are not normalised. A zero quaternion + * is left unchanged. + * + * @returns This quaternion, for chaining. + */ invert(): Quat { const dot = this.dot(this); if (dot === 0) return this; @@ -132,31 +237,51 @@ class Quat extends Vec4 implements V4Q { return this; } + /** + * Like `invert`, but returns a new quaternion and leaves this one unchanged. + * + * @returns A new, inverted Quat. + */ invertNew(): Quat { return (this.clone() as Quat).invert(); } + // Getters and setters + /** - * Getters and setters + * The w component a unit quaternion would have, given this one's x, y and z: + * `sqrt(|1 - x² - y² - z²|)`. Always 0 or positive. Does not read or change + * the stored w. Read-only. */ - - // Gets the calculated W component of this quaternion. get normalW(): number { return Math.sqrt( Math.abs(1.0 - this.x * this.x - this.y * this.y - this.z * this.z) ); } + // Static methods + /** - * Static methods + * Create an identity quaternion, `(0, 0, 0, 1)`, which represents no + * rotation. + * + * @returns A new Quat. */ - static identity(): Quat { return new Quat(0, 0, 0, 1); } /** - * Spherical linear interpolation between two quaternions. + * Spherical linear interpolation between two quaternions. Takes the + * shortest path: if the dot product is negative, `q2` is negated first. + * When the quaternions are nearly equal (`1 - dot` at or below 1e-6) it + * falls back to linear interpolation. `t` is not clamped, and the inputs + * should be normalised; the result is not normalised afterwards. + * + * @param q1 The start rotation, returned when `t` is 0. + * @param q2 The end rotation, returned (or its negation) when `t` is 1. + * @param t The interpolation amount, usually from 0 to 1. + * @returns A new Quat. */ static slerp(q1: Quat, q2: Quat, t: number): Quat { let dot = q1.dot(q2); @@ -189,13 +314,15 @@ class Quat extends Vec4 implements V4Q { } /** - * Creates a quaternion from a given axis and rotation + * Create a quaternion that rotates by an angle around an axis. The result + * is `(axis * sin(rad / 2), cos(rad / 2))` in x, y, z, w order. The axis is + * not normalised for you: pass a unit vector to get a unit quaternion. * - * @static - * @param {Vec3|Array} axis the axis around which to rotate - * @param {Number} rad the angle in radians - * @returns {Quat} - **/ + * @param axis The axis to rotate around, as a Vec3 or `[x, y, z]` array. + * Should be normalised. + * @param rad The angle in radians. + * @returns A new Quat. + */ static fromAxisAngle(axis: Vec3, rad: number): Quat { axis = Vec3.interpolate(axis); rad *= 0.5; @@ -203,6 +330,21 @@ class Quat extends Vec4 implements V4Q { return new Quat(s * axis.x, s * axis.y, s * axis.z, Math.cos(rad)); } + /** + * Create a quaternion from Euler angles in radians. + * + * The order string names the axes in the order the rotation matrices are + * multiplied, matching three.js: `"XYZ"` gives `Rx × Ry × Rz`, which is an + * intrinsic rotation about X, then the new Y, then the new Z (or extrinsic + * Z, then Y, then X). Supported orders are `"XYZ"`, `"YXZ"`, `"ZXY"`, + * `"ZYX"`, `"YZX"` and `"XZY"`; any other string returns the identity + * quaternion. + * + * @param euler The angles around the X, Y and Z axes, in radians, as a Vec3 + * or `[x, y, z]` array. + * @param order The rotation order. + * @returns A new Quat. + */ static fromEuler(euler: Vec3Like, order: string = "YXZ"): Quat { const ea = Array.isArray(euler) ? euler : [euler.x, euler.y, euler.z]; const out = new Quat(); diff --git a/src/Ray.ts b/src/Ray.ts index 2276e68..dea7f1b 100644 --- a/src/Ray.ts +++ b/src/Ray.ts @@ -1,12 +1,34 @@ +/** + * A ray in 3D space, with intersection tests against planes, spheres and + * axis-aligned boxes. Imported separately from the rest of wtc-math: + * + * ```ts + * import { Ray } from 'wtc-math/ray' + * ``` + * + * @module wtc-math/ray + */ import { Vec3 } from "./Vec3.js"; import type { Vec3Like } from "./types.js"; import { Plane } from "./Plane.js"; +/** + * A half-line starting at `origin` and extending forever along `direction`. + * Intersection methods return the nearest hit point in front of the origin, + * or `null` if there is none. + */ class Ray { + /** The point the ray starts from. */ origin: Vec3; + /** The unit direction the ray travels in. */ direction: Vec3; - // direction is normalized on construction + /** + * Creates a ray. The direction is normalised on construction. + * + * @param origin The start point. Defaults to `(0, 0, 0)`. + * @param direction The direction of travel. Defaults to `(0, 0, -1)`. + */ constructor( origin: Vec3Like = new Vec3(0, 0, 0), direction: Vec3Like = new Vec3(0, 0, -1) @@ -15,16 +37,32 @@ class Ray { this.direction = Vec3.interpolate(direction).normalise(); } + /** + * Copies this ray. + * + * @returns A new ray with copies of the origin and direction. + */ clone(): Ray { return new Ray(this.origin.clone(), this.direction.clone()); } - // Point along the ray at parameter t + /** + * Gets the point at distance `t` along the ray. + * + * @param t Distance from the origin. Negative values give points behind it. + * @returns A new {@link Vec3}: `origin + direction * t`. + */ at(t: number): Vec3 { return this.origin.addNew(this.direction.multiplyScalarNew(t)); } - // Shortest distance from the ray to a point + /** + * Shortest distance from the ray to a point. Points behind the origin are + * measured to the origin. + * + * @param point The point to measure. + * @returns The distance. + */ distanceTo(point: Vec3Like): number { const p = Vec3.interpolate(point); const diff = p.subtractNew(this.origin); @@ -32,13 +70,26 @@ class Ray { return diff.subtractNew(this.direction.multiplyScalarNew(t)).length; } - // Closest point on the ray to a given point + /** + * Closest point on the ray to a given point. For points behind the origin + * this is the origin. + * + * @param point The point to test. + * @returns A new {@link Vec3} on the ray. + */ closestPoint(point: Vec3Like): Vec3 { const p = Vec3.interpolate(point); const t = Math.max(0, p.subtractNew(this.origin).dot(this.direction)); return this.at(t); } + /** + * Intersects the ray with a plane. + * + * @param plane The plane to test. + * @returns A new {@link Vec3} where the ray meets the plane, or `null` if + * the ray is parallel to the plane or the plane is behind the origin. + */ intersectPlane(plane: Plane): Vec3 | null { const denom = plane.normal.dot(this.direction); if (Math.abs(denom) < 1e-6) return null; @@ -47,6 +98,15 @@ class Ray { return this.at(t); } + /** + * Intersects the ray with a sphere. If the origin is inside the sphere, + * returns the exit point. + * + * @param center The centre of the sphere. + * @param radius The radius of the sphere. + * @returns A new {@link Vec3} at the nearest hit in front of the origin, or + * `null` if the ray misses or the sphere is behind it. + */ intersectSphere(center: Vec3Like, radius: number): Vec3 | null { const c = Vec3.interpolate(center); const oc = this.origin.subtractNew(c); @@ -60,7 +120,15 @@ class Ray { return this.at(t); } - // AABB intersection via the slab method — Infinity arithmetic handles axis-aligned rays correctly + /** + * Intersects the ray with an axis-aligned box using the slab method. + * Rays parallel to an axis are handled through `Infinity` arithmetic. + * + * @param min The box corner with the smallest x, y and z. + * @param max The box corner with the largest x, y and z. + * @returns A new {@link Vec3} where the ray enters the box, or `null` if it + * misses, the box is behind it, or the origin is inside the box. + */ intersectBox(min: Vec3Like, max: Vec3Like): Vec3 | null { const lo = Vec3.interpolate(min); const hi = Vec3.interpolate(max); diff --git a/src/Utils.ts b/src/Utils.ts index a3ed848..0074110 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,9 +1,43 @@ +/** + * Clamps a value to a range. + * + * @param v The value to clamp. + * @param min The lower bound. + * @param max The upper bound. + * @returns `v` limited to `[min, max]`. + */ export const clamp = (v: number, min: number, max: number): number => Math.min(Math.max(v, min), max); +/** + * Linearly interpolates between two numbers. `t` is not clamped, so values + * outside 0–1 extrapolate. + * + * @param a The value at `t = 0`. + * @param b The value at `t = 1`. + * @param t The interpolation factor. + * @returns `a + (b - a) * t`. + */ export const lerp = (a: number, b: number, t: number): number => a + (b - a) * t; +/** + * Re-maps a value from one range to another. The result is not clamped, so + * values outside the input range map outside the output range. + * + * @param v The value to re-map. + * @param inMin The start of the input range. + * @param inMax The end of the input range. + * @param outMin The start of the output range. + * @param outMax The end of the output range. + * @returns `v` moved proportionally from `[inMin, inMax]` to `[outMin, outMax]`. + * + * @example + * ```ts + * map(5, 0, 10, 100, 200) // 150 + * map(0.25, 0, 1, -1, 1) // -0.5 + * ``` + */ export const map = ( v: number, inMin: number, @@ -12,20 +46,81 @@ export const map = ( outMax: number ): number => outMin + ((v - inMin) / (inMax - inMin)) * (outMax - outMin); +/** + * Hermite interpolation between two edges, as GLSL's `smoothstep`. Returns 0 + * at or below `edge0`, 1 at or above `edge1`, and an S-curve + * (`3t² − 2t³`) in between. + * + * @param edge0 The input value that maps to 0. + * @param edge1 The input value that maps to 1. + * @param x The input value. + * @returns A value in 0–1. + * + * @example + * ```ts + * smoothstep(0, 10, 5) // 0.5 + * smoothstep(0, 10, 2) // 0.104 + * smoothstep(0, 10, 12) // 1 + * ``` + */ export const smoothstep = (edge0: number, edge1: number, x: number): number => { const t = clamp((x - edge0) / (edge1 - edge0), 0, 1); return t * t * (3 - 2 * t); }; +/** + * Ken Perlin's smoother variant of {@link smoothstep}, using + * `6t⁵ − 15t⁴ + 10t³` so the first and second derivatives are zero at both + * edges. + * + * @param edge0 The input value that maps to 0. + * @param edge1 The input value that maps to 1. + * @param x The input value. + * @returns A value in 0–1. + * + * @example + * ```ts + * smootherstep(0, 10, 5) // 0.5 + * smootherstep(0, 10, 2) // 0.058 + * ``` + */ export const smootherstep = (edge0: number, edge1: number, x: number): number => { const t = clamp((x - edge0) / (edge1 - edge0), 0, 1); return t * t * t * (t * (t * 6 - 15) + 10); }; +/** + * Converts degrees to radians. + * + * @param deg The angle in degrees. + * @returns The angle in radians. + */ export const degToRad = (deg: number): number => deg * (Math.PI / 180); +/** + * Converts radians to degrees. + * + * @param rad The angle in radians. + * @returns The angle in degrees. + */ export const radToDeg = (rad: number): number => rad * (180 / Math.PI); +/** + * Bounces a value back and forth between 0 and `length`: it rises from 0 to + * `length` as `t` goes from 0 to `length`, then falls back to 0 by + * `2 * length`, and repeats. Expects `t` to be 0 or more. + * + * @param t The input value, such as elapsed time. + * @param length The peak value. + * @returns A value in `[0, length]`. + * + * @example + * ```ts + * pingpong(0.5, 1) // 0.5 + * pingpong(1.5, 1) // 0.5 + * pingpong(2.25, 1) // 0.25 + * ``` + */ export const pingpong = (t: number, length: number): number => { const mod = t % (length * 2); return mod < length ? mod : length * 2 - mod; diff --git a/src/Vec2.ts b/src/Vec2.ts index 08b09fc..047ccf1 100644 --- a/src/Vec2.ts +++ b/src/Vec2.ts @@ -2,35 +2,32 @@ import { radianToDegrees, degreesToRadian } from "./common.js"; import type { Vec2Like, Mat2Like, Mat3Like } from "./types.js"; /** - * A basic 2D Vector class that provides simple algebraic functionality in the form - * of 2D Vectors. + * A 2D vector with x and y components. * - * We use Getters/setters for both principle properties (x & y) as well as virtual - * properties (rotation, length etc.). + * Most operations come in two forms: the plain method changes this vector in + * place and returns it for chaining, and the `…New` variant returns a new + * vector and leaves this one unchanged. Length, angle and the swizzles + * (`xy`, `yx`, `xx`, `yy`) are exposed as getters and setters. * - * @class Vec2 * @author Liam Egan * @version 1.0.0 * @created Jan 07, 2020 */ class Vec2 { /** - * The Vector Class constructor + * Create a vector. Missing or `NaN` components default to 0. * - * @constructor - * @chainable - * @param args The x and y coordinates + * @param args The x and y components */ constructor(...args: number[]) { this.reset(...args); } /** - * Resets the vector coordinates + * Set the components in place. Missing or `NaN` components are set to 0. * - * @public - * @chainable - * @param args The x and y coordinates + * @param args The x and y components + * @returns This vector, for chaining */ reset(...args: number[]): Vec2 { let [x, y] = args; @@ -42,11 +39,10 @@ class Vec2 { } /** - * Resets the vector coordinates to another vector object + * Copy the components of another vector into this one. * - * @public - * @chainable - * @param {Vector} v The vector object to use to reset the coordinates + * @param v The vector to copy from + * @returns This vector, for chaining */ resetToVector(v: Vec2): Vec2 { this.x = v.x; @@ -55,23 +51,19 @@ class Vec2 { } /** - * Clones the vector + * Create a copy of this vector. * - * @public - * @chainable - * @return {Vector} The cloned vector + * @returns A new vector with the same components */ clone(): Vec2 { return new Vec2(this.x, this.y); } /** - * Adds one vector to another. + * Add another vector to this one, in place. * - * @public - * @chainable - * @param {Vec2} vector The vector to add to this one - * @return {Vec2} Returns itself, modified + * @param vector The vector to add + * @returns This vector, for chaining */ add(vector: Vec2): Vec2 { this.x += vector.x; @@ -79,47 +71,39 @@ class Vec2 { return this; } /** - * Clones the vector and adds the vector to it instead + * Like {@link Vec2.add}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec2} vector The vector to add to this one - * @return {Vec2} Returns the clone of itself, modified + * @param vector The vector to add + * @returns A new vector */ addNew(vector: Vec2): Vec2 { return this.clone().add(vector); } /** - * Adds a scalar to the vector, modifying both the x and y + * Add a scalar to both components, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec2} Returns itself, modified + * @param scalar The value to add to x and y + * @returns This vector, for chaining */ addScalar(scalar: number): Vec2 { return this.add(new Vec2(scalar, scalar)); } /** - * Clones the vector and adds the scalar to it instead + * Like {@link Vec2.addScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec2} Returns the clone of itself, modified + * @param scalar The value to add to x and y + * @returns A new vector */ addScalarNew(scalar: number): Vec2 { return this.clone().addScalar(scalar); } /** - * Subtracts one vector from another. + * Subtract another vector from this one, in place. * - * @public - * @chainable - * @param {Vec2} vector The vector to subtract from this one - * @return {Vec2} Returns itself, modified + * @param vector The vector to subtract + * @returns This vector, for chaining */ subtract(vector: Vec2): Vec2 { this.x -= vector.x; @@ -127,47 +111,40 @@ class Vec2 { return this; } /** - * Clones the vector and subtracts the vector from it instead + * Like {@link Vec2.subtract}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec2} vector The vector to subtract from this one - * @return {Vec2} Returns the clone of itself, modified + * @param vector The vector to subtract + * @returns A new vector */ subtractNew(vector: Vec2): Vec2 { return this.clone().subtract(vector); } /** - * Subtracts a scalar from the vector, modifying both the x and y + * Subtract a scalar from both components, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to subtract from the vector - * @return {Vec2} Returns itself, modified + * @param scalar The value to subtract from x and y + * @returns This vector, for chaining */ subtractScalar(scalar: number): Vec2 { return this.subtract(new Vec2(scalar, scalar)); } /** - * Clones the vector and subtracts the scalar from it instead + * Like {@link Vec2.subtractScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec2} Returns the clone of itself, modified + * @param scalar The value to subtract from x and y + * @returns A new vector */ subtractScalarNew(scalar: number): Vec2 { return this.clone().subtractScalar(scalar); } /** - * Divides one vector by another. + * Divide this vector component-wise by another, in place. Dividing a + * component by 0 sets that component to 0. * - * @public - * @chainable - * @param {Vec2} vector The vector to divide this by - * @return {Vec2} Returns itself, modified + * @param vector The vector to divide by + * @returns This vector, for chaining */ divide(vector: Vec2): Vec2 { if (vector.x !== 0) { @@ -183,48 +160,41 @@ class Vec2 { return this; } /** - * Clones the vector and divides it by the vector instead + * Like {@link Vec2.divide}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec2} vector The vector to divide the clone by - * @return {Vec2} Returns the clone of itself, modified + * @param vector The vector to divide by + * @returns A new vector */ divideNew(vector: Vec2): Vec2 { return this.clone().divide(vector); } /** - * Divides the vector by a scalar. + * Divide both components by a scalar, in place. Dividing by 0 sets both + * components to 0. * - * @public - * @chainable - * @param {number} scalar The scalar to divide both x and y by - * @return {Vec2} Returns itself, modified + * @param scalar The value to divide x and y by + * @returns This vector, for chaining */ divideScalar(scalar: number): Vec2 { var v = new Vec2(scalar, scalar); return this.divide(v); } /** - * Clones the vector and divides it by the provided scalar. + * Like {@link Vec2.divideScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to divide both x and y by - * @return {Vec2} Returns the clone of itself, modified + * @param scalar The value to divide x and y by + * @returns A new vector */ divideScalarNew(scalar: number): Vec2 { return this.clone().divideScalar(scalar); } /** - * Multiplies one vector by another. + * Multiply this vector component-wise by another, in place. * - * @public - * @chainable - * @param {Vec2} vector The vector to multiply this by - * @return {Vec2} Returns itself, modified + * @param vector The vector to multiply by + * @returns This vector, for chaining */ multiply(vector: Vec2): Vec2 { this.x *= vector.x; @@ -232,61 +202,60 @@ class Vec2 { return this; } /** - * Clones the vector and multiplies it by the vector instead + * Like {@link Vec2.multiply}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec2} vector The vector to multiply the clone by - * @return {Vec2} Returns the clone of itself, modified + * @param vector The vector to multiply by + * @returns A new vector */ multiplyNew(vector: Vec2): Vec2 { return this.clone().multiply(vector); } /** - * Multiplies the vector by a scalar. + * Multiply both components by a scalar, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to multiply both x and y by - * @return {Vec2} Returns itself, modified + * @param scalar The value to multiply x and y by + * @returns This vector, for chaining */ multiplyScalar(scalar: number): Vec2 { var v = new Vec2(scalar, scalar); return this.multiply(v); } /** - * Clones the vector and multiplies it by the provided scalar. + * Like {@link Vec2.multiplyScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to multiply both x and y by - * @return {Vec2} Returns the clone of itself, modified + * @param scalar The value to multiply x and y by + * @returns A new vector */ multiplyScalarNew(scalar: number): Vec2 { return this.clone().multiplyScalar(scalar); } /** - * Alias of {@link multiplyScalar} + * Alias of {@link Vec2.multiplyScalar}. Scales the vector in place. + * + * @param scalar The value to multiply x and y by + * @returns This vector, for chaining */ scale(scalar: number): Vec2 { return this.multiplyScalar(scalar); } /** - * Alias of {@link multiplyScalarNew} + * Alias of {@link Vec2.multiplyScalarNew}. Returns a new scaled vector. + * + * @param scalar The value to multiply x and y by + * @returns A new vector */ scaleNew(scalar: number): Vec2 { return this.multiplyScalarNew(scalar); } /** - * Rotates a vecor by a given amount, provided in radians. + * Rotate the vector anticlockwise about the origin by an angle in radians, + * in place. * - * @public - * @chainable - * @param {number} radian The angle, in radians, to rotate the vector by - * @return {Vec2} Returns itself, modified + * @param radian The angle to rotate by, in radians + * @returns This vector, for chaining */ rotate(radian: number): Vec2 { var x = this.x * Math.cos(radian) - this.y * Math.sin(radian); @@ -298,142 +267,135 @@ class Vec2 { return this; } /** - * Clones the vector and rotates it by the supplied radian value + * Like {@link Vec2.rotate}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} radian The angle, in radians, to rotate the vector by - * @return {Vec2} Returns the clone of itself, modified + * @param radian The angle to rotate by, in radians + * @returns A new vector */ rotateNew(radian: number): Vec2 { return this.clone().rotate(radian); } /** - * Rotates a vecor by a given amount, provided in degrees. Converts the degree - * value to radians and runs the rotaet method. + * Rotate the vector by an angle in degrees, in place. * - * @public - * @chainable - * @param {number} degrees The angle, in degrees, to rotate the vector by - * @return {Vec2} Returns itself, modified + * @param degrees The angle to rotate by, in degrees + * @returns This vector, for chaining */ rotateDeg(degrees: number): Vec2 { return this.rotate(degreesToRadian(degrees)); } /** - * Clones the vector and rotates it by the supplied degree value + * Like {@link Vec2.rotateDeg}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} degrees The angle, in degrees, to rotate the vector by - * @return {Vec2} Returns the clone of itself, modified + * @param degrees The angle to rotate by, in degrees + * @returns A new vector */ rotateDegNew(degrees: number): Vec2 { return this.rotateNew(degreesToRadian(degrees)); } /** - * Alias of {@link rotate} + * Alias of {@link Vec2.rotate}. Rotates in place by an angle in radians. + * + * @param radian The angle to rotate by, in radians + * @returns This vector, for chaining */ rotateBy(radian: number): Vec2 { return this.rotate(radian); } /** - * Alias of {@link rotateNew} + * Alias of {@link Vec2.rotateNew}. Returns a new vector rotated by an angle in radians. + * + * @param radian The angle to rotate by, in radians + * @returns A new vector */ rotateByNew(radian: number): Vec2 { return this.rotateNew(radian); } /** - * Alias of {@link rotateDeg} + * Alias of {@link Vec2.rotateDeg}. Rotates in place by an angle in degrees. + * + * @param degrees The angle to rotate by, in degrees + * @returns This vector, for chaining */ rotateDegBy(degrees: number): Vec2 { return this.rotateDeg(degrees); } /** - * Alias of {@link rotateDegNew} + * Alias of {@link Vec2.rotateDegNew}. Returns a new vector rotated by an angle in degrees. + * + * @param radian The angle to rotate by, in degrees (despite the parameter name) + * @returns A new vector */ rotateDegByNew(radian: number): Vec2 { return this.rotateDegNew(radian); } /** - * Rotates a vector to a specific angle + * Rotate the vector so it points at an absolute angle in radians, keeping + * its length, in place. * - * @public - * @chainable - * @param {number} radian The angle, in radians, to rotate the vector to - * @return {Vec2} Returns itself, modified + * @param radian The target angle, in radians, measured from the positive x axis + * @returns This vector, for chaining */ rotateTo(radian: number): Vec2 { return this.rotate(radian - this.angle); } /** - * Clones the vector and rotates it to the supplied radian value + * Like {@link Vec2.rotateTo}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} radian The angle, in radians, to rotate the vector to - * @return {Vec2} Returns the clone of itself, modified + * @param radian The target angle, in radians + * @returns A new vector */ rotateToNew(radian: number): Vec2 { return this.clone().rotateTo(radian); } /** - * Rotates a vecor to a given amount, provided in degrees. Converts the degree - * value to radians and runs the rotateTo method. + * Rotate the vector so it points at an absolute angle in degrees, keeping + * its length, in place. * - * @public - * @chainable - * @param {number} degrees The angle, in degrees, to rotate the vector to - * @return {Vec2} Returns itself, modified + * @param degrees The target angle, in degrees, measured from the positive x axis + * @returns This vector, for chaining */ rotateToDeg(degrees: number): Vec2 { return this.rotateTo(degreesToRadian(degrees)); } /** - * Clones the vector and rotates it to the supplied degree value + * Like {@link Vec2.rotateToDeg}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} degrees The angle, in degrees, to rotate the vector to - * @return {Vec2} Returns the clone of itself, modified + * @param degrees The target angle, in degrees + * @returns A new vector */ rotateToDegNew(degrees: number): Vec2 { return this.rotateToNew(degreesToRadian(degrees)); } /** - * Negates the vector. + * Negate both components, in place. * - * @public - * @chainable - * @return {Vec2} Returns itself, modified + * @returns This vector, for chaining */ negate(): Vec2 { return this.multiplyScalar(-1); } /** - * Clones the vector and negates it. + * Like {@link Vec2.negate}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec2} Returns itself, modified + * @returns A new vector */ negateNew(): Vec2 { return this.multiplyScalarNew(-1); } /** - * Inverses the vector. + * Replace each component with its reciprocal (`1 / x`, `1 / y`), in place. + * A zero component becomes `Infinity`. * - * @public - * @chainable - * @return {Vec2} Returns itself, modified + * @returns This vector, for chaining */ inverse(): Vec2 { this.x = 1 / this.x; @@ -442,11 +404,9 @@ class Vec2 { } /** - * Clones the vector and then inverses it. + * Like {@link Vec2.inverse}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec2} Returns itself, modified + * @returns A new vector */ inverseNew(): Vec2 { const c = this.clone(); @@ -456,147 +416,221 @@ class Vec2 { } /** - * Normalises the vector down to a length of 1 unit + * Scale the vector to a length of 1, in place. A zero-length vector stays + * at zero. * - * @public - * @chainable - * @return {Vec2} Returns itself, modified + * @returns This vector, for chaining */ normalise(): Vec2 { return this.divideScalar(this.length); } /** - * Clones the vector and normalises it + * Like {@link Vec2.normalise}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec2} Returns a clone of itself, modified + * @returns A new vector */ normaliseNew(): Vec2 { return this.divideScalarNew(this.length); } /** - * Calculates the distance between this and the supplied vector + * The distance between this vector and another, treating both as points. * - * @param {Vec2} vector The vector to calculate the distance from - * @return {number} The distance between this and the supplied vector + * @param vector The other point + * @returns The distance between the two points */ distance(vector: Vec2): number { return this.subtractNew(vector).length; } /** - * Calculates the distance on the X axis between this and the supplied vector + * The signed difference along the x axis, `this.x - vector.x`. * - * @param {Vec2} vector The vector to calculate the distance from - * @return {number} The distance, along the x axis, between this and the supplied vector + * @param vector The other point + * @returns The x distance, which can be negative */ distanceX(vector: Vec2): number { return this.x - vector.x; } /** - * Calculated the distance on the Y axis between this and the supplied vector + * The signed difference along the y axis, `this.y - vector.y`. * - * @param {Vec2} vector The vector to calculate the distance from - * @return {number} The distance, along the y axis, between this and the supplied vector + * @param vector The other point + * @returns The y distance, which can be negative */ distanceY(vector: Vec2): number { return this.y - vector.y; } /** - * Calculates the dot product between this and a supplied vectorT + * The dot product of this vector and another. * * @example - * // returns -14 - * new Vector(2, -3).dot(new Vector(-4, 2)) - * new Vector(-4, 2).dot(new Vector(2, -3)) - * new Vector(2, -4).dot(new Vector(-3, 2)) + * ```ts + * new Vec2(2, -3).dot(new Vec2(-4, 2)); // -14 + * ``` * - * @param {Vec2} vector The vector object against which to calculate the dot product - * @return {number} The dot product of the two vectors + * @param vector The other vector + * @returns The dot product */ dot(vector: Vec2): number { return this.x * vector.x + this.y * vector.y; } + /** + * The determinant of the 2×2 matrix formed by this vector and another, + * `this.x * vector.y - this.y * vector.x`. Same result as {@link Vec2.cross}. + * + * @param vector The other vector + * @returns The determinant + */ det(vector: Vec2): number { return this.x * vector.y - this.y * vector.x; } + /** + * The slope of the line from this point to another, `Δy / Δx`. Returns + * `±Infinity` for a vertical line and `NaN` when the points are equal. + * + * @param vector The other point + * @returns The slope of the line between the two points + */ slopeBetween(vector: Vec2): number { return (vector.y - this.y) / (vector.x - this.x); } /** - * Calculates the cross product between this and the supplied vector. + * The 2D cross product (the z component of the 3D cross product), + * `this.x * vector.y - this.y * vector.x`. Positive when `vector` is + * anticlockwise from this one. * * @example - * // returns -2 - * new Vector(2, -3).cross(new Vector(-4, 2)) - * new Vector(-4, 2).cross(new Vector(2, -3)) - * // returns 2 - * new Vector(2, -4).cross(new Vector(-3, 2)) + * ```ts + * new Vec2(2, -3).cross(new Vec2(-4, 2)); // -8 + * new Vec2(-4, 2).cross(new Vec2(2, -3)); // 8 + * ``` * - * @param {Vec2} vector The vector object against which to calculate the cross product - * @return {number} The cross product of the two vectors + * @param vector The other vector + * @returns The cross product */ cross(vector: Vec2): number { return this.x * vector.y - this.y * vector.x; } + /** + * Round both components up to the nearest integer, in place. + * + * @returns This vector, for chaining + */ ceil(): Vec2 { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); return this; } + /** + * Like {@link Vec2.ceil}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector + */ ceilNew(): Vec2 { return this.clone().ceil(); } + /** + * Round both components down to the nearest integer, in place. + * + * @returns This vector, for chaining + */ floor(): Vec2 { this.x = Math.floor(this.x); this.y = Math.floor(this.y); return this; } + /** + * Like {@link Vec2.floor}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector + */ floorNew(): Vec2 { return this.clone().floor(); } + /** + * Round both components to the nearest integer, in place. + * + * @returns This vector, for chaining + */ round(): Vec2 { this.x = Math.round(this.x); this.y = Math.round(this.y); return this; } + /** + * Like {@link Vec2.round}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector + */ roundNew(): Vec2 { return this.clone().round(); } + /** + * Set each component to its remainder after division by the matching + * component of another vector, in place. Uses JavaScript's `%`, so the + * result takes the sign of this vector's component (unlike GLSL `mod`), + * and a zero divisor gives `NaN`. + * + * @param vector The divisor + * @returns This vector, for chaining + */ mod(vector: Vec2): Vec2 { this.x = this.x % vector.x; this.y = this.y % vector.y; return this; } + /** + * Like {@link Vec2.mod}, but returns a new vector and leaves this one unchanged. + * + * @param vector The divisor + * @returns A new vector + */ modNew(vector: Vec2): Vec2 { return this.clone().mod(vector); } + /** + * Replace each component with its fractional part, `x - floor(x)`, in + * place. The result is always in the range [0, 1), as in GLSL `fract`. + * + * @returns This vector, for chaining + */ fract(): Vec2 { this.x -= Math.floor(this.x); this.y -= Math.floor(this.y); return this; } + /** + * Like {@link Vec2.fract}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector + */ fractNew(): Vec2 { return this.clone().fract(); } + /** + * Multiply this vector by a 2×2 matrix (`m * v`), in place. The matrix is + * column-major, as WebGL expects. + * + * @param m A Mat2 or a 4-element column-major array + * @returns This vector, for chaining + */ transformByMat2(m: Mat2Like): Vec2 { const ma = Array.isArray(m) ? m : m.array; const c = this.clone(); @@ -605,10 +639,25 @@ class Vec2 { return this; } + /** + * Like {@link Vec2.transformByMat2}, but returns a new vector and leaves this one unchanged. + * + * @param m A Mat2 or a 4-element column-major array + * @returns A new vector + */ transformByMat2New(m: Mat2Like): Vec2 { return this.clone().transformByMat2(m); } + /** + * Transform this vector as a point by a 3×3 matrix, in place. The vector + * is treated as `(x, y, 1)`, so the translation in the third column is + * applied; the third row is ignored (no perspective divide). The matrix is + * column-major, as WebGL expects. + * + * @param m A Mat3 or a 9-element column-major array + * @returns This vector, for chaining + */ transformByMat3(m: Mat3Like): Vec2 { const ma = Array.isArray(m) ? m : m.array; const c = this.clone(); @@ -617,6 +666,12 @@ class Vec2 { return this; } + /** + * Like {@link Vec2.transformByMat3}, but returns a new vector and leaves this one unchanged. + * + * @param m A Mat3 or a 9-element column-major array + * @returns A new vector + */ transformByMat3New(m: Mat3Like): Vec2 { return this.clone().transformByMat3(m); } @@ -625,13 +680,10 @@ class Vec2 { * Getters and setters */ + #x: number = 0; /** - * (getter/setter) The x value of the vector. - * - * @type {number} - * @default 0 + * Set the x component. Throws a `TypeError` if the value is not a number. */ - #x: number = 0; set x(x: number) { if (typeof x == "number") { this.#x = x; @@ -639,17 +691,19 @@ class Vec2 { throw new TypeError("X should be a number"); } } + /** + * The x component. Reads as 0 if the stored value is `NaN`. + * + * @default 0 + */ get x(): number { return this.#x || 0; } + #y: number = 0; /** - * (getter/setter) The y value of the vector. - * - * @type {number} - * @default 0 + * Set the y component. Throws a `TypeError` if the value is not a number. */ - #y: number = 0; set y(y: number) { if (typeof y == "number") { this.#y = y; @@ -657,16 +711,19 @@ class Vec2 { throw new TypeError("Y should be a number"); } } + /** + * The y component. Reads as 0 if the stored value is `NaN`. + * + * @default 0 + */ get y(): number { return this.#y || 0; } /** - * (getter/setter) The length of the vector presented as a square. If you're using - * length for comparison, this is quicker. - * - * @type {number} - * @default 0 + * Scale the vector by `value / lengthSquared`, keeping its direction. + * Note this multiplies the length (not the squared length) by that ratio. + * Throws a `TypeError` if the value is not a number. */ set lengthSquared(length: number) { var factor; @@ -677,15 +734,18 @@ class Vec2 { throw new TypeError("length should be a number"); } } + /** + * The squared length of the vector. Cheaper than {@link Vec2.length} when + * you only need to compare lengths. + */ get lengthSquared(): number { return this.x * this.x + this.y * this.y; } /** - * (getter/setter) The length of the vector - * - * @type {number} - * @default 0 + * Set the length of the vector, scaling it while keeping its direction. + * Has no effect on a zero-length vector. Throws a `TypeError` if the value + * is not a number. */ set length(length: number) { var factor; @@ -696,15 +756,14 @@ class Vec2 { throw new TypeError("length should be a number"); } } + /** The length of the vector. */ get length(): number { return Math.sqrt(this.lengthSquared); } /** - * (getter/setter) The angle of the vector, in radians - * - * @type {number} - * @default 0 + * Rotate the vector to point at this angle, in radians, keeping its length. + * Throws a `TypeError` if the value is not a number. */ set angle(radian: number) { if (typeof radian == "number") { @@ -713,15 +772,17 @@ class Vec2 { throw new TypeError("angle should be a number"); } } + /** + * The angle of the vector from the positive x axis, in radians, in the + * range (-π, π]. + */ get angle(): number { return Math.atan2(this.y, this.x); } /** - * (getter/setter) The angle of the vector, in radians - * - * @type {number} - * @default 0 + * Rotate the vector to point at this angle, in degrees, keeping its length. + * Throws a `TypeError` if the value is not a number. */ set angleInDegrees(degrees: number) { if (typeof degrees == "number") { @@ -730,50 +791,41 @@ class Vec2 { throw new TypeError("angle should be a number"); } } + /** + * The angle of the vector from the positive x axis, in degrees, in the + * range (-180, 180]. + */ get angleInDegrees(): number { return radianToDegrees(Math.atan2(this.y, this.x)); } - /** - * (getter/setter) Vector width. - * Alias of {@link x} - * - * @type {number} - */ + /** Set the width. Alias of setting {@link Vec2.x}. */ set width(w: number) { this.x = w; } + /** The width, when the vector is used as a size. Alias of {@link Vec2.x}. */ get width(): number { return this.x; } - /** - * (getter/setter) Vector height. - * Alias of {@link y} - * - * @type {number} - */ + /** Set the height. Alias of setting {@link Vec2.y}. */ set height(h: number) { this.y = h; } + /** The height, when the vector is used as a size. Alias of {@link Vec2.y}. */ get height(): number { return this.y; } - /** - * (getter) Vector area. - * @readonly - * - * @type {number} - */ + /** The area, when the vector is used as a size: `x * y`. */ get area(): number { return this.x * this.y; } /** - * (getter/setter) Vector slope. - * - * @type {number} + * Rotate the vector to match this slope, keeping its length. The new angle + * is `atan(value)`, so the result always points into the positive-x half + * (a vector pointing left is flipped). `NaN` is ignored. */ set slope(value: number) { if (!isNaN(value)) { @@ -781,28 +833,24 @@ class Vec2 { this.angle = angle; } } + /** The slope of the vector, `y / x`. Returns `±Infinity` or `NaN` when x is 0. */ get slope(): number { return this.y / this.x; } - /** - * (getter) Returns the basic array representation of this vector. - * @readonly - * - * @type {number} - */ + /** The components as a new `[x, y]` array. */ get array(): number[] { return [this.x, this.y]; } - /** - * (getter/sette) Swizzle XY - * - * @type {number} - */ + /** The x and y components as a new Vec2. */ get xy(): Vec2 | number[] { return new Vec2(this.x, this.y); } + /** + * Set x and y from a Vec2 or `[x, y]` array. Throws an `Error` for any + * other input. + */ set xy(v: Vec2 | number[]) { if (v instanceof Vec2) { this.resetToVector(v); @@ -813,39 +861,36 @@ class Vec2 { } } - /** - * (getter/sette) Swizzle YX - * - * @type {number} - */ + /** The y and x components as a new Vec2. */ get yx(): Vec2 { return new Vec2(this.y, this.x); } + /** Set y and x from a Vec2-like value or `[y, x]` array. */ set yx(v: Vec2Like) { this.xy = Vec2.interpolate(v).yx; } - /** - * (getter/sette) Swizzle XX - * - * @type {number} - */ + /** The x component repeated, as a new Vec2. */ get xx(): Vec2 { return new Vec2(this.x, this.x); } + /** + * Set x from the second component of a Vec2-like value or array. y is left + * unchanged. + */ set xx(v: Vec2Like) { const resolved = Vec2.interpolate(v); this.x = resolved.y; } - /** - * (getter/sette) Swizzle YY - * - * @type {number} - */ + /** The y component repeated, as a new Vec2. */ get yy(): Vec2 { return new Vec2(this.y, this.y); } + /** + * Set y from the second component of a Vec2-like value or array. x is left + * unchanged. + */ set yy(v: Vec2Like) { const resolved = Vec2.interpolate(v); this.y = resolved.y; @@ -855,10 +900,15 @@ class Vec2 { * Static methods */ /** - * Iterpolates a provided anonymous value into a vew Vec2 + * Create a new Vec2 from a loosely typed value: * - * @param {Vec2|array|string|number} v The value to interpolate - * @returns {Vec2} out + * - a number, used for both components (`NaN` throws) + * - a comma-separated string such as `"1,2"` (throws if it can't be parsed) + * - an array, using its first two elements + * - any object with `x` and `y` properties + * + * @param v The value to convert + * @returns A new vector */ static interpolate(v: Vec2Like | number | string): Vec2 { if (typeof v === "number") { // Single number @@ -882,23 +932,26 @@ class Vec2 { } /** - * Performs a linear interpolation between two vec2's + * Linearly interpolate between two vectors. `d` is not clamped, so values + * outside 0–1 extrapolate. * - * @param {vec2} v1 the first operand - * @param {vec2} v2 the second operand - * @param {Number} d interpolation amount in the range of 0 - 1 - * @returns {Vec2} + * @param v1 The start vector, returned when `d` is 0 + * @param v2 The end vector, returned when `d` is 1 + * @param d The interpolation amount + * @returns A new vector */ static lerp(v1: Vec2, v2: Vec2, d: number): Vec2 { return new Vec2(v1.x + d * (v2.x - v1.x), v1.y + d * (v2.y - v1.y)); } /** - * Finds the angle between 2 vectors. + * The unsigned angle between two vectors, in radians, in the range [0, π]. + * Neither input is changed. If either vector has zero length the result is + * π/2. * - * @param {vec2} a the first operand - * @param {vec2} b the second operand - * @returns {number} + * @param a The first vector + * @param b The second vector + * @returns The angle between them, in radians */ static getAngle(a: Vec2, b: Vec2): number { a = a.clone(); @@ -918,24 +971,9 @@ class Vec2 { } } - - /** - * Adds iteration to the object, allowing it - * to be destructured and iterated upon in - * various useful ways. - */ - [Symbol.iterator]() { - let values = this.array; - let index = 0; - return { - next() { - if (index < values.length) { - let value = values[index]; - index++; - return { value, done: false }; - } else return { done: true } - } - } + /** Iterate over the components, so the vector can be spread or destructured: `const [x, y] = v`. */ + [Symbol.iterator](): Iterator { + return this.array[Symbol.iterator](); } } diff --git a/src/Vec3.ts b/src/Vec3.ts index 1c7884a..8256377 100644 --- a/src/Vec3.ts +++ b/src/Vec3.ts @@ -2,34 +2,32 @@ import { Vec2 } from "./Vec2.js"; import type { Vec2Like, Vec3Like, QuatLike, Mat3Like, Mat4Like } from "./types.js"; /** - * A basic 3D Vector class that provides simple algebraic functionality in the form - * of 3D Vectors. + * A 3D vector with x, y and z components. * - * We use Getters/setters for both principle properties (x & y) as well as virtual - * properties (rotation, length etc.). + * Most operations come in two forms: one that changes the vector in place and + * returns it for chaining (`add`), and a `…New` variant that returns a new + * vector and leaves this one unchanged (`addNew`). Derived values such as + * length and the swizzles (`xy`, `yzx`, …) are exposed as getters and setters. * - * @class Vec3 * @author Liam Egan * @version 1.0.0 * @created Jan 07, 2020 */ class Vec3 { /** - * The Vector Class constructor + * Create a new vector. Missing or `NaN` components default to 0. * - * @constructor - * @param args The x, y and z coordinates + * @param args The x, y and z components. */ constructor(...args: number[]) { this.reset(...args); } /** - * Resets the vector coordinates + * Set the components in place. Missing or `NaN` components are set to 0. * - * @public - * @chainable - * @param args The x, y and z coordinates + * @param args The x, y and z components. + * @returns This vector, for chaining. */ reset(...args: number[]): Vec3 { let [x, y, z] = args; @@ -43,11 +41,11 @@ class Vec3 { } /** - * Resets the vector coordinates to another vector object + * Copy the components of another vector into this one, in place. Does + * nothing if `v` is not a `Vec3`. * - * @public - * @chainable - * @param {Vec3} v The vector object to use to reset the coordinates + * @param v The vector to copy from. + * @returns This vector, for chaining. */ resetToVector(v: Vec3): Vec3 { if (v instanceof Vec3) { @@ -59,22 +57,19 @@ class Vec3 { } /** - * Clones the vector + * Create a copy of this vector. * - * @public - * @return {Vec3} The cloned vector + * @returns A new vector with the same components. */ clone(): Vec3 { return new Vec3(this.x, this.y, this.z); } /** - * Adds one vector to another. + * Add another vector to this one, component by component, in place. * - * @public - * @chainable - * @param {Vec3} vector The vector to add to this one - * @return {Vec3} Returns itself, modified + * @param vector The vector to add. + * @returns This vector, for chaining. */ add(vector: Vec3): Vec3 { this.x += vector.x; @@ -83,47 +78,39 @@ class Vec3 { return this; } /** - * Clones the vector and adds the vector to it instead + * Like {@link Vec3.add}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec3} vector The vector to add to this one - * @return {Vec3} Returns the clone of itself, modified + * @param vector The vector to add. + * @returns A new vector. */ addNew(vector: Vec3): Vec3 { return this.clone().add(vector); } /** - * Adds a scalar to the vector, modifying both the x and y + * Add a scalar to each component, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec3} Returns itself, modified + * @param scalar The value to add to x, y and z. + * @returns This vector, for chaining. */ addScalar(scalar: number): Vec3 { return this.add(new Vec3(scalar, scalar, scalar)); } /** - * Clones the vector and adds the scalar to it instead + * Like {@link Vec3.addScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec3} Returns the clone of itself, modified + * @param scalar The value to add to x, y and z. + * @returns A new vector. */ addScalarNew(scalar: number): Vec3 { return this.clone().addScalar(scalar); } /** - * Subtracts one vector from another. + * Subtract another vector from this one, component by component, in place. * - * @public - * @chainable - * @param {Vec3} vector The vector to subtract from this one - * @return {Vec3} Returns itself, modified + * @param vector The vector to subtract. + * @returns This vector, for chaining. */ subtract(vector: Vec3): Vec3 { this.x -= vector.x; @@ -132,47 +119,40 @@ class Vec3 { return this; } /** - * Clones the vector and subtracts the vector from it instead + * Like {@link Vec3.subtract}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec3} vector The vector to subtract from this one - * @return {Vec3} Returns the clone of itself, modified + * @param vector The vector to subtract. + * @returns A new vector. */ subtractNew(vector: Vec3): Vec3 { return this.clone().subtract(vector); } /** - * Subtracts a scalar from the vector, modifying both the x and y + * Subtract a scalar from each component, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to subtract from the vector - * @return {Vec3} Returns itself, modified + * @param scalar The value to subtract from x, y and z. + * @returns This vector, for chaining. */ subtractScalar(scalar: number): Vec3 { return this.subtract(new Vec3(scalar, scalar, scalar)); } /** - * Clones the vector and subtracts the scalar from it instead + * Like {@link Vec3.subtractScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec3} Returns the clone of itself, modified + * @param scalar The value to subtract from x, y and z. + * @returns A new vector. */ subtractScalarNew(scalar: number): Vec3 { return this.clone().subtractScalar(scalar); } /** - * Divides one vector by another. + * Divide this vector by another, component by component, in place. Any + * component divided by zero is set to 0 rather than `Infinity`. * - * @public - * @chainable - * @param {Vec3} vector The vector to divide this by - * @return {Vec3} Returns itself, modified + * @param vector The vector to divide by. + * @returns This vector, for chaining. */ divide(vector: Vec3): Vec3 { if (vector.x !== 0) { @@ -193,48 +173,41 @@ class Vec3 { return this; } /** - * Clones the vector and divides it by the vector instead + * Like {@link Vec3.divide}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec3} vector The vector to divide the clone by - * @return {Vec3} Returns the clone of itself, modified + * @param vector The vector to divide by. + * @returns A new vector. */ divideNew(vector: Vec3): Vec3 { return this.clone().divide(vector); } /** - * Divides the vector by a scalar. + * Divide each component by a scalar, in place. Dividing by zero sets every + * component to 0. * - * @public - * @chainable - * @param {number} scalar The scalar to divide both x and y by - * @return {Vec3} Returns itself, modified + * @param scalar The value to divide x, y and z by. + * @returns This vector, for chaining. */ divideScalar(scalar: number): Vec3 { var v = new Vec3(scalar, scalar, scalar); return this.divide(v); } /** - * Clones the vector and divides it by the provided scalar. + * Like {@link Vec3.divideScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to divide both x and y by - * @return {Vec3} Returns the clone of itself, modified + * @param scalar The value to divide x, y and z by. + * @returns A new vector. */ divideScalarNew(scalar: number): Vec3 { return this.clone().divideScalar(scalar); } /** - * Multiplies one vector by another. + * Multiply this vector by another, component by component, in place. * - * @public - * @chainable - * @param {Vec3} vector The vector to multiply this by - * @return {Vec3} Returns itself, modified + * @param vector The vector to multiply by. + * @returns This vector, for chaining. */ multiply(vector: Vec3): Vec3 { this.x *= vector.x; @@ -243,54 +216,64 @@ class Vec3 { return this; } /** - * Clones the vector and multiplies it by the vector instead + * Like {@link Vec3.multiply}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec3} vector The vector to multiply the clone by - * @return {Vec3} Returns the clone of itself, modified + * @param vector The vector to multiply by. + * @returns A new vector. */ multiplyNew(vector: Vec3): Vec3 { return this.clone().multiply(vector); } /** - * Multiplies the vector by a scalar. + * Multiply each component by a scalar, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to multiply both x and y by - * @return {Vec3} Returns itself, modified + * @param scalar The value to multiply x, y and z by. + * @returns This vector, for chaining. */ multiplyScalar(scalar: number): Vec3 { var v = new Vec3(scalar, scalar, scalar); return this.multiply(v); } /** - * Clones the vector and multiplies it by the provided scalar. + * Like {@link Vec3.multiplyScalar}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to multiply both x and y by - * @return {Vec3} Returns the clone of itself, modified + * @param scalar The value to multiply x, y and z by. + * @returns A new vector. */ multiplyScalarNew(scalar: number): Vec3 { return this.clone().multiplyScalar(scalar); } /** - * Alias of {@link multiplyScalar} + * Alias of {@link Vec3.multiplyScalar}. Scales the vector in place. + * + * @param scalar The value to multiply x, y and z by. + * @returns This vector, for chaining. */ scale(scalar: number): Vec3 { return this.multiplyScalar(scalar); } /** - * Alias of {@link multiplyScalarNew} + * Alias of {@link Vec3.multiplyScalarNew}. Returns a new scaled vector and + * leaves this one unchanged. + * + * @param scalar The value to multiply x, y and z by. + * @returns A new vector. */ scaleNew(scalar: number): Vec3 { return this.multiplyScalarNew(scalar); } + /** + * Rotate the vector around an axis parallel to x that passes through + * `origin`, in place. Only y and z change. A positive angle turns y towards + * z (counter-clockwise when looking down the x axis towards the origin). + * + * @param origin The point to rotate around. + * @param radian The angle, in radians. + * @returns This vector, for chaining. + */ rotateX(origin: Vec3, radian: number): Vec3 { const s = Math.sin(radian); const c = Math.cos(radian); @@ -304,10 +287,26 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.rotateX}, but returns a new vector and leaves this one unchanged. + * + * @param origin The point to rotate around. + * @param radian The angle, in radians. + * @returns A new vector. + */ rotateXNew(origin: Vec3, radian: number): Vec3 { return this.clone().rotateX(origin, radian); } + /** + * Rotate the vector around an axis parallel to y that passes through + * `origin`, in place. Only x and z change. A positive angle turns z towards + * x (counter-clockwise when looking down the y axis towards the origin). + * + * @param origin The point to rotate around. + * @param radian The angle, in radians. + * @returns This vector, for chaining. + */ rotateY(origin: Vec3, radian: number): Vec3 { const s = Math.sin(radian); const c = Math.cos(radian); @@ -321,10 +320,26 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.rotateY}, but returns a new vector and leaves this one unchanged. + * + * @param origin The point to rotate around. + * @param radian The angle, in radians. + * @returns A new vector. + */ rotateYNew(origin: Vec3, radian: number): Vec3 { return this.clone().rotateY(origin, radian); } + /** + * Rotate the vector around an axis parallel to z that passes through + * `origin`, in place. Only x and y change. A positive angle turns x towards + * y (counter-clockwise when looking down the z axis towards the origin). + * + * @param origin The point to rotate around. + * @param radian The angle, in radians. + * @returns This vector, for chaining. + */ rotateZ(origin: Vec3, radian: number): Vec3 { const s = Math.sin(radian); const c = Math.cos(radian); @@ -338,10 +353,25 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.rotateZ}, but returns a new vector and leaves this one unchanged. + * + * @param origin The point to rotate around. + * @param radian The angle, in radians. + * @returns A new vector. + */ rotateZNew(origin: Vec3, radian: number): Vec3 { return this.clone().rotateZ(origin, radian); } + /** + * Transform the vector as a point (w = 1) by a 4×4 column-major matrix, in + * place, then divide by the resulting w. If w comes out as 0, it is treated + * as 1 so no divide by zero happens. + * + * @param m The matrix, as a Mat4 or a 16-element column-major array. + * @returns This vector, for chaining. + */ transformByMat4(m: Mat4Like): Vec3 { const ma = Array.isArray(m) ? m : m.array; const o = this.clone(); @@ -352,10 +382,22 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.transformByMat4}, but returns a new vector and leaves this one unchanged. + * + * @param m The matrix, as a Mat4 or a 16-element column-major array. + * @returns A new vector. + */ transformByMat4New(m: Mat4Like): Vec3 { return this.clone().transformByMat4(m); } + /** + * Multiply the vector by a 3×3 column-major matrix, in place. + * + * @param m The matrix, as a Mat3 or a 9-element column-major array. + * @returns This vector, for chaining. + */ transformByMat3(m: Mat3Like): Vec3 { const ma = Array.isArray(m) ? m : m.array; const o = this.clone(); @@ -365,10 +407,23 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.transformByMat3}, but returns a new vector and leaves this one unchanged. + * + * @param m The matrix, as a Mat3 or a 9-element column-major array. + * @returns A new vector. + */ transformByMat3New(m: Mat3Like): Vec3 { return this.clone().transformByMat3(m); } + /** + * Rotate the vector by a quaternion, in place. The quaternion should be + * normalised; a non-unit quaternion also scales the result. + * + * @param q The quaternion, as a Quat, an `{x, y, z, w}` object or an `[x, y, z, w]` array. + * @returns This vector, for chaining. + */ transformByQuat(q: QuatLike): Vec3 { const qa = Array.isArray(q) ? q : [q.x, q.y, q.z, q.w]; const o = this.clone(); @@ -389,38 +444,39 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.transformByQuat}, but returns a new vector and leaves this one unchanged. + * + * @param q The quaternion, as a Quat, an `{x, y, z, w}` object or an `[x, y, z, w]` array. + * @returns A new vector. + */ transformByQuatNew(q: QuatLike): Vec3 { return this.clone().transformByQuat(q); } /** - * Negates the vector. + * Negate each component, in place. * - * @public - * @chainable - * @return {Vec3} Returns itself, modified + * @returns This vector, for chaining. */ negate(): Vec3 { return this.multiplyScalar(-1); } /** - * Clones the vector and negates it. + * Like {@link Vec3.negate}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec3} Returns itself, modified + * @returns A new vector. */ negateNew(): Vec3 { return this.multiplyScalarNew(-1); } /** - * Inverses the vector. + * Replace each component with its reciprocal (1 / value), in place. Unlike + * {@link Vec3.divide}, a zero component becomes `Infinity`. * - * @public - * @chainable - * @return {Vec3} Returns itself, modified + * @returns This vector, for chaining. */ inverse(): Vec3 { this.x = 1 / this.x; @@ -430,11 +486,9 @@ class Vec3 { } /** - * Clones the vector and then inverses it. + * Like {@link Vec3.inverse}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec3} Returns itself, modified + * @returns A new vector. */ inverseNew(): Vec3 { const c = this.clone(); @@ -445,94 +499,92 @@ class Vec3 { } /** - * Normalises the vector down to a length of 1 unit + * Scale the vector to a length of 1, in place, keeping its direction. A zero + * vector stays zero. * - * @public - * @chainable - * @return {Vec3} Returns itself, modified + * @returns This vector, for chaining. */ normalise(): Vec3 { return this.divideScalar(this.length); } /** - * Clones the vector and normalises it + * Like {@link Vec3.normalise}, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec3} Returns a clone of itself, modified + * @returns A new vector. */ normaliseNew(): Vec3 { return this.divideScalarNew(this.length); } /** - * Calculates the distance between this and the supplied vector + * The straight-line distance between this vector and another. * - * @param {Vec3} vector The vector to calculate the distance from - * @return {number} The distance between this and the supplied vector + * @param vector The other vector. + * @returns The distance. */ distance(vector: Vec3): number { return this.subtractNew(vector).length; } /** - * Calculates the distance on the X axis between this and the supplied vector + * The signed distance along x from another vector to this one + * (`this.x - vector.x`). * - * @param {Vec3} vector The vector to calculate the distance from - * @return {number} The distance, along the x axis, between this and the supplied vector + * @param vector The other vector. + * @returns The difference in x. */ distanceX(vector: Vec3): number { return this.x - vector.x; } /** - * Calculated the distance on the Y axis between this and the supplied vector + * The signed distance along y from another vector to this one + * (`this.y - vector.y`). * - * @param {Vec3} vector The vector to calculate the distance from - * @return {number} The distance, along the y axis, between this and the supplied vector + * @param vector The other vector. + * @returns The difference in y. */ distanceY(vector: Vec3): number { return this.y - vector.y; } /** - * Calculated the distance on the Z axis between this and the supplied vector + * The signed distance along z from another vector to this one + * (`this.z - vector.z`). * - * @param {Vec3} vector The vector to calculate the distance from - * @return {number} The distance, along the y axis, between this and the supplied vector + * @param vector The other vector. + * @returns The difference in z. */ distanceZ(vector: Vec3): number { return this.z - vector.z; } /** - * Calculates the dot product between this and a supplied vector + * The dot product of this vector and another. * * @example - * // returns -14 - * new Vector(2, -3).dot(new Vector(-4, 2)) - * new Vector(-4, 2).dot(new Vector(2, -3)) - * new Vector(2, -4).dot(new Vector(-3, 2)) + * ```ts + * new Vec3(1, 2, 3).dot(new Vec3(4, -5, 6)); // 12 + * ``` * - * @param {Vec3} vector The vector object against which to calculate the dot product - * @return {number} The dot product of the two vectors + * @param vector The other vector. + * @returns The dot product. */ dot(vector: Vec3): number { return this.x * vector.x + this.y * vector.y + this.z * vector.z; } /** - * Calculates the cross product between this and the supplied vector. + * The cross product of this vector and another (`this × vector`). This + * vector is not changed; the result is always a new vector. * * @example - * // returns -2 - * new Vector(2, -3).cross(new Vector(-4, 2)) - * new Vector(-4, 2).cross(new Vector(2, -3)) - * // returns 2 - * new Vector(2, -4).cross(new Vector(-3, 2)) + * ```ts + * new Vec3(1, 0, 0).cross(new Vec3(0, 1, 0)); // Vec3(0, 0, 1) + * ``` * - * @param {Vec3} vector The vector object against which to calculate the cross product - * @return {Vec3} The cross product of the two vectors + * @param vector The other vector. + * @returns A new vector perpendicular to both. */ cross(vector: Vec3): Vec3 { return new Vec3( @@ -542,10 +594,22 @@ class Vec3 { ); } + /** + * Same as {@link Vec3.cross}: returns the cross product as a new vector and + * leaves this one unchanged. + * + * @param vector The other vector. + * @returns A new vector perpendicular to both. + */ crossNew(vector: Vec3): Vec3 { return this.clone().cross(vector); } + /** + * Round each component up to the nearest integer, in place. + * + * @returns This vector, for chaining. + */ ceil(): Vec3 { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); @@ -553,10 +617,20 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.ceil}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector. + */ ceilNew(): Vec3 { return this.clone().ceil(); } + /** + * Round each component down to the nearest integer, in place. + * + * @returns This vector, for chaining. + */ floor(): Vec3 { this.x = Math.floor(this.x); this.y = Math.floor(this.y); @@ -564,10 +638,21 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.floor}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector. + */ floorNew(): Vec3 { return this.clone().floor(); } + /** + * Round each component to the nearest integer, in place (using `Math.round`, + * so halves round up). + * + * @returns This vector, for chaining. + */ round(): Vec3 { this.x = Math.round(this.x); this.y = Math.round(this.y); @@ -575,10 +660,22 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.round}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector. + */ roundNew(): Vec3 { return this.clone().round(); } + /** + * Replace each component with its fractional part (`value - floor(value)`), + * in place. Results are always in the range [0, 1), including for negative + * values. + * + * @returns This vector, for chaining. + */ fract(): Vec3 { this.x -= Math.floor(this.x); this.y -= Math.floor(this.y); @@ -586,21 +683,23 @@ class Vec3 { return this; } + /** + * Like {@link Vec3.fract}, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector. + */ fractNew(): Vec3 { return this.clone().fract(); } - /** - * Getters and setters - */ + // Getters and setters + #x: number = 0; /** - * (getter/setter) The x value of the vector. + * Set the x component. Throws a `TypeError` if the value is not a number. * - * @type {number} * @default 0 */ - #x: number = 0; set x(x: number) { if (typeof x == "number") { this.#x = x; @@ -608,17 +707,21 @@ class Vec3 { throw new TypeError("X should be a number"); } } + /** + * The x component. `NaN` reads as 0. + * + * @default 0 + */ get x(): number { return this.#x || 0; } + #y: number = 0; /** - * (getter/setter) The y value of the vector. + * Set the y component. Throws a `TypeError` if the value is not a number. * - * @type {number} * @default 0 */ - #y: number = 0; set y(y: number) { if (typeof y == "number") { this.#y = y; @@ -626,17 +729,21 @@ class Vec3 { throw new TypeError("Y should be a number"); } } + /** + * The y component. `NaN` reads as 0. + * + * @default 0 + */ get y(): number { return this.#y || 0; } + #z: number = 0; /** - * (getter/setter) The y value of the vector. + * Set the z component. Throws a `TypeError` if the value is not a number. * - * @type {number} * @default 0 */ - #z: number = 0; set z(z: number) { if (typeof z == "number") { this.#z = z; @@ -644,16 +751,20 @@ class Vec3 { throw new TypeError("Z should be a number"); } } + /** + * The z component. `NaN` reads as 0. + * + * @default 0 + */ get z(): number { return this.#z || 0; } /** - * (getter/setter) The length of the vector presented as a square. If you're using - * length for comparison, this is quicker. - * - * @type {number} - * @default 0 + * Scale the vector in place by `value / lengthSquared`. Note this scales by + * the ratio of squared lengths, so the resulting squared length is not + * `value` unless the current squared length is 1. Throws a `TypeError` if + * the value is not a number. */ set lengthSquared(length: number) { var factor; @@ -664,15 +775,18 @@ class Vec3 { throw new TypeError("length should be a number"); } } + /** + * The squared length of the vector. Cheaper than {@link Vec3.length}, so + * use it when only comparing lengths. + */ get lengthSquared(): number { return this.x * this.x + this.y * this.y + this.z * this.z; } /** - * (getter/setter) The length of the vector - * - * @type {number} - * @default 0 + * Set the length of the vector, scaling it while keeping its direction. + * Throws a `TypeError` if the value is not a number. A zero vector cannot be + * scaled and stays zero. */ set length(length: number) { var factor; @@ -683,116 +797,104 @@ class Vec3 { throw new TypeError("length should be a number"); } } + /** The length (magnitude) of the vector. */ get length(): number { return Math.sqrt(this.lengthSquared); } /** - * (getter/setter) Spherical radius. For using a vec3 as spherical coordinates. - * Alias of {@link x} - * - * @type {number} + * Set the spherical radius. Alias of {@link Vec3.x}. No conversion between + * spherical and Cartesian coordinates is done. */ set radius(s: number) { this.x = s; } + /** + * The spherical radius, for using the vector to hold spherical coordinates + * (radius, phi, theta). Alias of {@link Vec3.x}; the value is stored as + * given, with no conversion. + */ get radius(): number { return this.x; } /** - * (getter/setter) Spherical phi. For using a vec3 as spherical coordinates. - * Alias of {@link y} - * - * @type {number} + * Set the spherical angle phi. Alias of {@link Vec3.y}. No conversion + * between spherical and Cartesian coordinates is done. */ set phi(p: number) { this.y = p; } + /** + * The spherical angle phi, for using the vector to hold spherical + * coordinates (radius, phi, theta). Alias of {@link Vec3.y}; the value is + * stored as given, so the unit and convention are up to the caller. + */ get phi(): number { return this.y; } /** - * (getter/setter) Spherical theta. For using a vec3 as spherical coordinates. - * Alias of {@link z} - * - * @type {number} + * Set the spherical angle theta. Alias of {@link Vec3.z}. No conversion + * between spherical and Cartesian coordinates is done. */ set theta(t: number) { this.z = t; } + /** + * The spherical angle theta, for using the vector to hold spherical + * coordinates (radius, phi, theta). Alias of {@link Vec3.z}; the value is + * stored as given, so the unit and convention are up to the caller. + */ get theta(): number { return this.z; } - /** - * (getter/setter) Vector width. - * Alias of {@link x} - * - * @type {number} - */ + /** Set the width. Alias of {@link Vec3.x}. */ set width(w: number) { this.x = w; } + /** The width, for using the vector as a size. Alias of {@link Vec3.x}. */ get width(): number { return this.x; } - /** - * (getter/setter) Vector height. - * Alias of {@link y} - * - * @type {number} - */ + /** Set the height. Alias of {@link Vec3.y}. */ set height(h: number) { this.y = h; } + /** The height, for using the vector as a size. Alias of {@link Vec3.y}. */ get height(): number { return this.y; } - /** - * (getter/setter) Vector depth. - * Alias of {@link z} - * - * @type {number} - */ + /** Set the depth. Alias of {@link Vec3.z}. */ set depth(h: number) { this.z = h; } + /** The depth, for using the vector as a size. Alias of {@link Vec3.z}. */ get depth(): number { return this.z; } - /** - * (getter) Vector area. - * @readonly - * - * @type {number} - */ + /** The product of the components (`x * y * z`): the volume of a box of this size. */ get area(): number { return this.x * this.y * this.z; } - /** - * (getter) Returns the basic array representation of this vector. - * @readonly - * - * @type {number} - */ + /** The components as a new array: `[x, y, z]`. */ get array(): number[] { return [this.x, this.y, this.z]; } - /** - * (getter/sette) Swizzle XYZ - * - * @type {Vec3} - */ + /** The x, y and z components as a new Vec3. */ get xyz(): Vec3 { return new Vec3(this.x, this.y, this.z); } + /** + * Set x, y and z from a Vec3, an `{x, y, z}` object or an `[x, y, z]` array. + * For arrays, missing or `NaN` values become 0. + */ set xyz(v: Vec3Like) { if (Array.isArray(v)) { this.reset(v[0], v[1], v[2]); @@ -803,147 +905,134 @@ class Vec3 { } } - /** - * (getter/sette) Swizzle YZX - * - * @type {Vec3} - */ + /** The y, z and x components as a new Vec3. */ get yzx(): Vec3 { return new Vec3(this.y, this.z, this.x); } + /** + * Set the components from a Vec3 or array by reading the value's own y, z + * and x components into x, y and z. So `v.yzx = [a, b, c]` gives + * `x = b, y = c, z = a`, which is not the inverse of the getter. + */ set yzx(v: Vec3Like) { this.xyz = Vec3.interpolate(v).yzx; } - /** - * (getter/sette) Swizzle ZXY - * - * @type {Vec3} - */ + /** The z, x and y components as a new Vec3. */ get zxy(): Vec3 { return new Vec3(this.z, this.x, this.y); } + /** + * Set the components from a Vec3 or array by reading the value's own z, x + * and y components into x, y and z. So `v.zxy = [a, b, c]` gives + * `x = c, y = a, z = b`, which is not the inverse of the getter. + */ set zxy(v: Vec3Like) { this.xyz = Vec3.interpolate(v).zxy; } - /** - * (getter/sette) Swizzle XY - * - * @type {Vec2} - */ + /** The x and y components as a new Vec2. */ get xy(): Vec2 { return new Vec2(this.x, this.y); } + /** Set x and y from a Vec2 or array. z is unchanged. */ set xy(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.x; this.y = v.y; } - /** - * (getter/sette) Swizzle YZ - * - * @type {Vec2} - */ + /** The y and z components as a new Vec2. */ get yz(): Vec2 { return new Vec2(this.y, this.z); } + /** Set y and z from a Vec2 or array. x is unchanged. */ set yz(v: Vec2Like) { v = Vec2.interpolate(v); this.y = v.x; this.z = v.y; } - /** - * (getter/sette) Swizzle zx - * - * @type {Vec2} - */ + /** The z and x components as a new Vec2. */ get zx(): Vec2 { return new Vec2(this.z, this.x); } + /** Set z and x from a Vec2 or array. y is unchanged. */ set zx(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.x; this.x = v.y; } - /** - * (getter/sette) Swizzle YX - * - * @type {number} - */ + /** The y and x components as a new Vec2. */ get yx(): Vec2 { return new Vec2(this.y, this.x); } + /** Set y and x from a Vec2 or array. z is unchanged. */ set yx(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.y; this.y = v.x; } - /** - * (getter/sette) Swizzle ZY - * - * @type {number} - */ + /** The z and y components as a new Vec2. */ get zy(): Vec2 { return new Vec2(this.z, this.y); } + /** + * Set z and y from a Vec2 or array. x is unchanged. Note that the current + * code assigns the first value to y and the second to z, the same as + * {@link Vec3.yz}. + */ set zy(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.y; this.y = v.x; } - /** - * (getter/sette) Swizzle XX - * - * @type {number} - */ + /** The x component twice, as a new Vec2. */ get xx(): Vec2 { return new Vec2(this.x, this.x); } + /** Set x from the second value of a Vec2 or array. y and z are unchanged. */ set xx(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.y; } - /** - * (getter/sette) Swizzle YY - * - * @type {number} - */ + /** The y component twice, as a new Vec2. */ get yy(): Vec2 { return new Vec2(this.y, this.y); } + /** Set y from the second value of a Vec2 or array. x and z are unchanged. */ set yy(v: Vec2Like) { v = Vec2.interpolate(v); this.y = v.y; } - /** - * (getter/sette) Swizzle ZZ - * - * @type {number} - */ + /** The z component twice, as a new Vec2. */ get zz(): Vec2 { return new Vec2(this.z, this.z); } + /** Set z from the second value of a Vec2 or array. x and y are unchanged. */ set zz(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.y; } + // Static methods + /** - * Static methods - */ - /** - * Iterpolates a provided anonymous value into a vew Vec3 + * Create a new Vec3 from a loosely typed value. * - * @param {Vec3|array|string|number} v The value to interpolate - * @returns {Vec3} out + * - A number sets all three components to it. `NaN` throws. + * - A string is read as comma-separated `"x,y,z"`. Throws if there are fewer + * than three values or any of the first three is not a number. + * - An array is read as `[x, y, z]`; missing or `NaN` values become 0. + * - Any other object is read from its `x`, `y` and `z` properties. + * + * @param v The value to convert. + * @returns A new vector. */ static interpolate(v: Vec3Like | number | string): Vec3 { if (typeof v === "number") { @@ -976,12 +1065,13 @@ class Vec3 { } /** - * Performs a linear interpolation between two Vec3's + * Linearly interpolate between two vectors. `d` is not clamped, so values + * outside 0 to 1 extrapolate. * - * @param {Vec3} v1 the first operand - * @param {Vec3} v2 the second operand - * @param {Number} d interpolation amount in the range of 0 - 1 - * @returns {Vec3} + * @param v1 The start vector, returned when `d` is 0. + * @param v2 The end vector, returned when `d` is 1. + * @param d The interpolation amount. + * @returns A new vector. */ static lerp(v1: Vec3, v2: Vec3, d: number): Vec3 { return new Vec3( @@ -991,6 +1081,14 @@ class Vec3 { ); } + /** + * The angle between two vectors, in radians, from 0 to π. If either vector + * has zero length the result is π / 2. + * + * @param a The first vector. + * @param b The second vector. + * @returns The angle in radians. + */ static getAngle(a: Vec3, b: Vec3) { let len1 = a.lengthSquared; if (len1 > 0) len1 = 1 / Math.sqrt(len1); @@ -1009,6 +1107,21 @@ class Vec3 { } } + /** + * Extract Euler angles, in radians, from the rotation part of a 4×4 + * column-major matrix. The upper 3×3 must be a pure rotation (no scale). + * + * Follows the same convention as three.js's `Euler.setFromRotationMatrix`: + * the order names the axes in the order the matrix is composed, so `"XYZ"` + * means the matrix is Rx · Ry · Rz. Supported orders are `"XYZ"`, `"YXZ"`, + * `"ZXY"`, `"ZYX"`, `"YZX"` and `"XZY"`; any other string returns + * (0, 0, 0). At gimbal lock (the middle angle at ±90°) the third angle is + * set to 0 and the rotation is put in the first. + * + * @param m The matrix, as a Mat4 or a 16-element column-major array. + * @param order The rotation order. + * @returns A new vector holding the rotation about x, y and z, in radians. + */ static fromRotationMatrix(m: Mat4Like, order: string = "YXZ"): Vec3 { const ma = Array.isArray(m) ? m : m.array; const v = new Vec3(); @@ -1070,23 +1183,9 @@ class Vec3 { return v; } - /** - * Adds iteration to the object, allowing it - * to be destructured and iterated upon in - * various useful ways. - */ - [Symbol.iterator]() { - let values = this.array; - let index = 0; - return { - next() { - if (index < values.length) { - let value = values[index]; - index++; - return { value, done: false }; - } else return { done: true }; - }, - }; + /** Iterate over the components, so the vector can be spread or destructured: `const [x, y, z] = v`. */ + [Symbol.iterator](): Iterator { + return this.array[Symbol.iterator](); } } diff --git a/src/Vec4.ts b/src/Vec4.ts index 1bcc7b4..88f966e 100644 --- a/src/Vec4.ts +++ b/src/Vec4.ts @@ -93,34 +93,33 @@ interface V4Q { } /** - * A basic 3D Vector class that provides simple algebraic functionality in the form - * of 3D Vectors. + * A four-component vector with x, y, z and w components. * - * We use Getters/setters for both principle properties (x & y) as well as virtual - * properties (rotation, length etc.). + * Most operations come in two forms: one that changes the vector in place and + * returns it for chaining (`add`), and a `…New` variant that returns a new + * vector and leaves the original unchanged (`addNew`). Components are exposed + * through getters and setters, along with derived values such as `length` and + * swizzles such as `xyz`. * - * @class Vec4 * @author Liam Egan * @version 1.0.0 * @created Jan 07, 2020 */ class Vec4 implements V4Q { /** - * The Vector Class constructor + * Create a new vector. Missing or `NaN` components default to 0. * - * @constructor - * @param args The x, y, z and w coordinates + * @param args The x, y, z and w components, in that order. */ constructor(...args: number[]) { this.reset(...args); } /** - * Resets the vector coordinates + * Set the components in place. Missing or `NaN` components are set to 0. * - * @public - * @chainable - * @param args The x, y, z and w coordinates + * @param args The x, y, z and w components, in that order. + * @returns This vector, for chaining. */ reset(...args: number[]): V4Q { let [x, y, z, w] = args; @@ -136,11 +135,11 @@ class Vec4 implements V4Q { } /** - * Resets the vector coordinates to another vector object + * Copy the components of another vector into this one, in place. Does + * nothing if `v` is not a Vec4 instance (a Quat counts, as it extends Vec4). * - * @public - * @chainable - * @param {Vec4} v The vector object to use to reset the coordinates + * @param v The vector to copy from. + * @returns This vector, for chaining. */ resetToVector(v: V4Q): V4Q { if (v instanceof Vec4) { @@ -153,22 +152,19 @@ class Vec4 implements V4Q { } /** - * Clones the vector + * Create a copy of this vector. * - * @public - * @return {Vec4} The cloned vector + * @returns A new Vec4 with the same components. */ clone(): V4Q { return new Vec4(this.x, this.y, this.z, this.w); } /** - * Adds one vector to another. + * Add another vector to this one, component by component, in place. * - * @public - * @chainable - * @param {Vec4} vector The vector to add to this one - * @return {Vec4} Returns itself, modified + * @param vector The vector to add. + * @returns This vector, for chaining. */ add(vector: V4Q): V4Q { this.x += vector.x; @@ -178,47 +174,39 @@ class Vec4 implements V4Q { return this; } /** - * Clones the vector and adds the vector to it instead + * Like `add`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec4} vector The vector to add to this one - * @return {Vec4} Returns the clone of itself, modified + * @param vector The vector to add. + * @returns A new vector holding the sum. */ addNew(vector: V4Q): V4Q { return this.clone().add(vector); } /** - * Adds a scalar to the vector, modifying both the x and y + * Add a scalar to every component, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec4} Returns itself, modified + * @param scalar The value to add to x, y, z and w. + * @returns This vector, for chaining. */ addScalar(scalar: number): V4Q { return this.add(new Vec4(scalar, scalar, scalar, scalar)); } /** - * Clones the vector and adds the scalar to it instead + * Like `addScalar`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec4} Returns the clone of itself, modified + * @param scalar The value to add to x, y, z and w. + * @returns A new vector holding the result. */ addScalarNew(scalar: number): V4Q { return this.clone().addScalar(scalar); } /** - * Subtracts one vector from another. + * Subtract another vector from this one, component by component, in place. * - * @public - * @chainable - * @param {Vec4} vector The vector to subtract from this one - * @return {Vec4} Returns itself, modified + * @param vector The vector to subtract. + * @returns This vector, for chaining. */ subtract(vector: V4Q): V4Q { this.x -= vector.x; @@ -228,47 +216,41 @@ class Vec4 implements V4Q { return this; } /** - * Clones the vector and subtracts the vector from it instead + * Like `subtract`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec4} vector The vector to subtract from this one - * @return {Vec4} Returns the clone of itself, modified + * @param vector The vector to subtract. + * @returns A new vector holding the difference. */ subtractNew(vector: V4Q): V4Q { return this.clone().subtract(vector); } /** - * Subtracts a scalar from the vector, modifying both the x and y + * Subtract a scalar from every component, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to subtract from the vector - * @return {Vec4} Returns itself, modified + * @param scalar The value to subtract from x, y, z and w. + * @returns This vector, for chaining. */ subtractScalar(scalar: number): V4Q { return this.subtract(new Vec4(scalar, scalar, scalar, scalar)); } /** - * Clones the vector and subtracts the scalar from it instead + * Like `subtractScalar`, but returns a new vector and leaves this one + * unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to add to the vector - * @return {Vec4} Returns the clone of itself, modified + * @param scalar The value to subtract from x, y, z and w. + * @returns A new vector holding the result. */ subtractScalarNew(scalar: number): V4Q { return this.clone().subtractScalar(scalar); } /** - * Divides one vector by another. + * Divide this vector by another, component by component, in place. Any + * component divided by 0 is set to 0 rather than `Infinity`. * - * @public - * @chainable - * @param {Vec4} vector The vector to divide this by - * @return {Vec4} Returns itself, modified + * @param vector The vector to divide by. + * @returns This vector, for chaining. */ divide(vector: V4Q): V4Q { if (vector.x !== 0) { @@ -294,48 +276,42 @@ class Vec4 implements V4Q { return this; } /** - * Clones the vector and divides it by the vector instead + * Like `divide`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec4} vector The vector to divide the clone by - * @return {Vec4} Returns the clone of itself, modified + * @param vector The vector to divide by. + * @returns A new vector holding the quotient. */ divideNew(vector: V4Q): V4Q { return this.clone().divide(vector); } /** - * Divides the vector by a scalar. + * Divide every component by a scalar, in place. Dividing by 0 sets every + * component to 0. * - * @public - * @chainable - * @param {number} scalar The scalar to divide both x and y by - * @return {Vec4} Returns itself, modified + * @param scalar The value to divide x, y, z and w by. + * @returns This vector, for chaining. */ divideScalar(scalar: number): V4Q { var v = new Vec4(scalar, scalar, scalar, scalar); return this.divide(v); } /** - * Clones the vector and divides it by the provided scalar. + * Like `divideScalar`, but returns a new vector and leaves this one + * unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to divide both x and y by - * @return {Vec4} Returns the clone of itself, modified + * @param scalar The value to divide x, y, z and w by. + * @returns A new vector holding the result. */ divideScalarNew(scalar: number): V4Q { return this.clone().divideScalar(scalar); } /** - * Multiplies one vector by another. + * Multiply this vector by another, component by component, in place. * - * @public - * @chainable - * @param {Vec4} vector The vector to multiply this by - * @return {Vec4} Returns itself, modified + * @param vector The vector to multiply by. + * @returns This vector, for chaining. */ multiply(vector: V4Q): V4Q { this.x *= vector.x; @@ -345,54 +321,64 @@ class Vec4 implements V4Q { return this; } /** - * Clones the vector and multiplies it by the vector instead + * Like `multiply`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @param {Vec4} q The vector to multiply the clone by - * @return {Vec4} Returns the clone of itself, modified + * @param q The vector to multiply by. + * @returns A new vector holding the product. */ multiplyNew(q: V4Q): V4Q { return this.clone().multiply(q); } /** - * Multiplies the vector by a scalar. + * Multiply every component by a scalar, in place. * - * @public - * @chainable - * @param {number} scalar The scalar to multiply both x and y by - * @return {Vec4} Returns itself, modified + * @param scalar The value to multiply x, y, z and w by. + * @returns This vector, for chaining. */ multiplyScalar(scalar: number): V4Q { var v: Vec4 = new Vec4(scalar, scalar, scalar, scalar); return this.multiply(v); } /** - * Clones the vector and multiplies it by the provided scalar. + * Like `multiplyScalar`, but returns a new vector and leaves this one + * unchanged. * - * @public - * @chainable - * @param {number} scalar The scalar to multiply both x and y by - * @return {Vec4} Returns the clone of itself, modified + * @param scalar The value to multiply x, y, z and w by. + * @returns A new vector holding the result. */ multiplyScalarNew(scalar: number): V4Q { return this.clone().multiplyScalar(scalar); } /** - * Alias of {@link multiplyScalar} + * Alias of `multiplyScalar`: multiply every component by a scalar, in place. + * + * @param scalar The value to multiply x, y, z and w by. + * @returns This vector, for chaining. */ scale(scalar: number): V4Q { return this.multiplyScalar(scalar); } /** - * Alias of {@link multiplyScalarNew} + * Alias of `multiplyScalarNew`: like `scale`, but returns a new vector and + * leaves this one unchanged. + * + * @param scalar The value to multiply x, y, z and w by. + * @returns A new vector holding the result. */ scaleNew(scalar: number): V4Q { return this.multiplyScalarNew(scalar); } + /** + * Rotate the vector around the X axis through a point, in place. Only y and + * z change; x and w are left as they are. + * + * @param origin The point to rotate around. Only its y and z are used. + * @param radian The angle in radians. + * @returns This vector, for chaining. + */ rotateX(origin: V4Q, radian: number): V4Q { const s = Math.sin(radian); const c = Math.cos(radian); @@ -406,10 +392,25 @@ class Vec4 implements V4Q { return this; } + /** + * Like `rotateX`, but returns a new vector and leaves this one unchanged. + * + * @param origin The point to rotate around. + * @param radian The angle in radians. + * @returns A new, rotated copy. + */ rotateXNew(origin: V4Q, radian: number): V4Q { return this.clone().rotateX(origin, radian); } + /** + * Rotate the vector around the Y axis through a point, in place. Only x and + * z change; y and w are left as they are. + * + * @param origin The point to rotate around. Only its x and z are used. + * @param radian The angle in radians. + * @returns This vector, for chaining. + */ rotateY(origin: V4Q, radian: number): V4Q { const s = Math.sin(radian); const c = Math.cos(radian); @@ -423,10 +424,25 @@ class Vec4 implements V4Q { return this; } + /** + * Like `rotateY`, but returns a new vector and leaves this one unchanged. + * + * @param origin The point to rotate around. + * @param radian The angle in radians. + * @returns A new, rotated copy. + */ rotateYNew(origin: V4Q, radian: number): V4Q { return this.clone().rotateY(origin, radian); } + /** + * Rotate the vector around the Z axis through a point, in place. Only x and + * y change; z and w are left as they are. + * + * @param origin The point to rotate around. Only its x and y are used. + * @param radian The angle in radians. + * @returns This vector, for chaining. + */ rotateZ(origin: V4Q, radian: number): V4Q { const s = Math.sin(radian); const c = Math.cos(radian); @@ -440,10 +456,24 @@ class Vec4 implements V4Q { return this; } + /** + * Like `rotateZ`, but returns a new vector and leaves this one unchanged. + * + * @param origin The point to rotate around. + * @param radian The angle in radians. + * @returns A new, rotated copy. + */ rotateZNew(origin: V4Q, radian: number): V4Q { return this.clone().rotateZ(origin, radian); } + /** + * Multiply the vector by a 4×4 matrix (`m × v`), in place. The matrix is + * read in column-major order, as WebGL uses. + * + * @param m The matrix, as a Mat4 or a 16-element array. + * @returns This vector, for chaining. + */ transformByMat4(m: Mat4Like): V4Q { const ma = Array.isArray(m) ? m : m.array; const o = this.clone(); @@ -454,10 +484,24 @@ class Vec4 implements V4Q { return this; } + /** + * Like `transformByMat4`, but returns a new vector and leaves this one + * unchanged. + * + * @param m The matrix, as a Mat4 or a 16-element array. + * @returns A new, transformed vector. + */ transformByMat4New(m: Mat4Like): V4Q { return this.clone().transformByMat4(m); } + /** + * Rotate the x, y and z components by a quaternion, in place. w is left as + * it is. The quaternion should be normalised. + * + * @param q The quaternion, as a Quat or an `[x, y, z, w]` array. + * @returns This vector, for chaining. + */ transformByQuat(q: QuatLike): V4Q { const qa = Array.isArray(q) ? q : [q.x, q.y, q.z, q.w]; const uv = new Vec4( @@ -472,38 +516,40 @@ class Vec4 implements V4Q { return this; } + /** + * Like `transformByQuat`, but returns a new vector and leaves this one + * unchanged. + * + * @param q The quaternion, as a Quat or an `[x, y, z, w]` array. + * @returns A new, rotated vector. + */ transformByQuatNew(q: QuatLike): V4Q { return this.clone().transformByQuat(q); } /** - * Negates the vector. + * Negate every component, in place. * - * @public - * @chainable - * @return {Vec4} Returns itself, modified + * @returns This vector, for chaining. */ negate(): V4Q { return this.multiplyScalar(-1); } /** - * Clones the vector and negates it. + * Like `negate`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec4} Returns itself, modified + * @returns A new, negated vector. */ negateNew(): V4Q { return this.multiplyScalarNew(-1); } /** - * Inverses the vector. + * Replace every component with its reciprocal (`1 / n`), in place. A 0 + * component becomes `Infinity`. * - * @public - * @chainable - * @return {Vec4} Returns itself, modified + * @returns This vector, for chaining. */ inverse(): V4Q { this.x = 1 / this.x; @@ -514,11 +560,9 @@ class Vec4 implements V4Q { } /** - * Clones the vector and then inverses it. + * Like `inverse`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec4} Returns itself, modified + * @returns A new vector holding the reciprocals. */ inverseNew(): V4Q { const c: V4Q = this.clone(); @@ -530,11 +574,10 @@ class Vec4 implements V4Q { } /** - * Normalises the vector down to a length of 1 unit + * Scale the vector to a length of 1, in place. A zero-length vector becomes + * `(0, 0, 0, 1)`. * - * @public - * @chainable - * @return {Vec4} Returns itself, modified + * @returns This vector, for chaining. */ normalise(): V4Q { const l: number = this.length; @@ -549,77 +592,74 @@ class Vec4 implements V4Q { return this; } /** - * Clones the vector and normalises it + * Like `normalise`, but returns a new vector and leaves this one unchanged. * - * @public - * @chainable - * @return {Vec4} Returns a clone of itself, modified + * @returns A new, normalised vector. */ normaliseNew(): V4Q { return this.clone().normalise(); } /** - * Calculates the distance between this and the supplied vector + * The distance between this vector and another. * - * @param {Vec4} vector The vector to calculate the distance from - * @return {number} The distance between this and the supplied vector + * @param vector The other vector. + * @returns The length of the difference between the two vectors. */ distance(vector: V4Q): number { return this.subtractNew(vector).length; } /** - * Calculates the distance on the X axis between this and the supplied vector + * The signed difference between the x components of this vector and another. * - * @param {Vec4} vector The vector to calculate the distance from - * @return {number} The distance, along the x axis, between this and the supplied vector + * @param vector The other vector. + * @returns `this.x - vector.x`. Can be negative. */ distanceX(vector: V4Q): number { return this.x - vector.x; } /** - * Calculated the distance on the Y axis between this and the supplied vector + * The signed difference between the y components of this vector and another. * - * @param {Vec4} vector The vector to calculate the distance from - * @return {number} The distance, along the y axis, between this and the supplied vector + * @param vector The other vector. + * @returns `this.y - vector.y`. Can be negative. */ distanceY(vector: V4Q): number { return this.y - vector.y; } /** - * Calculated the distance on the Z axis between this and the supplied vector + * The signed difference between the z components of this vector and another. * - * @param {Vec4} vector The vector to calculate the distance from - * @return {number} The distance, along the y axis, between this and the supplied vector + * @param vector The other vector. + * @returns `this.z - vector.z`. Can be negative. */ distanceZ(vector: V4Q): number { return this.z - vector.z; } /** - * Calculated the distance on the W axis between this and the supplied vector + * The signed difference between the w components of this vector and another. * - * @param {Vec4} vector The vector to calculate the distance from - * @return {number} The distance, along the y axis, between this and the supplied vector + * @param vector The other vector. + * @returns `this.w - vector.w`. Can be negative. */ distanceW(vector: V4Q): number { return this.w - vector.w; } /** - * Calculates the dot product between this and a supplied vector + * The dot product of this vector and another. * * @example - * // returns -14 - * new Vector(2, -3).dot(new Vector(-4, 2)) - * new Vector(-4, 2).dot(new Vector(2, -3)) - * new Vector(2, -4).dot(new Vector(-3, 2)) + * ```ts + * new Vec4(1, 2, 3, 4).dot(new Vec4(5, 6, 7, 8)); // 70 + * ``` * - * @param {Vec4} vector The vector object against which to calculate the dot product - * @return {number} The dot product of the two vectors + * @param vector The other vector. + * @returns The sum of the products of the matching components. */ dot(vector: V4Q): number { return ( @@ -631,18 +671,12 @@ class Vec4 implements V4Q { } /** - * Calculates the cross product between this and two other supplied vectors + * The four-dimensional cross product of this vector and two others: a + * vector perpendicular to all three. Does not change this vector. * - * @example - * // returns -2 - * new Vector(2, -3).cross(new Vector(-4, 2)) - * new Vector(-4, 2).cross(new Vector(2, -3)) - * // returns 2 - * new Vector(2, -4).cross(new Vector(-3, 2)) - * - * @param {Vec4} v The first other vector - * @param {Vec4} w The second other vector - * @return {Vec4} The cross product of the two vectors + * @param v The second vector. + * @param w The third vector. + * @returns A new Vec4 holding the result. */ cross(v: V4Q, w: V4Q): V4Q { const u = this.clone(); @@ -666,10 +700,22 @@ class Vec4 implements V4Q { ); } + /** + * Same as `cross`: returns a new vector and leaves this one unchanged. + * + * @param v The second vector. + * @param w The third vector. + * @returns A new Vec4 holding the result. + */ crossNew(v: V4Q, w: V4Q): V4Q { return this.clone().cross(v, w); } + /** + * Round every component up to the nearest integer, in place. + * + * @returns This vector, for chaining. + */ ceil(): V4Q { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); @@ -678,10 +724,20 @@ class Vec4 implements V4Q { return this; } + /** + * Like `ceil`, but returns a new vector and leaves this one unchanged. + * + * @returns A new, rounded vector. + */ ceilNew(): V4Q { return this.clone().ceil(); } + /** + * Round every component down to the nearest integer, in place. + * + * @returns This vector, for chaining. + */ floor(): V4Q { this.x = Math.floor(this.x); this.y = Math.floor(this.y); @@ -690,10 +746,21 @@ class Vec4 implements V4Q { return this; } + /** + * Like `floor`, but returns a new vector and leaves this one unchanged. + * + * @returns A new, rounded vector. + */ floorNew(): V4Q { return this.clone().floor(); } + /** + * Round every component to the nearest integer, in place, using + * `Math.round` (halves round up). + * + * @returns This vector, for chaining. + */ round(): V4Q { this.x = Math.round(this.x); this.y = Math.round(this.y); @@ -702,10 +769,22 @@ class Vec4 implements V4Q { return this; } + /** + * Like `round`, but returns a new vector and leaves this one unchanged. + * + * @returns A new, rounded vector. + */ roundNew(): V4Q { return this.clone().round(); } + /** + * Replace every component with its fractional part (`n - floor(n)`), in + * place. Results are always in the range [0, 1), including for negative + * values. + * + * @returns This vector, for chaining. + */ fract(): V4Q { this.x -= Math.floor(this.x); this.y -= Math.floor(this.y); @@ -714,21 +793,21 @@ class Vec4 implements V4Q { return this; } + /** + * Like `fract`, but returns a new vector and leaves this one unchanged. + * + * @returns A new vector holding the fractional parts. + */ fractNew(): V4Q { return this.clone().fract(); } - /** - * Getters and setters - */ + // Getters and setters + private _x: number = 0; /** - * (getter/setter) The x value of the vector. - * - * @type {number} - * @default 0 + * Set the x component. Throws a `TypeError` if the value is not a number. */ - private _x: number = 0; set x(x) { if (typeof x == "number") { this._x = x; @@ -736,17 +815,19 @@ class Vec4 implements V4Q { throw new TypeError("X should be a number"); } } + /** + * The x component of the vector. + * + * @default 0 + */ get x() { return this._x || 0; } + private _y: number = 0; /** - * (getter/setter) The y value of the vector. - * - * @type {number} - * @default 0 + * Set the y component. Throws a `TypeError` if the value is not a number. */ - private _y: number = 0; set y(y) { if (typeof y == "number") { this._y = y; @@ -754,17 +835,19 @@ class Vec4 implements V4Q { throw new TypeError("Y should be a number"); } } + /** + * The y component of the vector. + * + * @default 0 + */ get y() { return this._y || 0; } + private _z: number = 0; /** - * (getter/setter) The y value of the vector. - * - * @type {number} - * @default 0 + * Set the z component. Throws a `TypeError` if the value is not a number. */ - private _z: number = 0; set z(z) { if (typeof z == "number") { this._z = z; @@ -772,17 +855,19 @@ class Vec4 implements V4Q { throw new TypeError("Z should be a number"); } } + /** + * The z component of the vector. + * + * @default 0 + */ get z() { return this._z || 0; } + private _w: number = 0; /** - * (getter/setter) The y value of the vector. - * - * @type {number} - * @default 0 + * Set the w component. Throws a `TypeError` if the value is not a number. */ - private _w: number = 0; set w(w) { if (typeof w == "number") { this._w = w; @@ -790,16 +875,21 @@ class Vec4 implements V4Q { throw new TypeError("W should be a number"); } } + /** + * The w component of the vector. + * + * @default 0 + */ get w() { return this._w || 0; } /** - * (getter/setter) The length of the vector presented as a square. If you're using - * length for comparison, this is quicker. + * Scale the vector by `value / lengthSquared`. Throws a `TypeError` if the + * value is not a number. * - * @type {number} - * @default 0 + * Note that this does not leave `lengthSquared` equal to the value set: the + * squared length ends up as `value² / lengthSquared`. */ set lengthSquared(length: number) { var factor; @@ -810,6 +900,10 @@ class Vec4 implements V4Q { throw new TypeError("length should be a number"); } } + /** + * The squared length of the vector. Quicker than `length` when you only + * need to compare lengths. + */ get lengthSquared(): number { return ( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w @@ -817,10 +911,9 @@ class Vec4 implements V4Q { } /** - * (getter/setter) The length of the vector - * - * @type {number} - * @default 0 + * Set the length of the vector, scaling it while keeping its direction. + * A zero-length vector cannot be scaled and its components become `NaN`. + * Throws a `TypeError` if the value is not a number. */ set length(length: number) { var factor; @@ -831,77 +924,53 @@ class Vec4 implements V4Q { throw new TypeError("length should be a number"); } } + /** The length of the vector. */ get length(): number { return Math.sqrt(this.lengthSquared); } - /** - * (getter/setter) Vector width. - * Alias of {@link x} - * - * @type {number} - */ + /** Set the x component. Alias of `x`. */ set width(w: number) { this.x = w; } + /** The x component. Alias of `x`, for vectors used as sizes. */ get width(): number { return this.x; } - /** - * (getter/setter) Vector height. - * Alias of {@link y} - * - * @type {number} - */ + /** Set the y component. Alias of `y`. */ set height(h: number) { this.y = h; } + /** The y component. Alias of `y`, for vectors used as sizes. */ get height(): number { return this.y; } - /** - * (getter/setter) Vector depth. - * Alias of {@link z} - * - * @type {number} - */ + /** Set the z component. Alias of `z`. */ set depth(h: number) { this.z = h; } + /** The z component. Alias of `z`, for vectors used as sizes. */ get depth(): number { return this.z; } - /** - * (getter) Vector area. - * @readonly - * - * @type {number} - */ + /** The product of all four components (`x * y * z * w`). Read-only. */ get area(): number { return this.x * this.y * this.z * this.w; } - /** - * (getter) Returns the basic array representation of this vector. - * @readonly - * - * @type {number} - */ + /** The components as a new `[x, y, z, w]` array. Read-only. */ get array(): number[] { return [this.x, this.y, this.z, this.w]; } - /** - * (getter/sette) Swizzle XYZW - * - * @type {Vec4} - */ + /** The x, y, z and w components as a new Vec4. */ get xyzw(): Vec4 { return new Vec4(this.x, this.y, this.z, this.w); } + /** Set x, y, z and w from a Vec4 or array, in that order. */ set xyzw(v: Vec4Like) { if (Array.isArray(v)) { this.x = v[0]; this.y = v[1]; this.z = v[2]; this.w = v[3]; @@ -910,14 +979,11 @@ class Vec4 implements V4Q { } } - /** - * (getter/sette) Swizzle YZWX - * - * @type {Vec4} - */ + /** The y, z, w and x components as a new Vec4. */ get yzwx(): Vec4 { return new Vec4(this.y, this.z, this.w, this.x); } + /** Set y, z, w and x from a Vec4 or array, in that order. */ set yzwx(v: Vec4Like) { if (Array.isArray(v)) { this.y = v[0]; this.z = v[1]; this.w = v[2]; this.x = v[3]; @@ -926,14 +992,11 @@ class Vec4 implements V4Q { } } - /** - * (getter/sette) Swizzle ZWXY - * - * @type {Vec4} - */ + /** The z, w, x and y components as a new Vec4. */ get zwxy(): Vec4 { return new Vec4(this.z, this.w, this.x, this.y); } + /** Set z, w, x and y from a Vec4 or array, in that order. */ set zwxy(v: Vec4Like) { if (Array.isArray(v)) { this.z = v[0]; this.w = v[1]; this.x = v[2]; this.y = v[3]; @@ -942,14 +1005,11 @@ class Vec4 implements V4Q { } } - /** - * (getter/sette) Swizzle WXYZ - * - * @type {Vec4} - */ + /** The w, x, y and z components as a new Vec4. */ get wxyz(): Vec4 { return new Vec4(this.w, this.x, this.y, this.z); } + /** Set w, x, y and z from a Vec4 or array, in that order. */ set wxyz(v: Vec4Like) { if (Array.isArray(v)) { this.w = v[0]; this.x = v[1]; this.y = v[2]; this.z = v[3]; @@ -960,14 +1020,11 @@ class Vec4 implements V4Q { // I'm skipping all the silly combinations of 4 here because they're largely useless - /** - * (getter/sette) Swizzle YZX - * - * @type {Vec3} - */ + /** The x, y and z components as a new Vec3. */ get xyz(): Vec3 { return new Vec3(this.x, this.y, this.z); } + /** Set x, y and z from a Vec3 or array, in that order. w is unchanged. */ set xyz(v: Vec3Like) { if (Array.isArray(v)) { this.x = v[0]; @@ -980,14 +1037,14 @@ class Vec4 implements V4Q { } } - /** - * (getter/sette) Swizzle YZX - * - * @type {Vec3} - */ + /** The y, z and x components as a new Vec3. */ get yzx(): Vec3 { return new Vec3(this.y, this.z, this.x); } + /** + * Set x, y and z from a Vec3 or array: x from the second component, y from + * the third and z from the first. w is unchanged. + */ set yzx(v: Vec3Like) { if (Array.isArray(v)) { this.x = v[1]; @@ -1000,14 +1057,14 @@ class Vec4 implements V4Q { } } - /** - * (getter/sette) Swizzle ZXY - * - * @type {Vec3} - */ + /** The z, x and y components as a new Vec3. */ get zxy(): Vec3 { return new Vec3(this.z, this.x, this.y); } + /** + * Set x, y and z from a Vec3 or array: x from the third component, y from + * the first and z from the second. w is unchanged. + */ set zxy(v: Vec3Like) { if (Array.isArray(v)) { this.x = v[2]; @@ -1020,235 +1077,208 @@ class Vec4 implements V4Q { } } - /** - * (getter/sette) Swizzle XX - * - * @type {number} - */ + /** The x component twice, as a new Vec2. */ get xx(): Vec2 { return new Vec2(this.x, this.x); } + /** + * Set x from the second component of a Vec2 or array. The first component + * is ignored. + */ set xx(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.y; } - /** - * (getter/sette) Swizzle XY - * - * @type {Vec2} - */ + /** The x and y components as a new Vec2. */ get xy(): Vec2 { return new Vec2(this.x, this.y); } + /** Set x and y from a Vec2 or array, in that order. */ set xy(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.x; this.y = v.y; } - /** - * (getter/sette) Swizzle XY - * - * @type {Vec2} - */ + /** The x and z components as a new Vec2. */ get xz(): Vec2 { return new Vec2(this.x, this.z); } + /** Set x and z from a Vec2 or array, in that order. */ set xz(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.x; this.z = v.y; } - /** - * (getter/sette) Swizzle XY - * - * @type {Vec2} - */ + /** The x and w components as a new Vec2. */ get xw(): Vec2 { return new Vec2(this.x, this.w); } + /** Set x and w from a Vec2 or array, in that order. */ set xw(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.x; this.w = v.y; } - /** - * (getter/sette) Swizzle YX - * - * @type {number} - */ + /** The y and x components as a new Vec2. */ get yx(): Vec2 { return new Vec2(this.y, this.x); } + /** Set y and x from a Vec2 or array, in that order. */ set yx(v: Vec2Like) { v = Vec2.interpolate(v); this.x = v.y; this.y = v.x; } - /** - * (getter/sette) Swizzle YY - * - * @type {number} - */ + /** The y component twice, as a new Vec2. */ get yy(): Vec2 { return new Vec2(this.y, this.y); } + /** + * Set y from the second component of a Vec2 or array. The first component + * is ignored. + */ set yy(v: Vec2Like) { v = Vec2.interpolate(v); this.y = v.y; } - /** - * (getter/sette) Swizzle YZ - * - * @type {Vec2} - */ + /** The y and z components as a new Vec2. */ get yz(): Vec2 { return new Vec2(this.y, this.z); } + /** Set y and z from a Vec2 or array, in that order. */ set yz(v: Vec2Like) { v = Vec2.interpolate(v); this.y = v.x; this.z = v.y; } - /** - * (getter/sette) Swizzle YZ - * - * @type {Vec2} - */ + /** The y and w components as a new Vec2. */ get yw(): Vec2 { return new Vec2(this.y, this.w); } + /** Set y and w from a Vec2 or array, in that order. */ set yw(v: Vec2Like) { v = Vec2.interpolate(v); this.y = v.x; this.w = v.y; } - /** - * (getter/sette) Swizzle zx - * - * @type {Vec2} - */ + /** The z and x components as a new Vec2. */ get zx(): Vec2 { return new Vec2(this.z, this.x); } + /** Set z and x from a Vec2 or array, in that order. */ set zx(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.x; this.x = v.y; } - /** - * (getter/sette) Swizzle ZY - * - * @type {number} - */ + /** The z and y components as a new Vec2. */ get zy(): Vec2 { return new Vec2(this.z, this.y); } + /** + * Set z and y from a Vec2 or array. Note that z is taken from the second + * component and y from the first, the reverse of the getter's order. + */ set zy(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.y; this.y = v.x; } - /** - * (getter/sette) Swizzle ZZ - * - * @type {number} - */ + /** The z component twice, as a new Vec2. */ get zz(): Vec2 { return new Vec2(this.z, this.z); } + /** + * Set z from the second component of a Vec2 or array. The first component + * is ignored. + */ set zz(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.y; } - /** - * (getter/sette) Swizzle XY - * - * @type {Vec2} - */ + /** The z and w components as a new Vec2. */ get zw(): Vec2 { return new Vec2(this.z, this.w); } + /** Set z and w from a Vec2 or array, in that order. */ set zw(v: Vec2Like) { v = Vec2.interpolate(v); this.z = v.x; this.w = v.y; } - /** - * (getter/sette) Swizzle wx - * - * @type {Vec2} - */ + /** The w and x components as a new Vec2. */ get wx(): Vec2 { return new Vec2(this.w, this.x); } + /** Set w and x from a Vec2 or array, in that order. */ set wx(v: Vec2Like) { v = Vec2.interpolate(v); this.w = v.x; this.x = v.y; } - /** - * (getter/sette) Swizzle WY - * - * @type {number} - */ + /** The w and y components as a new Vec2. */ get wy(): Vec2 { return new Vec2(this.w, this.y); } + /** Set w and y from a Vec2 or array, in that order. */ set wy(v: Vec2Like) { v = Vec2.interpolate(v); this.w = v.x; this.y = v.y; } - /** - * (getter/sette) Swizzle WZ - * - * @type {number} - */ + /** The w and z components as a new Vec2. */ get wz(): Vec2 { return new Vec2(this.w, this.z); } + /** Set w and z from a Vec2 or array, in that order. */ set wz(v: Vec2Like) { v = Vec2.interpolate(v); this.w = v.x; this.z = v.y; } - /** - * (getter/sette) Swizzle WW - * - * @type {Vec2} - */ + /** The w component twice, as a new Vec2. */ get ww(): Vec2 { return new Vec2(this.w, this.w); } + /** + * Set w from the second component of a Vec2 or array. The first component + * is ignored. + */ set ww(v: Vec2Like) { v = Vec2.interpolate(v); this.w = v.y; } - /** - * Static methods - */ + // Static methods /** - * Iterpolates a provided anonymous value into a vew Vec4 + * Convert a loosely typed value into a new Vec4. + * + * - A number is used for all four components. + * - A string is read as comma-separated `"x, y, z, w"`. + * - An array is read as `[x, y, z, w]`. + * - Any other object is read from its x, y, z and w properties. + * + * Throws an `Error` for `NaN`, or for a string with fewer than four numeric + * values. * - * @param {Vec4|array|string|number} v The value to interpolate - * @returns {Vec4} out + * @param v The value to convert. + * @returns A new Vec4. */ static interpolate(v: Vec4Like | number | string): Vec4 { if (typeof v === "number") { @@ -1273,12 +1303,13 @@ class Vec4 implements V4Q { } /** - * Performs a linear interpolation between two Vec4's + * Linearly interpolate between two vectors. `d` is not clamped, so values + * outside 0–1 extrapolate. * - * @param {Vec4} v1 the first operand - * @param {Vec4} v2 the second operand - * @param {Number} d interpolation amount in the range of 0 - 1 - * @returns {Vec4} + * @param v1 The start vector, returned when `d` is 0. + * @param v2 The end vector, returned when `d` is 1. + * @param d The interpolation amount, usually from 0 to 1. + * @returns A new Vec4 (also when called as `Quat.lerp`). */ static lerp(v1: Vec4, v2: Vec4, d: number) { return new Vec4( @@ -1289,29 +1320,24 @@ class Vec4 implements V4Q { ); } + /** + * The rotation angle between two unit quaternions, in radians, computed as + * `acos(2 * dot(a, b)² - 1)`. This is not the angle between two general + * 4D vectors: the inputs must be normalised for the result to be meaningful. + * + * @param a The first unit quaternion. + * @param b The second unit quaternion. + * @returns The angle in radians, from 0 to π. + */ static getAngle(a: Vec4, b: Vec4) { let dotproduct = a.dot(b); return Math.acos(2 * dotproduct * dotproduct - 1); } - - /** - * Adds iteration to the object, allowing it - * to be destructured and iterated upon in - * various useful ways. - */ - [Symbol.iterator]() { - let values = this.array; - let index = 0; - return { - next() { - if (index < values.length) { - let value = values[index]; - index++; - return { value, done: false }; - } else return { done: true } - } - } + + /** Iterate over the components, so the vector can be spread or destructured: `const [x, y, z, w] = v`. */ + [Symbol.iterator](): Iterator { + return this.array[Symbol.iterator](); } } diff --git a/src/index.ts b/src/index.ts index 961b6f8..a18ada2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,15 @@ +/** + * Vectors, matrices, quaternions and scalar functions: + * + * ```ts + * import { Vec2, Vec3, Mat4, Quat, clamp } from 'wtc-math' + * ``` + * + * `Color`, `Plane` and `Ray` have entry points of their own: + * `wtc-math/color`, `wtc-math/plane` and `wtc-math/ray`. + * + * @module wtc-math + */ import { Vec2 } from "./Vec2.js"; export type { Vec2Like, diff --git a/src/types.ts b/src/types.ts index cf91c02..29a89f3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,70 @@ -export type Vec2Like = { x: number; y: number } | [number, number]; -export type Vec3Like = { x: number; y: number; z: number } | [number, number, number]; -export type Vec4Like = { x: number; y: number; z: number; w: number } | [number, number, number, number]; +/** + * A 2D vector: a {@link Vec2}, any object with `x` and `y`, or an `[x, y]` array. + */ +export type Vec2Like = + | { + /** The x component. */ + x: number; + /** The y component. */ + y: number; + } + | [number, number]; +/** + * A 3D vector: a {@link Vec3}, any object with `x`, `y` and `z`, or an `[x, y, z]` array. + */ +export type Vec3Like = + | { + /** The x component. */ + x: number; + /** The y component. */ + y: number; + /** The z component. */ + z: number; + } + | [number, number, number]; +/** + * A 4D vector: a {@link Vec4}, any object with `x`, `y`, `z` and `w`, or an `[x, y, z, w]` array. + */ +export type Vec4Like = + | { + /** The x component. */ + x: number; + /** The y component. */ + y: number; + /** The z component. */ + z: number; + /** The w component. */ + w: number; + } + | [number, number, number, number]; +/** + * A quaternion: a {@link Quat} or anything accepted as a {@link Vec4Like}, ordered x, y, z, w. + */ export type QuatLike = Vec4Like; -export type Mat2Like = { array: number[] } | number[]; -export type Mat3Like = { array: number[] } | number[]; -export type Mat4Like = { array: number[] } | number[]; +/** + * A 2×2 matrix: a {@link Mat2}, any object with an `array` of elements, or a plain array of 4 numbers. + */ +export type Mat2Like = + | { + /** The matrix elements. */ + array: number[]; + } + | number[]; +/** + * A 3×3 matrix: a {@link Mat3}, any object with an `array` of elements, or a plain array of 9 numbers. + */ +export type Mat3Like = + | { + /** The matrix elements. */ + array: number[]; + } + | number[]; +/** + * A 4×4 matrix: a {@link Mat4}, any object with an `array` of elements, or a plain array of 16 numbers. + */ +export type Mat4Like = + | { + /** The matrix elements. */ + array: number[]; + } + | number[]; diff --git a/tsconfig.json b/tsconfig.json index 22182e2..230bf99 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,17 +9,6 @@ "declaration": true, "declarationDir": "./dist" }, - "include": ["src", "test", "vite.config.ts", "vite.site.config.ts"], - "exclude": ["dist", "dist-site", "node_modules", "demos"], - "typedocOptions": { - "out": "documentation", - "entryPoints": "src/index.ts", - "exclude": ["dist/*+.ts*"], - "intentionallyNotExported": [ - "V4Q", - "Mat3DeterminantFunction", - "Mat4DeterminantFunction", - "src/Mat3.ts:Mat4" - ] - } + "include": ["src", "test", "vite.config.ts"], + "exclude": ["dist", "node_modules", "docs"] } diff --git a/vite.site.config.ts b/vite.site.config.ts deleted file mode 100644 index 6871acd..0000000 --- a/vite.site.config.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { resolve } from "path"; -import { existsSync } from "node:fs"; -import { defineConfig, type Plugin } from "vite"; -import pug from "pug"; - -function pugPlugin(): Plugin { - return { - name: "vite-pug", - transformIndexHtml: { - order: "pre", - handler(_, ctx) { - const pugPath = ctx.filename.replace(/\.html$/, ".pug"); - if (!existsSync(pugPath)) return _; - return pug.renderFile(pugPath, { pretty: true }); - }, - }, - handleHotUpdate({ file, server }) { - if (file.endsWith(".pug")) { - server.ws.send({ type: "full-reload" }); - return []; - } - }, - }; -} - -export default defineConfig({ - root: "demos", - base: "/wtc-math/", - plugins: [pugPlugin()], - build: { - outDir: resolve(__dirname, "dist-site"), - emptyOutDir: true, - rollupOptions: { - input: { - main: resolve(__dirname, "demos/index.html"), - camera: resolve(__dirname, "demos/camera.html"), - gradients: resolve(__dirname, "demos/gradients.html"), - color: resolve(__dirname, "demos/color.html"), - colorspaces: resolve(__dirname, "demos/colorspaces.html"), - plane: resolve(__dirname, "demos/plane.html"), - ray: resolve(__dirname, "demos/ray.html"), - colormath: resolve(__dirname, "demos/colormath.html"), - harmonies: resolve(__dirname, "demos/harmonies.html"), - }, - }, - }, -});