isard 1.1.0 → 1.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/CHANGELOG.md +121 -0
- package/README.md +44 -39
- package/dist/basemap/basemaps.d.ts +1 -1
- package/dist/basemap/basemaps.js +2 -2
- package/dist/basemap/basemaps.js.map +1 -1
- package/dist/basemap/grid.d.ts +5 -5
- package/dist/basemap/grid.js +59 -65
- package/dist/basemap/grid.js.map +1 -1
- package/dist/basemap/mvt.d.ts +1 -1
- package/dist/basemap/mvt.js +6 -6
- package/dist/basemap/mvt.js.map +1 -1
- package/dist/basemap/pmtiles.d.ts +10 -10
- package/dist/basemap/pmtiles.js +39 -31
- package/dist/basemap/pmtiles.js.map +1 -1
- package/dist/basemap/pmtileslayer.d.ts +33 -0
- package/dist/basemap/pmtileslayer.js +97 -0
- package/dist/basemap/pmtileslayer.js.map +1 -0
- package/dist/basemap/resample.d.ts +2 -2
- package/dist/basemap/resample.js +16 -14
- package/dist/basemap/resample.js.map +1 -1
- package/dist/basemap/terrain.d.ts +3 -3
- package/dist/basemap/terrain.js +6 -6
- package/dist/basemap/terrain.js.map +1 -1
- package/dist/basemap/trees.d.ts +26 -0
- package/dist/basemap/trees.js +141 -0
- package/dist/basemap/trees.js.map +1 -0
- package/dist/basemap/vectorstyle.d.ts +22 -10
- package/dist/basemap/vectorstyle.js +163 -110
- package/dist/basemap/vectorstyle.js.map +1 -1
- package/dist/basemap/vectortiles.d.ts +70 -47
- package/dist/basemap/vectortiles.js +480 -358
- package/dist/basemap/vectortiles.js.map +1 -1
- package/dist/basemap/wmts.d.ts +3 -3
- package/dist/basemap/wmts.js +16 -11
- package/dist/basemap/wmts.js.map +1 -1
- package/dist/basemap/workerpool.d.ts +17 -0
- package/dist/basemap/workerpool.js +194 -0
- package/dist/basemap/workerpool.js.map +1 -0
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +21 -13
- package/dist/bind/layers.d.ts +13 -4
- package/dist/bind/layers.js +64 -40
- package/dist/bind/layers.js.map +1 -1
- package/dist/data/crs.d.ts +10 -10
- package/dist/data/crs.js +38 -34
- package/dist/data/crs.js.map +1 -1
- package/dist/data/gpx.d.ts +1 -1
- package/dist/data/gpx.js +20 -20
- package/dist/data/gpx.js.map +1 -1
- package/dist/data/kml.d.ts +1 -1
- package/dist/data/kml.js +42 -39
- package/dist/data/kml.js.map +1 -1
- package/dist/data/topojson.d.ts +1 -1
- package/dist/data/topojson.js +15 -10
- package/dist/data/topojson.js.map +1 -1
- package/dist/data/xml.d.ts +5 -5
- package/dist/data/xml.js +19 -18
- package/dist/data/xml.js.map +1 -1
- package/dist/decoder.worker.js +4 -4
- package/dist/decoder.worker.js.map +6 -6
- package/dist/engine/decoders.d.ts +2 -2
- package/dist/engine/decoders.js +28 -25
- package/dist/engine/decoders.js.map +1 -1
- package/dist/engine/loader.js +13 -14
- package/dist/engine/loader.js.map +1 -1
- package/dist/engine/requests.d.ts +1 -1
- package/dist/engine/requests.js +19 -16
- package/dist/engine/requests.js.map +1 -1
- package/dist/engine-loader.d.ts +13 -9
- package/dist/engine-loader.js +38 -28
- package/dist/engine-loader.js.map +1 -1
- package/dist/geoplateforme.d.ts +26 -10
- package/dist/geoplateforme.js +45 -20
- package/dist/geoplateforme.js.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/isard_points_bg.wasm +0 -0
- package/dist/isard_tess_bg.wasm +0 -0
- package/dist/layers/extrusions.d.ts +1 -1
- package/dist/layers/extrusions.js +10 -5
- package/dist/layers/extrusions.js.map +1 -1
- package/dist/layers/features.d.ts +10 -10
- package/dist/layers/features.js +41 -42
- package/dist/layers/features.js.map +1 -1
- package/dist/layers/glyphs.d.ts +3 -3
- package/dist/layers/glyphs.js +34 -40
- package/dist/layers/glyphs.js.map +1 -1
- package/dist/layers/icons.d.ts +8 -8
- package/dist/layers/icons.js +76 -68
- package/dist/layers/icons.js.map +1 -1
- package/dist/layers/layers.d.ts +1 -1
- package/dist/layers/layers.js +42 -29
- package/dist/layers/layers.js.map +1 -1
- package/dist/layers/panoramas.d.ts +2 -2
- package/dist/layers/panoramas.js +52 -41
- package/dist/layers/panoramas.js.map +1 -1
- package/dist/layers/pointclouds.d.ts +3 -3
- package/dist/layers/pointclouds.js +25 -33
- package/dist/layers/pointclouds.js.map +1 -1
- package/dist/layers/symbols.d.ts +1 -1
- package/dist/layers/symbols.js +68 -71
- package/dist/layers/symbols.js.map +1 -1
- package/dist/layers/vectors.d.ts +60 -0
- package/dist/layers/vectors.js +130 -0
- package/dist/layers/vectors.js.map +1 -0
- package/dist/map/basemap-layers.d.ts +26 -0
- package/dist/map/basemap-layers.js +61 -0
- package/dist/map/basemap-layers.js.map +1 -0
- package/dist/map/canvas.d.ts +17 -0
- package/dist/map/canvas.js +56 -0
- package/dist/map/canvas.js.map +1 -0
- package/dist/map/checks.d.ts +11 -0
- package/dist/map/checks.js +39 -0
- package/dist/map/checks.js.map +1 -0
- package/dist/map/credits.d.ts +17 -0
- package/dist/map/credits.js +34 -0
- package/dist/map/credits.js.map +1 -0
- package/dist/map/engine-settings.d.ts +15 -0
- package/dist/map/engine-settings.js +45 -0
- package/dist/map/engine-settings.js.map +1 -0
- package/dist/map/engines.d.ts +41 -0
- package/dist/map/engines.js +77 -0
- package/dist/map/engines.js.map +1 -0
- package/dist/map/events.d.ts +14 -0
- package/dist/map/events.js +46 -0
- package/dist/map/events.js.map +1 -0
- package/dist/map/frame-loop.d.ts +64 -0
- package/dist/map/frame-loop.js +145 -0
- package/dist/map/frame-loop.js.map +1 -0
- package/dist/map/hover-pick.d.ts +30 -0
- package/dist/map/hover-pick.js +56 -0
- package/dist/map/hover-pick.js.map +1 -0
- package/dist/map/layer-spec.d.ts +42 -0
- package/dist/map/layer-spec.js +34 -0
- package/dist/map/layer-spec.js.map +1 -0
- package/dist/map/layer-stack.d.ts +36 -0
- package/dist/map/layer-stack.js +101 -0
- package/dist/map/layer-stack.js.map +1 -0
- package/dist/map/overlay-host.d.ts +36 -0
- package/dist/map/overlay-host.js +101 -0
- package/dist/map/overlay-host.js.map +1 -0
- package/dist/map/panorama-host.d.ts +5 -0
- package/dist/map/panorama-host.js +32 -0
- package/dist/map/panorama-host.js.map +1 -0
- package/dist/map/raster-source.d.ts +11 -0
- package/dist/map/raster-source.js +26 -0
- package/dist/map/raster-source.js.map +1 -0
- package/dist/map/symbol-atlases.d.ts +26 -0
- package/dist/map/symbol-atlases.js +59 -0
- package/dist/map/symbol-atlases.js.map +1 -0
- package/dist/map/viewshed.d.ts +5 -0
- package/dist/map/viewshed.js +28 -0
- package/dist/map/viewshed.js.map +1 -0
- package/dist/map/workers.d.ts +46 -0
- package/dist/map/workers.js +73 -0
- package/dist/map/workers.js.map +1 -0
- package/dist/map.d.ts +54 -126
- package/dist/map.js +227 -698
- package/dist/map.js.map +1 -1
- package/dist/react/Control.d.ts +11 -0
- package/dist/react/Control.js +18 -0
- package/dist/react/Control.js.map +1 -0
- package/dist/react/CustomLayer.d.ts +11 -0
- package/dist/react/CustomLayer.js +30 -0
- package/dist/react/CustomLayer.js.map +1 -0
- package/dist/react/IsardMap.d.ts +43 -0
- package/dist/react/IsardMap.js +147 -0
- package/dist/react/IsardMap.js.map +1 -0
- package/dist/react/Layer.d.ts +42 -0
- package/dist/react/Layer.js +74 -0
- package/dist/react/Layer.js.map +1 -0
- package/dist/react/Marker.d.ts +24 -0
- package/dist/react/Marker.js +53 -0
- package/dist/react/Marker.js.map +1 -0
- package/dist/react/Panel.d.ts +11 -0
- package/dist/react/Panel.js +37 -0
- package/dist/react/Panel.js.map +1 -0
- package/dist/react/Popup.d.ts +18 -0
- package/dist/react/Popup.js +60 -0
- package/dist/react/Popup.js.map +1 -0
- package/dist/react/Swipe.d.ts +16 -0
- package/dist/react/Swipe.js +52 -0
- package/dist/react/Swipe.js.map +1 -0
- package/dist/react/VectorGeometry.d.ts +35 -0
- package/dist/react/VectorGeometry.js +82 -0
- package/dist/react/VectorGeometry.js.map +1 -0
- package/dist/react/Viewshed.d.ts +5 -0
- package/dist/react/Viewshed.js +28 -0
- package/dist/react/Viewshed.js.map +1 -0
- package/dist/react/context.d.ts +33 -0
- package/dist/react/context.js +20 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/index.d.ts +16 -108
- package/dist/react/index.js +11 -397
- package/dist/react/index.js.map +1 -1
- package/dist/settings.d.ts +5 -9
- package/dist/settings.js +17 -15
- package/dist/settings.js.map +1 -1
- package/dist/types.d.ts +27 -4
- package/dist/types.js.map +1 -1
- package/dist/ui/controls.js +6 -4
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/interaction.d.ts +2 -2
- package/dist/ui/interaction.js +8 -7
- package/dist/ui/interaction.js.map +1 -1
- package/dist/ui/minimap.d.ts +25 -0
- package/dist/ui/minimap.js +90 -0
- package/dist/ui/minimap.js.map +1 -0
- package/dist/ui/overlay.js +18 -20
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/scale.d.ts +19 -0
- package/dist/ui/scale.js +44 -0
- package/dist/ui/scale.js.map +1 -0
- package/dist/ui/search.d.ts +25 -0
- package/dist/ui/search.js +119 -0
- package/dist/ui/search.js.map +1 -0
- package/dist/ui/style.d.ts +1 -1
- package/dist/ui/style.js +19 -2
- package/dist/ui/style.js.map +1 -1
- package/dist/util/animation.d.ts +3 -3
- package/dist/util/animation.js +6 -6
- package/dist/util/animation.js.map +1 -1
- package/dist/util/color.d.ts +1 -1
- package/dist/util/color.js +14 -16
- package/dist/util/color.js.map +1 -1
- package/dist/util/geo.d.ts +6 -6
- package/dist/util/geo.js +12 -12
- package/dist/util/geo.js.map +1 -1
- package/dist/util/guards.d.ts +7 -0
- package/dist/util/guards.js +8 -0
- package/dist/util/guards.js.map +1 -0
- package/dist/util/lru.js.map +1 -1
- package/dist/util/sun.d.ts +11 -0
- package/dist/util/sun.js +26 -0
- package/dist/util/sun.js.map +1 -0
- package/dist/wasm/isard.d.ts +250 -7
- package/dist/wasm/isard.js +375 -8
- package/dist/wasm/isard_core.d.ts +226 -7
- package/dist/wasm/isard_core.js +351 -8
- package/dist/wasm/isard_tess.d.ts +109 -0
- package/dist/wasm/isard_tess.js +398 -0
- package/dist/workers/basemap/geometry.d.ts +72 -0
- package/dist/workers/basemap/labels.d.ts +8 -0
- package/dist/workers/basemap/raster.d.ts +10 -0
- package/dist/workers/basemap/tiles.d.ts +65 -0
- package/dist/workers/basemap/trees.d.ts +19 -0
- package/dist/workers/basemap.worker.d.ts +126 -22
- package/dist/workers/basemap.worker.js +76 -544
- package/dist/workers/basemap.worker.js.map +1 -1
- package/package.json +5 -4
- package/vite.js +10 -2
package/dist/layers/glyphs.js
CHANGED
|
@@ -62,7 +62,7 @@ class Reader {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
/** Glyphs of a range file: id → metrics and bitmap */
|
|
65
|
-
|
|
65
|
+
const parse = (buffer) => {
|
|
66
66
|
const out = new Map();
|
|
67
67
|
const root = new Reader(new Uint8Array(buffer));
|
|
68
68
|
while (!root.done) {
|
|
@@ -115,7 +115,7 @@ function parse(buffer) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
return out;
|
|
118
|
-
}
|
|
118
|
+
};
|
|
119
119
|
/** The glyphs of a map and their atlas */
|
|
120
120
|
export class Glyphs {
|
|
121
121
|
url;
|
|
@@ -160,47 +160,45 @@ export class Glyphs {
|
|
|
160
160
|
}
|
|
161
161
|
/** Loads these fonts from another glyph URL (a style's `glyphs`); a font keeps the first URL given for it */
|
|
162
162
|
register(url, fonts) {
|
|
163
|
-
|
|
163
|
+
[...fonts].forEach((font) => {
|
|
164
164
|
if (!this.sources.has(font))
|
|
165
165
|
this.sources.set(font, url);
|
|
166
|
+
});
|
|
166
167
|
}
|
|
167
168
|
/** Loads the glyphs of these code points in a font */
|
|
168
169
|
async load(font, codes) {
|
|
169
170
|
const glyphs = this.fonts.get(font) ?? new Map();
|
|
170
171
|
this.fonts.set(font, glyphs);
|
|
171
|
-
const starts = new Set();
|
|
172
|
-
for (const code of codes)
|
|
173
|
-
if (!glyphs.has(code))
|
|
174
|
-
starts.add(Math.floor(code / 256) * 256);
|
|
172
|
+
const starts = new Set([...codes].filter((code) => !glyphs.has(code)).map((code) => Math.floor(code / 256) * 256));
|
|
175
173
|
await Promise.all([...starts].map((start) => this.range(font, start, glyphs)));
|
|
176
174
|
return glyphs;
|
|
177
175
|
}
|
|
178
176
|
range(font, start, glyphs) {
|
|
179
177
|
const key = `${font}/${start}`;
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
glyphs.set(id, glyph);
|
|
178
|
+
const cached = this.ranges.get(key);
|
|
179
|
+
if (cached)
|
|
180
|
+
return cached;
|
|
181
|
+
const url = (this.sources.get(font) ?? this.url)
|
|
182
|
+
.replace('{fontstack}', encodeURIComponent(font))
|
|
183
|
+
.replace('{range}', `${start}-${start + 255}`);
|
|
184
|
+
const pending = fetch(url, withHeaders(url))
|
|
185
|
+
.then((r) => (r.ok ? r.arrayBuffer() : Promise.reject(new Error(`${url}: ${r.status}`))))
|
|
186
|
+
.then((buffer) => {
|
|
187
|
+
parse(buffer).forEach(({ glyph, bitmap }, id) => {
|
|
188
|
+
if (glyph.width > 0 && bitmap.length >= (glyph.width + 2 * BUFFER) * (glyph.height + 2 * BUFFER)) {
|
|
189
|
+
this.pack(glyph, bitmap);
|
|
193
190
|
}
|
|
194
|
-
|
|
195
|
-
// One upload for the range
|
|
196
|
-
this.flush();
|
|
197
|
-
})
|
|
198
|
-
.catch((error) => {
|
|
199
|
-
// A missing range is not retried this session; its characters stay blank
|
|
200
|
-
console.warn('isard: glyphs', error);
|
|
191
|
+
glyphs.set(id, glyph);
|
|
201
192
|
});
|
|
202
|
-
this.
|
|
203
|
-
|
|
193
|
+
this.version += 1;
|
|
194
|
+
// One upload for the range
|
|
195
|
+
this.flush();
|
|
196
|
+
})
|
|
197
|
+
.catch((error) => {
|
|
198
|
+
// A missing range is not retried this session; its characters stay blank
|
|
199
|
+
console.warn('isard: glyphs', error);
|
|
200
|
+
});
|
|
201
|
+
this.ranges.set(key, pending);
|
|
204
202
|
return pending;
|
|
205
203
|
}
|
|
206
204
|
/**
|
|
@@ -220,11 +218,11 @@ export class Glyphs {
|
|
|
220
218
|
}
|
|
221
219
|
/** Sends the rows changed since the last upload to the engine */
|
|
222
220
|
flush() {
|
|
223
|
-
|
|
221
|
+
this.dirty.forEach(([y0, y1], page) => {
|
|
224
222
|
const data = this.pages[page];
|
|
225
223
|
if (data)
|
|
226
224
|
this.engine?.updateGlyphPage(page, 0, y0, this.size, y1 - y0, data.subarray(y0 * this.size, y1 * this.size));
|
|
227
|
-
}
|
|
225
|
+
});
|
|
228
226
|
this.dirty.clear();
|
|
229
227
|
}
|
|
230
228
|
/**
|
|
@@ -300,18 +298,14 @@ export class Glyphs {
|
|
|
300
298
|
}
|
|
301
299
|
}
|
|
302
300
|
/** Code points of a text, for loading */
|
|
303
|
-
export
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
for (const ch of p.text)
|
|
307
|
-
out.add(ch.codePointAt(0) ?? 32);
|
|
308
|
-
return out;
|
|
309
|
-
}
|
|
301
|
+
export const codes = (parts) => {
|
|
302
|
+
return new Set(parts.flatMap((p) => [...p.text].map((ch) => ch.codePointAt(0) ?? 32)));
|
|
303
|
+
};
|
|
310
304
|
/**
|
|
311
305
|
* Lays out a label: lines split at `\n` and wrapped at `maxWidth` ems, centered, the block placed by `anchor` around
|
|
312
306
|
* the anchor point and moved by `offset` (ems); `size` in CSS pixels. Glyphs not loaded take no room.
|
|
313
307
|
*/
|
|
314
|
-
export
|
|
308
|
+
export const shape = (parts, glyphsOf, options) => {
|
|
315
309
|
const { size, maxWidth, lineHeight, anchor, offset } = options;
|
|
316
310
|
const k = size / EM;
|
|
317
311
|
const lines = [[]];
|
|
@@ -412,5 +406,5 @@ export function shape(parts, glyphsOf, options) {
|
|
|
412
406
|
box: [(x0 + dx) * k, (y0 + dy) * k, (x1 + dx) * k, (y1 + dy) * k],
|
|
413
407
|
layout: [(dx - widest / 2) * k, (middle - height / 2) * k, (dx + widest / 2) * k, (middle + height / 2) * k],
|
|
414
408
|
};
|
|
415
|
-
}
|
|
409
|
+
};
|
|
416
410
|
//# sourceMappingURL=glyphs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glyphs.js","sourceRoot":"","sources":["../../src/layers/glyphs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,iFAAiF;AACjF,MAAM,CAAC,MAAM,UAAU,GAAG,6DAA6D,CAAC;AAExF,wCAAwC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAEhD,kEAAkE;AAClE,MAAM,EAAE,GAAG,EAAE,CAAC;AACd,MAAM,MAAM,GAAG,CAAC,CAAC;AAkBjB,4GAA4G;AAC5G,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,oDAAoD;AACpD,MAAM,MAAM;IAEmB;IAD7B,GAAG,GAAG,CAAC,CAAC;IACR,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAChD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACrC,CAAC;IACD,MAAM;QACJ,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,SAAS,CAAC;YACR,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAA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phs for the symbol layers: signed distance fields in MapLibre's glyph format (ranges of 256 code points per\n * protobuf file, 24 px glyphs with a 3 px buffer), loaded on first use (from OpenFreeMap's fonts by default, a vector\n * basemap's labels from the glyphs of its style), packed into an atlas the engine samples; and the shaping of a label:\n * its lines (explicit and wrapped), their glyphs placed around the anchor.\n *\n * The atlas has pages of one size: the first one grows up to the page size limit, then pages are added, so it never\n * runs out. A glyph's atlas row counts the rows of the pages before its own (`y + page × size`, the pages stacked):\n * the coordinates of the glyphs placed so far stay valid as the atlas grows.\n */\n\nimport { withHeaders } from '../engine/requests.ts';\nimport type { Anchor } from '../ui/overlay.ts';\nimport type { Engine } from '../wasm/isard.js';\n\n/** OpenFreeMap's fonts, those of its styles (Noto Sans Regular, Bold, Italic) */\nexport const GLYPHS_URL = 'https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf';\n\n/** The font of labels that name none */\nexport const DEFAULT_FONT = 'Noto Sans Regular';\n\n/** Size the glyphs are drawn at in the files, and their buffer */\nconst EM = 24;\nconst BUFFER = 3;\n\nexport interface Glyph {\n width: number;\n height: number;\n left: number;\n top: number;\n advance: number;\n /**\n * Place of its bitmap ((width + 6) × (height + 6)) in the atlas, `y` counting the rows of the pages before its\n * own; undefined for an empty one (a space)\n */\n x?: number;\n y?: number;\n /** Its page of the atlas */\n page?: number;\n}\n\n/** Largest side of a page of the atlas, and most pages (WebGL2 guarantees 256 layers of a texture array) */\nconst PAGE_MAX = 2048;\nconst MAX_PAGES = 256;\n\n/** A protobuf reader, enough for the glyph files */\nclass Reader {\n pos = 0;\n constructor(private readonly buf: Uint8Array) {}\n get done(): boolean {\n return this.pos >= this.buf.length;\n }\n varint(): number {\n let value = 0;\n let shift = 0;\n for (;;) {\n const b = this.buf[this.pos++] ?? 0;\n value += (b & 0x7f) * 2 ** shift;\n if (b < 0x80) return value;\n shift += 7;\n }\n }\n sint(): number {\n const v = this.varint();\n return v % 2 === 1 ? -(v + 1) / 2 : v / 2;\n }\n bytes(): Uint8Array {\n const n = this.varint();\n const out = this.buf.subarray(this.pos, this.pos + n);\n this.pos += n;\n return out;\n }\n skip(wire: number): void {\n if (wire === 0) this.varint();\n else if (wire === 2) this.pos += this.varint();\n else if (wire === 5) this.pos += 4;\n else if (wire === 1) this.pos += 8;\n }\n}\n\n/** Glyphs of a range file: id → metrics and bitmap */\nfunction parse(buffer: ArrayBuffer): Map<number, { glyph: Glyph; bitmap: Uint8Array }> {\n const out = new Map<number, { glyph: Glyph; bitmap: Uint8Array }>();\n const root = new Reader(new Uint8Array(buffer));\n while (!root.done) {\n const tag = root.varint();\n if (tag >> 3 !== 1) {\n root.skip(tag & 7);\n continue;\n }\n // A fontstack\n const stack = new Reader(root.bytes());\n while (!stack.done) {\n const t = stack.varint();\n if (t >> 3 !== 3) {\n stack.skip(t & 7);\n continue;\n }\n const g = new Reader(stack.bytes());\n let id = 0;\n let bitmap: Uint8Array = new Uint8Array(0);\n const glyph: Glyph = { width: 0, height: 0, left: 0, top: 0, advance: 0 };\n while (!g.done) {\n const f = g.varint();\n switch (f >> 3) {\n case 1:\n id = g.varint();\n break;\n case 2:\n bitmap = g.bytes();\n break;\n case 3:\n glyph.width = g.varint();\n break;\n case 4:\n glyph.height = g.varint();\n break;\n case 5:\n glyph.left = g.sint();\n break;\n case 6:\n glyph.top = g.sint();\n break;\n case 7:\n glyph.advance = g.varint();\n break;\n default:\n g.skip(f & 7);\n }\n }\n out.set(id, { glyph, bitmap });\n }\n }\n return out;\n}\n\n/** A shelf of the packer: its page, y, height, and the x of the next free place */\ninterface Shelf {\n page: number;\n y: number;\n height: number;\n x: number;\n}\n\n/** The glyphs of a map and their atlas */\nexport class Glyphs {\n /** Side of the pages */\n private size = 512;\n private pages: Uint8Array[] = [new Uint8Array(512 * 512)];\n /** Pages allocated in the engine (doubled when more are needed: fewer reallocations) */\n private capacity = 1;\n private shelves: Shelf[] = [];\n /** Rows of each page holding glyphs (from its top): the rest is blank, never sent */\n private readonly used: number[] = [0];\n private readonly fonts = new Map<string, Map<number, Glyph>>();\n private readonly ranges = new Map<string, Promise<void>>();\n /** Glyph URLs of fonts other than the map's (those of a vector basemap's style) */\n private readonly sources = new Map<string, string>();\n private engine: Engine | undefined;\n /** Rows of each page changed since the last upload: first, end */\n private readonly dirty = new Map<number, [number, number]>();\n /** The atlas has its most pages: new glyphs stay blank */\n private full = false;\n /** Largest side of a page */\n private readonly maxSize: number;\n /** Bumped each time glyphs are added: labels shaped while some of theirs were missing are shaped again */\n version = 0;\n\n /** `maxSize`: the GPU's texture size limit if known (the pages are at most 2048 × 2048) */\n constructor(\n private readonly url = GLYPHS_URL,\n maxSize = 4096,\n ) {\n this.maxSize = Math.max(512, Math.min(PAGE_MAX, maxSize));\n }\n\n /** Sends the whole atlas to an engine (a new one after a context loss) */\n attach(engine: Engine): void {\n this.engine = engine;\n this.dirty.clear();\n this.upload();\n }\n\n /** Side of the pages of the atlas */\n get atlasSize(): number {\n return this.size;\n }\n\n get pageCount(): number {\n return this.pages.length;\n }\n\n /** Loads these fonts from another glyph URL (a style's `glyphs`); a font keeps the first URL given for it */\n register(url: string, fonts: Iterable<string>): void {\n for (const font of fonts) if (!this.sources.has(font)) this.sources.set(font, url);\n }\n\n /** Loads the glyphs of these code points in a font */\n async load(font: string, codes: Iterable<number>): Promise<Map<number, Glyph>> {\n const glyphs = this.fonts.get(font) ?? new Map<number, Glyph>();\n this.fonts.set(font, glyphs);\n const starts = new Set<number>();\n for (const code of codes) if (!glyphs.has(code)) starts.add(Math.floor(code / 256) * 256);\n await Promise.all([...starts].map((start) => this.range(font, start, glyphs)));\n return glyphs;\n }\n\n private range(font: string, start: number, glyphs: Map<number, Glyph>): Promise<void> {\n const key = `${font}/${start}`;\n let pending = this.ranges.get(key);\n if (!pending) {\n const url = (this.sources.get(font) ?? this.url)\n .replace('{fontstack}', encodeURIComponent(font))\n .replace('{range}', `${start}-${start + 255}`);\n pending = fetch(url, withHeaders(url))\n .then((r) => (r.ok ? r.arrayBuffer() : Promise.reject(new Error(`${url}: ${r.status}`))))\n .then((buffer) => {\n for (const [id, { glyph, bitmap }] of parse(buffer)) {\n if (glyph.width > 0 && bitmap.length >= (glyph.width + 2 * BUFFER) * (glyph.height + 2 * BUFFER)) {\n this.pack(glyph, bitmap);\n }\n glyphs.set(id, glyph);\n }\n this.version += 1;\n // One upload for the range\n this.flush();\n })\n .catch((error: unknown) => {\n // A missing range is not retried this session; its characters stay blank\n console.warn('isard: glyphs', error);\n });\n this.ranges.set(key, pending);\n }\n return pending;\n }\n\n /**\n * Allocates the pages in the engine and sends what they hold (their rows with glyphs). The engine allocates its\n * pages again empty: everything is sent each time, the pages doubled to make it rare\n */\n private upload(): void {\n const engine = this.engine;\n if (!engine) return;\n engine.setGlyphPages(this.size, this.size, this.capacity);\n this.pages.forEach((page, i) => {\n const rows = this.used[i] ?? 0;\n if (rows > 0) engine.updateGlyphPage(i, 0, 0, this.size, rows, page.subarray(0, rows * this.size));\n });\n }\n\n /** Sends the rows changed since the last upload to the engine */\n private flush(): void {\n for (const [page, [y0, y1]] of this.dirty) {\n const data = this.pages[page];\n if (data)\n this.engine?.updateGlyphPage(page, 0, y0, this.size, y1 - y0, data.subarray(y0 * this.size, y1 * this.size));\n }\n this.dirty.clear();\n }\n\n /**\n * Places a bitmap in the atlas (growing the first page, then adding pages when full); `flush` sends it to the\n * engine\n */\n private pack(glyph: Glyph, bitmap: Uint8Array): void {\n const w = glyph.width + 2 * BUFFER;\n const h = glyph.height + 2 * BUFFER;\n // One texel of padding between bitmaps: linear filtering never reads a neighbour\n let shelf = this.shelves.find((s) => s.height >= h && s.height <= h + 4 && s.x + w + 1 <= this.size);\n if (!shelf) {\n const page = this.pages.length - 1;\n // New shelves go on the last page only: the last shelf is on it, unless the page is new\n const last = this.shelves.at(-1);\n const y = last && last.page === page ? last.y + last.height + 1 : 0;\n if (y + h > this.size) {\n if (this.pages.length === 1 && this.size * 2 <= this.maxSize) this.grow();\n else if (this.pages.length < MAX_PAGES) this.addPage();\n else {\n // Full: the glyph takes its room in the text but is not drawn\n if (!this.full) console.warn(`isard: the glyph atlas is full (${MAX_PAGES} pages)`);\n this.full = true;\n return;\n }\n this.pack(glyph, bitmap);\n return;\n }\n shelf = { page, y, height: h, x: 0 };\n this.shelves.push(shelf);\n }\n const data = this.pages[shelf.page];\n if (!data) return;\n glyph.x = shelf.x;\n glyph.y = shelf.page * this.size + shelf.y;\n glyph.page = shelf.page;\n shelf.x += w + 1;\n for (let row = 0; row < h; row += 1) {\n data.set(bitmap.subarray(row * w, row * w + w), (shelf.y + row) * this.size + glyph.x);\n }\n this.used[shelf.page] = Math.max(this.used[shelf.page] ?? 0, shelf.y + h);\n const dirty = this.dirty.get(shelf.page);\n this.dirty.set(shelf.page, [Math.min(dirty?.[0] ?? shelf.y, shelf.y), Math.max(dirty?.[1] ?? 0, shelf.y + h)]);\n }\n\n /** Doubles the only page; the glyphs keep their places (texel coordinates) */\n private grow(): void {\n const size = this.size * 2;\n const old = this.pages[0] ?? new Uint8Array(this.size * this.size);\n const page = new Uint8Array(size * size);\n for (let row = 0; row < this.size; row += 1) {\n page.set(old.subarray(row * this.size, (row + 1) * this.size), row * size);\n }\n this.size = size;\n this.pages = [page];\n // The whole atlas is sent with what it holds so far\n this.dirty.clear();\n this.upload();\n }\n\n /** A new empty page, after the others; the engine's pages are allocated again only past its capacity */\n private addPage(): void {\n this.pages.push(new Uint8Array(this.size * this.size));\n this.used.push(0);\n if (this.pages.length > this.capacity) {\n this.capacity = Math.min(MAX_PAGES, this.capacity * 2);\n // The pages are allocated again: everything is sent, pending changes included\n this.dirty.clear();\n this.upload();\n }\n }\n}\n\n/** A run of text with its own scale (MapLibre's `format` with `font-scale`) and font */\nexport interface TextPart {\n text: string;\n scale?: number;\n font?: string;\n}\n\nexport type { Anchor } from '../ui/overlay.ts';\n\nexport interface Shaping {\n /** Glyph quads: x, y, width, height (CSS pixels from the anchor), atlas u0, v0, u1, v1, font scale */\n quads: number[][];\n /** Ink box from the anchor: min x, min y, max x, max y */\n box: [number, number, number, number];\n /** Layout box from the anchor, what an icon fitted to the text frames: the advances of its widest line across, its\n * lines' height (`lineHeight` each) down, centered on the ink */\n layout: [number, number, number, number];\n}\n\n/** Code points of a text, for loading */\nexport function codes(parts: readonly TextPart[]): Set<number> {\n const out = new Set<number>();\n for (const p of parts) for (const ch of p.text) out.add(ch.codePointAt(0) ?? 32);\n return out;\n}\n\n/**\n * Lays out a label: lines split at `\\n` and wrapped at `maxWidth` ems, centered, the block placed by `anchor` around\n * the anchor point and moved by `offset` (ems); `size` in CSS pixels. Glyphs not loaded take no room.\n */\nexport function shape(\n parts: readonly TextPart[],\n glyphsOf: (font: string) => Map<number, Glyph> | undefined,\n options: {\n font: string;\n size: number;\n maxWidth: number;\n lineHeight: number;\n anchor: Anchor;\n offset: [number, number];\n },\n): Shaping {\n const { size, maxWidth, lineHeight, anchor, offset } = options;\n const k = size / EM;\n // Characters with their glyph and scale, split into lines\n type Char = { glyph: Glyph | undefined; scale: number; space: boolean };\n const lines: Char[][] = [[]];\n for (const part of parts) {\n const glyphs = glyphsOf(part.font ?? options.font);\n for (const ch of part.text) {\n if (ch === '\\n') {\n lines.push([]);\n continue;\n }\n const code = ch.codePointAt(0) ?? 32;\n lines.at(-1)?.push({ glyph: glyphs?.get(code), scale: part.scale ?? 1, space: /\\s/.test(ch) });\n }\n }\n const advance = (c: Char) => (c.glyph?.advance ?? (c.space ? EM / 4 : 0)) * c.scale;\n // Wrapping at spaces, greedy\n const limit = maxWidth * EM;\n const wrapped: Char[][] = [];\n for (const line of lines) {\n let current: Char[] = [];\n let width = 0;\n let lastSpace = -1;\n for (const c of line) {\n current.push(c);\n width += advance(c);\n if (c.space) lastSpace = current.length - 1;\n if (width > limit && lastSpace > 0) {\n wrapped.push(current.slice(0, lastSpace));\n current = current.slice(lastSpace + 1);\n width = current.reduce((s, x) => s + advance(x), 0);\n lastSpace = -1;\n }\n }\n wrapped.push(current);\n }\n // Glyphs on their lines, each line centered on x = 0, in units of the 24 px font\n const quads: number[][] = [];\n let [x0, y0, x1, y1] = [\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n ];\n let baseline = 0;\n let widest = 0;\n let height = 0;\n wrapped.forEach((line, i) => {\n const scale = Math.max(1, ...line.map((c) => c.scale));\n if (i > 0) baseline += lineHeight * EM * scale;\n height += lineHeight * EM * scale;\n const width = line.reduce((s, c) => s + advance(c), 0);\n widest = Math.max(widest, width);\n let pen = -width / 2;\n for (const c of line) {\n const g = c.glyph;\n if (g && g.x !== undefined && g.y !== undefined && g.width > 0) {\n const qx = pen + (g.left - BUFFER) * c.scale;\n const qy = baseline - (g.top + BUFFER) * c.scale;\n const qw = (g.width + 2 * BUFFER) * c.scale;\n const qh = (g.height + 2 * BUFFER) * c.scale;\n quads.push([qx, qy, qw, qh, g.x, g.y, g.x + g.width + 2 * BUFFER, g.y + g.height + 2 * BUFFER, c.scale]);\n x0 = Math.min(x0, qx + BUFFER * c.scale);\n y0 = Math.min(y0, qy + BUFFER * c.scale);\n x1 = Math.max(x1, qx + qw - BUFFER * c.scale);\n y1 = Math.max(y1, qy + qh - BUFFER * c.scale);\n }\n pen += advance(c);\n }\n });\n if (!quads.length) return { quads, box: [0, 0, 0, 0], layout: [0, 0, 0, 0] };\n // The block placed around the anchor by its ink box\n // The side of the box at the anchor: its start, its end, or its middle\n const side = (start: boolean, end: boolean, lo: number, hi: number) => {\n if (start) return -lo;\n if (end) return -hi;\n return -(lo + hi) / 2;\n };\n const horizontal = side(anchor.includes('left'), anchor.includes('right'), x0, x1);\n const vertical = side(anchor.startsWith('top'), anchor.startsWith('bottom'), y0, y1);\n const dx = horizontal + offset[0] * EM;\n const dy = vertical + offset[1] * EM;\n for (const q of quads) {\n q[0] = ((q[0] ?? 0) + dx) * k;\n q[1] = ((q[1] ?? 0) + dy) * k;\n q[2] = (q[2] ?? 0) * k;\n q[3] = (q[3] ?? 0) * k;\n q[8] = (q[8] ?? 1) * k;\n }\n const middle = (y0 + y1) / 2 + dy;\n height = Math.max(height, y1 - y0);\n return {\n quads,\n box: [(x0 + dx) * k, (y0 + dy) * k, (x1 + dx) * k, (y1 + dy) * k],\n layout: [(dx - widest / 2) * k, (middle - height / 2) * k, (dx + widest / 2) * k, (middle + height / 2) * k],\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"glyphs.js","sourceRoot":"","sources":["../../src/layers/glyphs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,iFAAiF;AACjF,MAAM,CAAC,MAAM,UAAU,GAAG,6DAA6D,CAAC;AAExF,wCAAwC;AACxC,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAC;AAEhD,kEAAkE;AAClE,MAAM,EAAE,GAAG,EAAE,CAAC;AACd,MAAM,MAAM,GAAG,CAAC,CAAC;AAkBjB,4GAA4G;AAC5G,MAAM,QAAQ,GAAG,IAAI,CAAC;AACtB,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,oDAAoD;AACpD,MAAM,MAAM;IAEmB;IAD7B,GAAG,GAAG,CAAC,CAAC;IACR,YAA6B,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;IAAG,CAAC;IAChD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACrC,CAAC;IACD,MAAM;QACJ,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,SAAS,CAAC;YACR,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YAEpC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;YACjC,IAAI,CAAC,GAAG,IAAI;gBAAE,OAA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AC,CAAC;KAC7G,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * Glyphs for the symbol layers: signed distance fields in MapLibre's glyph format (ranges of 256 code points per\n * protobuf file, 24 px glyphs with a 3 px buffer), loaded on first use (from OpenFreeMap's fonts by default, a vector\n * basemap's labels from the glyphs of its style), packed into an atlas the engine samples; and the shaping of a label:\n * its lines (explicit and wrapped), their glyphs placed around the anchor.\n *\n * The atlas has pages of one size: the first one grows up to the page size limit, then pages are added, so it never\n * runs out. A glyph's atlas row counts the rows of the pages before its own (`y + page × size`, the pages stacked):\n * the coordinates of the glyphs placed so far stay valid as the atlas grows.\n */\n\nimport { withHeaders } from '../engine/requests.ts';\nimport type { Anchor } from '../ui/overlay.ts';\nimport type { Engine } from '../wasm/isard.js';\n\n/** OpenFreeMap's fonts, those of its styles (Noto Sans Regular, Bold, Italic) */\nexport const GLYPHS_URL = 'https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf';\n\n/** The font of labels that name none */\nexport const DEFAULT_FONT = 'Noto Sans Regular';\n\n/** Size the glyphs are drawn at in the files, and their buffer */\nconst EM = 24;\nconst BUFFER = 3;\n\nexport interface Glyph {\n width: number;\n height: number;\n left: number;\n top: number;\n advance: number;\n /**\n * Place of its bitmap ((width + 6) × (height + 6)) in the atlas, `y` counting the rows of the pages before its\n * own; undefined for an empty one (a space)\n */\n x?: number;\n y?: number;\n /** Its page of the atlas */\n page?: number;\n}\n\n/** Largest side of a page of the atlas, and most pages (WebGL2 guarantees 256 layers of a texture array) */\nconst PAGE_MAX = 2048;\nconst MAX_PAGES = 256;\n\n/** A protobuf reader, enough for the glyph files */\nclass Reader {\n pos = 0;\n constructor(private readonly buf: Uint8Array) {}\n get done(): boolean {\n return this.pos >= this.buf.length;\n }\n varint(): number {\n let value = 0;\n let shift = 0;\n\n for (;;) {\n const b = this.buf[this.pos++] ?? 0;\n\n value += (b & 0x7f) * 2 ** shift;\n if (b < 0x80) return value;\n shift += 7;\n }\n }\n sint(): number {\n const v = this.varint();\n\n return v % 2 === 1 ? -(v + 1) / 2 : v / 2;\n }\n bytes(): Uint8Array {\n const n = this.varint();\n const out = this.buf.subarray(this.pos, this.pos + n);\n\n this.pos += n;\n\n return out;\n }\n skip(wire: number): void {\n if (wire === 0) this.varint();\n else if (wire === 2) this.pos += this.varint();\n else if (wire === 5) this.pos += 4;\n else if (wire === 1) this.pos += 8;\n }\n}\n\n/** Glyphs of a range file: id → metrics and bitmap */\nconst parse = (buffer: ArrayBuffer): Map<number, { glyph: Glyph; bitmap: Uint8Array }> => {\n const out = new Map<number, { glyph: Glyph; bitmap: Uint8Array }>();\n const root = new Reader(new Uint8Array(buffer));\n\n while (!root.done) {\n const tag = root.varint();\n\n if (tag >> 3 !== 1) {\n root.skip(tag & 7);\n continue;\n }\n\n // A fontstack\n const stack = new Reader(root.bytes());\n\n while (!stack.done) {\n const t = stack.varint();\n\n if (t >> 3 !== 3) {\n stack.skip(t & 7);\n continue;\n }\n\n const g = new Reader(stack.bytes());\n let id = 0;\n let bitmap: Uint8Array = new Uint8Array(0);\n const glyph: Glyph = { width: 0, height: 0, left: 0, top: 0, advance: 0 };\n\n while (!g.done) {\n const f = g.varint();\n\n switch (f >> 3) {\n case 1:\n id = g.varint();\n break;\n case 2:\n bitmap = g.bytes();\n break;\n case 3:\n glyph.width = g.varint();\n break;\n case 4:\n glyph.height = g.varint();\n break;\n case 5:\n glyph.left = g.sint();\n break;\n case 6:\n glyph.top = g.sint();\n break;\n case 7:\n glyph.advance = g.varint();\n break;\n default:\n g.skip(f & 7);\n }\n }\n out.set(id, { glyph, bitmap });\n }\n }\n\n return out;\n};\n\n/** A shelf of the packer: its page, y, height, and the x of the next free place */\ninterface Shelf {\n page: number;\n y: number;\n height: number;\n x: number;\n}\n\n/** The glyphs of a map and their atlas */\nexport class Glyphs {\n /** Side of the pages */\n private size = 512;\n private pages: Uint8Array[] = [new Uint8Array(512 * 512)];\n /** Pages allocated in the engine (doubled when more are needed: fewer reallocations) */\n private capacity = 1;\n private shelves: Shelf[] = [];\n /** Rows of each page holding glyphs (from its top): the rest is blank, never sent */\n private readonly used: number[] = [0];\n private readonly fonts = new Map<string, Map<number, Glyph>>();\n private readonly ranges = new Map<string, Promise<void>>();\n /** Glyph URLs of fonts other than the map's (those of a vector basemap's style) */\n private readonly sources = new Map<string, string>();\n private engine: Engine | undefined;\n /** Rows of each page changed since the last upload: first, end */\n private readonly dirty = new Map<number, [number, number]>();\n /** The atlas has its most pages: new glyphs stay blank */\n private full = false;\n /** Largest side of a page */\n private readonly maxSize: number;\n /** Bumped each time glyphs are added: labels shaped while some of theirs were missing are shaped again */\n version = 0;\n\n /** `maxSize`: the GPU's texture size limit if known (the pages are at most 2048 × 2048) */\n constructor(\n private readonly url = GLYPHS_URL,\n maxSize = 4096,\n ) {\n this.maxSize = Math.max(512, Math.min(PAGE_MAX, maxSize));\n }\n\n /** Sends the whole atlas to an engine (a new one after a context loss) */\n attach(engine: Engine): void {\n this.engine = engine;\n this.dirty.clear();\n this.upload();\n }\n\n /** Side of the pages of the atlas */\n get atlasSize(): number {\n return this.size;\n }\n\n get pageCount(): number {\n return this.pages.length;\n }\n\n /** Loads these fonts from another glyph URL (a style's `glyphs`); a font keeps the first URL given for it */\n register(url: string, fonts: Iterable<string>): void {\n [...fonts].forEach((font) => {\n if (!this.sources.has(font)) this.sources.set(font, url);\n });\n }\n\n /** Loads the glyphs of these code points in a font */\n async load(font: string, codes: Iterable<number>): Promise<Map<number, Glyph>> {\n const glyphs = this.fonts.get(font) ?? new Map<number, Glyph>();\n\n this.fonts.set(font, glyphs);\n\n const starts = new Set([...codes].filter((code) => !glyphs.has(code)).map((code) => Math.floor(code / 256) * 256));\n\n await Promise.all([...starts].map((start) => this.range(font, start, glyphs)));\n\n return glyphs;\n }\n\n private range(font: string, start: number, glyphs: Map<number, Glyph>): Promise<void> {\n const key = `${font}/${start}`;\n const cached = this.ranges.get(key);\n\n if (cached) return cached;\n\n const url = (this.sources.get(font) ?? this.url)\n .replace('{fontstack}', encodeURIComponent(font))\n .replace('{range}', `${start}-${start + 255}`);\n const pending = fetch(url, withHeaders(url))\n .then((r) => (r.ok ? r.arrayBuffer() : Promise.reject(new Error(`${url}: ${r.status}`))))\n .then((buffer) => {\n parse(buffer).forEach(({ glyph, bitmap }, id) => {\n if (glyph.width > 0 && bitmap.length >= (glyph.width + 2 * BUFFER) * (glyph.height + 2 * BUFFER)) {\n this.pack(glyph, bitmap);\n }\n glyphs.set(id, glyph);\n });\n this.version += 1;\n // One upload for the range\n this.flush();\n })\n .catch((error: unknown) => {\n // A missing range is not retried this session; its characters stay blank\n console.warn('isard: glyphs', error);\n });\n\n this.ranges.set(key, pending);\n\n return pending;\n }\n\n /**\n * Allocates the pages in the engine and sends what they hold (their rows with glyphs). The engine allocates its\n * pages again empty: everything is sent each time, the pages doubled to make it rare\n */\n private upload(): void {\n const engine = this.engine;\n\n if (!engine) return;\n engine.setGlyphPages(this.size, this.size, this.capacity);\n this.pages.forEach((page, i) => {\n const rows = this.used[i] ?? 0;\n\n if (rows > 0) engine.updateGlyphPage(i, 0, 0, this.size, rows, page.subarray(0, rows * this.size));\n });\n }\n\n /** Sends the rows changed since the last upload to the engine */\n private flush(): void {\n this.dirty.forEach(([y0, y1], page) => {\n const data = this.pages[page];\n\n if (data)\n this.engine?.updateGlyphPage(page, 0, y0, this.size, y1 - y0, data.subarray(y0 * this.size, y1 * this.size));\n });\n this.dirty.clear();\n }\n\n /**\n * Places a bitmap in the atlas (growing the first page, then adding pages when full); `flush` sends it to the\n * engine\n */\n private pack(glyph: Glyph, bitmap: Uint8Array): void {\n const w = glyph.width + 2 * BUFFER;\n const h = glyph.height + 2 * BUFFER;\n // One texel of padding between bitmaps: linear filtering never reads a neighbour\n let shelf = this.shelves.find((s) => s.height >= h && s.height <= h + 4 && s.x + w + 1 <= this.size);\n\n if (!shelf) {\n const page = this.pages.length - 1;\n // New shelves go on the last page only: the last shelf is on it, unless the page is new\n const last = this.shelves.at(-1);\n const y = last && last.page === page ? last.y + last.height + 1 : 0;\n\n if (y + h > this.size) {\n if (this.pages.length === 1 && this.size * 2 <= this.maxSize) this.grow();\n else if (this.pages.length < MAX_PAGES) this.addPage();\n else {\n // Full: the glyph takes its room in the text but is not drawn\n if (!this.full) console.warn(`isard: the glyph atlas is full (${MAX_PAGES} pages)`);\n this.full = true;\n\n return;\n }\n this.pack(glyph, bitmap);\n\n return;\n }\n shelf = { page, y, height: h, x: 0 };\n this.shelves.push(shelf);\n }\n\n const data = this.pages[shelf.page];\n\n if (!data) return;\n glyph.x = shelf.x;\n glyph.y = shelf.page * this.size + shelf.y;\n glyph.page = shelf.page;\n shelf.x += w + 1;\n for (let row = 0; row < h; row += 1) {\n data.set(bitmap.subarray(row * w, row * w + w), (shelf.y + row) * this.size + glyph.x);\n }\n this.used[shelf.page] = Math.max(this.used[shelf.page] ?? 0, shelf.y + h);\n\n const dirty = this.dirty.get(shelf.page);\n\n this.dirty.set(shelf.page, [Math.min(dirty?.[0] ?? shelf.y, shelf.y), Math.max(dirty?.[1] ?? 0, shelf.y + h)]);\n }\n\n /** Doubles the only page; the glyphs keep their places (texel coordinates) */\n private grow(): void {\n const size = this.size * 2;\n const old = this.pages[0] ?? new Uint8Array(this.size * this.size);\n const page = new Uint8Array(size * size);\n\n for (let row = 0; row < this.size; row += 1) {\n page.set(old.subarray(row * this.size, (row + 1) * this.size), row * size);\n }\n this.size = size;\n this.pages = [page];\n // The whole atlas is sent with what it holds so far\n this.dirty.clear();\n this.upload();\n }\n\n /** A new empty page, after the others; the engine's pages are allocated again only past its capacity */\n private addPage(): void {\n this.pages.push(new Uint8Array(this.size * this.size));\n this.used.push(0);\n if (this.pages.length > this.capacity) {\n this.capacity = Math.min(MAX_PAGES, this.capacity * 2);\n // The pages are allocated again: everything is sent, pending changes included\n this.dirty.clear();\n this.upload();\n }\n }\n}\n\n/** A run of text with its own scale (MapLibre's `format` with `font-scale`) and font */\nexport interface TextPart {\n text: string;\n scale?: number;\n font?: string;\n}\n\nexport type { Anchor } from '../ui/overlay.ts';\n\nexport interface Shaping {\n /** Glyph quads: x, y, width, height (CSS pixels from the anchor), atlas u0, v0, u1, v1, font scale */\n quads: number[][];\n /** Ink box from the anchor: min x, min y, max x, max y */\n box: [number, number, number, number];\n /** Layout box from the anchor, what an icon fitted to the text frames: the advances of its widest line across, its\n * lines' height (`lineHeight` each) down, centered on the ink */\n layout: [number, number, number, number];\n}\n\n/** Code points of a text, for loading */\nexport const codes = (parts: readonly TextPart[]): Set<number> => {\n return new Set(parts.flatMap((p) => [...p.text].map((ch) => ch.codePointAt(0) ?? 32)));\n};\n\n/**\n * Lays out a label: lines split at `\\n` and wrapped at `maxWidth` ems, centered, the block placed by `anchor` around\n * the anchor point and moved by `offset` (ems); `size` in CSS pixels. Glyphs not loaded take no room.\n */\nexport const shape = (\n parts: readonly TextPart[],\n glyphsOf: (font: string) => Map<number, Glyph> | undefined,\n options: {\n font: string;\n size: number;\n maxWidth: number;\n lineHeight: number;\n anchor: Anchor;\n offset: [number, number];\n },\n): Shaping => {\n const { size, maxWidth, lineHeight, anchor, offset } = options;\n const k = size / EM;\n\n // Characters with their glyph and scale, split into lines\n type Char = { glyph: Glyph | undefined; scale: number; space: boolean };\n\n const lines: Char[][] = [[]];\n\n for (const part of parts) {\n const glyphs = glyphsOf(part.font ?? options.font);\n\n for (const ch of part.text) {\n if (ch === '\\n') {\n lines.push([]);\n continue;\n }\n\n const code = ch.codePointAt(0) ?? 32;\n\n lines.at(-1)?.push({ glyph: glyphs?.get(code), scale: part.scale ?? 1, space: /\\s/.test(ch) });\n }\n }\n\n const advance = (c: Char) => (c.glyph?.advance ?? (c.space ? EM / 4 : 0)) * c.scale;\n // Wrapping at spaces, greedy\n const limit = maxWidth * EM;\n const wrapped: Char[][] = [];\n\n for (const line of lines) {\n let current: Char[] = [];\n let width = 0;\n let lastSpace = -1;\n\n for (const c of line) {\n current.push(c);\n width += advance(c);\n if (c.space) lastSpace = current.length - 1;\n if (width > limit && lastSpace > 0) {\n wrapped.push(current.slice(0, lastSpace));\n current = current.slice(lastSpace + 1);\n width = current.reduce((s, x) => s + advance(x), 0);\n lastSpace = -1;\n }\n }\n wrapped.push(current);\n }\n\n // Glyphs on their lines, each line centered on x = 0, in units of the 24 px font\n const quads: number[][] = [];\n let [x0, y0, x1, y1] = [\n Number.POSITIVE_INFINITY,\n Number.POSITIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n Number.NEGATIVE_INFINITY,\n ];\n let baseline = 0;\n let widest = 0;\n let height = 0;\n\n wrapped.forEach((line, i) => {\n const scale = Math.max(1, ...line.map((c) => c.scale));\n\n if (i > 0) baseline += lineHeight * EM * scale;\n height += lineHeight * EM * scale;\n\n const width = line.reduce((s, c) => s + advance(c), 0);\n\n widest = Math.max(widest, width);\n\n let pen = -width / 2;\n\n for (const c of line) {\n const g = c.glyph;\n\n if (g && g.x !== undefined && g.y !== undefined && g.width > 0) {\n const qx = pen + (g.left - BUFFER) * c.scale;\n const qy = baseline - (g.top + BUFFER) * c.scale;\n const qw = (g.width + 2 * BUFFER) * c.scale;\n const qh = (g.height + 2 * BUFFER) * c.scale;\n\n quads.push([qx, qy, qw, qh, g.x, g.y, g.x + g.width + 2 * BUFFER, g.y + g.height + 2 * BUFFER, c.scale]);\n x0 = Math.min(x0, qx + BUFFER * c.scale);\n y0 = Math.min(y0, qy + BUFFER * c.scale);\n x1 = Math.max(x1, qx + qw - BUFFER * c.scale);\n y1 = Math.max(y1, qy + qh - BUFFER * c.scale);\n }\n pen += advance(c);\n }\n });\n if (!quads.length) return { quads, box: [0, 0, 0, 0], layout: [0, 0, 0, 0] };\n\n // The block placed around the anchor by its ink box\n // The side of the box at the anchor: its start, its end, or its middle\n const side = (start: boolean, end: boolean, lo: number, hi: number) => {\n if (start) return -lo;\n if (end) return -hi;\n\n return -(lo + hi) / 2;\n };\n const horizontal = side(anchor.includes('left'), anchor.includes('right'), x0, x1);\n const vertical = side(anchor.startsWith('top'), anchor.startsWith('bottom'), y0, y1);\n const dx = horizontal + offset[0] * EM;\n const dy = vertical + offset[1] * EM;\n\n for (const q of quads) {\n q[0] = ((q[0] ?? 0) + dx) * k;\n q[1] = ((q[1] ?? 0) + dy) * k;\n q[2] = (q[2] ?? 0) * k;\n q[3] = (q[3] ?? 0) * k;\n q[8] = (q[8] ?? 1) * k;\n }\n\n const middle = (y0 + y1) / 2 + dy;\n\n height = Math.max(height, y1 - y0);\n\n return {\n quads,\n box: [(x0 + dx) * k, (y0 + dy) * k, (x1 + dx) * k, (y1 + dy) * k],\n layout: [(dx - widest / 2) * k, (middle - height / 2) * k, (dx + widest / 2) * k, (middle + height / 2) * k],\n };\n};\n"]}
|
package/dist/layers/icons.d.ts
CHANGED
|
@@ -51,12 +51,12 @@ export interface SpriteSource {
|
|
|
51
51
|
url: string;
|
|
52
52
|
}
|
|
53
53
|
/** The sprites of a style's `sprite`: one URL, or several with their ids (MapLibre's style specification) */
|
|
54
|
-
export declare
|
|
54
|
+
export declare const spriteSources: (sprite: string | readonly SpriteSource[] | undefined) => SpriteSource[];
|
|
55
55
|
/** The name of an image of a sprite in the style: its own in the `default` sprite, `id:name` in another */
|
|
56
|
-
export declare
|
|
56
|
+
export declare const spriteName: (id: string, name: string) => string;
|
|
57
57
|
/** The URL of a sprite's index or sheet: `.json` or `.png`, `@2x` before it for high-density screens, before the
|
|
58
58
|
* query of the URL if it has one */
|
|
59
|
-
export declare
|
|
59
|
+
export declare const spriteFile: (url: string, extension: "json" | "png", ratio: number) => string;
|
|
60
60
|
/** A sprite loaded: its images by name (with the sprite's prefix) and its sheet */
|
|
61
61
|
export interface LoadedSprite {
|
|
62
62
|
icons: SpriteIndex;
|
|
@@ -64,12 +64,12 @@ export interface LoadedSprite {
|
|
|
64
64
|
}
|
|
65
65
|
/** Loads a style's sprites (`@2x` above a device pixel ratio of 1, the 1x ones if a server has none); the sprites
|
|
66
66
|
* that fail are left out */
|
|
67
|
-
export declare
|
|
67
|
+
export declare const loadSprites: (sprite: string | readonly SpriteSource[] | undefined, ratio?: number) => Promise<LoadedSprite[]>;
|
|
68
68
|
/** The pixels of an image (read back through a canvas) */
|
|
69
|
-
export declare
|
|
69
|
+
export declare const readPixels: (image: CanvasImageSource & {
|
|
70
70
|
width: number;
|
|
71
71
|
height: number;
|
|
72
|
-
})
|
|
72
|
+
}) => Pixels | undefined;
|
|
73
73
|
/** The icons of a map and their atlas: a square that doubles as it fills, up to the texture size limit */
|
|
74
74
|
export declare class Icons {
|
|
75
75
|
private size;
|
|
@@ -140,7 +140,7 @@ type Pieces = [number, number, number, number][];
|
|
|
140
140
|
* stretchable zones (the whole image by default) taking the room the fixed parts (at `scale` CSS pixels per image
|
|
141
141
|
* pixel) leave
|
|
142
142
|
*/
|
|
143
|
-
export declare
|
|
143
|
+
export declare const stretch: (length: number, zones: readonly [number, number][] | undefined, content: [number, number] | undefined, lo: number, hi: number, scale: number) => Pieces;
|
|
144
144
|
/** Lays an icon out around its anchor: placed by its anchor and offset, or fitted to its text */
|
|
145
|
-
export declare
|
|
145
|
+
export declare const layoutIcon: (icon: Icon, options: IconLayoutOptions) => IconLayout;
|
|
146
146
|
export {};
|
package/dist/layers/icons.js
CHANGED
|
@@ -6,26 +6,36 @@
|
|
|
6
6
|
* the stretchable zones and the content box of its image when it has them (`stretchX`, `stretchY`, `content`).
|
|
7
7
|
*/
|
|
8
8
|
import { withHeaders } from "../engine/requests.js";
|
|
9
|
+
import { isNumbers, isRecord } from "../util/guards.js";
|
|
10
|
+
const isPairs = (value) => Array.isArray(value) && value.every((pair) => isNumbers(pair) && pair.length === 2);
|
|
11
|
+
/** An icon of a sprite index: its place, and what is drawn from the rest */
|
|
12
|
+
const isSpriteIcon = (value) => isRecord(value) &&
|
|
13
|
+
[value.x, value.y, value.width, value.height].every((v) => typeof v === 'number') &&
|
|
14
|
+
(value.pixelRatio === undefined || typeof value.pixelRatio === 'number') &&
|
|
15
|
+
(value.sdf === undefined || typeof value.sdf === 'boolean') &&
|
|
16
|
+
(value.stretchX === undefined || isPairs(value.stretchX)) &&
|
|
17
|
+
(value.stretchY === undefined || isPairs(value.stretchY)) &&
|
|
18
|
+
(value.content === undefined || (isNumbers(value.content) && value.content.length === 4));
|
|
9
19
|
/** The sprites of a style's `sprite`: one URL, or several with their ids (MapLibre's style specification) */
|
|
10
|
-
export
|
|
20
|
+
export const spriteSources = (sprite) => {
|
|
11
21
|
if (typeof sprite === 'string')
|
|
12
22
|
return sprite ? [{ id: 'default', url: sprite }] : [];
|
|
13
23
|
return Array.isArray(sprite) ? sprite.filter((s) => typeof s?.url === 'string' && typeof s.id === 'string') : [];
|
|
14
|
-
}
|
|
24
|
+
};
|
|
15
25
|
/** The name of an image of a sprite in the style: its own in the `default` sprite, `id:name` in another */
|
|
16
|
-
export
|
|
26
|
+
export const spriteName = (id, name) => {
|
|
17
27
|
return id === 'default' ? name : `${id}:${name}`;
|
|
18
|
-
}
|
|
28
|
+
};
|
|
19
29
|
/** The URL of a sprite's index or sheet: `.json` or `.png`, `@2x` before it for high-density screens, before the
|
|
20
30
|
* query of the URL if it has one */
|
|
21
|
-
export
|
|
31
|
+
export const spriteFile = (url, extension, ratio) => {
|
|
22
32
|
const suffix = `${ratio > 1 ? '@2x' : ''}.${extension}`;
|
|
23
33
|
const query = url.search(/[?#]/);
|
|
24
34
|
return query < 0 ? `${url}${suffix}` : `${url.slice(0, query)}${suffix}${url.slice(query)}`;
|
|
25
|
-
}
|
|
35
|
+
};
|
|
26
36
|
/** Loads a style's sprites (`@2x` above a device pixel ratio of 1, the 1x ones if a server has none); the sprites
|
|
27
37
|
* that fail are left out */
|
|
28
|
-
export async
|
|
38
|
+
export const loadSprites = async (sprite, ratio = typeof devicePixelRatio === 'number' ? devicePixelRatio : 1) => {
|
|
29
39
|
const one = async ({ id, url }, r) => {
|
|
30
40
|
const [json, png] = await Promise.all([
|
|
31
41
|
fetch(spriteFile(url, 'json', r), withHeaders(spriteFile(url, 'json', r))),
|
|
@@ -33,29 +43,28 @@ export async function loadSprites(sprite, ratio = typeof devicePixelRatio === 'n
|
|
|
33
43
|
]);
|
|
34
44
|
if (!json.ok || !png.ok)
|
|
35
45
|
return r > 1 ? one({ id, url }, 1) : undefined;
|
|
36
|
-
const index =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
const index = await json.json();
|
|
47
|
+
if (!isRecord(index))
|
|
48
|
+
return r > 1 ? one({ id, url }, 1) : undefined;
|
|
49
|
+
const icons = Object.fromEntries(Object.entries(index).flatMap(([name, icon]) => (isSpriteIcon(icon) ? [[spriteName(id, name), icon]] : [])));
|
|
40
50
|
return { icons, image: await createImageBitmap(await png.blob()) };
|
|
41
51
|
};
|
|
42
52
|
const loaded = await Promise.all(spriteSources(sprite).map((s) => one(s, ratio).catch(() => undefined)));
|
|
43
53
|
return loaded.filter((s) => s !== undefined);
|
|
44
|
-
}
|
|
54
|
+
};
|
|
45
55
|
/** The pixels of an image (read back through a canvas) */
|
|
46
|
-
export
|
|
56
|
+
export const readPixels = (image) => {
|
|
47
57
|
const { width, height } = image;
|
|
48
58
|
if (!(width > 0 && height > 0))
|
|
49
59
|
return undefined;
|
|
50
|
-
const
|
|
51
|
-
? new OffscreenCanvas(width, height)
|
|
52
|
-
: Object.assign(document.createElement('canvas'), { width, height });
|
|
53
|
-
const g = canvas.getContext('2d');
|
|
60
|
+
const g = typeof OffscreenCanvas === 'function'
|
|
61
|
+
? new OffscreenCanvas(width, height).getContext('2d')
|
|
62
|
+
: Object.assign(document.createElement('canvas'), { width, height }).getContext('2d');
|
|
54
63
|
if (!g)
|
|
55
64
|
return undefined;
|
|
56
65
|
g.drawImage(image, 0, 0);
|
|
57
66
|
return g.getImageData(0, 0, width, height);
|
|
58
|
-
}
|
|
67
|
+
};
|
|
59
68
|
/** The icons of a map and their atlas: a square that doubles as it fills, up to the texture size limit */
|
|
60
69
|
export class Icons {
|
|
61
70
|
size = 256;
|
|
@@ -100,12 +109,12 @@ export class Icons {
|
|
|
100
109
|
}
|
|
101
110
|
return pixels;
|
|
102
111
|
};
|
|
103
|
-
|
|
112
|
+
Object.entries(index).forEach(([name, icon]) => {
|
|
104
113
|
if (!icon || typeof icon !== 'object')
|
|
105
|
-
|
|
114
|
+
return;
|
|
106
115
|
const { x, y, width, height, ...options } = icon;
|
|
107
116
|
this.define(`${prefix}${name}`, { pixels: once, x, y, width, height, options }, false);
|
|
108
|
-
}
|
|
117
|
+
});
|
|
109
118
|
this.version += 1;
|
|
110
119
|
}
|
|
111
120
|
define(name, source, bump = true) {
|
|
@@ -120,12 +129,12 @@ export class Icons {
|
|
|
120
129
|
}
|
|
121
130
|
/** Forgets an image, or every image whose name starts with `prefix` (a sprite's) */
|
|
122
131
|
remove(name, prefix = false) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
132
|
+
[...this.sources.keys()]
|
|
133
|
+
.filter((key) => (prefix ? key.startsWith(name) : key === name))
|
|
134
|
+
.forEach((key) => {
|
|
135
|
+
this.sources.delete(key);
|
|
136
|
+
this.packed.delete(key);
|
|
137
|
+
});
|
|
129
138
|
this.version += 1;
|
|
130
139
|
}
|
|
131
140
|
/** The icon of this name, packed into the atlas on first use; undefined if there is none (`flush` uploads it) */
|
|
@@ -237,9 +246,10 @@ export class Icons {
|
|
|
237
246
|
* stretchable zones (the whole image by default) taking the room the fixed parts (at `scale` CSS pixels per image
|
|
238
247
|
* pixel) leave
|
|
239
248
|
*/
|
|
240
|
-
export
|
|
249
|
+
export const stretch = (length, zones, content, lo, hi, scale) => {
|
|
241
250
|
const clamp = (v) => Math.max(0, Math.min(length, Number(v) || 0));
|
|
242
|
-
const
|
|
251
|
+
const whole = [[0, length]];
|
|
252
|
+
const spans = (zones?.length ? zones : whole)
|
|
243
253
|
.map(([a, b]) => [clamp(Math.min(a, b)), clamp(Math.max(a, b))])
|
|
244
254
|
.filter(([a, b]) => b > a);
|
|
245
255
|
const cuts = [...new Set([0, length, ...spans.flat()])].sort((a, b) => a - b);
|
|
@@ -257,47 +267,44 @@ export function stretch(length, zones, content, lo, hi, scale) {
|
|
|
257
267
|
const at = (x) => pieces.reduce((n, [a, b, s]) => n + Math.max(0, Math.min(x, b) - a) * (s ? k : scale), 0);
|
|
258
268
|
const origin = lo - at(c0);
|
|
259
269
|
return pieces.map(([a, b]) => [a, b, origin + at(a), origin + at(b)]);
|
|
260
|
-
}
|
|
270
|
+
};
|
|
261
271
|
/** Where an anchor's side lies along an axis of the icon: at its start 0, at its end 1, else the middle */
|
|
262
|
-
|
|
272
|
+
const align = (start, end) => {
|
|
263
273
|
if (start)
|
|
264
274
|
return 0;
|
|
265
275
|
return end ? 1 : 0.5;
|
|
266
|
-
}
|
|
276
|
+
};
|
|
267
277
|
/** Lays an icon out around its anchor: placed by its anchor and offset, or fitted to its text */
|
|
268
|
-
export
|
|
278
|
+
export const layoutIcon = (icon, options) => {
|
|
269
279
|
const { size, anchor, offset, rotate, fit, padding, text } = options;
|
|
270
280
|
const { width: w, height: h, pixelRatio } = icon;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
281
|
+
const [xs, ys] = (() => {
|
|
282
|
+
if (fit !== 'none' && text) {
|
|
283
|
+
const [top, right, bottom, left] = padding;
|
|
284
|
+
const [x0, y0, x1, y1] = [text[0] - left, text[1] - top, text[2] + right, text[3] + bottom];
|
|
285
|
+
// The fixed parts at the image's own size; an axis not fitted at the icon's size, centered on the text
|
|
286
|
+
const own = 1 / pixelRatio;
|
|
287
|
+
const scaled = size / pixelRatio;
|
|
288
|
+
const centered = (length, lo, hi) => {
|
|
289
|
+
const c = (lo + hi) / 2;
|
|
290
|
+
return [[0, length, c - (length * scaled) / 2, c + (length * scaled) / 2]];
|
|
291
|
+
};
|
|
292
|
+
const content = icon.content;
|
|
293
|
+
return [
|
|
294
|
+
fit === 'height'
|
|
295
|
+
? centered(w, x0, x1)
|
|
296
|
+
: stretch(w, icon.stretchX, content && [content[0], content[2]], x0, x1, own),
|
|
297
|
+
fit === 'width'
|
|
298
|
+
? centered(h, y0, y1)
|
|
299
|
+
: stretch(h, icon.stretchY, content && [content[1], content[3]], y0, y1, own),
|
|
300
|
+
];
|
|
301
|
+
}
|
|
294
302
|
const [dw, dh] = [(w / pixelRatio) * size, (h / pixelRatio) * size];
|
|
295
303
|
const ax = align(anchor.includes('left'), anchor.includes('right'));
|
|
296
304
|
const ay = align(anchor.startsWith('top'), anchor.startsWith('bottom'));
|
|
297
305
|
const [left, top] = [offset[0] * size - dw * ax, offset[1] * size - dh * ay];
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
306
|
+
return [[[0, w, left, left + dw]], [[0, h, top, top + dh]]];
|
|
307
|
+
})();
|
|
301
308
|
const angle = ((Number(rotate) || 0) * Math.PI) / 180;
|
|
302
309
|
const kind = icon.sdf ? -2 : -1;
|
|
303
310
|
const quads = [];
|
|
@@ -308,10 +315,10 @@ export function layoutIcon(icon, options) {
|
|
|
308
315
|
Number.NEGATIVE_INFINITY,
|
|
309
316
|
Number.NEGATIVE_INFINITY,
|
|
310
317
|
];
|
|
311
|
-
|
|
312
|
-
|
|
318
|
+
ys.forEach(([v0, v1, top, bottom]) => {
|
|
319
|
+
xs.forEach(([u0, u1, left, right]) => {
|
|
313
320
|
if (right <= left || bottom <= top)
|
|
314
|
-
|
|
321
|
+
return;
|
|
315
322
|
quads.push([
|
|
316
323
|
left,
|
|
317
324
|
top,
|
|
@@ -325,20 +332,21 @@ export function layoutIcon(icon, options) {
|
|
|
325
332
|
angle,
|
|
326
333
|
]);
|
|
327
334
|
// The box of the turned corners
|
|
328
|
-
|
|
335
|
+
const corners = [
|
|
329
336
|
[left, top],
|
|
330
337
|
[right, top],
|
|
331
338
|
[left, bottom],
|
|
332
339
|
[right, bottom],
|
|
333
|
-
]
|
|
340
|
+
];
|
|
341
|
+
corners.forEach(([px, py]) => {
|
|
334
342
|
const [rx, ry] = [px * cs - py * sn, px * sn + py * cs];
|
|
335
343
|
box[0] = Math.min(box[0], rx);
|
|
336
344
|
box[1] = Math.min(box[1], ry);
|
|
337
345
|
box[2] = Math.max(box[2], rx);
|
|
338
346
|
box[3] = Math.max(box[3], ry);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
});
|
|
342
350
|
return { quads, box: quads.length ? box : [0, 0, 0, 0] };
|
|
343
|
-
}
|
|
351
|
+
};
|
|
344
352
|
//# sourceMappingURL=icons.js.map
|