@tangram.gl/tangram-renderer 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -2
- package/dist/core.js +36923 -0
- package/dist/core.js.map +6 -0
- package/dist/index.js +32 -0
- package/dist/loaders-gl-worker.js +82 -0
- package/dist/loaders-gl-worker.js.map +6 -0
- package/dist/map-logic.js +2 -0
- package/dist/map-logic.js.map +6 -0
- package/dist/projected-basemaps-worker.js +3 -0
- package/dist/projected-basemaps-worker.js.map +6 -0
- package/dist/shader-modules.js +141 -0
- package/dist/shader-modules.js.map +6 -0
- package/dist/style-schema.js +126 -0
- package/dist/style-schema.js.map +6 -0
- package/dist/tangram-style.schema.json +882 -0
- package/dist/tangram.debug.mjs +37139 -0
- package/dist/tangram.debug.mjs.map +6 -0
- package/dist/tangram.min.mjs +4950 -0
- package/dist/types/builders/earcut.d.ts +15 -0
- package/dist/types/core.d.ts +29 -0
- package/dist/types/gl/constants.d.ts +2 -0
- package/dist/types/gl/globe_mesh.d.ts +48 -0
- package/dist/types/gl/glsl.d.ts +17 -0
- package/dist/types/gl/vertex-constants.d.ts +4 -0
- package/dist/types/gl/vertex-types.d.ts +34 -0
- package/dist/types/gl/vertex_data.d.ts +32 -0
- package/dist/types/gl/vertex_elements.d.ts +8 -0
- package/dist/types/gl/vertex_layout.d.ts +32 -0
- package/dist/types/glsl.d.ts +14 -0
- package/dist/types/gpu/luma_device_renderer.d.ts +66 -0
- package/dist/types/gpu/resource_lifecycle.d.ts +4 -0
- package/dist/types/gpu/tangram_gpu_backend.d.ts +151 -0
- package/dist/types/index.d.ts +155 -0
- package/dist/types/lights/light-definitions.d.ts +121 -0
- package/dist/types/map-logic/draped-terrain-bounds.d.ts +41 -0
- package/dist/types/map-logic/globe-terrain-preparation.d.ts +85 -0
- package/dist/types/map-logic/globe-terrain.d.ts +54 -0
- package/dist/types/map-logic/index.d.ts +33 -0
- package/dist/types/map-logic/label-identity.d.ts +22 -0
- package/dist/types/map-logic/label-placement.d.ts +32 -0
- package/dist/types/map-logic/screen-bounds.d.ts +15 -0
- package/dist/types/map-logic/terrain-data.d.ts +55 -0
- package/dist/types/map-logic/terrain-error.d.ts +51 -0
- package/dist/types/map-logic/terrain-ground-topology.d.ts +26 -0
- package/dist/types/map-logic/terrain-height-field.d.ts +59 -0
- package/dist/types/map-logic/terrain-navigation.d.ts +27 -0
- package/dist/types/map-logic/terrain-neighborhood.d.ts +5 -0
- package/dist/types/map-logic/terrain-query.d.ts +33 -0
- package/dist/types/map-logic/terrain-resource-budget.d.ts +51 -0
- package/dist/types/map-logic/terrain-transition-topology.d.ts +23 -0
- package/dist/types/map-logic/tile-build-queue.d.ts +51 -0
- package/dist/types/map-logic/tile-cache-policy.d.ts +46 -0
- package/dist/types/map-logic/tile-residency.d.ts +17 -0
- package/dist/types/map-logic/triangle-query-index.d.ts +87 -0
- package/dist/types/procedures/js-yaml.d.ts +15 -0
- package/dist/types/procedures/mesh-projector.d.ts +107 -0
- package/dist/types/procedures/mvt-dependencies.d.ts +20 -0
- package/dist/types/procedures/projected-coordinate-transform.d.ts +27 -0
- package/dist/types/procedures/projection-batch-executor.d.ts +53 -0
- package/dist/types/procedures/scene-yaml-legacy.d.ts +6 -0
- package/dist/types/procedures/terrain-draping.d.ts +165 -0
- package/dist/types/procedures/terrain-globe.d.ts +6 -0
- package/dist/types/procedures/terrain-styled-topology.d.ts +34 -0
- package/dist/types/procedures/web-mercator-legacy.d.ts +4 -0
- package/dist/types/procedures/web-mercator-math.d.ts +4 -0
- package/dist/types/scene/globals.d.ts +11 -0
- package/dist/types/scene/ground_footprint.d.ts +16 -0
- package/dist/types/scene/host_frame.d.ts +54 -0
- package/dist/types/scene/projection_math.d.ts +52 -0
- package/dist/types/scene/scene-resource-types.d.ts +177 -0
- package/dist/types/scene/scene_bundle.d.ts +69 -0
- package/dist/types/scene/visibility_adapter.d.ts +106 -0
- package/dist/types/selection/draped-terrain-surface.d.ts +78 -0
- package/dist/types/selection/terrain_surface.d.ts +149 -0
- package/dist/types/shader-modules/globe-horizon.d.ts +15 -0
- package/dist/types/shader-modules/height-decode.d.ts +13 -0
- package/dist/types/shader-modules/hillshade.d.ts +13 -0
- package/dist/types/shader-modules/index.d.ts +6 -0
- package/dist/types/shader-modules/planar.d.ts +12 -0
- package/dist/types/shader-modules/sphere-map.d.ts +13 -0
- package/dist/types/shader-modules/triplanar.d.ts +15 -0
- package/dist/types/sources/decoded_tile_store.d.ts +95 -0
- package/dist/types/sources/tile_source_metadata.d.ts +32 -0
- package/dist/types/styles/text/fontfaceobserver.d.ts +10 -0
- package/dist/types/tile/tile_id.d.ts +37 -0
- package/dist/types/tile/tile_traversal_adapter.d.ts +63 -0
- package/dist/types/types.d.ts +293 -0
- package/dist/types/utils/geo.d.ts +57 -0
- package/dist/types/utils/hash.d.ts +1 -0
- package/dist/types/utils/log.d.ts +27 -0
- package/dist/types/utils/props.d.ts +6 -0
- package/dist/types/utils/subscribe.d.ts +10 -0
- package/dist/types/utils/thread.d.ts +6 -0
- package/dist/types/utils/urls.d.ts +26 -0
- package/dist/types/utils/utils.d.ts +26 -0
- package/dist/types/utils/version.d.ts +2 -0
- package/dist/types/utils/worker-types.d.ts +68 -0
- package/dist/types/utils/worker_broker.d.ts +3 -0
- package/package.json +103 -3
- package/src/builders/common.ts +41 -0
- package/src/builders/earcut.d.ts +15 -0
- package/src/builders/geometry-types.ts +60 -0
- package/src/builders/points.ts +115 -0
- package/src/builders/polygons.ts +225 -0
- package/src/builders/polylines.ts +682 -0
- package/src/builders/wireframe.ts +31 -0
- package/src/core.d.ts +29 -0
- package/src/core.ts +33 -0
- package/src/experimental/loaders-gl-worker.ts +19 -0
- package/src/experimental/projected-basemaps-worker.ts +13 -0
- package/src/experimental/projected-mesh-cache.ts +137 -0
- package/src/experimental/projected-mesh-domain.ts +110 -0
- package/src/experimental/projected-mesh-refinement.ts +193 -0
- package/src/experimental/projected-mesh.ts +399 -0
- package/src/experimental/projected-normal.ts +26 -0
- package/src/experimental/projected-symbol-mesh.ts +74 -0
- package/src/gl/constants.ts +18 -0
- package/src/gl/context.ts +103 -0
- package/src/gl/extensions.ts +30 -0
- package/src/gl/globe_mesh.ts +285 -0
- package/src/gl/glsl.ts +257 -0
- package/src/gl/mesh-types.ts +56 -0
- package/src/gl/render_state.ts +111 -0
- package/src/gl/shader_program.ts +1310 -0
- package/src/gl/texture.ts +814 -0
- package/src/gl/uniform_buffer.ts +340 -0
- package/src/gl/vao.ts +154 -0
- package/src/gl/vbo_mesh.ts +349 -0
- package/src/gl/vertex-constants.ts +19 -0
- package/src/gl/vertex-types.ts +35 -0
- package/src/gl/vertex_data.ts +126 -0
- package/src/gl/vertex_elements.ts +54 -0
- package/src/gl/vertex_layout.ts +241 -0
- package/src/glsl.d.ts +14 -0
- package/src/gpu/luma_device_renderer.ts +579 -0
- package/src/gpu/pixel_readback.ts +51 -0
- package/src/gpu/resource_lifecycle.ts +32 -0
- package/src/gpu/tangram_gpu_backend.ts +195 -0
- package/src/index.d.ts +155 -0
- package/src/index.ts +105 -0
- package/src/labels/collision-types.ts +94 -0
- package/src/labels/collision.ts +273 -0
- package/src/labels/collision_grid.ts +61 -0
- package/src/labels/intersect.ts +30 -0
- package/src/labels/label-types.ts +91 -0
- package/src/labels/label.ts +207 -0
- package/src/labels/label_line.ts +801 -0
- package/src/labels/label_point.ts +131 -0
- package/src/labels/main-pass-types.ts +73 -0
- package/src/labels/main_pass.ts +221 -0
- package/src/labels/point_anchor.ts +100 -0
- package/src/labels/point_placement.ts +150 -0
- package/src/labels/projected-pass.ts +259 -0
- package/src/labels/repeat_group.ts +72 -0
- package/src/lights/ambient_light.glsl +18 -0
- package/src/lights/directional_light.glsl +39 -0
- package/src/lights/geographic-lights.ts +21 -0
- package/src/lights/light-definitions.ts +285 -0
- package/src/lights/light.ts +590 -0
- package/src/lights/lighting-uniforms.ts +80 -0
- package/src/lights/lighting-wgsl.ts +116 -0
- package/src/lights/material.glsl +237 -0
- package/src/lights/material.ts +145 -0
- package/src/lights/native-falloff.ts +37 -0
- package/src/lights/point_light.glsl +96 -0
- package/src/lights/spot_light.glsl +111 -0
- package/src/map-logic/draped-terrain-bounds.ts +71 -0
- package/src/map-logic/globe-terrain-preparation.ts +217 -0
- package/src/map-logic/globe-terrain.ts +296 -0
- package/src/map-logic/index.ts +37 -0
- package/src/map-logic/label-identity.ts +36 -0
- package/src/map-logic/label-placement.ts +117 -0
- package/src/map-logic/screen-bounds.ts +34 -0
- package/src/map-logic/terrain-data.ts +107 -0
- package/src/map-logic/terrain-error.ts +134 -0
- package/src/map-logic/terrain-ground-topology.ts +164 -0
- package/src/map-logic/terrain-height-field.ts +254 -0
- package/src/map-logic/terrain-navigation.ts +50 -0
- package/src/map-logic/terrain-neighborhood.ts +43 -0
- package/src/map-logic/terrain-query.ts +51 -0
- package/src/map-logic/terrain-resource-budget.ts +124 -0
- package/src/map-logic/terrain-transition-topology.ts +164 -0
- package/src/map-logic/tile-build-queue.ts +110 -0
- package/src/map-logic/tile-cache-policy.ts +89 -0
- package/src/map-logic/tile-residency.ts +50 -0
- package/src/map-logic/triangle-query-index.ts +265 -0
- package/src/procedures/js-yaml.d.ts +15 -0
- package/src/procedures/mesh-projector.ts +191 -0
- package/src/procedures/mlt-loaders.ts +55 -0
- package/src/procedures/mvt-dependencies.d.ts +20 -0
- package/src/procedures/mvt-legacy.ts +150 -0
- package/src/procedures/mvt-loaders.ts +53 -0
- package/src/procedures/mvt-parser.ts +48 -0
- package/src/procedures/mvt-properties.ts +36 -0
- package/src/procedures/mvt-tile-provider.ts +72 -0
- package/src/procedures/pmtiles-loader.ts +75 -0
- package/src/procedures/projected-coordinate-transform.ts +79 -0
- package/src/procedures/projection-batch-executor.ts +140 -0
- package/src/procedures/scene-yaml-legacy.ts +16 -0
- package/src/procedures/scene-yaml-loaders.ts +10 -0
- package/src/procedures/terrain-draping.ts +713 -0
- package/src/procedures/terrain-globe.ts +32 -0
- package/src/procedures/terrain-styled-topology.ts +184 -0
- package/src/procedures/web-mercator-legacy.ts +24 -0
- package/src/procedures/web-mercator-math.ts +50 -0
- package/src/scene/camera.ts +298 -0
- package/src/scene/camera_base.ts +116 -0
- package/src/scene/classic_scene.ts +20 -0
- package/src/scene/external_camera.ts +101 -0
- package/src/scene/globals.ts +120 -0
- package/src/scene/ground_footprint.ts +139 -0
- package/src/scene/host_frame.ts +326 -0
- package/src/scene/projected_tile_lod.ts +125 -0
- package/src/scene/projection_math.ts +142 -0
- package/src/scene/projection_shaders.ts +183 -0
- package/src/scene/renderer.ts +516 -0
- package/src/scene/scene-resource-types.ts +174 -0
- package/src/scene/scene.ts +2378 -0
- package/src/scene/scene_bundle.ts +304 -0
- package/src/scene/scene_debug.ts +129 -0
- package/src/scene/scene_loader.ts +402 -0
- package/src/scene/scene_worker.ts +528 -0
- package/src/scene/view.ts +683 -0
- package/src/scene/visibility_adapter.ts +319 -0
- package/src/scene/worker_url.ts +15 -0
- package/src/selection/draped-terrain-surface.ts +377 -0
- package/src/selection/selection-types.ts +79 -0
- package/src/selection/selection.ts +542 -0
- package/src/selection/selection_fragment.glsl +18 -0
- package/src/selection/selection_globals.glsl +9 -0
- package/src/selection/selection_pixels.ts +59 -0
- package/src/selection/selection_vertex.glsl +15 -0
- package/src/selection/terrain_surface.ts +298 -0
- package/src/shader-modules/globe-horizon.ts +52 -0
- package/src/shader-modules/height-decode.ts +41 -0
- package/src/shader-modules/hillshade.ts +70 -0
- package/src/shader-modules/index.ts +10 -0
- package/src/shader-modules/planar.ts +24 -0
- package/src/shader-modules/sphere-map.ts +38 -0
- package/src/shader-modules/triplanar.ts +45 -0
- package/src/sources/aligned_tile_source.ts +122 -0
- package/src/sources/data_source.ts +655 -0
- package/src/sources/decoded_tile_store.ts +245 -0
- package/src/sources/geojson.ts +300 -0
- package/src/sources/mvt.ts +247 -0
- package/src/sources/raster.ts +341 -0
- package/src/sources/shared_tile_source_adapter.ts +117 -0
- package/src/sources/sources.ts +10 -0
- package/src/sources/tile_source_adapter.ts +84 -0
- package/src/sources/tile_source_metadata.ts +65 -0
- package/src/sources/tile_source_state.ts +112 -0
- package/src/sources/topojson.ts +90 -0
- package/src/styles/feature_annotations.ts +16 -0
- package/src/styles/filter.ts +190 -0
- package/src/styles/geometry-style-types.ts +209 -0
- package/src/styles/globe_visibility_wgsl.ts +22 -0
- package/src/styles/layer-types.ts +45 -0
- package/src/styles/layer.ts +586 -0
- package/src/styles/lines/dasharray.ts +49 -0
- package/src/styles/lines/lines.ts +707 -0
- package/src/styles/lines/lines_wgsl.ts +224 -0
- package/src/styles/points/point-runtime-types.ts +125 -0
- package/src/styles/points/points.ts +1079 -0
- package/src/styles/points/points_fragment.glsl +126 -0
- package/src/styles/points/points_vertex.glsl +230 -0
- package/src/styles/points/points_wgsl.ts +189 -0
- package/src/styles/polygons/polygons.ts +268 -0
- package/src/styles/polygons/polygons_fragment.glsl +173 -0
- package/src/styles/polygons/polygons_vertex.glsl +213 -0
- package/src/styles/polygons/polygons_wgsl.ts +127 -0
- package/src/styles/property-types.ts +125 -0
- package/src/styles/raster/raster.ts +33 -0
- package/src/styles/raster/raster_globals.glsl +46 -0
- package/src/styles/style-mixing-types.ts +101 -0
- package/src/styles/style-runtime-types.ts +220 -0
- package/src/styles/style-schema.ts +133 -0
- package/src/styles/style.ts +1033 -0
- package/src/styles/style_globals.glsl +69 -0
- package/src/styles/style_manager.ts +464 -0
- package/src/styles/style_parser.ts +620 -0
- package/src/styles/text/font_manager.ts +180 -0
- package/src/styles/text/fontfaceobserver.d.ts +10 -0
- package/src/styles/text/text-types.ts +220 -0
- package/src/styles/text/text.ts +378 -0
- package/src/styles/text/text_canvas.ts +773 -0
- package/src/styles/text/text_labels.ts +436 -0
- package/src/styles/text/text_segments.ts +142 -0
- package/src/styles/text/text_settings.ts +228 -0
- package/src/styles/text/text_wgsl.ts +159 -0
- package/src/styles/text/text_wrap.ts +194 -0
- package/src/tile/globe_tile_preload.ts +40 -0
- package/src/tile/tangram_tileset_2d.ts +108 -0
- package/src/tile/tile-build-types.ts +155 -0
- package/src/tile/tile.ts +807 -0
- package/src/tile/tile_id.ts +172 -0
- package/src/tile/tile_manager.ts +889 -0
- package/src/tile/tile_pyramid.ts +119 -0
- package/src/tile/tile_resource_cache.ts +91 -0
- package/src/tile/tile_traversal_adapter.ts +132 -0
- package/src/types.ts +332 -0
- package/src/utils/debounce.ts +17 -0
- package/src/utils/debug_settings.ts +43 -0
- package/src/utils/errors.ts +12 -0
- package/src/utils/functions.ts +95 -0
- package/src/utils/geo.ts +364 -0
- package/src/utils/hash.ts +14 -0
- package/src/utils/log.ts +108 -0
- package/src/utils/media_capture.ts +193 -0
- package/src/utils/merge.ts +44 -0
- package/src/utils/obb.ts +134 -0
- package/src/utils/props.ts +43 -0
- package/src/utils/slice.ts +14 -0
- package/src/utils/subscribe.ts +58 -0
- package/src/utils/task.ts +154 -0
- package/src/utils/thread.ts +26 -0
- package/src/utils/urls.ts +223 -0
- package/src/utils/utils.ts +310 -0
- package/src/utils/vector.ts +197 -0
- package/src/utils/version.ts +8 -0
- package/src/utils/worker-types.ts +79 -0
- package/src/utils/worker_broker.ts +523 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Tangram
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2013-2016 Brett Camper and Mapzen
|
|
4
|
+
|
|
5
|
+
import log from '../../utils/log';
|
|
6
|
+
import Utils from '../../utils/utils';
|
|
7
|
+
import FontFaceObserver from 'fontfaceobserver';
|
|
8
|
+
|
|
9
|
+
interface FontFaceDefinition {
|
|
10
|
+
url?: string;
|
|
11
|
+
weight?: string | number;
|
|
12
|
+
style?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type FontDefinition = FontFaceDefinition | FontFaceDefinition[] | 'external';
|
|
17
|
+
type FontCollection = Record<string, FontDefinition>;
|
|
18
|
+
|
|
19
|
+
interface FontFaceOptions {
|
|
20
|
+
family: string;
|
|
21
|
+
weight?: string | number;
|
|
22
|
+
style?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface FontManagerApi {
|
|
27
|
+
fonts_loaded: Promise<void>;
|
|
28
|
+
last_loaded: string | null;
|
|
29
|
+
supports_native_font_loading?: boolean;
|
|
30
|
+
loadFonts(fonts?: FontCollection | null): Promise<void>;
|
|
31
|
+
loadFontFace(family: string, face: FontDefinition): Promise<void>;
|
|
32
|
+
injectFontFace(options: FontFaceOptions & {url?: string}): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const FontManager: FontManagerApi = {
|
|
36
|
+
|
|
37
|
+
// Font detection
|
|
38
|
+
fonts_loaded: Promise.resolve(), // resolves when all requested fonts have been detected
|
|
39
|
+
last_loaded: null, // tracks last set of fonts loaded
|
|
40
|
+
|
|
41
|
+
// Load set of custom font faces
|
|
42
|
+
// `fonts` is an object where the key is a font family name, and the value is one or more font face
|
|
43
|
+
// definitions. The value can be either a single object, or an array of such objects.
|
|
44
|
+
// If the special string value 'external' is used, it indicates the the font will be loaded via external CSS.
|
|
45
|
+
loadFonts (fonts?: FontCollection | null): Promise<void> {
|
|
46
|
+
const same = (JSON.stringify(fonts) === this.last_loaded);
|
|
47
|
+
if (fonts && !same) {
|
|
48
|
+
const queue = [];
|
|
49
|
+
for (const family in fonts) {
|
|
50
|
+
if (Array.isArray(fonts[family])) {
|
|
51
|
+
fonts[family].forEach(face => queue.push(this.loadFontFace(family, face)));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
queue.push(this.loadFontFace(family, fonts[family]));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.last_loaded = JSON.stringify(fonts);
|
|
59
|
+
this.fonts_loaded = Promise.all(queue.filter(x => x)).then(() => undefined);
|
|
60
|
+
}
|
|
61
|
+
return this.fonts_loaded;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// Load a single font face
|
|
65
|
+
// `face` contains the font face definition, with optional parameters for `weight`, `style`, and `url`.
|
|
66
|
+
// If the `url` is defined, the font is injected into the document as a CSS font-face.
|
|
67
|
+
// If the object's value is the special string 'external', or if no `url` is defined, then the font face
|
|
68
|
+
// is assumed is assumed to been loaded via external CSS. In either case, the function returns a promise
|
|
69
|
+
// that resolves when the font face has loaded, or times out.
|
|
70
|
+
async loadFontFace (family: string, face: FontDefinition): Promise<void> {
|
|
71
|
+
if (face == null || (typeof face !== 'object' && face !== 'external')) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const options: FontFaceOptions = {family};
|
|
76
|
+
|
|
77
|
+
if (typeof face === 'object' && !Array.isArray(face)) {
|
|
78
|
+
Object.assign(options, face);
|
|
79
|
+
|
|
80
|
+
// If URL is defined, inject font into document
|
|
81
|
+
if (typeof face.url === 'string') {
|
|
82
|
+
await this.injectFontFace(options);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Wait for font to load
|
|
87
|
+
try {
|
|
88
|
+
// FontFaceObserver does not directly support variable fonts syntax, which allows for ranges,
|
|
89
|
+
// e.g. `font-weight: 100 800`. FontFaceObserver will insert the entire string value into a
|
|
90
|
+
// CSS `font` shorthand property, causing an error. To get around this, we simply take the first
|
|
91
|
+
// value, because as soon as one variant of the variable font is available, they all should be.
|
|
92
|
+
// See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
|
|
93
|
+
options.weight = typeof options.weight === 'string' ? options.weight.split(' ')[0] : options.weight;
|
|
94
|
+
const observer = new FontFaceObserver(family, options);
|
|
95
|
+
await observer.load();
|
|
96
|
+
// Promise resolves, font is available
|
|
97
|
+
log('debug', `Font face '${family}' is available`, options);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
// Promise rejects, font is not available
|
|
101
|
+
log('warn', `Font face '${family}' is NOT available`, options, e);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// Loads a font face via either the native FontFace API, or CSS injection
|
|
106
|
+
// TODO: consider support for multiple format URLs per face, unicode ranges
|
|
107
|
+
async injectFontFace ({family, url, weight, style}: FontFaceOptions & {url?: string}): Promise<void> {
|
|
108
|
+
if (!url) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (this.supports_native_font_loading === undefined) {
|
|
113
|
+
this.supports_native_font_loading = (window.FontFace !== undefined);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Convert blob URLs, depending on whether the native FontFace API will be used or not.
|
|
117
|
+
//
|
|
118
|
+
// When the FontFace API *is* supported, the blob URL is read into a raw data array.
|
|
119
|
+
// NB: it's inefficient to be converting blob URLs into typed arrays here, since they originated
|
|
120
|
+
// as raw data *before* they were converted into blob URLs. However, this process should be fast since
|
|
121
|
+
// these are native browser functions and all data is local (no network request), and it keeps the
|
|
122
|
+
// logic streamlined by allowing us to continue to use a URL-based interface for all scene resources.
|
|
123
|
+
//
|
|
124
|
+
// When the FontFace API is *not* supported, the blob URL data is converted to a base64 data URL.
|
|
125
|
+
// This avoids security restricions in some browsers.
|
|
126
|
+
// Also see https://github.com/bramstein/fontloader/blob/598e9399117bdc946ff786fa2c5007a6bd7d3b9e/src/fontface.js#L145-L153
|
|
127
|
+
let data: string | Uint8Array = url;
|
|
128
|
+
if (url.slice(0, 5) === 'blob:') {
|
|
129
|
+
const body = (await Utils.io(url, 60000, 'arraybuffer')).body as ArrayBuffer;
|
|
130
|
+
let bytes = new Uint8Array(body);
|
|
131
|
+
if (this.supports_native_font_loading) {
|
|
132
|
+
data = bytes; // use raw binary data
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
let str = '';
|
|
136
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
137
|
+
str += String.fromCharCode(bytes[i]);
|
|
138
|
+
}
|
|
139
|
+
data = 'data:font/opentype;base64,' + btoa(str); // base64 encode as data URL
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (this.supports_native_font_loading) {
|
|
144
|
+
// Use native FontFace API
|
|
145
|
+
let face;
|
|
146
|
+
if (typeof data === 'string') { // add as URL
|
|
147
|
+
face = new FontFace(family, `url(${encodeURI(data)})`, {weight: weight == null ? undefined : String(weight), style});
|
|
148
|
+
}
|
|
149
|
+
else if (data instanceof Uint8Array) { // add as binary data
|
|
150
|
+
face = new FontFace(family, data.buffer as ArrayBuffer, {weight: weight == null ? undefined : String(weight), style});
|
|
151
|
+
}
|
|
152
|
+
if (!face) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
document.fonts.add(face);
|
|
156
|
+
log('trace', 'Adding FontFace to document.fonts:', face);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// Use CSS injection
|
|
160
|
+
if (typeof data !== 'string') {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let css = `
|
|
164
|
+
@font-face {
|
|
165
|
+
font-family: '${family}';
|
|
166
|
+
font-weight: ${weight || 'normal'};
|
|
167
|
+
font-style: ${style || 'normal'};
|
|
168
|
+
src: url(${encodeURI(data)});
|
|
169
|
+
}`;
|
|
170
|
+
let style_el = document.createElement('style');
|
|
171
|
+
style_el.appendChild(document.createTextNode(''));
|
|
172
|
+
document.head.appendChild(style_el);
|
|
173
|
+
style_el.sheet?.insertRule(css, 0);
|
|
174
|
+
log('trace', 'Injecting CSS font face:', css);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export default FontManager;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
declare module 'fontfaceobserver' {
|
|
6
|
+
export default class FontFaceObserver {
|
|
7
|
+
constructor (family: string, options?: Record<string, unknown>);
|
|
8
|
+
load (): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {CollisionObject} from '../../labels/collision-types';
|
|
6
|
+
import type {LabelLayout, LabelPointCoordinate} from '../../labels/label-types';
|
|
7
|
+
import type LabelPoint from '../../labels/label_point';
|
|
8
|
+
import type LabelLine from '../../labels/label_line';
|
|
9
|
+
import type TextCanvas from './text_canvas';
|
|
10
|
+
import type {TextDraw, TextSettingsResult} from './text_settings';
|
|
11
|
+
import type {TaskRecord} from '../../utils/task';
|
|
12
|
+
import type {PropertyCache} from '../property-types';
|
|
13
|
+
|
|
14
|
+
/** Labels submitted by standalone text and attached point text. */
|
|
15
|
+
export type TextRenderLabel = LabelPoint | Exclude<ReturnType<typeof LabelLine.create>, false>;
|
|
16
|
+
|
|
17
|
+
/** Tile metadata needed for text placement and cancellation. */
|
|
18
|
+
export interface TextTile {
|
|
19
|
+
id: string;
|
|
20
|
+
key: string;
|
|
21
|
+
generation: number;
|
|
22
|
+
canceled?: boolean;
|
|
23
|
+
overzoom2: number;
|
|
24
|
+
units_per_pixel?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Supported tile-local feature geometry. */
|
|
28
|
+
export type TextGeometry =
|
|
29
|
+
| {type: 'Point'; coordinates: LabelPointCoordinate}
|
|
30
|
+
| {type: 'MultiPoint' | 'LineString'; coordinates: LabelPointCoordinate[]}
|
|
31
|
+
| {type: 'MultiLineString' | 'Polygon'; coordinates: LabelPointCoordinate[][]}
|
|
32
|
+
| {type: 'MultiPolygon'; coordinates: LabelPointCoordinate[][][]};
|
|
33
|
+
|
|
34
|
+
/** Feature passed to text-source callbacks and label placement. */
|
|
35
|
+
export interface TextFeature {
|
|
36
|
+
/** Stable optional source identity, shared by buffered tile copies. */
|
|
37
|
+
id?: string | number;
|
|
38
|
+
geometry: TextGeometry;
|
|
39
|
+
properties: Record<string, TextValue>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Legacy text sources may return numeric/falsy values as well as strings. */
|
|
43
|
+
export type TextValue = string | number | boolean | null | undefined;
|
|
44
|
+
|
|
45
|
+
/** Evaluation context supplied to dynamic style properties. */
|
|
46
|
+
export interface TextContext {
|
|
47
|
+
tile: TextTile;
|
|
48
|
+
geometry: string;
|
|
49
|
+
layer?: string;
|
|
50
|
+
[property: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Property lookup or dynamic text callback, with optional fallbacks. */
|
|
54
|
+
export type TextSourceValue = string | ((context: TextContext) => TextValue);
|
|
55
|
+
/** Single source, ordered fallbacks, or named boundary-label sources. */
|
|
56
|
+
export type TextSource = TextSourceValue | TextSourceValue[] | Record<string, TextSourceValue | TextSourceValue[]>;
|
|
57
|
+
|
|
58
|
+
/** Text draw properties before/after property-cache preprocessing. */
|
|
59
|
+
export interface TextLabelDraw extends TextDraw {
|
|
60
|
+
/** Standalone projected text altitude, cached in physical meters after preprocessing. */
|
|
61
|
+
z?: PropertyCache;
|
|
62
|
+
/** Internal scene draw-group identity, used to keep independent annotations separate. */
|
|
63
|
+
key?: string;
|
|
64
|
+
/** Enable collision placement; projected annotations resolve it in screen space. */
|
|
65
|
+
collide?: boolean | ((context: TextContext) => boolean);
|
|
66
|
+
text_source?: TextSource;
|
|
67
|
+
offset?: unknown;
|
|
68
|
+
buffer?: unknown;
|
|
69
|
+
repeat_distance?: unknown;
|
|
70
|
+
repeat_group?: string | ((context: TextContext) => string);
|
|
71
|
+
align?: string;
|
|
72
|
+
blend_order?: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Parsed text candidate, before its feature and geometry are queued. */
|
|
76
|
+
export interface ParsedTextFeature {
|
|
77
|
+
draw: TextLabelDraw;
|
|
78
|
+
text: string;
|
|
79
|
+
text_settings_key: string;
|
|
80
|
+
layout: LabelLayout;
|
|
81
|
+
feature?: TextFeature;
|
|
82
|
+
context?: TextContext;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Complete feature queue entry supplied by a rendering style. */
|
|
86
|
+
export interface TextFeatureQueue extends ParsedTextFeature {
|
|
87
|
+
feature: TextFeature;
|
|
88
|
+
context: TextContext;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Collision container retaining text/style/feature information. */
|
|
92
|
+
export interface TextLabelCandidate extends TextFeatureQueue, CollisionObject {
|
|
93
|
+
label: TextRenderLabel;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Measured canvas line; structural to avoid exposing the private wrapper class. */
|
|
97
|
+
export interface TextLine {
|
|
98
|
+
text: string;
|
|
99
|
+
width: number;
|
|
100
|
+
height: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Logical/collision sizes and device-pixel atlas dimensions. */
|
|
104
|
+
export interface TextSize {
|
|
105
|
+
collision_size: LabelPointCoordinate;
|
|
106
|
+
texture_size: LabelPointCoordinate;
|
|
107
|
+
logical_size: LabelPointCoordinate;
|
|
108
|
+
horizontal_buffer: number;
|
|
109
|
+
vertical_buffer: number;
|
|
110
|
+
dpr: number;
|
|
111
|
+
line_height: number;
|
|
112
|
+
background_size: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Cached measurement, including wrapped lines. */
|
|
116
|
+
export interface TextMeasurement {
|
|
117
|
+
lines: TextLine[];
|
|
118
|
+
size: TextSize;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Packed sprite coordinates and owning atlas index. */
|
|
122
|
+
export interface TextSprite {
|
|
123
|
+
texture_id: number;
|
|
124
|
+
texcoord: number[];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Point alignment populated during packing, then rasterization. */
|
|
128
|
+
export interface TextAlignment {
|
|
129
|
+
texture_id?: number;
|
|
130
|
+
texture_position?: LabelPointCoordinate;
|
|
131
|
+
texcoords?: number[];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** One unique text/style record, progressively measured and rasterized. */
|
|
135
|
+
export interface TextInfo {
|
|
136
|
+
text_settings: TextSettingsResult;
|
|
137
|
+
ref: number;
|
|
138
|
+
size?: TextSize;
|
|
139
|
+
segment_sizes?: TextSize[];
|
|
140
|
+
segments?: string[];
|
|
141
|
+
isRTL?: boolean;
|
|
142
|
+
no_curving?: boolean;
|
|
143
|
+
vertical_buffer?: number;
|
|
144
|
+
align?: Record<string, TextAlignment>;
|
|
145
|
+
type?: string[];
|
|
146
|
+
textures?: (number | number[])[];
|
|
147
|
+
texcoords?: {straight?: TextSprite; curved?: TextSprite[]};
|
|
148
|
+
texcoords_stroke?: number[][];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Unique strings indexed first by style key and then by original text. */
|
|
152
|
+
export type TextTable = Record<string, Record<string, TextInfo>>;
|
|
153
|
+
|
|
154
|
+
/** Per-word atlas cache shared by straight and curved rasterization. */
|
|
155
|
+
export interface TextSpriteCache {
|
|
156
|
+
texture_id: number;
|
|
157
|
+
texture_position: LabelPointCoordinate;
|
|
158
|
+
texcoord?: number[];
|
|
159
|
+
texcoord_stroke?: number[];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Single atlas produced by the packing pass. */
|
|
163
|
+
export interface TextAtlas {
|
|
164
|
+
texture_size: LabelPointCoordinate;
|
|
165
|
+
texcoord_cache: Record<string, Record<string, TextSpriteCache>>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Mutable column-packing cursor. */
|
|
169
|
+
export interface TextAtlasCursor {
|
|
170
|
+
cx: number;
|
|
171
|
+
cy: number;
|
|
172
|
+
width: number;
|
|
173
|
+
height: number;
|
|
174
|
+
column_width: number;
|
|
175
|
+
texture_id: number;
|
|
176
|
+
texcoord_cache: TextAtlas['texcoord_cache'];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Cooperative text measurement/rasterization progress. */
|
|
180
|
+
export interface TextTaskCursor {
|
|
181
|
+
styles: string[];
|
|
182
|
+
texts: string[] | null;
|
|
183
|
+
style_idx: number | null;
|
|
184
|
+
text_idx: number | null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Measurement task payload carried by the generic scheduler. */
|
|
188
|
+
export interface TextSizesTask extends TaskRecord<TextTable> {
|
|
189
|
+
texts: TextTable;
|
|
190
|
+
cursor: TextTaskCursor;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Raster task payload, retaining names for cancellation cleanup. */
|
|
194
|
+
export interface TextRasterTask extends TaskRecord<string[]> {
|
|
195
|
+
texts: TextTable;
|
|
196
|
+
textures: TextAtlas[];
|
|
197
|
+
texture_prefix: string;
|
|
198
|
+
resource_context: unknown;
|
|
199
|
+
cursor: TextTaskCursor & {
|
|
200
|
+
texture_idx: number;
|
|
201
|
+
texture_resize: boolean;
|
|
202
|
+
texture_names: string[];
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Shared style state required by the text-label mixin. */
|
|
207
|
+
export interface TextLabelState {
|
|
208
|
+
/** Host-driven billboard candidates remain available until every eye is known. */
|
|
209
|
+
screen_space_labels?: boolean;
|
|
210
|
+
/** Projected candidates must bypass worker-local Mercator repeat culling. */
|
|
211
|
+
cpu_projection?: import('../../procedures/mesh-projector').ProjectedBasemapOptions;
|
|
212
|
+
name: string;
|
|
213
|
+
main_thread_target: string;
|
|
214
|
+
max_texture_size: number;
|
|
215
|
+
resource_context: unknown;
|
|
216
|
+
canvas: TextCanvas;
|
|
217
|
+
texts: Record<string, TextTable>;
|
|
218
|
+
computeLayout(target: Partial<LabelLayout>, feature: TextFeature, draw: TextLabelDraw, context: TextContext, tile: TextTile): LabelLayout;
|
|
219
|
+
buildTextLabels(tile: TextTile, queue: TextFeatureQueue[]): TextLabelCandidate[];
|
|
220
|
+
}
|