@zwishing/emap 0.1.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/LICENSE +373 -0
  3. package/README.md +294 -0
  4. package/SECURITY.md +56 -0
  5. package/dist/adapter/mapshaper-adapter.d.ts +282 -0
  6. package/dist/core/drag-pan-handler.d.ts +28 -0
  7. package/dist/core/events.d.ts +16 -0
  8. package/dist/core/interactions.d.ts +20 -0
  9. package/dist/core/mapshaper-worker-pool.d.ts +151 -0
  10. package/dist/core/tween.d.ts +26 -0
  11. package/dist/edit/commands/composite.d.ts +16 -0
  12. package/dist/edit/commands/dataset-replace.d.ts +43 -0
  13. package/dist/edit/commands/feature-affine.d.ts +72 -0
  14. package/dist/edit/commands/feature-create.d.ts +47 -0
  15. package/dist/edit/commands/feature-delete.d.ts +72 -0
  16. package/dist/edit/commands/feature-property-change.d.ts +34 -0
  17. package/dist/edit/commands/feature-translate.d.ts +55 -0
  18. package/dist/edit/commands/field-add.d.ts +24 -0
  19. package/dist/edit/commands/field-remove.d.ts +20 -0
  20. package/dist/edit/commands/field-rename.d.ts +19 -0
  21. package/dist/edit/commands/split-shared-arcs.d.ts +71 -0
  22. package/dist/edit/commands/vertex-delete.d.ts +26 -0
  23. package/dist/edit/commands/vertex-insert.d.ts +26 -0
  24. package/dist/edit/commands/vertex-move.d.ts +45 -0
  25. package/dist/edit/edit-command.d.ts +72 -0
  26. package/dist/edit/edit-history.d.ts +130 -0
  27. package/dist/edit/transaction.d.ts +59 -0
  28. package/dist/emap-worker.js +1 -0
  29. package/dist/emap.css +157 -0
  30. package/dist/emap.js +5 -0
  31. package/dist/emap.mjs +5 -0
  32. package/dist/geo/bounds.d.ts +18 -0
  33. package/dist/geo/crs-resolver.d.ts +35 -0
  34. package/dist/geo/projection.d.ts +28 -0
  35. package/dist/geo/transform.d.ts +19 -0
  36. package/dist/geo/viewport.d.ts +52 -0
  37. package/dist/index.d.ts +86 -0
  38. package/dist/map/attribute-ops.d.ts +61 -0
  39. package/dist/map/command-args.d.ts +28 -0
  40. package/dist/map/edit-sessions.d.ts +97 -0
  41. package/dist/map/edit-state-store.d.ts +41 -0
  42. package/dist/map/emap-host.d.ts +79 -0
  43. package/dist/map/feature-accessor.d.ts +43 -0
  44. package/dist/map/feature-query.d.ts +58 -0
  45. package/dist/map/highlight-manager.d.ts +17 -0
  46. package/dist/map/layer-registry.d.ts +33 -0
  47. package/dist/map/layer.d.ts +29 -0
  48. package/dist/map/map.d.ts +386 -0
  49. package/dist/map/mapshaper-ops.d.ts +56 -0
  50. package/dist/map/op-result.d.ts +46 -0
  51. package/dist/map/ops/_context.d.ts +41 -0
  52. package/dist/map/ops/_runner.d.ts +55 -0
  53. package/dist/map/ops/affine.d.ts +4 -0
  54. package/dist/map/ops/buffer.d.ts +4 -0
  55. package/dist/map/ops/check-geometry.d.ts +4 -0
  56. package/dist/map/ops/clean.d.ts +4 -0
  57. package/dist/map/ops/clip-erase.d.ts +5 -0
  58. package/dist/map/ops/data-fill.d.ts +4 -0
  59. package/dist/map/ops/dissolve.d.ts +20 -0
  60. package/dist/map/ops/divide.d.ts +4 -0
  61. package/dist/map/ops/drop-layer.d.ts +4 -0
  62. package/dist/map/ops/each-filter.d.ts +5 -0
  63. package/dist/map/ops/explode.d.ts +4 -0
  64. package/dist/map/ops/filter-fields.d.ts +4 -0
  65. package/dist/map/ops/filter-geom.d.ts +4 -0
  66. package/dist/map/ops/filter-islands.d.ts +4 -0
  67. package/dist/map/ops/filter-slivers.d.ts +4 -0
  68. package/dist/map/ops/innerlines.d.ts +4 -0
  69. package/dist/map/ops/intersection-points.d.ts +4 -0
  70. package/dist/map/ops/join-table.d.ts +4 -0
  71. package/dist/map/ops/lines.d.ts +4 -0
  72. package/dist/map/ops/merge-layers.d.ts +4 -0
  73. package/dist/map/ops/mosaic.d.ts +4 -0
  74. package/dist/map/ops/points.d.ts +4 -0
  75. package/dist/map/ops/polygons.d.ts +4 -0
  76. package/dist/map/ops/project.d.ts +4 -0
  77. package/dist/map/ops/rebuild-topology.d.ts +4 -0
  78. package/dist/map/ops/rename-fields.d.ts +4 -0
  79. package/dist/map/ops/rename-layer.d.ts +4 -0
  80. package/dist/map/ops/simplify.d.ts +4 -0
  81. package/dist/map/ops/snap.d.ts +4 -0
  82. package/dist/map/ops/sort-features.d.ts +4 -0
  83. package/dist/map/ops/split-layer.d.ts +4 -0
  84. package/dist/map/ops/union.d.ts +4 -0
  85. package/dist/map/ops/unique-features.d.ts +4 -0
  86. package/dist/map/selection.d.ts +73 -0
  87. package/dist/map/types.d.ts +1072 -0
  88. package/dist/map/worker-routing.d.ts +40 -0
  89. package/dist/mapshaper-vendor.js +1 -0
  90. package/dist/renderer/canvas-painter.d.ts +50 -0
  91. package/dist/renderer/edit-overlay-renderer.d.ts +22 -0
  92. package/dist/renderer/painter.d.ts +52 -0
  93. package/dist/shim.d.ts +1 -0
  94. package/dist/source/display-arcs.d.ts +49 -0
  95. package/dist/source/layer-utils.d.ts +12 -0
  96. package/dist/source/mapshaper-runner.d.ts +22 -0
  97. package/dist/source/source.d.ts +80 -0
  98. package/dist/source/topology-source.d.ts +145 -0
  99. package/dist/types/mapshaper-types.d.ts +182 -0
  100. package/dist/ui/basemap-control.d.ts +35 -0
  101. package/dist/ui/box-select-control.d.ts +67 -0
  102. package/dist/ui/control.d.ts +6 -0
  103. package/dist/ui/draw-feature-control.d.ts +82 -0
  104. package/dist/ui/edit-toolbar.d.ts +27 -0
  105. package/dist/ui/history-control.d.ts +29 -0
  106. package/dist/ui/lasso-select-control.d.ts +96 -0
  107. package/dist/ui/navigation-control.d.ts +16 -0
  108. package/dist/ui/simplify-control.d.ts +40 -0
  109. package/dist/ui/status-control.d.ts +23 -0
  110. package/dist/ui/vertex-edit-control.d.ts +111 -0
  111. package/dist/validation/builtin/topology.d.ts +19 -0
  112. package/dist/validation/registry.d.ts +23 -0
  113. package/dist/validation/validator.d.ts +47 -0
  114. package/package.json +90 -0
