ts-maps 0.2.7 → 0.3.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/LICENSE.md +21 -0
- package/README.md +202 -141
- package/dist/core-map/assets/embedded-icons.d.ts +8 -0
- package/dist/core-map/control/AttributionControl.d.ts +12 -0
- package/dist/core-map/control/Control.d.ts +14 -0
- package/dist/core-map/control/LayersControl.d.ts +38 -0
- package/dist/core-map/control/ScaleControl.d.ts +14 -0
- package/dist/core-map/control/ZoomControl.d.ts +14 -0
- package/dist/core-map/control/index.d.ts +5 -0
- package/dist/core-map/core/Browser.d.ts +24 -0
- package/dist/core-map/core/Class.d.ts +12 -0
- package/dist/core-map/core/Events.d.ts +31 -0
- package/dist/core-map/core/Handler.d.ts +12 -0
- package/dist/core-map/core/Util.d.ts +24 -0
- package/dist/core-map/core/index.d.ts +7 -0
- package/dist/core-map/dom/Animation.d.ts +50 -0
- package/dist/core-map/dom/DomEvent.DoubleTap.d.ts +6 -0
- package/dist/core-map/dom/DomEvent.PointerEvents.d.ts +4 -0
- package/dist/core-map/dom/DomEvent.d.ts +15 -0
- package/dist/core-map/dom/DomUtil.d.ts +22 -0
- package/dist/core-map/dom/Draggable.d.ts +26 -0
- package/dist/core-map/dom/PosAnimation.d.ts +19 -0
- package/dist/core-map/dom/easing.d.ts +41 -0
- package/dist/core-map/dom/index.d.ts +8 -0
- package/dist/core-map/geo/LatLng.d.ts +18 -0
- package/dist/core-map/geo/LatLngBounds.d.ts +27 -0
- package/dist/core-map/geo/TerrainSource.d.ts +35 -0
- package/dist/core-map/geo/crs/CRS.d.ts +23 -0
- package/dist/core-map/geo/crs/EPSG3395.d.ts +7 -0
- package/dist/core-map/geo/crs/EPSG3857.d.ts +10 -0
- package/dist/core-map/geo/crs/EPSG4326.d.ts +7 -0
- package/dist/core-map/geo/crs/EarthCRS.d.ts +7 -0
- package/dist/core-map/geo/crs/SimpleCRS.d.ts +11 -0
- package/dist/core-map/geo/crs/index.d.ts +6 -0
- package/dist/core-map/geo/elevation.d.ts +23 -0
- package/dist/core-map/geo/index.d.ts +13 -0
- package/dist/core-map/geo/index.js +1204 -0
- package/dist/core-map/geo/projection/Projection.Globe.d.ts +30 -0
- package/dist/core-map/geo/projection/Projection.LonLat.d.ts +11 -0
- package/dist/core-map/geo/projection/Projection.Mercator.d.ts +6 -0
- package/dist/core-map/geo/projection/Projection.SphericalMercator.d.ts +6 -0
- package/dist/core-map/geo/projection/index.d.ts +5 -0
- package/dist/core-map/geo/terrainMesh.d.ts +21 -0
- package/dist/core-map/geometry/Bounds.d.ts +23 -0
- package/dist/core-map/geometry/LineUtil.d.ts +13 -0
- package/dist/core-map/geometry/Point.d.ts +35 -0
- package/dist/core-map/geometry/PolyUtil.d.ts +6 -0
- package/dist/core-map/geometry/RTree.d.ts +35 -0
- package/dist/core-map/geometry/Transformation.d.ts +12 -0
- package/dist/core-map/geometry/earcut.d.ts +17 -0
- package/dist/core-map/geometry/index.d.ts +10 -0
- package/dist/core-map/geometry/index.js +1586 -0
- package/dist/core-map/index.d.ts +59 -0
- package/dist/core-map/layer/BlanketOverlay.d.ts +24 -0
- package/dist/core-map/layer/DivOverlay.d.ts +40 -0
- package/dist/core-map/layer/FeatureGroup.d.ts +11 -0
- package/dist/core-map/layer/GeoJSON.d.ts +17 -0
- package/dist/core-map/layer/GeoJSONClusterSource.d.ts +54 -0
- package/dist/core-map/layer/HeatmapLayer.d.ts +40 -0
- package/dist/core-map/layer/ImageOverlay.d.ts +27 -0
- package/dist/core-map/layer/Layer.d.ts +18 -0
- package/dist/core-map/layer/LayerGroup.d.ts +16 -0
- package/dist/core-map/layer/Popup.d.ts +18 -0
- package/dist/core-map/layer/SVGOverlay.d.ts +4 -0
- package/dist/core-map/layer/Tooltip.d.ts +15 -0
- package/dist/core-map/layer/VideoOverlay.d.ts +4 -0
- package/dist/core-map/layer/index.d.ts +18 -0
- package/dist/core-map/layer/marker/DefaultIcon.d.ts +7 -0
- package/dist/core-map/layer/marker/DivIcon.d.ts +5 -0
- package/dist/core-map/layer/marker/Icon.d.ts +10 -0
- package/dist/core-map/layer/marker/Marker.Drag.d.ts +17 -0
- package/dist/core-map/layer/marker/Marker.d.ts +37 -0
- package/dist/core-map/layer/marker/index.d.ts +5 -0
- package/dist/core-map/layer/tile/GridLayer.d.ts +88 -0
- package/dist/core-map/layer/tile/RasterDEMLayer.d.ts +46 -0
- package/dist/core-map/layer/tile/TileLayer.d.ts +22 -0
- package/dist/core-map/layer/tile/VectorTileMapLayer.d.ts +145 -0
- package/dist/core-map/layer/tile/WMSTileLayer.d.ts +12 -0
- package/dist/core-map/layer/tile/index.d.ts +15 -0
- package/dist/core-map/layer/tile/urlTemplate.d.ts +17 -0
- package/dist/core-map/layer/vector/Canvas.d.ts +52 -0
- package/dist/core-map/layer/vector/Circle.d.ts +7 -0
- package/dist/core-map/layer/vector/CircleMarker.d.ts +22 -0
- package/dist/core-map/layer/vector/Path.d.ts +20 -0
- package/dist/core-map/layer/vector/Polygon.d.ts +13 -0
- package/dist/core-map/layer/vector/Polyline.d.ts +30 -0
- package/dist/core-map/layer/vector/Rectangle.d.ts +6 -0
- package/dist/core-map/layer/vector/Renderer.d.ts +12 -0
- package/dist/core-map/layer/vector/Renderer.getRenderer.d.ts +1 -0
- package/dist/core-map/layer/vector/SVG.d.ts +21 -0
- package/dist/core-map/layer/vector/index.d.ts +10 -0
- package/dist/core-map/map/Map.d.ts +353 -0
- package/dist/core-map/map/Style.d.ts +29 -0
- package/dist/core-map/map/handler/BoxZoomHandler.d.ts +23 -0
- package/dist/core-map/map/handler/DoubleClickZoomHandler.d.ts +6 -0
- package/dist/core-map/map/handler/DragHandler.d.ts +27 -0
- package/dist/core-map/map/handler/KeyboardHandler.d.ts +18 -0
- package/dist/core-map/map/handler/PinchZoomHandler.d.ts +20 -0
- package/dist/core-map/map/handler/ScrollWheelZoomHandler.d.ts +12 -0
- package/dist/core-map/map/handler/TapHoldHandler.d.ts +15 -0
- package/dist/core-map/map/handler/TwoFingerPitchHandler.d.ts +21 -0
- package/dist/core-map/map/handler/TwoFingerRotateHandler.d.ts +17 -0
- package/dist/core-map/map/index.d.ts +11 -0
- package/dist/core-map/mvt/VectorTile.d.ts +9 -0
- package/dist/core-map/mvt/VectorTileFeature.d.ts +59 -0
- package/dist/core-map/mvt/VectorTileLayer.d.ts +13 -0
- package/dist/core-map/proto/Pbf.d.ts +84 -0
- package/dist/core-map/renderer/webgl/GLContext.d.ts +22 -0
- package/dist/core-map/renderer/webgl/WebGLTileRenderer.d.ts +86 -0
- package/dist/core-map/renderer/webgl/index.d.ts +9 -0
- package/dist/core-map/renderer/webgl/mat4.d.ts +14 -0
- package/dist/core-map/services/index.d.ts +26 -0
- package/dist/core-map/services/index.js +1230 -0
- package/dist/core-map/services/providers/Google.d.ts +16 -0
- package/dist/core-map/services/providers/Mapbox.d.ts +26 -0
- package/dist/core-map/services/providers/Maptiler.d.ts +11 -0
- package/dist/core-map/services/providers/Nominatim.d.ts +11 -0
- package/dist/core-map/services/providers/OSRM.d.ts +20 -0
- package/dist/core-map/services/providers/Photon.d.ts +10 -0
- package/dist/core-map/services/providers/Valhalla.d.ts +20 -0
- package/dist/core-map/services/types.d.ts +84 -0
- package/dist/core-map/storage/TileCache.d.ts +40 -0
- package/dist/core-map/storage/cachedFetch.d.ts +13 -0
- package/dist/core-map/storage/defaultCache.d.ts +3 -0
- package/dist/core-map/storage/index.d.ts +13 -0
- package/dist/core-map/storage/index.js +283 -0
- package/dist/core-map/storage/offlineRegion.d.ts +26 -0
- package/dist/core-map/style-spec/diff.d.ts +17 -0
- package/dist/core-map/style-spec/expressions/Color.d.ts +16 -0
- package/dist/core-map/style-spec/expressions/compile.d.ts +4 -0
- package/dist/core-map/style-spec/expressions/errors.d.ts +8 -0
- package/dist/core-map/style-spec/expressions/index.d.ts +16 -0
- package/dist/core-map/style-spec/expressions/legacyFilter.d.ts +6 -0
- package/dist/core-map/style-spec/expressions/operators/conversion.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/interpolate.d.ts +14 -0
- package/dist/core-map/style-spec/expressions/operators/logical.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/lookup.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/math.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/operators/string.d.ts +1 -0
- package/dist/core-map/style-spec/expressions/registry.d.ts +29 -0
- package/dist/core-map/style-spec/expressions/types.d.ts +48 -0
- package/dist/core-map/style-spec/expressions/validate.d.ts +13 -0
- package/dist/core-map/style-spec/index.d.ts +68 -0
- package/dist/core-map/style-spec/index.js +2529 -0
- package/dist/core-map/style-spec/schema.d.ts +381 -0
- package/dist/core-map/style-spec/types.d.ts +375 -0
- package/dist/core-map/style-spec/validate.d.ts +14 -0
- package/dist/core-map/symbols/CollisionIndex.d.ts +21 -0
- package/dist/core-map/symbols/GlyphAtlas.d.ts +38 -0
- package/dist/core-map/symbols/IconAtlas.d.ts +18 -0
- package/dist/core-map/symbols/index.d.ts +6 -0
- package/dist/core-map/symbols/index.js +501 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +18414 -1857
- package/package.json +50 -58
- package/src/core-map/ts-maps.css +725 -0
- package/dist/components/base.d.ts +0 -17
- package/dist/components/concerns/interactable.d.ts +0 -1
- package/dist/components/line.d.ts +0 -29
- package/dist/components/marker.d.ts +0 -50
- package/dist/components/region.d.ts +0 -46
- package/dist/components/tooltip.d.ts +0 -22
- package/dist/core/apply-transform.d.ts +0 -7
- package/dist/core/coords-to-point.d.ts +0 -12
- package/dist/core/create-lines.d.ts +0 -2
- package/dist/core/create-markers.d.ts +0 -2
- package/dist/core/create-regions.d.ts +0 -2
- package/dist/core/create-series.d.ts +0 -3
- package/dist/core/get-inset-for-point.d.ts +0 -13
- package/dist/core/get-marker-position.d.ts +0 -6
- package/dist/core/index.d.ts +0 -1
- package/dist/core/reposition-labels.d.ts +0 -2
- package/dist/core/reposition-lines.d.ts +0 -2
- package/dist/core/reposition-markers.d.ts +0 -2
- package/dist/core/resize.d.ts +0 -3
- package/dist/core/set-focus.d.ts +0 -2
- package/dist/core/set-scale.d.ts +0 -2
- package/dist/core/setup-container-events.d.ts +0 -2
- package/dist/core/setup-container-touch-events.d.ts +0 -2
- package/dist/core/setup-element-events.d.ts +0 -2
- package/dist/core/setup-zoom-buttons.d.ts +0 -2
- package/dist/core/update-size.d.ts +0 -2
- package/dist/data-visualization.d.ts +0 -17
- package/dist/defaults/events.d.ts +0 -1
- package/dist/defaults/options.d.ts +0 -1
- package/dist/event-handler.d.ts +0 -1
- package/dist/legend.d.ts +0 -17
- package/dist/map.d.ts +0 -81
- package/dist/maps/brasil.d.ts +0 -2
- package/dist/maps/brasil.js +0 -7
- package/dist/maps/canada.d.ts +0 -2
- package/dist/maps/canada.js +0 -7
- package/dist/maps/iraq.d.ts +0 -2
- package/dist/maps/iraq.js +0 -84
- package/dist/maps/italy.d.ts +0 -2
- package/dist/maps/italy.js +0 -7
- package/dist/maps/russia.d.ts +0 -2
- package/dist/maps/russia.js +0 -366
- package/dist/maps/spain.d.ts +0 -2
- package/dist/maps/spain.js +0 -7
- package/dist/maps/us-aea-en.d.ts +0 -2
- package/dist/maps/us-aea-en.js +0 -7
- package/dist/maps/us-lcc-en.d.ts +0 -2
- package/dist/maps/us-lcc-en.js +0 -7
- package/dist/maps/us-merc-en.d.ts +0 -2
- package/dist/maps/us-merc-en.js +0 -7
- package/dist/maps/us-mill-en.d.ts +0 -2
- package/dist/maps/us-mill-en.js +0 -7
- package/dist/maps/world-merc.d.ts +0 -2
- package/dist/maps/world-merc.js +0 -7
- package/dist/maps/world.d.ts +0 -2
- package/dist/maps/world.js +0 -7
- package/dist/projection.d.ts +0 -1
- package/dist/scales/ordinal-scale.d.ts +0 -12
- package/dist/series.d.ts +0 -14
- package/dist/svg/base-element.d.ts +0 -19
- package/dist/svg/canvas-element.d.ts +0 -21
- package/dist/svg/image-element.d.ts +0 -12
- package/dist/svg/shape-element.d.ts +0 -19
- package/dist/svg/text-element.d.ts +0 -7
- package/dist/types.d.ts +0 -418
- package/dist/util/deep-merge.d.ts +0 -2
- package/dist/util/index.d.ts +0 -18
- package/dist/utils.d.ts +0 -87
- package/dist/vector-map.d.ts +0 -5
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
39
|
+
|
|
40
|
+
// src/core-map/symbols/CollisionIndex.ts
|
|
41
|
+
class CollisionIndex {
|
|
42
|
+
_cellSize;
|
|
43
|
+
_cols;
|
|
44
|
+
_rows;
|
|
45
|
+
_cells;
|
|
46
|
+
constructor(opts) {
|
|
47
|
+
this._cellSize = opts?.cellSize ?? 64;
|
|
48
|
+
const width = opts?.width ?? 1;
|
|
49
|
+
const height = opts?.height ?? 1;
|
|
50
|
+
this._cols = Math.max(1, Math.ceil(width / this._cellSize));
|
|
51
|
+
this._rows = Math.max(1, Math.ceil(height / this._cellSize));
|
|
52
|
+
this._cells = [];
|
|
53
|
+
for (let i = 0;i < this._cols * this._rows; i++)
|
|
54
|
+
this._cells.push([]);
|
|
55
|
+
}
|
|
56
|
+
tryInsert(box) {
|
|
57
|
+
const range = this._cellRange(box);
|
|
58
|
+
for (let cy = range.y0;cy <= range.y1; cy++) {
|
|
59
|
+
for (let cx = range.x0;cx <= range.x1; cx++) {
|
|
60
|
+
const bucket = this._cells[cy * this._cols + cx];
|
|
61
|
+
for (const other of bucket) {
|
|
62
|
+
if (!overlaps(box, other))
|
|
63
|
+
continue;
|
|
64
|
+
if (other.priority === undefined || box.priority === undefined)
|
|
65
|
+
return false;
|
|
66
|
+
if (other.priority >= box.priority)
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
this._insertBucketed(box, range);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
insert(box) {
|
|
75
|
+
this._insertBucketed(box, this._cellRange(box));
|
|
76
|
+
}
|
|
77
|
+
clear() {
|
|
78
|
+
for (let i = 0;i < this._cells.length; i++)
|
|
79
|
+
this._cells[i] = [];
|
|
80
|
+
}
|
|
81
|
+
_cellRange(box) {
|
|
82
|
+
const cs = this._cellSize;
|
|
83
|
+
let x0 = Math.floor(box.minX / cs);
|
|
84
|
+
let y0 = Math.floor(box.minY / cs);
|
|
85
|
+
let x1 = Math.floor(box.maxX / cs);
|
|
86
|
+
let y1 = Math.floor(box.maxY / cs);
|
|
87
|
+
if (x0 < 0)
|
|
88
|
+
x0 = 0;
|
|
89
|
+
if (y0 < 0)
|
|
90
|
+
y0 = 0;
|
|
91
|
+
if (x1 > this._cols - 1)
|
|
92
|
+
x1 = this._cols - 1;
|
|
93
|
+
if (y1 > this._rows - 1)
|
|
94
|
+
y1 = this._rows - 1;
|
|
95
|
+
if (x1 < x0)
|
|
96
|
+
x1 = x0;
|
|
97
|
+
if (y1 < y0)
|
|
98
|
+
y1 = y0;
|
|
99
|
+
return { x0, y0, x1, y1 };
|
|
100
|
+
}
|
|
101
|
+
_insertBucketed(box, range) {
|
|
102
|
+
for (let cy = range.y0;cy <= range.y1; cy++) {
|
|
103
|
+
for (let cx = range.x0;cx <= range.x1; cx++) {
|
|
104
|
+
this._cells[cy * this._cols + cx].push(box);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function overlaps(a, b) {
|
|
110
|
+
if (a.maxX < b.minX)
|
|
111
|
+
return false;
|
|
112
|
+
if (a.minX > b.maxX)
|
|
113
|
+
return false;
|
|
114
|
+
if (a.maxY < b.minY)
|
|
115
|
+
return false;
|
|
116
|
+
if (a.minY > b.maxY)
|
|
117
|
+
return false;
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/core-map/symbols/GlyphAtlas.ts
|
|
122
|
+
function styleKey(k) {
|
|
123
|
+
if (!k)
|
|
124
|
+
return "r";
|
|
125
|
+
return `${k.italic ? "i" : "r"}${k.bold ? "b" : ""}`;
|
|
126
|
+
}
|
|
127
|
+
function cacheKey(k) {
|
|
128
|
+
return `${k.codePoint}:${styleKey(k)}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class GlyphAtlas {
|
|
132
|
+
canvas;
|
|
133
|
+
_ctx;
|
|
134
|
+
_fontFamily;
|
|
135
|
+
_fontSize;
|
|
136
|
+
_padding;
|
|
137
|
+
_glyphs;
|
|
138
|
+
_shelfY;
|
|
139
|
+
_shelfX;
|
|
140
|
+
_shelfH;
|
|
141
|
+
constructor(opts) {
|
|
142
|
+
this._fontFamily = opts?.fontFamily ?? "system-ui, -apple-system, Segoe UI, Roboto";
|
|
143
|
+
this._fontSize = opts?.fontSize ?? 24;
|
|
144
|
+
this._padding = opts?.padding ?? 4;
|
|
145
|
+
const bucketSize = opts?.bucketSize ?? 512;
|
|
146
|
+
this.canvas = document.createElement("canvas");
|
|
147
|
+
this.canvas.width = bucketSize;
|
|
148
|
+
this.canvas.height = bucketSize;
|
|
149
|
+
this._ctx = this.canvas.getContext("2d");
|
|
150
|
+
this._glyphs = new Map;
|
|
151
|
+
this._shelfX = 0;
|
|
152
|
+
this._shelfY = 0;
|
|
153
|
+
this._shelfH = 0;
|
|
154
|
+
}
|
|
155
|
+
getOrAddGlyph(codePoint, style) {
|
|
156
|
+
const key = {
|
|
157
|
+
codePoint,
|
|
158
|
+
italic: !!style?.italic,
|
|
159
|
+
bold: !!style?.bold
|
|
160
|
+
};
|
|
161
|
+
const existing = this._glyphs.get(cacheKey(key));
|
|
162
|
+
if (existing)
|
|
163
|
+
return existing;
|
|
164
|
+
return this._rasterize(key);
|
|
165
|
+
}
|
|
166
|
+
measure(text, style) {
|
|
167
|
+
let width = 0;
|
|
168
|
+
let height = 0;
|
|
169
|
+
for (const ch of text) {
|
|
170
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
171
|
+
const g = this.getOrAddGlyph(cp, style);
|
|
172
|
+
width += g.advance;
|
|
173
|
+
if (g.height > height)
|
|
174
|
+
height = g.height;
|
|
175
|
+
}
|
|
176
|
+
return { width, height };
|
|
177
|
+
}
|
|
178
|
+
drawText(ctx, text, x, y, options) {
|
|
179
|
+
const style = { italic: !!options.italic, bold: !!options.bold };
|
|
180
|
+
const scale = options.size / this._fontSize;
|
|
181
|
+
if (options.haloColor && options.haloWidth && options.haloWidth > 0) {
|
|
182
|
+
ctx.save();
|
|
183
|
+
ctx.globalCompositeOperation = "destination-over";
|
|
184
|
+
ctx.fillStyle = options.haloColor;
|
|
185
|
+
this._drawRun(ctx, text, x, y, scale, style, options.haloWidth);
|
|
186
|
+
ctx.restore();
|
|
187
|
+
}
|
|
188
|
+
ctx.save();
|
|
189
|
+
ctx.fillStyle = options.color;
|
|
190
|
+
this._drawRun(ctx, text, x, y, scale, style, 0);
|
|
191
|
+
ctx.restore();
|
|
192
|
+
}
|
|
193
|
+
_buildSDF(imageData) {
|
|
194
|
+
const w = imageData.width;
|
|
195
|
+
const h = imageData.height;
|
|
196
|
+
const radius = this._padding;
|
|
197
|
+
const INF = 1 << 20;
|
|
198
|
+
const inside = new Int32Array(w * h);
|
|
199
|
+
const outside = new Int32Array(w * h);
|
|
200
|
+
for (let i = 0;i < w * h; i++) {
|
|
201
|
+
const a = imageData.data[i * 4 + 3];
|
|
202
|
+
if (a >= 128) {
|
|
203
|
+
outside[i] = INF;
|
|
204
|
+
inside[i] = 0;
|
|
205
|
+
} else {
|
|
206
|
+
outside[i] = 0;
|
|
207
|
+
inside[i] = INF;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
chamfer34(outside, w, h);
|
|
211
|
+
chamfer34(inside, w, h);
|
|
212
|
+
const out = createImageData(w, h);
|
|
213
|
+
for (let i = 0;i < w * h; i++) {
|
|
214
|
+
const d = (outside[i] - inside[i]) / 3;
|
|
215
|
+
let v = 128 - d / radius * 128;
|
|
216
|
+
if (v < 0)
|
|
217
|
+
v = 0;
|
|
218
|
+
else if (v > 255)
|
|
219
|
+
v = 255;
|
|
220
|
+
out.data[i * 4 + 0] = 255;
|
|
221
|
+
out.data[i * 4 + 1] = 255;
|
|
222
|
+
out.data[i * 4 + 2] = 255;
|
|
223
|
+
out.data[i * 4 + 3] = v | 0;
|
|
224
|
+
}
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
_drawRun(ctx, text, x, y, scale, style, haloInflate) {
|
|
228
|
+
let pen = x;
|
|
229
|
+
for (const ch of text) {
|
|
230
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
231
|
+
const g = this.getOrAddGlyph(cp, style);
|
|
232
|
+
if (g.width > 0 && g.height > 0) {
|
|
233
|
+
const dx = pen + g.bearingX * scale - haloInflate;
|
|
234
|
+
const dy = y - g.bearingY * scale - haloInflate;
|
|
235
|
+
const dw = g.width * scale + haloInflate * 2;
|
|
236
|
+
const dh = g.height * scale + haloInflate * 2;
|
|
237
|
+
ctx.drawImage(this.canvas, g.x, g.y, g.width, g.height, dx, dy, dw, dh);
|
|
238
|
+
}
|
|
239
|
+
pen += g.advance * scale;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
_rasterize(key) {
|
|
243
|
+
const ctx = this._ctx;
|
|
244
|
+
if (!ctx) {
|
|
245
|
+
const metrics2 = {
|
|
246
|
+
codePoint: key.codePoint,
|
|
247
|
+
x: 0,
|
|
248
|
+
y: 0,
|
|
249
|
+
width: 0,
|
|
250
|
+
height: 0,
|
|
251
|
+
advance: this._fontSize * 0.6,
|
|
252
|
+
bearingX: 0,
|
|
253
|
+
bearingY: 0
|
|
254
|
+
};
|
|
255
|
+
this._glyphs.set(cacheKey(key), metrics2);
|
|
256
|
+
return metrics2;
|
|
257
|
+
}
|
|
258
|
+
const font = this._buildFontSpec(key);
|
|
259
|
+
ctx.font = font;
|
|
260
|
+
const ch = String.fromCodePoint(key.codePoint);
|
|
261
|
+
const m = ctx.measureText(ch);
|
|
262
|
+
const advance = m.width && m.width > 0 ? m.width : this._fontSize * 0.6;
|
|
263
|
+
const ascent = m.actualBoundingBoxAscent && m.actualBoundingBoxAscent > 0 ? m.actualBoundingBoxAscent : this._fontSize * 0.8;
|
|
264
|
+
const descent = m.actualBoundingBoxDescent && m.actualBoundingBoxDescent > 0 ? m.actualBoundingBoxDescent : this._fontSize * 0.2;
|
|
265
|
+
const pad = this._padding;
|
|
266
|
+
const bmpW = Math.max(1, Math.ceil(advance)) + pad * 2;
|
|
267
|
+
const bmpH = Math.max(1, Math.ceil(ascent + descent)) + pad * 2;
|
|
268
|
+
const scratch = document.createElement("canvas");
|
|
269
|
+
scratch.width = bmpW;
|
|
270
|
+
scratch.height = bmpH;
|
|
271
|
+
const sctx = scratch.getContext("2d");
|
|
272
|
+
if (sctx) {
|
|
273
|
+
sctx.font = font;
|
|
274
|
+
sctx.fillStyle = "#000";
|
|
275
|
+
sctx.textBaseline = "alphabetic";
|
|
276
|
+
sctx.fillText(ch, pad, pad + ascent);
|
|
277
|
+
try {
|
|
278
|
+
const src = sctx.getImageData(0, 0, bmpW, bmpH);
|
|
279
|
+
const sdf = this._buildSDF(src);
|
|
280
|
+
sctx.putImageData(sdf, 0, 0);
|
|
281
|
+
} catch {}
|
|
282
|
+
}
|
|
283
|
+
if (this._shelfX + bmpW > this.canvas.width) {
|
|
284
|
+
this._shelfY += this._shelfH;
|
|
285
|
+
this._shelfX = 0;
|
|
286
|
+
this._shelfH = 0;
|
|
287
|
+
}
|
|
288
|
+
if (this._shelfY + bmpH > this.canvas.height)
|
|
289
|
+
this._growAtlas(Math.max(this.canvas.width * 2, this._shelfY + bmpH));
|
|
290
|
+
if (this._shelfX + bmpW > this.canvas.width)
|
|
291
|
+
this._growAtlas(Math.max(this.canvas.width * 2, this._shelfX + bmpW));
|
|
292
|
+
const dx = this._shelfX;
|
|
293
|
+
const dy = this._shelfY;
|
|
294
|
+
ctx.drawImage(scratch, dx, dy);
|
|
295
|
+
this._shelfX += bmpW;
|
|
296
|
+
if (bmpH > this._shelfH)
|
|
297
|
+
this._shelfH = bmpH;
|
|
298
|
+
const metrics = {
|
|
299
|
+
codePoint: key.codePoint,
|
|
300
|
+
x: dx,
|
|
301
|
+
y: dy,
|
|
302
|
+
width: bmpW,
|
|
303
|
+
height: bmpH,
|
|
304
|
+
advance,
|
|
305
|
+
bearingX: -pad,
|
|
306
|
+
bearingY: ascent + pad
|
|
307
|
+
};
|
|
308
|
+
this._glyphs.set(cacheKey(key), metrics);
|
|
309
|
+
return metrics;
|
|
310
|
+
}
|
|
311
|
+
_buildFontSpec(key) {
|
|
312
|
+
const parts = [];
|
|
313
|
+
if (key.italic)
|
|
314
|
+
parts.push("italic");
|
|
315
|
+
if (key.bold)
|
|
316
|
+
parts.push("bold");
|
|
317
|
+
parts.push(`${this._fontSize}px`);
|
|
318
|
+
parts.push(this._fontFamily);
|
|
319
|
+
return parts.join(" ");
|
|
320
|
+
}
|
|
321
|
+
_growAtlas(newSide) {
|
|
322
|
+
const old = this.canvas;
|
|
323
|
+
const target = document.createElement("canvas");
|
|
324
|
+
target.width = Math.max(newSide, old.width);
|
|
325
|
+
target.height = Math.max(newSide, old.height);
|
|
326
|
+
const tctx = target.getContext("2d");
|
|
327
|
+
if (tctx)
|
|
328
|
+
tctx.drawImage(old, 0, 0);
|
|
329
|
+
this.canvas = target;
|
|
330
|
+
this._ctx = tctx;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function createImageData(width, height) {
|
|
334
|
+
const data = new Uint8ClampedArray(width * height * 4);
|
|
335
|
+
const ctor = globalThis.ImageData;
|
|
336
|
+
if (typeof ctor === "function") {
|
|
337
|
+
try {
|
|
338
|
+
return new ctor(data, width, height);
|
|
339
|
+
} catch {}
|
|
340
|
+
}
|
|
341
|
+
return { data, width, height, colorSpace: "srgb" };
|
|
342
|
+
}
|
|
343
|
+
function chamfer34(buf, w, h) {
|
|
344
|
+
for (let y = 0;y < h; y++) {
|
|
345
|
+
for (let x = 0;x < w; x++) {
|
|
346
|
+
const i = y * w + x;
|
|
347
|
+
let v = buf[i];
|
|
348
|
+
if (y > 0) {
|
|
349
|
+
if (x > 0) {
|
|
350
|
+
const c = buf[i - w - 1] + 4;
|
|
351
|
+
if (c < v)
|
|
352
|
+
v = c;
|
|
353
|
+
}
|
|
354
|
+
const c2 = buf[i - w] + 3;
|
|
355
|
+
if (c2 < v)
|
|
356
|
+
v = c2;
|
|
357
|
+
if (x < w - 1) {
|
|
358
|
+
const c3 = buf[i - w + 1] + 4;
|
|
359
|
+
if (c3 < v)
|
|
360
|
+
v = c3;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (x > 0) {
|
|
364
|
+
const c4 = buf[i - 1] + 3;
|
|
365
|
+
if (c4 < v)
|
|
366
|
+
v = c4;
|
|
367
|
+
}
|
|
368
|
+
buf[i] = v;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
for (let y = h - 1;y >= 0; y--) {
|
|
372
|
+
for (let x = w - 1;x >= 0; x--) {
|
|
373
|
+
const i = y * w + x;
|
|
374
|
+
let v = buf[i];
|
|
375
|
+
if (y < h - 1) {
|
|
376
|
+
if (x < w - 1) {
|
|
377
|
+
const c = buf[i + w + 1] + 4;
|
|
378
|
+
if (c < v)
|
|
379
|
+
v = c;
|
|
380
|
+
}
|
|
381
|
+
const c2 = buf[i + w] + 3;
|
|
382
|
+
if (c2 < v)
|
|
383
|
+
v = c2;
|
|
384
|
+
if (x > 0) {
|
|
385
|
+
const c3 = buf[i + w - 1] + 4;
|
|
386
|
+
if (c3 < v)
|
|
387
|
+
v = c3;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (x < w - 1) {
|
|
391
|
+
const c4 = buf[i + 1] + 3;
|
|
392
|
+
if (c4 < v)
|
|
393
|
+
v = c4;
|
|
394
|
+
}
|
|
395
|
+
buf[i] = v;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// src/core-map/symbols/IconAtlas.ts
|
|
401
|
+
class IconAtlas {
|
|
402
|
+
canvas;
|
|
403
|
+
_ctx;
|
|
404
|
+
_sprites;
|
|
405
|
+
_cursorX;
|
|
406
|
+
_cursorY;
|
|
407
|
+
_rowH;
|
|
408
|
+
constructor() {
|
|
409
|
+
this.canvas = document.createElement("canvas");
|
|
410
|
+
this.canvas.width = 512;
|
|
411
|
+
this.canvas.height = 512;
|
|
412
|
+
this._ctx = this.canvas.getContext("2d");
|
|
413
|
+
this._sprites = new Map;
|
|
414
|
+
this._cursorX = 0;
|
|
415
|
+
this._cursorY = 0;
|
|
416
|
+
this._rowH = 0;
|
|
417
|
+
}
|
|
418
|
+
addSprite(entry, source) {
|
|
419
|
+
const w = entry.width;
|
|
420
|
+
const h = entry.height;
|
|
421
|
+
if (this._cursorX + w > this.canvas.width) {
|
|
422
|
+
this._cursorY += this._rowH;
|
|
423
|
+
this._cursorX = 0;
|
|
424
|
+
this._rowH = 0;
|
|
425
|
+
}
|
|
426
|
+
if (this._cursorY + h > this.canvas.height)
|
|
427
|
+
this._grow(Math.max(this.canvas.width * 2, this._cursorY + h));
|
|
428
|
+
const dx = this._cursorX;
|
|
429
|
+
const dy = this._cursorY;
|
|
430
|
+
const ctx = this._ctx;
|
|
431
|
+
if (ctx) {
|
|
432
|
+
if (isImageData(source)) {
|
|
433
|
+
const detour = document.createElement("canvas");
|
|
434
|
+
detour.width = source.width;
|
|
435
|
+
detour.height = source.height;
|
|
436
|
+
const dctx = detour.getContext("2d");
|
|
437
|
+
if (dctx) {
|
|
438
|
+
dctx.putImageData(source, 0, 0);
|
|
439
|
+
ctx.drawImage(detour, entry.x, entry.y, w, h, dx, dy, w, h);
|
|
440
|
+
}
|
|
441
|
+
} else {
|
|
442
|
+
ctx.drawImage(source, entry.x, entry.y, w, h, dx, dy, w, h);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
const packed = {
|
|
446
|
+
id: entry.id,
|
|
447
|
+
x: dx,
|
|
448
|
+
y: dy,
|
|
449
|
+
width: w,
|
|
450
|
+
height: h,
|
|
451
|
+
pixelRatio: entry.pixelRatio ?? 1
|
|
452
|
+
};
|
|
453
|
+
this._sprites.set(entry.id, packed);
|
|
454
|
+
this._cursorX += w;
|
|
455
|
+
if (h > this._rowH)
|
|
456
|
+
this._rowH = h;
|
|
457
|
+
}
|
|
458
|
+
get(id) {
|
|
459
|
+
return this._sprites.get(id);
|
|
460
|
+
}
|
|
461
|
+
drawIcon(ctx, id, dx, dy, opts) {
|
|
462
|
+
const s = this._sprites.get(id);
|
|
463
|
+
if (!s)
|
|
464
|
+
return;
|
|
465
|
+
const target = opts?.size ?? s.width;
|
|
466
|
+
const scale = target / s.width;
|
|
467
|
+
const w = s.width * scale;
|
|
468
|
+
const h = s.height * scale;
|
|
469
|
+
if (opts?.rotation) {
|
|
470
|
+
ctx.save();
|
|
471
|
+
ctx.translate(dx, dy);
|
|
472
|
+
ctx.rotate(opts.rotation);
|
|
473
|
+
ctx.drawImage(this.canvas, s.x, s.y, s.width, s.height, -w / 2, -h / 2, w, h);
|
|
474
|
+
ctx.restore();
|
|
475
|
+
} else {
|
|
476
|
+
ctx.drawImage(this.canvas, s.x, s.y, s.width, s.height, dx - w / 2, dy - h / 2, w, h);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
_grow(newSide) {
|
|
480
|
+
const old = this.canvas;
|
|
481
|
+
const target = document.createElement("canvas");
|
|
482
|
+
target.width = Math.max(newSide, old.width);
|
|
483
|
+
target.height = Math.max(newSide, old.height);
|
|
484
|
+
const tctx = target.getContext("2d");
|
|
485
|
+
if (tctx)
|
|
486
|
+
tctx.drawImage(old, 0, 0);
|
|
487
|
+
this.canvas = target;
|
|
488
|
+
this._ctx = tctx;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function isImageData(v) {
|
|
492
|
+
if (!v || typeof v !== "object")
|
|
493
|
+
return false;
|
|
494
|
+
const anyV = v;
|
|
495
|
+
return typeof anyV.width === "number" && typeof anyV.height === "number" && (anyV.data instanceof Uint8ClampedArray || anyV.data instanceof Uint8Array);
|
|
496
|
+
}
|
|
497
|
+
export {
|
|
498
|
+
IconAtlas,
|
|
499
|
+
GlyphAtlas,
|
|
500
|
+
CollisionIndex
|
|
501
|
+
};
|
package/dist/index.d.ts
CHANGED