mudlet-map-renderer 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +520 -0
- package/dist/AreaMapRenderer.d.ts +125 -0
- package/dist/CullingManager.d.ts +15 -0
- package/dist/ExitRenderer.d.ts +109 -0
- package/dist/InteractionHandler.d.ts +47 -0
- package/dist/MapGraph.d.ts +28 -0
- package/dist/MapReader-mU_4JWv_.js +224 -0
- package/dist/MapReader-mU_4JWv_.js.map +1 -0
- package/dist/MapState.d.ts +110 -0
- package/dist/PathData.d.ts +18 -0
- package/dist/PathFinder.d.ts +12 -0
- package/dist/ScenePipeline.d.ts +226 -0
- package/dist/SvgTypes.d.ts +21 -0
- package/dist/TypedEventEmitter.d.ts +17 -0
- package/dist/binary/BinaryMapReader.d.ts +36 -0
- package/dist/binary/index.d.ts +2 -0
- package/dist/binary.mjs +34 -0
- package/dist/binary.mjs.map +1 -0
- package/dist/camera/Camera.d.ts +118 -0
- package/dist/coord/CoordFn.d.ts +13 -0
- package/dist/directions.d.ts +25 -0
- package/dist/draw/DrawCommand.d.ts +104 -0
- package/dist/draw/DrawCommandBuilder.d.ts +19 -0
- package/dist/export/CanvasExporter.d.ts +71 -0
- package/dist/export/Exporter.d.ts +58 -0
- package/dist/export/PngExporter.d.ts +23 -0
- package/dist/export/SvgExporter.d.ts +19 -0
- package/dist/export/canvasToBytes.d.ts +19 -0
- package/dist/export/clipSceneToViewport.d.ts +48 -0
- package/dist/export/flushSceneShapes.d.ts +21 -0
- package/dist/export/sceneBounds.d.ts +24 -0
- package/dist/hit/HitTester.d.ts +101 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.mjs +6670 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lens/ExplorationLens.d.ts +29 -0
- package/dist/lens/RoomLens.d.ts +47 -0
- package/dist/lens/composeLenses.d.ts +31 -0
- package/dist/lens/index.d.ts +5 -0
- package/dist/overlay/AmbientLightOverlay.d.ts +32 -0
- package/dist/overlay/LiveEffect.d.ts +33 -0
- package/dist/overlay/SceneOverlay.d.ts +68 -0
- package/dist/reader/Area.d.ts +63 -0
- package/dist/reader/Exit.d.ts +15 -0
- package/dist/reader/MapReader.d.ts +34 -0
- package/dist/reader/Plane.d.ts +33 -0
- package/dist/render/CanvasRenderer.d.ts +17 -0
- package/dist/render/RecordingLayer.d.ts +158 -0
- package/dist/render/SvgRenderer.d.ts +7 -0
- package/dist/render/shapeToRecording.d.ts +3 -0
- package/dist/rendering/KonvaRenderBackend.d.ts +122 -0
- package/dist/rendering/MapRenderer.d.ts +213 -0
- package/dist/rendering/SceneManager.d.ts +54 -0
- package/dist/scene/AmbientLightStyle.d.ts +29 -0
- package/dist/scene/GridStyle.d.ts +21 -0
- package/dist/scene/InnerExitStyle.d.ts +24 -0
- package/dist/scene/OverlayStyle.d.ts +47 -0
- package/dist/scene/RoomStyle.d.ts +32 -0
- package/dist/scene/Shape.d.ts +151 -0
- package/dist/scene/SpecialExitStyle.d.ts +37 -0
- package/dist/scene/StubStyle.d.ts +15 -0
- package/dist/scene/elements/ExitLayout.d.ts +22 -0
- package/dist/scene/elements/GridLayout.d.ts +24 -0
- package/dist/scene/elements/LabelLayout.d.ts +11 -0
- package/dist/scene/elements/OverlayLayout.d.ts +14 -0
- package/dist/scene/elements/RoomLayout.d.ts +19 -0
- package/dist/scene/elements/SpecialExitLayout.d.ts +19 -0
- package/dist/scene/elements/StubLayout.d.ts +19 -0
- package/dist/style/Style.d.ts +60 -0
- package/dist/style/applyStyle.d.ts +3 -0
- package/dist/style/index.d.ts +21 -0
- package/dist/style/shape/BlueprintStyle.d.ts +11 -0
- package/dist/style/shape/ConstructionStyle.d.ts +17 -0
- package/dist/style/shape/IsometricStyle.d.ts +32 -0
- package/dist/style/shape/NeonStyle.d.ts +17 -0
- package/dist/style/shape/ParchmentStyle.d.ts +13 -0
- package/dist/style/shape/SciFiStyle.d.ts +16 -0
- package/dist/style/shape/SketchyStyle.d.ts +22 -0
- package/dist/style/shape/index.d.ts +25 -0
- package/dist/style/shape/paintMap.d.ts +25 -0
- package/dist/style/shape/wobble.d.ts +24 -0
- package/{src/types/MapData.ts → dist/types/MapData.d.ts} +70 -90
- package/dist/types/Settings.d.ts +206 -0
- package/dist/utils/color.d.ts +12 -0
- package/dist/utils/textMeasure.d.ts +38 -0
- package/package.json +67 -37
- package/demo/colors.json +0 -1
- package/demo/index.html +0 -102
- package/demo/main.ts +0 -389
- package/demo/mapExport.json +0 -1
- package/demo/tsconfig.json +0 -11
- package/src/ExitRenderer.ts +0 -275
- package/src/PathFinder.ts +0 -93
- package/src/PathRenderer.ts +0 -129
- package/src/Renderer.ts +0 -374
- package/src/directions.ts +0 -66
- package/src/index.ts +0 -4
- package/src/reader/Area.ts +0 -96
- package/src/reader/Exit.ts +0 -36
- package/src/reader/ExplorationArea.ts +0 -132
- package/src/reader/MapReader.ts +0 -123
- package/src/reader/Plane.ts +0 -42
- package/tsconfig.json +0 -17
- package/vercel.json +0 -5
- package/vite.config.ts +0 -29
- package/vite.demo.config.ts +0 -15
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Exporter, ExportContext, ExportCanvas } from './Exporter';
|
|
2
|
+
export interface CanvasExportOptions {
|
|
3
|
+
/** Width of the output image in pixels. */
|
|
4
|
+
width: number;
|
|
5
|
+
/** Height of the output image in pixels. */
|
|
6
|
+
height: number;
|
|
7
|
+
/** Room ID to center the export on. If omitted, exports the full area. */
|
|
8
|
+
roomId?: number;
|
|
9
|
+
/** Padding in map units around the exported region. Default: 3 */
|
|
10
|
+
padding?: number;
|
|
11
|
+
/** Overlays to render over the scene (position marker, highlights, paths). */
|
|
12
|
+
overlays?: {
|
|
13
|
+
position?: {
|
|
14
|
+
roomId: number;
|
|
15
|
+
};
|
|
16
|
+
highlights?: Array<{
|
|
17
|
+
roomId: number;
|
|
18
|
+
color: string;
|
|
19
|
+
}>;
|
|
20
|
+
paths?: Array<{
|
|
21
|
+
locations: number[];
|
|
22
|
+
color: string;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Renders the current scene into a canvas at the requested width/height by
|
|
28
|
+
* driving {@link ScenePipeline} → {@link buildDrawCommands} →
|
|
29
|
+
* {@link renderToCanvas}.
|
|
30
|
+
*
|
|
31
|
+
* Decoupled from the live Konva stage: the pipeline is rebuilt against the
|
|
32
|
+
* export bounds, shapes are projected through a fitted camera transform, and
|
|
33
|
+
* the result is rasterized onto a fresh 2D canvas. Background colour is
|
|
34
|
+
* filled before any draw commands replay, so PNG / JPEG output looks identical
|
|
35
|
+
* to the on-screen map.
|
|
36
|
+
*
|
|
37
|
+
* Unlike {@link PngExporter} (which captures the on-screen viewport via the
|
|
38
|
+
* live Konva stage), `CanvasExporter` is fully headless and reproducible.
|
|
39
|
+
*/
|
|
40
|
+
export declare class CanvasExporter implements Exporter<ExportCanvas | undefined> {
|
|
41
|
+
private readonly options;
|
|
42
|
+
constructor(options: CanvasExportOptions);
|
|
43
|
+
render({ state, style, sceneOverlays }: ExportContext): ExportCanvas | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface PngBytesExportOptions extends CanvasExportOptions {
|
|
46
|
+
/** MIME type to encode. Defaults to `'image/png'`. */
|
|
47
|
+
mimeType?: string;
|
|
48
|
+
/** Encoder quality (0..1). Only used for lossy formats like `'image/jpeg'`. */
|
|
49
|
+
quality?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Headless PNG/JPEG bytes at a specific width × height.
|
|
53
|
+
*
|
|
54
|
+
* Composes {@link CanvasExporter} with a portable `toDataURL` → `Uint8Array`
|
|
55
|
+
* decode, so callers get bytes directly without touching a canvas or casting
|
|
56
|
+
* to platform-specific types:
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const png = renderer.export(new PngBytesExporter({ width: 1920, height: 1080 }));
|
|
60
|
+
* fs.writeFileSync('out.png', png!); // Node
|
|
61
|
+
* new Blob([png!], { type: 'image/png' }); // Browser
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* For JPEG: `new PngBytesExporter({ width, height, mimeType: 'image/jpeg', quality: 0.9 })`.
|
|
65
|
+
*/
|
|
66
|
+
export declare class PngBytesExporter implements Exporter<Uint8Array | undefined> {
|
|
67
|
+
private readonly options;
|
|
68
|
+
private readonly canvasExporter;
|
|
69
|
+
constructor(options: PngBytesExportOptions);
|
|
70
|
+
render(context: ExportContext): Uint8Array | undefined;
|
|
71
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MapState } from '../MapState';
|
|
2
|
+
import { Style } from '../style/Style';
|
|
3
|
+
import { SceneOverlay } from '../overlay/SceneOverlay';
|
|
4
|
+
import { InteractiveBackend } from '../rendering/MapRenderer';
|
|
5
|
+
/**
|
|
6
|
+
* Context handed to every {@link Exporter} by {@link MapRenderer.export}.
|
|
7
|
+
* Exporters pull whatever they need — state + style for SVG, backend for
|
|
8
|
+
* canvas/PNG rasterization — so callers never have to wire `renderer.backend`
|
|
9
|
+
* (or any other internal) into an exporter themselves.
|
|
10
|
+
*/
|
|
11
|
+
export interface ExportContext {
|
|
12
|
+
readonly state: MapState;
|
|
13
|
+
readonly backend: InteractiveBackend;
|
|
14
|
+
readonly style: Style;
|
|
15
|
+
readonly sceneOverlays: Iterable<SceneOverlay>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Pluggable output format. An {@link Exporter} consumes an {@link ExportContext}
|
|
19
|
+
* and returns an output of type `T` (a string, a Blob promise, a canvas, bytes…).
|
|
20
|
+
*
|
|
21
|
+
* Adding a new output format means implementing `Exporter<T>`. `MapRenderer`'s
|
|
22
|
+
* surface does not change — users just pass the new exporter to `renderer.export`.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* renderer.export(new SvgExporter({ padding: 5 })); // string
|
|
26
|
+
* renderer.export(new PngExporter({ pixelRatio: 2 })); // string (data URL)
|
|
27
|
+
* renderer.export(new CanvasExporter({ width, height })); // ExportCanvas
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export interface Exporter<T> {
|
|
31
|
+
render(context: ExportContext): T;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Canvas returned by {@link CanvasExporter} and
|
|
35
|
+
* {@link InteractiveBackend.exportCanvas}. Describes the portable surface
|
|
36
|
+
* common to the browser `HTMLCanvasElement` and the `canvas` package's
|
|
37
|
+
* Node-side Canvas:
|
|
38
|
+
*
|
|
39
|
+
* - Portable: `width`, `height`, `getContext`, `toDataURL`.
|
|
40
|
+
* - Browser: `toBlob(cb)` (optional here; use when serializing to a Blob).
|
|
41
|
+
*
|
|
42
|
+
* Platform-specific serializers (e.g. node-canvas's `toBuffer`) are intentionally
|
|
43
|
+
* not part of this interface. Cast when you need them:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import type { Canvas } from 'canvas';
|
|
47
|
+
* const canvas = renderer.export(new CanvasExporter({width, height})) as unknown as Canvas;
|
|
48
|
+
* const png = canvas.toBuffer('image/png');
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface ExportCanvas {
|
|
52
|
+
readonly width: number;
|
|
53
|
+
readonly height: number;
|
|
54
|
+
getContext(contextId: '2d', options?: any): CanvasRenderingContext2D | null;
|
|
55
|
+
toDataURL(type?: string, quality?: any): string;
|
|
56
|
+
/** Browser only; undefined in Node. */
|
|
57
|
+
toBlob?(callback: (blob: Blob | null) => void, type?: string, quality?: any): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Exporter, ExportContext } from './Exporter';
|
|
2
|
+
export interface PngExportOptions {
|
|
3
|
+
pixelRatio?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Exports the current interactive canvas as a PNG data URL. Rasterizes the
|
|
7
|
+
* live Konva stage — whatever style the renderer currently has applied is
|
|
8
|
+
* what gets captured.
|
|
9
|
+
*
|
|
10
|
+
* For re-framing with an explicit width/height (e.g. server-side rendering),
|
|
11
|
+
* use {@link CanvasExporter} and serialize its output yourself.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PngExporter implements Exporter<string | undefined> {
|
|
14
|
+
private readonly options;
|
|
15
|
+
constructor(options?: PngExportOptions);
|
|
16
|
+
render({ backend }: ExportContext): string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Companion to {@link PngExporter} that returns a Blob instead of a data URL. */
|
|
19
|
+
export declare class PngBlobExporter implements Exporter<Promise<Blob> | undefined> {
|
|
20
|
+
private readonly options;
|
|
21
|
+
constructor(options?: PngExportOptions);
|
|
22
|
+
render({ backend }: ExportContext): Promise<Blob> | undefined;
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvgExportOptions } from '../SvgTypes';
|
|
2
|
+
import { Exporter, ExportContext } from './Exporter';
|
|
3
|
+
/**
|
|
4
|
+
* Renders the current scene as an SVG string by driving
|
|
5
|
+
* {@link ScenePipeline} → {@link buildDrawCommands} → {@link svgFromBatches}.
|
|
6
|
+
*
|
|
7
|
+
* The pipeline is rebuilt with bounded viewport bounds (so the grid layout
|
|
8
|
+
* matches the export region), then `sceneShapes` is flushed through the
|
|
9
|
+
* draw-command pipeline at scale 1 — coordinates land inside the SVG
|
|
10
|
+
* viewBox in world space, identical to the legacy SvgBackend output. Active
|
|
11
|
+
* {@link SceneOverlay}s are still rendered against an {@link SvgBackend}
|
|
12
|
+
* so user code that builds custom overlays via the DrawingBackend keeps
|
|
13
|
+
* working until the overlay API is migrated to shapes.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SvgExporter implements Exporter<string | undefined> {
|
|
16
|
+
private readonly options;
|
|
17
|
+
constructor(options?: SvgExportOptions);
|
|
18
|
+
render({ state, style, sceneOverlays }: ExportContext): string | undefined;
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ExportCanvas } from './Exporter';
|
|
2
|
+
/**
|
|
3
|
+
* Serialize an {@link ExportCanvas} to raw bytes, synchronously, using the
|
|
4
|
+
* portable `toDataURL` API. Works identically in the browser and in Node.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* const canvas = renderer.export(new CanvasExporter({ width, height }));
|
|
8
|
+
* const png = canvasToBytes(canvas); // Uint8Array
|
|
9
|
+
* fs.writeFileSync('out.png', png); // Node
|
|
10
|
+
* // or: new Blob([png], { type: 'image/png' }) — browser
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param canvas Canvas produced by {@link CanvasExporter} or the
|
|
14
|
+
* interactive backend's `exportCanvas`.
|
|
15
|
+
* @param mimeType Output format. Defaults to `'image/png'`. Pass `'image/jpeg'`
|
|
16
|
+
* + `quality` (0..1) for JPEG.
|
|
17
|
+
* @param quality JPEG quality (ignored for PNG).
|
|
18
|
+
*/
|
|
19
|
+
export declare function canvasToBytes(canvas: ExportCanvas, mimeType?: string, quality?: number): Uint8Array;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { SceneBuildResult, SceneShapesByLayer } from '../ScenePipeline';
|
|
2
|
+
import { ViewportBounds, Settings } from '../types/Settings';
|
|
3
|
+
import { Shape } from '../scene/Shape';
|
|
4
|
+
/**
|
|
5
|
+
* Interactive-path optimised alternative to {@link clipSceneToViewport}.
|
|
6
|
+
*
|
|
7
|
+
* Returns a single `Map<Shape, boolean>` where `true` means the shape is
|
|
8
|
+
* inside the viewport and `false` means it should be hidden. Shapes absent
|
|
9
|
+
* from the map are "unmanaged" pass-throughs (noScaling labels, overlays) and
|
|
10
|
+
* should be treated as visible.
|
|
11
|
+
*
|
|
12
|
+
* Allocation budget per frame: 1 Map instead of the 12 Sets + 2 filtered
|
|
13
|
+
* arrays that {@link clipSceneToViewport} produces.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildCullingVisibilityMap(result: SceneBuildResult, viewportBounds: ViewportBounds, settings: Settings, transforms?: SceneTransforms): Map<Shape, boolean>;
|
|
16
|
+
type TransformFn = (x: number, y: number) => {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
/** Forward and inverse coordinate transforms for styles that warp space (e.g. Isometric). */
|
|
21
|
+
export type SceneTransforms = {
|
|
22
|
+
/** World → scene (for culling bounding-box projection). */
|
|
23
|
+
forward?: TransformFn;
|
|
24
|
+
/** Scene → world (for grid-line Cartesian-bounds computation). */
|
|
25
|
+
inverse?: TransformFn;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Filter scene shapes to only those that intersect the given viewport, and
|
|
29
|
+
* generate the grid for that viewport — the shared cull step used by export
|
|
30
|
+
* paths (SVG, PNG).
|
|
31
|
+
*
|
|
32
|
+
* Uses {@link buildCullingVisibilityMap} for the predicate so culling logic
|
|
33
|
+
* lives in one place. Shapes absent from the map are unmanaged pass-throughs
|
|
34
|
+
* (noScaling labels, overlays) and are always included.
|
|
35
|
+
*
|
|
36
|
+
* Interactive path uses {@link buildCullingVisibilityMap} directly and skips
|
|
37
|
+
* building these filtered arrays.
|
|
38
|
+
*
|
|
39
|
+
* When `settings.cullingEnabled` is false the original {@link SceneShapesByLayer}
|
|
40
|
+
* is returned (with grid appended).
|
|
41
|
+
*
|
|
42
|
+
* `transforms.forward` projects world → rendered space for styles like
|
|
43
|
+
* Isometric that warp coordinates (pass `style.worldToScene` when available).
|
|
44
|
+
* `transforms.inverse` projects rendered → world space (pass `style.sceneToWorld`)
|
|
45
|
+
* for correct grid-line Cartesian-bounds computation under warped styles.
|
|
46
|
+
*/
|
|
47
|
+
export declare function clipSceneToViewport(result: SceneBuildResult, viewportBounds: ViewportBounds, settings: Settings, transforms?: SceneTransforms): SceneShapesByLayer;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SceneShapesByLayer } from '../ScenePipeline';
|
|
2
|
+
import { Shape } from '../scene/Shape';
|
|
3
|
+
import { MapState } from '../MapState';
|
|
4
|
+
import { SceneOverlay } from '../overlay/SceneOverlay';
|
|
5
|
+
import { ViewportBounds } from '../types/Settings';
|
|
6
|
+
import { SvgOverlays } from '../SvgTypes';
|
|
7
|
+
export interface SceneFlushContext {
|
|
8
|
+
state: MapState;
|
|
9
|
+
viewportBounds: ViewportBounds;
|
|
10
|
+
sceneOverlays: Iterable<SceneOverlay>;
|
|
11
|
+
overlays?: SvgOverlays;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Walk the canonical scene-layer order, calling `flush` once per layer.
|
|
15
|
+
* Order: grid → link → room → built-in overlays → scene overlays → topLabel.
|
|
16
|
+
*
|
|
17
|
+
* Single source of truth for what static exporters must render — adding a new
|
|
18
|
+
* exporter no longer means re-typing the sequence and risking a silent omission.
|
|
19
|
+
*/
|
|
20
|
+
export declare function flushSceneShapes(sceneShapes: SceneShapesByLayer, context: SceneFlushContext, flush: (shapes: Shape[]) => void): void;
|
|
21
|
+
export declare function buildBuiltInOverlayShapes(state: MapState, overlaysInput?: SvgOverlays): Shape[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Style } from '../style/Style';
|
|
2
|
+
export interface ExportBounds {
|
|
3
|
+
readonly x: number;
|
|
4
|
+
readonly y: number;
|
|
5
|
+
readonly w: number;
|
|
6
|
+
readonly h: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Convert world-space export bounds into the scene-space AABB an exporter
|
|
10
|
+
* (SVG, canvas) should target.
|
|
11
|
+
*
|
|
12
|
+
* Coordinate-warping styles (e.g. Isometric) project world coords into a
|
|
13
|
+
* different render space, so the SVG viewBox / canvas fit must be sized to
|
|
14
|
+
* the projected region — otherwise the rendered scene drifts outside the
|
|
15
|
+
* background rect and is partially clipped.
|
|
16
|
+
*
|
|
17
|
+
* For non-warping styles (identity, parchment, sketchy, …) `worldToScene`
|
|
18
|
+
* is undefined and the bounds pass through unchanged.
|
|
19
|
+
*
|
|
20
|
+
* `scenePad` adds a uniform buffer in scene space — used to absorb
|
|
21
|
+
* decorations the projection itself doesn't account for (cube depth in
|
|
22
|
+
* Isometric, neon glow, …).
|
|
23
|
+
*/
|
|
24
|
+
export declare function projectExportBoundsToScene(bounds: ExportBounds, style: Style, scenePad?: number): ExportBounds;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Shape, Bbox } from '../scene/Shape';
|
|
2
|
+
export type CoordTransform = (x: number, y: number) => {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
/** Result returned by {@link HitTester.pick} et al. */
|
|
7
|
+
export interface HitResult {
|
|
8
|
+
kind: string;
|
|
9
|
+
id?: number | string;
|
|
10
|
+
payload?: unknown;
|
|
11
|
+
/** Distance from the query point to the shape (rendered space units). */
|
|
12
|
+
distance: number;
|
|
13
|
+
/** Effective priority used when ranking (per-kind default unless overridden). */
|
|
14
|
+
priority: number;
|
|
15
|
+
/** Center of the shape's rendered bbox — useful for hover effects. */
|
|
16
|
+
centerX: number;
|
|
17
|
+
centerY: number;
|
|
18
|
+
}
|
|
19
|
+
/** One entry returned by {@link HitTester.debugEntries} for visualisation. */
|
|
20
|
+
export interface HitDebugEntry {
|
|
21
|
+
kind: string;
|
|
22
|
+
geoms: ReadonlyArray<HitGeom>;
|
|
23
|
+
/** Max distance from shape edge that still registers as a hit (rendered-space units). */
|
|
24
|
+
marginRadius: number;
|
|
25
|
+
/** Rendered-space bbox of the hit geometry. */
|
|
26
|
+
minX: number;
|
|
27
|
+
maxX: number;
|
|
28
|
+
minY: number;
|
|
29
|
+
maxY: number;
|
|
30
|
+
}
|
|
31
|
+
export type HitGeom = {
|
|
32
|
+
type: "polyline";
|
|
33
|
+
pts: number[];
|
|
34
|
+
closed: boolean;
|
|
35
|
+
} | {
|
|
36
|
+
type: "circle";
|
|
37
|
+
cx: number;
|
|
38
|
+
cy: number;
|
|
39
|
+
r: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Spatial index for hittable shapes. Rebuilt cheaply after each scene build.
|
|
43
|
+
*/
|
|
44
|
+
export declare class HitTester {
|
|
45
|
+
private entries;
|
|
46
|
+
private bucketSize;
|
|
47
|
+
private roomSize;
|
|
48
|
+
private spatialIndex;
|
|
49
|
+
private transform;
|
|
50
|
+
/**
|
|
51
|
+
* Rebuild from a fresh set of world-space shapes.
|
|
52
|
+
*
|
|
53
|
+
* @param shapes Top-level shape list from {@link ScenePipeline}.
|
|
54
|
+
* @param roomSize Current room size (world units) — used as base pick margin.
|
|
55
|
+
* @param coordTransform World→rendered projection; omit for flat (identity).
|
|
56
|
+
*/
|
|
57
|
+
build(shapes: Shape[], roomSize: number, coordTransform?: CoordTransform): void;
|
|
58
|
+
clear(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Find the best-matching hittable shape at a rendered-space point.
|
|
61
|
+
* Best = highest priority, then closest. Returns `null` when no shape
|
|
62
|
+
* is within its margin of the point.
|
|
63
|
+
*/
|
|
64
|
+
pick(x: number, y: number): HitResult | null;
|
|
65
|
+
/**
|
|
66
|
+
* Return every hittable shape at a rendered-space point, sorted by
|
|
67
|
+
* priority desc then distance asc. Used for Alt+click cycling and
|
|
68
|
+
* disambiguation menus.
|
|
69
|
+
*/
|
|
70
|
+
pickAll(x: number, y: number): HitResult[];
|
|
71
|
+
/**
|
|
72
|
+
* Return every hittable shape whose rendered-space center falls inside
|
|
73
|
+
* the rect, optionally filtered by kind. Used for marquee selection.
|
|
74
|
+
*/
|
|
75
|
+
pickInRect(minX: number, minY: number, maxX: number, maxY: number, kinds?: string[]): HitResult[];
|
|
76
|
+
/**
|
|
77
|
+
* Convenience wrapper: return the room whose hit shape is nearest to
|
|
78
|
+
* the given rendered-space point, or `null` when none is within range.
|
|
79
|
+
*/
|
|
80
|
+
findRoomAtPoint(x: number, y: number): MapData.Room | null;
|
|
81
|
+
/**
|
|
82
|
+
* Returns hit geometry for every entry, for debug visualisation.
|
|
83
|
+
* Coordinates are in **rendered space** (world space for flat styles).
|
|
84
|
+
*/
|
|
85
|
+
debugEntries(): HitDebugEntry[];
|
|
86
|
+
/** Walk the 9 buckets around the point and emit candidates within margin. */
|
|
87
|
+
private forEachCandidate;
|
|
88
|
+
private toResult;
|
|
89
|
+
private collectHitShapes;
|
|
90
|
+
private indexEntry;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Compute the axis-aligned bounding box of a shape in world space.
|
|
94
|
+
* `offsetX/Y` is the cumulative parent group origin.
|
|
95
|
+
*
|
|
96
|
+
* Note: this does NOT apply the HitTester's coord transform. Callers that
|
|
97
|
+
* need rendered-space extents should transform the four corners themselves.
|
|
98
|
+
* Kept exported for backends that need a quick world-space AABB (e.g. cull
|
|
99
|
+
* entry construction, scene bounds), and for tests.
|
|
100
|
+
*/
|
|
101
|
+
export declare function computeShapeBbox(shape: Shape, offsetX: number, offsetY: number): Bbox;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export { createSettings } from './types/Settings';
|
|
2
|
+
export type { Settings, ViewportBounds, RendererEventMap, CullingMode, RoomShape, LabelRenderMode, PlayerMarkerStyle, RoomClickEventDetail, RoomContextMenuEventDetail, ZoomChangeEventDetail, AreaExitClickEventDetail, PanEventDetail, } from './types/Settings';
|
|
3
|
+
export { darkenColor, colorLightness, hexToRgba } from './utils/color';
|
|
4
|
+
export { MapRenderer } from './rendering/MapRenderer';
|
|
5
|
+
export type { InteractiveBackend } from './rendering/MapRenderer';
|
|
6
|
+
export type { DrawnExitEntry, DrawnSpecialExitEntry, DrawnStubEntry } from './ScenePipeline';
|
|
7
|
+
export type { ExitDrawData, ExitDrawLine, ExitDrawArrow, ExitDrawDoor } from './ExitRenderer';
|
|
8
|
+
export { MapState } from './MapState';
|
|
9
|
+
export type { MapStateEventMap, HighlightEntry, PathEntry } from './MapState';
|
|
10
|
+
export { Camera } from './camera/Camera';
|
|
11
|
+
export type { CameraEventMap } from './camera/Camera';
|
|
12
|
+
export { HitTester } from './hit/HitTester';
|
|
13
|
+
export type { HitResult } from './hit/HitTester';
|
|
14
|
+
export { CullingManager } from './CullingManager';
|
|
15
|
+
export type { CoordFn } from './coord/CoordFn';
|
|
16
|
+
export { IDENTITY_TRANSFORM } from './coord/CoordFn';
|
|
17
|
+
export { DrawCommandLayerNode, MaterializingLayerNode, RecordingLayerNode, RecordingGroupNode, } from './render/RecordingLayer';
|
|
18
|
+
export type { DrawEntry, RecordingDrawCommand } from './render/RecordingLayer';
|
|
19
|
+
export { shapeToRecording } from './render/shapeToRecording';
|
|
20
|
+
export type { Shape, ShapeBase, RectShape, CircleShape, LineShape, PolygonShape, TextShape, ImageShape, GroupShape, Paint, HitInfo, LayerId, Bbox, SceneIR, } from './scene/Shape';
|
|
21
|
+
export type { DrawCommand, DrawCommandBatch, RectCommand, CircleCommand, LineCommand, PolygonCommand, TextCommand, ImageCommand, PrimitiveDrawCommand, StackDrawCommand, PushTransformCommand, PopTransformCommand, PushClipCommand, PopClipCommand, } from './draw/DrawCommand';
|
|
22
|
+
export { buildDrawCommands } from './draw/DrawCommandBuilder';
|
|
23
|
+
export type { CameraTransform } from './draw/DrawCommandBuilder';
|
|
24
|
+
export { svgFromBatches } from './render/SvgRenderer';
|
|
25
|
+
export { renderToCanvas } from './render/CanvasRenderer';
|
|
26
|
+
export type { ImageFactory, CanvasRenderOptions } from './render/CanvasRenderer';
|
|
27
|
+
export { Parchment, Blueprint, Neon, Sketchy, Isometric, Construction, SciFi, compose, identityStyle, applyStyleToShapes, } from './style';
|
|
28
|
+
export type { Style, StyleContext, SketchyOptions, IsometricOptions, IsometricRotation, } from './style';
|
|
29
|
+
export type { Exporter, ExportContext, ExportCanvas } from './export/Exporter';
|
|
30
|
+
export { SvgExporter } from './export/SvgExporter';
|
|
31
|
+
export { PngExporter, PngBlobExporter } from './export/PngExporter';
|
|
32
|
+
export type { PngExportOptions } from './export/PngExporter';
|
|
33
|
+
export { CanvasExporter, PngBytesExporter } from './export/CanvasExporter';
|
|
34
|
+
export type { CanvasExportOptions, PngBytesExportOptions } from './export/CanvasExporter';
|
|
35
|
+
export { canvasToBytes } from './export/canvasToBytes';
|
|
36
|
+
export type { SceneOverlay, SceneOverlayContext } from './overlay/SceneOverlay';
|
|
37
|
+
export type { LiveEffect, CoordinateTransform } from './overlay/LiveEffect';
|
|
38
|
+
export { AmbientLightOverlay } from './overlay/AmbientLightOverlay';
|
|
39
|
+
export type { AmbientLightOptions } from './overlay/AmbientLightOverlay';
|
|
40
|
+
export { default as MapReader } from './reader/MapReader';
|
|
41
|
+
export type { IMapReader } from './reader/MapReader';
|
|
42
|
+
export { default as PathFinder } from './PathFinder';
|
|
43
|
+
export type { PathFindingAlgorithm } from './PathFinder';
|
|
44
|
+
export { MapGraph } from './MapGraph';
|
|
45
|
+
export type { Edge, GraphData } from './MapGraph';
|
|
46
|
+
export { default as Area } from './reader/Area';
|
|
47
|
+
export type { IArea } from './reader/Area';
|
|
48
|
+
export { default as Plane } from './reader/Plane';
|
|
49
|
+
export type { IPlane } from './reader/Plane';
|
|
50
|
+
export type { IExit, Kind as ExitKind } from './reader/Exit';
|
|
51
|
+
export type { RoomLens, ExitTreatment } from './lens/RoomLens';
|
|
52
|
+
export { ALL_VISIBLE, defaultExitTreatment } from './lens/RoomLens';
|
|
53
|
+
export { composeLenses } from './lens/composeLenses';
|
|
54
|
+
export type { ComposeOptions, ExitConflictStrategy } from './lens/composeLenses';
|
|
55
|
+
export { ExplorationLens } from './lens/ExplorationLens';
|
|
56
|
+
export { AreaMapRenderer, createAreaMapSettings } from './AreaMapRenderer';
|
|
57
|
+
export type { AreaMapSettings } from './AreaMapRenderer';
|
|
58
|
+
export type { AreaDomainInfo, DomainFilter } from './AreaMapRenderer';
|
|
59
|
+
export type { SvgExportOptions, SvgOverlays } from './SvgTypes';
|
|
60
|
+
export { computePathData } from './PathData';
|
|
61
|
+
export type { PathResult, PathSegment, PathInnerMarker } from './PathData';
|