@@ -0,0 +1,18 @@
1
+ export declare class Bounds {
2
+ xmin: number;
3
+ ymin: number;
4
+ xmax: number;
5
+ ymax: number;
6
+ constructor(xmin?: number, ymin?: number, xmax?: number, ymax?: number);
7
+ static fromArray(arr: [number, number, number, number]): Bounds;
8
+ get width(): number;
9
+ get height(): number;
10
+ get centerX(): number;
11
+ get centerY(): number;
12
+ hasBounds(): boolean;
13
+ clone(): Bounds;
14
+ mergePoint(x: number, y: number): void;
15
+ merge(other: Bounds): void;
16
+ fillOut(aspect: number, focusX?: number, focusY?: number): this;
17
+ scale(k: number): void;
18
+ }
@@ -0,0 +1,35 @@
1
+ import type { MapshaperDataset } from '../types/mapshaper-types';
2
+ /** Default fallback when no metadata identifies a CRS. */
3
+ export declare const DEFAULT_CRS = "EPSG:4326";
4
+ /**
5
+ * Resolve a canonical CRS identifier (typically `EPSG:NNNN` or a passthrough
6
+ * label) for a mapshaper dataset.
7
+ *
8
+ * Lookup order, first hit wins:
9
+ *
10
+ * 1. `info.crs_string` — normalised via {@link normalizeCrsString}.
11
+ * 2. `info.prj` (raw WKT) — `AUTHORITY["EPSG", "..."]` clause first;
12
+ * then Web-Mercator / WGS84 datum heuristics.
13
+ * 3. `info.crs` (mapshaper's parsed Proj4 descriptor) —
14
+ * `is_latlong` ⇒ EPSG:4326; spheroid `merc` + `a=6378137` ⇒ EPSG:3857.
15
+ * 4. {@link DEFAULT_CRS}.
16
+ */
17
+ export declare function resolveDatasetCRS(dataset: MapshaperDataset | undefined): string;
18
+ /**
19
+ * Map a free-text CRS label (`'wgs84'`, `'webmercator'`, `'epsg:4326'`, …)
20
+ * onto a canonical `EPSG:NNNN` string. Inputs that already look canonical
21
+ * are upper-cased; everything else passes through upper-cased so callers
22
+ * still see a stable shape they can branch on.
23
+ */
24
+ export declare function normalizeCrsString(str: string): string;
25
+ /**
26
+ * Heuristic-extract a CRS identifier from a raw WKT `.prj` body.
27
+ * Returns `null` when nothing matches; callers fall through to the next
28
+ * resolver stage.
29
+ *
30
+ * Recognised:
31
+ * - `AUTHORITY["EPSG", "<code>"]` anywhere in the body → `EPSG:<code>`.
32
+ * - Web-Mercator name fragments → `EPSG:3857`.
33
+ * - WGS_1984 datum + GEOGCS top-level → `EPSG:4326`.
34
+ */
35
+ export declare function inferFromPrj(prj: string): string | null;
@@ -0,0 +1,28 @@
1
+ import { Bounds } from './bounds';
2
+ import { TopologySource } from '../source/source';
3
+ /**
4
+ * Projection manages the coordinate reference system and provides
5
+ * coordinate conversion between CRS-specific units and view-agnostic
6
+ * representations.
7
+ */
8
+ export declare class Projection {
9
+ private _crs;
10
+ get crs(): string;
11
+ setCRS(crs: string): void;
12
+ /**
13
+ * Compute the map center in geographic coordinates.
14
+ * For Web Mercator, converts projected coords to lat/lng.
15
+ */
16
+ getCenter(cx: number, cy: number): [number, number];
17
+ /**
18
+ * Compute a zoom level from the scale factor.
19
+ * Only meaningful for Web Mercator.
20
+ */
21
+ getZoom(mx: number): number;
22
+ /**
23
+ * Reproject all sources to a target CRS.
24
+ * Returns the merged extent of all reprojected layers.
25
+ */
26
+ reproject(targetCrs: string, sources: globalThis.Map<string, TopologySource>): Promise<Bounds>;
27
+ private _webMercatorToLatLng;
28
+ }
@@ -0,0 +1,19 @@
1
+ import { Bounds } from './bounds';
2
+ /**
3
+ * Pure affine 2D transformation: scale + translate.
4
+ * Represents the matrix [mx 0 bx; 0 my by; 0 0 1].
5
+ */
6
+ export declare class AffineTransform {
7
+ mx: number;
8
+ my: number;
9
+ bx: number;
10
+ by: number;
11
+ constructor(mx?: number, my?: number, bx?: number, by?: number);
12
+ static fromBounds(src: Bounds, dst: Bounds, flipY?: boolean): AffineTransform;
13
+ project(x: number, y: number): [number, number];
14
+ unproject(px: number, py: number): [number, number];
15
+ translate(dx: number, dy: number): void;
16
+ scale(k: number, px: number, py: number): void;
17
+ clone(): AffineTransform;
18
+ }
19
+ export { AffineTransform as Transform };
@@ -0,0 +1,52 @@
1
+ import { AffineTransform } from './transform';
2
+ import { Bounds } from './bounds';
3
+ /**
4
+ * Viewport owns the affine transform that maps data coordinates to screen
5
+ * pixels. It handles zoom animation, pan constraints, and LOD parameters.
6
+ */
7
+ export declare class Viewport {
8
+ private _transform;
9
+ private _extent;
10
+ private _width;
11
+ private _height;
12
+ private _initialMX;
13
+ private _initialExtent;
14
+ private _zoomTween;
15
+ private _zoomFocus;
16
+ private _animatingTransform;
17
+ /** Callback fired whenever the view changes (move / zoom) */
18
+ onViewChange: (() => void) | null;
19
+ private _crs;
20
+ setCRS(crs: string): void;
21
+ get transform(): AffineTransform;
22
+ get extent(): Bounds;
23
+ get width(): number;
24
+ get height(): number;
25
+ get initialMX(): number;
26
+ updateSize(width: number, height: number): void;
27
+ setExtent(bounds: Bounds): void;
28
+ reset(): void;
29
+ clearInitialState(): void;
30
+ private _updateTransform;
31
+ pan(dx: number, dy: number): void;
32
+ cancelZoomAnimation(): void;
33
+ applyWheelZoom(direction: number, multiplier: number, x: number, y: number): void;
34
+ zoomIn(): void;
35
+ zoomOut(): void;
36
+ private _zoomTo;
37
+ /** Connect the zoom tween – call once during init */
38
+ initZoomTween(): void;
39
+ project(x: number, y: number): [number, number];
40
+ unproject(px: number, py: number): [number, number];
41
+ getLineScale(): number;
42
+ getArcFilter(arcs: {
43
+ arcIsSmaller?(i: number, minLen: number): boolean;
44
+ arcIntersectsBBox?(i: number, bbox: number[]): boolean;
45
+ }): (i: number) => boolean;
46
+ getViewBounds(): number[] | null;
47
+ private _getViewBounds;
48
+ private _applyConstraints;
49
+ private _getMaxMX;
50
+ private _getStrictBounds;
51
+ private _getMinMX;
52
+ }
@@ -0,0 +1,86 @@
1
+ import './shim';
2
+ import 'mapshaper';
3
+ export { Emap } from './map/map';
4
+ export type { ExpressionEvaluationPolicy, QueryFeaturesOptions, QueriedFeature, FeatureRef, HighlightFeatureRef, HighlightStyle, FeatureTranslateSession, FeatureAffineSession, ClipEraseOptions, DissolveOptions, CleanOptions, BufferOptions, ApplyExpressionOptions, ExplodeOptions, InnerlinesOptions, FilterOptions, FilterIslandsOptions, FilterSliversOptions, FilterGeomOptions, AffineLayerOptions, DataFillOptions, SnapOptions, MosaicOptions, UnionOptions, DivideOptions, PointsOptions, PointsMode, LinesOptions, PolygonsOptions, SimplifyOptions, SimplifyMethod, ProjectOptions, RebuildTopologyOptions, RenameLayerOptions, MergeLayersOptions, SplitLayerOptions, DropLayerOptions, SortFeaturesOptions, UniqueFeaturesOptions, FilterFieldsOptions, RenameFieldsOptions, JoinTableOptions, JoinTableData, CheckGeometryOptions, GeometryCheckReport, IntersectionPointsLayerOptions, ExportSnapshotOptions, LoadSnapshotOptions, } from './map/map';
5
+ export type { LayerSpecification, LayerType, LayerPaint, LayerLayout, FillPaint, LinePaint, CirclePaint, } from './map/layer';
6
+ export { resolveStrokeStyle, resolvePointStyle } from './map/layer';
7
+ export { HighlightManager } from './map/highlight-manager';
8
+ export { Selection } from './map/selection';
9
+ export type { SelectMode, SelectionDiff, SelectionSnapshot } from './map/selection';
10
+ export { FeatureQuery } from './map/feature-query';
11
+ export { FeatureAccessor } from './map/feature-accessor';
12
+ export type { Feature } from './map/feature-accessor';
13
+ export { Err, OK, okValue } from './map/op-result';
14
+ export type { OpError, OpResult } from './map/op-result';
15
+ export { quoteCliArg, isValidLayerName, isValidFieldName, findInvalidFieldName, } from './map/command-args';
16
+ export type { ArcCollection, ArcIterator, ArcVertexData, Coord2, DataTable, FeatureShape, GeometryType, LegacyPointShape, MapshaperDataset, MapshaperLayer, PathGeometryType, PathLayer, PathPart, PathShape, PointLayer, PointShape, PointStyle, SignedArcId, StrokeStyle, VertexDotStyle, } from './types/mapshaper-types';
17
+ export { isPathLayer, isPointLayer, bumpEditVersion } from './types/mapshaper-types';
18
+ export { DefaultMapshaperAdapter, getDefaultMapshaperAdapter, setDefaultMapshaperAdapter, } from './adapter/mapshaper-adapter';
19
+ export type { ExportedFile, MapshaperAdapter, MapshaperBBox, PackedSession, RunnerInputFiles, SegmentIntersection, } from './adapter/mapshaper-adapter';
20
+ export { MapshaperWorkerPool } from './core/mapshaper-worker-pool';
21
+ export type { MapshaperWorkerPoolOptions } from './core/mapshaper-worker-pool';
22
+ export { TopologySource } from './source/topology-source';
23
+ export type { TopologySourceData, TopologySourceInput, TopologySourceOptions, ZipExtractionLimits, } from './source/topology-source';
24
+ export type { TopologySource as ITopologySource, ExportFormat, ExportOptions } from './source/source';
25
+ export { Bounds } from './geo/bounds';
26
+ export { AffineTransform, AffineTransform as Transform } from './geo/transform';
27
+ export { Viewport } from './geo/viewport';
28
+ export { Projection } from './geo/projection';
29
+ export { DEFAULT_CRS, inferFromPrj, normalizeCrsString, resolveDatasetCRS, } from './geo/crs-resolver';
30
+ export { CanvasPainter } from './renderer/canvas-painter';
31
+ export { EditOverlayRenderer } from './renderer/edit-overlay-renderer';
32
+ export { EventDispatcher } from './core/events';
33
+ export type { EventListener } from './core/events';
34
+ export { DragPanHandler } from './core/drag-pan-handler';
35
+ export type { EditCommand } from './edit/edit-command';
36
+ export { EditHistory } from './edit/edit-history';
37
+ export type { HistoryStateSnapshot, EditHistoryOptions } from './edit/edit-history';
38
+ export { Transaction } from './edit/transaction';
39
+ export { ValidatorRegistry } from './validation/registry';
40
+ export type { Validator, ValidatorPhase, ValidatorResult, ValidationChange, ValidationIssue, ValidationReport, } from './validation/validator';
41
+ export { topologyValidator } from './validation/builtin/topology';
42
+ export type { TopologyValidatorOptions } from './validation/builtin/topology';
43
+ export { VertexMoveCommand } from './edit/commands/vertex-move';
44
+ export { VertexInsertCommand } from './edit/commands/vertex-insert';
45
+ export { VertexDeleteCommand } from './edit/commands/vertex-delete';
46
+ export { FeatureCreateCommand } from './edit/commands/feature-create';
47
+ export { FeatureDeleteCommand, BulkFeatureDeleteCommand } from './edit/commands/feature-delete';
48
+ export type { FeatureDeleteCommandOptions, BulkFeatureDeleteCommandOptions, } from './edit/commands/feature-delete';
49
+ export { FeatureTranslateCommand } from './edit/commands/feature-translate';
50
+ export type { FeatureTranslateCommandOptions, TranslatedPointFeature, } from './edit/commands/feature-translate';
51
+ export { FeatureAffineCommand, rotateMatrix, scaleMatrix, invertMatrix, composeMatrix, IDENTITY_MATRIX, } from './edit/commands/feature-affine';
52
+ export type { FeatureAffineCommandOptions, AffineMatrix, } from './edit/commands/feature-affine';
53
+ export { SplitSharedArcsCommand, planSharedArcSplit } from './edit/commands/split-shared-arcs';
54
+ export type { SplitSharedArcsCommandOptions, SplitSharedArcsRemap, AppendedArc, } from './edit/commands/split-shared-arcs';
55
+ export { CompositeCommand } from './edit/commands/composite';
56
+ export { DatasetReplaceCommand } from './edit/commands/dataset-replace';
57
+ export type { DatasetReplaceCommandOptions } from './edit/commands/dataset-replace';
58
+ export { FeaturePropertyChangeCommand } from './edit/commands/feature-property-change';
59
+ export type { FeaturePropertyChangeCommandOptions } from './edit/commands/feature-property-change';
60
+ export { FieldAddCommand } from './edit/commands/field-add';
61
+ export type { FieldAddCommandOptions } from './edit/commands/field-add';
62
+ export { FieldRemoveCommand } from './edit/commands/field-remove';
63
+ export type { FieldRemoveCommandOptions } from './edit/commands/field-remove';
64
+ export { FieldRenameCommand } from './edit/commands/field-rename';
65
+ export type { FieldRenameCommandOptions } from './edit/commands/field-rename';
66
+ export type { Control, ControlPosition } from './ui/control';
67
+ export { NavigationControl } from './ui/navigation-control';
68
+ export type { NavigationOptions } from './ui/navigation-control';
69
+ export { StatusControl } from './ui/status-control';
70
+ export type { StatusOptions } from './ui/status-control';
71
+ export { BasemapControl } from './ui/basemap-control';
72
+ export type { BasemapOptions, BasemapStyle } from './ui/basemap-control';
73
+ export { VertexEditControl } from './ui/vertex-edit-control';
74
+ export type { VertexEditControlOptions } from './ui/vertex-edit-control';
75
+ export { EditToolbar } from './ui/edit-toolbar';
76
+ export type { EditToolbarOptions } from './ui/edit-toolbar';
77
+ export { DrawFeatureControl } from './ui/draw-feature-control';
78
+ export type { DrawFeatureControlOptions, DrawGeometryType } from './ui/draw-feature-control';
79
+ export { HistoryControl } from './ui/history-control';
80
+ export type { HistoryControlOptions } from './ui/history-control';
81
+ export { BoxSelectControl } from './ui/box-select-control';
82
+ export type { BoxSelectControlOptions, BoxSelectStyle } from './ui/box-select-control';
83
+ export { LassoSelectControl, pointInPolygon, featureMatchesLasso, } from './ui/lasso-select-control';
84
+ export type { LassoSelectControlOptions, LassoSelectStyle } from './ui/lasso-select-control';
85
+ export { SimplifyControl } from './ui/simplify-control';
86
+ export type { SimplifyControlOptions } from './ui/simplify-control';
@@ -0,0 +1,61 @@
1
+ import type { FeatureRef } from './types';
2
+ import type { EmapHostInternal } from './emap-host';
3
+ import { type OpResult } from './op-result';
4
+ /**
5
+ * Attribute-editing manager. Owned by Emap and exposed as `emap.attributes`.
6
+ * Construction takes the host Emap; the manager calls back into a small
7
+ * surface of internal helpers (`layers.resolve`, `_history`, ...) on the host.
8
+ *
9
+ * Every method returns `OpResult<void>` — `{ ok: true, value: undefined }` on
10
+ * success, `{ ok: false, error: OpError }` for unresolvable refs or no-op
11
+ * calls. Errors carry a structured `kind` so UIs can branch on the cause.
12
+ */
13
+ export declare class AttributeOps {
14
+ private _emap;
15
+ constructor(_emap: EmapHostInternal);
16
+ setFeatureProperty(ref: FeatureRef, key: string, value: unknown): OpResult;
17
+ /**
18
+ * Set multiple properties on one feature in a single undo entry.
19
+ *
20
+ * Per-key semantics:
21
+ * - `props[key] === undefined` → delete the key from the record
22
+ * - any other value → set / overwrite the key
23
+ *
24
+ * Returns a `validation` error when every key already has the requested
25
+ * value (no-op call); no command is pushed and no events fire.
26
+ */
27
+ setFeatureProperties(ref: FeatureRef, props: Record<string, unknown>): OpResult;
28
+ /**
29
+ * Add a new column to a layer's data table. Records that already carry the
30
+ * key are skipped (and not rolled back by undo). `defaultValue` defaults to
31
+ * `null`. Returns a `not-found` error when the source / target / data table
32
+ * cannot be resolved.
33
+ */
34
+ addField(opts: {
35
+ source: string;
36
+ target: string;
37
+ field: string;
38
+ defaultValue?: unknown;
39
+ }): OpResult;
40
+ /**
41
+ * Drop a column from a layer's data table. Per-record values are
42
+ * snapshotted for undo so removing the field is fully reversible.
43
+ */
44
+ removeField(opts: {
45
+ source: string;
46
+ target: string;
47
+ field: string;
48
+ }): OpResult;
49
+ /**
50
+ * Rename a column on every record in a layer. Refuses with a `validation`
51
+ * error when any record already carries both `from` and `to` so silent
52
+ * overwrites are impossible. Use `removeField(to)` first if that is the
53
+ * intent.
54
+ */
55
+ renameField(opts: {
56
+ source: string;
57
+ target: string;
58
+ from: string;
59
+ to: string;
60
+ }): OpResult;
61
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Escape a value for embedding inside a double-quoted CLI argument.
3
+ *
4
+ * Wraps the result in `"..."`. Inside the quotes:
5
+ * - `\` → `\\`
6
+ * - `"` → `\"`
7
+ * - `\n` / `\r` / `\t` / `\0` → escaped escape sequences. `\n`/`\r`
8
+ * would otherwise terminate mapshaper's argument scan; `\0` would
9
+ * truncate the C-style strings inside mapshaper-vendor's bundled
10
+ * mproj. Other control chars (U+0001..U+001F minus the ones above)
11
+ * get rejected by validators upstream so they never reach here.
12
+ *
13
+ * The function does NOT validate the argument is identifier-safe — it only
14
+ * makes whatever you hand it round-trip safely through mapshaper's quote
15
+ * stripper. Pair it with {@link isValidLayerName} / {@link isValidFieldName}
16
+ * for inputs that are supposed to be identifiers.
17
+ */
18
+ export declare function quoteCliArg(value: string): string;
19
+ /** True iff `value` looks like a safe mapshaper layer name. */
20
+ export declare function isValidLayerName(value: unknown): value is string;
21
+ /** True iff `value` looks like a safe mapshaper field name. */
22
+ export declare function isValidFieldName(value: unknown): value is string;
23
+ /**
24
+ * Validate a list of field names. Returns `null` on success or the FIRST
25
+ * offending name as a structured-friendly error tuple. Empty arrays are
26
+ * permitted (caller decides whether to reject).
27
+ */
28
+ export declare function findInvalidFieldName(values: ReadonlyArray<unknown>): string | null;
@@ -0,0 +1,97 @@
1
+ import { type TranslatedPointFeature } from '../edit/commands/feature-translate';
2
+ import { type AffineMatrix } from '../edit/commands/feature-affine';
3
+ import { SplitSharedArcsCommand } from '../edit/commands/split-shared-arcs';
4
+ import type { TopologySource } from '../source/source';
5
+ import type { EmapHostInternal } from './emap-host';
6
+ import { type OpResult } from './op-result';
7
+ import type { DragSessionOptions, FeatureTranslateSession, FeatureAffineSession } from './types';
8
+ /**
9
+ * Selection-editing manager. Owned by Emap and exposed as `emap.editSession`.
10
+ * Provides translate / rotate / scale operations on the current selection
11
+ * plus the live "drag" sessions (see {@link FeatureTranslateSession}).
12
+ */
13
+ export declare class EditSessions {
14
+ private _emap;
15
+ constructor(_emap: EmapHostInternal);
16
+ translateSelected(dx: number, dy: number): OpResult;
17
+ /**
18
+ * Begin a translate "drag session" against the current selection.
19
+ *
20
+ * The session lets a UI animate a translate (e.g. follow the cursor)
21
+ * without spamming the undo stack with one entry per mousemove. Geometry
22
+ * mutates on every `move(dx, dy)`; only `commit()` pushes a single
23
+ * cumulative `FeatureTranslateCommand` (or `CompositeCommand`) to history.
24
+ * `cancel()` rolls the geometry back to the pre-session state and
25
+ * pushes nothing.
26
+ *
27
+ * Returns `null` when the selection is empty. The session captures the
28
+ * selection at start time — concurrent edits to the selection during
29
+ * a drag are intentionally ignored.
30
+ */
31
+ /**
32
+ * Shared scaffolding for translate/affine sessions: groups the active
33
+ * selection by source into buckets of `(arcIds, pointFeatures)`, and
34
+ * (when `splitShared` is true) duplicates any arc shared with an
35
+ * unselected feature so the drag doesn't drag the neighbour along.
36
+ *
37
+ * Returns `null` for an empty / fully-resolved-empty selection. The
38
+ * returned `splitCmds` have already been `do()`-applied; the caller
39
+ * must push them onto a composite at commit and call `undo()` on
40
+ * cancel.
41
+ */
42
+ _buildSelectionBuckets(splitShared: boolean): {
43
+ buckets: Array<{
44
+ sourceId: string;
45
+ source: TopologySource;
46
+ arcIds: number[];
47
+ pointFeatures: TranslatedPointFeature[];
48
+ }>;
49
+ splitCmds: SplitSharedArcsCommand[];
50
+ } | null;
51
+ beginTranslateSession(opts?: DragSessionOptions): FeatureTranslateSession | null;
52
+ /**
53
+ * Begin a rotate / scale / arbitrary-affine "drag session" against the
54
+ * current selection. Same one-history-entry-per-drag semantics as
55
+ * {@link beginTranslateSession}, but the per-frame delta is an arbitrary
56
+ * affine matrix (typically `rotateMatrix(theta, ox, oy)` or
57
+ * `scaleMatrix(sx, sy, ox, oy)` with the session's `origin`).
58
+ *
59
+ * The pivot is captured at session start: pass `origin` explicitly or let
60
+ * it default to the selection bbox centroid. Subsequent matrices should
61
+ * use the same pivot; otherwise the cumulative composed matrix on commit
62
+ * won't match the visually applied sequence.
63
+ */
64
+ beginAffineSession(this: any, origin?: [number, number], opts?: DragSessionOptions): FeatureAffineSession | null;
65
+ /**
66
+ * Rotate every selected feature around `origin` by `angleDegrees`.
67
+ * Default `origin` is the bbox centroid of the affected vertices.
68
+ *
69
+ * Lightweight in-place transform on the same path as `translateSelected`:
70
+ * not a history barrier, selection survives, multi-source selections wrap
71
+ * in a `CompositeCommand`. Returns `false` for empty selection or zero
72
+ * angle.
73
+ */
74
+ rotateSelected(angleDegrees: number, origin?: [number, number]): OpResult;
75
+ /**
76
+ * Scale every selected feature by `(sx, sy)` around `origin`.
77
+ * `sy` defaults to `sx` (uniform scale). Default `origin` is the bbox
78
+ * centroid of the affected vertices.
79
+ */
80
+ scaleSelected(sx: number, sy?: number, origin?: [number, number]): OpResult;
81
+ /**
82
+ * Shared scaffolding for rotate / scale: walks the current selection,
83
+ * groups by source, computes the bbox centroid (when no origin supplied),
84
+ * builds one `FeatureAffineCommand` per source, and pushes either the
85
+ * single command or a `CompositeCommand` wrapping all sources.
86
+ */
87
+ _applyAffineToSelection(this: any, matrixForOrigin: (ox: number, oy: number) => AffineMatrix, origin: [number, number] | undefined, labelFor: (totalFeatures: number) => string): OpResult;
88
+ /**
89
+ * Compute the bbox centroid of every vertex the bySource buckets reference
90
+ * (across path-feature arcs and point-feature shapes). Returns `null` when
91
+ * no vertex was found (e.g., empty arcs).
92
+ */
93
+ _computeSelectionCentroid(this: any, bySource: globalThis.Map<string, {
94
+ arcIdSet: Set<number>;
95
+ pointFeatures: TranslatedPointFeature[];
96
+ }>): [number, number] | null;
97
+ }
@@ -0,0 +1,41 @@
1
+ import type { EditVertexState, EditDrawState } from './types';
2
+ export type EditMode = 'none' | 'vertex' | 'draw';
3
+ export interface EditStateSnapshot {
4
+ mode: EditMode;
5
+ vertex: EditVertexState | null;
6
+ draw: EditDrawState | null;
7
+ }
8
+ export interface EditStateChange {
9
+ /** Snapshot after the mutation. */
10
+ current: EditStateSnapshot;
11
+ /** Mode before the mutation. Equal to `current.mode` for non-mode mutations. */
12
+ previousMode: EditMode;
13
+ /** True iff `current.mode !== previousMode`. */
14
+ modeChanged: boolean;
15
+ }
16
+ /**
17
+ * Single source of truth for edit-mode state. The owner (Emap) supplies
18
+ * an `onChange` callback at construction; the store calls it on every
19
+ * effective mutation so the owner can re-render, toggle the drag-pan
20
+ * gesture, and emit `editmodechange` exactly once.
21
+ *
22
+ * Invariant: vertex/draw state is auto-cleared whenever the mode leaves
23
+ * the corresponding edit mode, so a stale `setEditMode('none')` no
24
+ * longer leaks the previous overlay into the next frame.
25
+ */
26
+ export declare class EditStateStore {
27
+ private _onChange;
28
+ private _mode;
29
+ private _vertex;
30
+ private _draw;
31
+ constructor(_onChange: (change: EditStateChange) => void);
32
+ get mode(): EditMode;
33
+ get vertex(): EditVertexState | null;
34
+ get draw(): EditDrawState | null;
35
+ setMode(mode: EditMode): void;
36
+ setVertex(state: EditVertexState | null): void;
37
+ clearVertex(): void;
38
+ setDraw(state: EditDrawState | null): void;
39
+ clearDraw(): void;
40
+ private _fire;
41
+ }
@@ -0,0 +1,79 @@
1
+ import type { TopologySource } from '../source/source';
2
+ import type { MapshaperWorkerPool } from '../core/mapshaper-worker-pool';
3
+ import type { EditHistory } from '../edit/edit-history';
4
+ import type { TransactionInternal } from '../edit/transaction';
5
+ import type { Selection } from './selection';
6
+ import type { MapshaperLayer } from '../types/mapshaper-types';
7
+ import type { LayerRegistry } from './layer-registry';
8
+ import type { ValidatorRegistry } from '../validation/registry';
9
+ /**
10
+ * Sentinel returned by `_runDatasetCommand` callers when the host has
11
+ * been removed mid-await. Managers interpret this as "drop the result on
12
+ * the floor, do not mutate state, do not emit events".
13
+ */
14
+ export declare const HOST_REMOVED: unique symbol;
15
+ export interface EmapHostInternal {
16
+ /** `true` once `Emap.remove()` has been called. Async ops MUST check
17
+ * this before applying results. */
18
+ readonly _removed: boolean;
19
+ readonly _sources: globalThis.Map<string, TopologySource>;
20
+ readonly _history: EditHistory;
21
+ readonly _selection: Selection;
22
+ /**
23
+ * Currently active {@link Transaction}, or `null`. Set by
24
+ * `Transaction`'s constructor and cleared on commit / rollback. The
25
+ * runner consults this in `_applyDatasetReplace` to record per-source
26
+ * first-touch snapshots — kept on the host (rather than threaded
27
+ * through `OpContext`) so existing op signatures don't have to learn
28
+ * about transactions.
29
+ */
30
+ _activeTransaction: TransactionInternal | null;
31
+ /**
32
+ * Validator registry — owns the set of post-commit validators (e.g.
33
+ * topology checks, attribute schemas). The Emap instance listens to
34
+ * its own `historychange` event and asks the registry to run every
35
+ * `'after-commit'` validator; failures fire `validationfailed`.
36
+ */
37
+ readonly _validators: ValidatorRegistry;
38
+ readonly _workerPool: MapshaperWorkerPool | null;
39
+ readonly _workerMode: boolean | 'auto';
40
+ readonly _workerThreshold: number;
41
+ readonly _workerRouting?: import('./worker-routing').WorkerRoutingFn;
42
+ /**
43
+ * Single source of truth for `(sourceId, layerId) → MapshaperLayer`
44
+ * resolution. Replaces the legacy `_resolveLayer` method on the host;
45
+ * managers should prefer `host.layers.resolve(...)` going forward.
46
+ */
47
+ readonly layers: LayerRegistry;
48
+ /**
49
+ * @deprecated Use `host.layers.resolve(sourceId, layerId)` instead. Kept
50
+ * as a thin shim for one release so in-flight refactors don't all need
51
+ * to land at once.
52
+ */
53
+ _resolveLayer(sourceId: string, layerId: string): MapshaperLayer | null;
54
+ _scheduleRender(): void;
55
+ _fireHistoryChange(): void;
56
+ _fireSelectionChange(diff: import('./selection').SelectionDiff): void;
57
+ _invalidateShapeCachesForSources(sourceIds: Iterable<string>): void;
58
+ _clearSpatialIndexesForSources(sourceIds: Iterable<string>): void;
59
+ _allowExpressionEvaluation(values: Array<string | undefined>, operation: string): boolean;
60
+ fire(type: 'error', payload: {
61
+ error: unknown;
62
+ }): void;
63
+ fire(type: 'workerjobstart', payload: {
64
+ id: number;
65
+ cmd: string;
66
+ label: string;
67
+ datasetVertexCount: number;
68
+ }): void;
69
+ fire(type: 'workerjobend', payload: {
70
+ id: number;
71
+ ok: boolean;
72
+ durationMs: number;
73
+ errorMessage?: string;
74
+ }): void;
75
+ fire(type: 'validationfailed', payload: {
76
+ results: import('../validation/validator').ValidatorResult[];
77
+ label: string;
78
+ }): void;
79
+ }
@@ -0,0 +1,43 @@
1
+ import type { FeatureRef } from './types';
2
+ import type { PathShape, PointShape, LegacyPointShape } from '../types/mapshaper-types';
3
+ import type { EmapHostInternal } from './emap-host';
4
+ /**
5
+ * Read-only view of a single feature — geometry + frozen properties.
6
+ * Returned by every successful {@link FeatureAccessor.get} / `iter`
7
+ * call. The `properties` object is `Object.freeze`d so accidental
8
+ * mutation by the caller can't bleed back into the underlying dataset
9
+ * record.
10
+ */
11
+ export interface Feature {
12
+ ref: FeatureRef;
13
+ /**
14
+ * Geometry shape for this feature, or `null` when the feature row
15
+ * exists but has no geometry attached (legal in mapshaper for
16
+ * data-only layers and for explicit holes in some pipelines).
17
+ */
18
+ geometry: PathShape | PointShape | LegacyPointShape | null;
19
+ /** Frozen view of the row's attribute record (or empty object). */
20
+ properties: Readonly<Record<string, unknown>>;
21
+ }
22
+ /**
23
+ * Read-only feature lookups. Hangs off `Emap.features`. Stateless
24
+ * beyond the host reference; safe to call from any phase.
25
+ */
26
+ export declare class FeatureAccessor {
27
+ private readonly _host;
28
+ constructor(_host: EmapHostInternal);
29
+ /**
30
+ * Look up one feature by reference. Returns `null` if the source,
31
+ * layer, or id can't be resolved (instead of throwing) so call sites
32
+ * can write `if (!f) skip` ergonomically.
33
+ */
34
+ get(ref: FeatureRef): Feature | null;
35
+ /**
36
+ * Iterate every feature in `(sourceId, layerId)`. Yields nothing if
37
+ * the layer doesn't resolve or has no shapes. Each yielded `Feature`
38
+ * is a fresh allocation — safe to retain across iterations.
39
+ */
40
+ iter(sourceId: string, layerId: string): IterableIterator<Feature>;
41
+ /** Number of features in the layer, or `0` for unresolved layers. */
42
+ count(sourceId: string, layerId: string): number;
43
+ }
@@ -0,0 +1,58 @@
1
+ import { AffineTransform } from '../geo/transform';
2
+ import { TopologySource } from '../source/source';
3
+ import type { QueryFeaturesOptions, QueriedFeature } from './map';
4
+ /**
5
+ * Handles spatial feature queries (point hit-testing, bbox selection).
6
+ * Extracted from Emap to keep the map class focused on coordination.
7
+ */
8
+ export declare class FeatureQuery {
9
+ private _sources;
10
+ private _getTransform;
11
+ private _getSize;
12
+ private _getInitialMX;
13
+ private _indexCache;
14
+ constructor(sources: globalThis.Map<string, TopologySource>, getTransform: () => AffineTransform, getSize: () => {
15
+ width: number;
16
+ height: number;
17
+ }, getInitialMX: () => number);
18
+ /**
19
+ * Eagerly build spatial indexes for every layer of one source (or all
20
+ * sources when omitted). Idempotent — already-cached entries are
21
+ * skipped. Used by `Emap.prebuildSpatialIndex` to pay the build cost
22
+ * in idle time before the first user query.
23
+ */
24
+ prebuild(sourceId?: string): void;
25
+ /**
26
+ * Drop cached spatial indexes for one source (or all). Necessary after
27
+ * in-place geometry edits (translateSelected, vertex commands) that
28
+ * mutate arc coordinates without changing shape / arc counts — without
29
+ * this call, the cache key wouldn't notice and queries would return
30
+ * prefilter-stale results.
31
+ */
32
+ clear(sourceId?: string): void;
33
+ private _prebuildSource;
34
+ /**
35
+ * Lazily build a Flatbush index for one layer, cached by
36
+ * (sourceId, layerIndex, shapeCount, arcCount). Returns `null` for
37
+ * shape-less layers — caller falls back to the no-index loop.
38
+ *
39
+ * Per-shape bbox: point layers union of their coords; path layers
40
+ * union of `arcs.getSimpleShapeBbox()` over each part. Same precision
41
+ * as the existing inline test, just memoized.
42
+ */
43
+ private _getOrBuildIndex;
44
+ query(geometryOrOptions?: [number, number] | [[number, number], [number, number]] | QueryFeaturesOptions, options?: QueryFeaturesOptions, visibleLayers?: Set<string>): QueriedFeature[];
45
+ private _layerMatchesFilter;
46
+ private _unproject;
47
+ private _getHitBuffer;
48
+ private _getZoomAdjustedHitBuffer;
49
+ private _findHitCandidates;
50
+ private _sortByDistance;
51
+ private _pickNearestCandidates;
52
+ private _pointTest;
53
+ private _polylineTest;
54
+ private _polygonTest;
55
+ private _polygonVertexTest;
56
+ private _queryFeaturesAtPoint;
57
+ private _queryFeaturesInBBox;
58
+ }