@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.
Files changed (321) hide show
  1. package/README.md +59 -2
  2. package/dist/core.js +36923 -0
  3. package/dist/core.js.map +6 -0
  4. package/dist/index.js +32 -0
  5. package/dist/loaders-gl-worker.js +82 -0
  6. package/dist/loaders-gl-worker.js.map +6 -0
  7. package/dist/map-logic.js +2 -0
  8. package/dist/map-logic.js.map +6 -0
  9. package/dist/projected-basemaps-worker.js +3 -0
  10. package/dist/projected-basemaps-worker.js.map +6 -0
  11. package/dist/shader-modules.js +141 -0
  12. package/dist/shader-modules.js.map +6 -0
  13. package/dist/style-schema.js +126 -0
  14. package/dist/style-schema.js.map +6 -0
  15. package/dist/tangram-style.schema.json +882 -0
  16. package/dist/tangram.debug.mjs +37139 -0
  17. package/dist/tangram.debug.mjs.map +6 -0
  18. package/dist/tangram.min.mjs +4950 -0
  19. package/dist/types/builders/earcut.d.ts +15 -0
  20. package/dist/types/core.d.ts +29 -0
  21. package/dist/types/gl/constants.d.ts +2 -0
  22. package/dist/types/gl/globe_mesh.d.ts +48 -0
  23. package/dist/types/gl/glsl.d.ts +17 -0
  24. package/dist/types/gl/vertex-constants.d.ts +4 -0
  25. package/dist/types/gl/vertex-types.d.ts +34 -0
  26. package/dist/types/gl/vertex_data.d.ts +32 -0
  27. package/dist/types/gl/vertex_elements.d.ts +8 -0
  28. package/dist/types/gl/vertex_layout.d.ts +32 -0
  29. package/dist/types/glsl.d.ts +14 -0
  30. package/dist/types/gpu/luma_device_renderer.d.ts +66 -0
  31. package/dist/types/gpu/resource_lifecycle.d.ts +4 -0
  32. package/dist/types/gpu/tangram_gpu_backend.d.ts +151 -0
  33. package/dist/types/index.d.ts +155 -0
  34. package/dist/types/lights/light-definitions.d.ts +121 -0
  35. package/dist/types/map-logic/draped-terrain-bounds.d.ts +41 -0
  36. package/dist/types/map-logic/globe-terrain-preparation.d.ts +85 -0
  37. package/dist/types/map-logic/globe-terrain.d.ts +54 -0
  38. package/dist/types/map-logic/index.d.ts +33 -0
  39. package/dist/types/map-logic/label-identity.d.ts +22 -0
  40. package/dist/types/map-logic/label-placement.d.ts +32 -0
  41. package/dist/types/map-logic/screen-bounds.d.ts +15 -0
  42. package/dist/types/map-logic/terrain-data.d.ts +55 -0
  43. package/dist/types/map-logic/terrain-error.d.ts +51 -0
  44. package/dist/types/map-logic/terrain-ground-topology.d.ts +26 -0
  45. package/dist/types/map-logic/terrain-height-field.d.ts +59 -0
  46. package/dist/types/map-logic/terrain-navigation.d.ts +27 -0
  47. package/dist/types/map-logic/terrain-neighborhood.d.ts +5 -0
  48. package/dist/types/map-logic/terrain-query.d.ts +33 -0
  49. package/dist/types/map-logic/terrain-resource-budget.d.ts +51 -0
  50. package/dist/types/map-logic/terrain-transition-topology.d.ts +23 -0
  51. package/dist/types/map-logic/tile-build-queue.d.ts +51 -0
  52. package/dist/types/map-logic/tile-cache-policy.d.ts +46 -0
  53. package/dist/types/map-logic/tile-residency.d.ts +17 -0
  54. package/dist/types/map-logic/triangle-query-index.d.ts +87 -0
  55. package/dist/types/procedures/js-yaml.d.ts +15 -0
  56. package/dist/types/procedures/mesh-projector.d.ts +107 -0
  57. package/dist/types/procedures/mvt-dependencies.d.ts +20 -0
  58. package/dist/types/procedures/projected-coordinate-transform.d.ts +27 -0
  59. package/dist/types/procedures/projection-batch-executor.d.ts +53 -0
  60. package/dist/types/procedures/scene-yaml-legacy.d.ts +6 -0
  61. package/dist/types/procedures/terrain-draping.d.ts +165 -0
  62. package/dist/types/procedures/terrain-globe.d.ts +6 -0
  63. package/dist/types/procedures/terrain-styled-topology.d.ts +34 -0
  64. package/dist/types/procedures/web-mercator-legacy.d.ts +4 -0
  65. package/dist/types/procedures/web-mercator-math.d.ts +4 -0
  66. package/dist/types/scene/globals.d.ts +11 -0
  67. package/dist/types/scene/ground_footprint.d.ts +16 -0
  68. package/dist/types/scene/host_frame.d.ts +54 -0
  69. package/dist/types/scene/projection_math.d.ts +52 -0
  70. package/dist/types/scene/scene-resource-types.d.ts +177 -0
  71. package/dist/types/scene/scene_bundle.d.ts +69 -0
  72. package/dist/types/scene/visibility_adapter.d.ts +106 -0
  73. package/dist/types/selection/draped-terrain-surface.d.ts +78 -0
  74. package/dist/types/selection/terrain_surface.d.ts +149 -0
  75. package/dist/types/shader-modules/globe-horizon.d.ts +15 -0
  76. package/dist/types/shader-modules/height-decode.d.ts +13 -0
  77. package/dist/types/shader-modules/hillshade.d.ts +13 -0
  78. package/dist/types/shader-modules/index.d.ts +6 -0
  79. package/dist/types/shader-modules/planar.d.ts +12 -0
  80. package/dist/types/shader-modules/sphere-map.d.ts +13 -0
  81. package/dist/types/shader-modules/triplanar.d.ts +15 -0
  82. package/dist/types/sources/decoded_tile_store.d.ts +95 -0
  83. package/dist/types/sources/tile_source_metadata.d.ts +32 -0
  84. package/dist/types/styles/text/fontfaceobserver.d.ts +10 -0
  85. package/dist/types/tile/tile_id.d.ts +37 -0
  86. package/dist/types/tile/tile_traversal_adapter.d.ts +63 -0
  87. package/dist/types/types.d.ts +293 -0
  88. package/dist/types/utils/geo.d.ts +57 -0
  89. package/dist/types/utils/hash.d.ts +1 -0
  90. package/dist/types/utils/log.d.ts +27 -0
  91. package/dist/types/utils/props.d.ts +6 -0
  92. package/dist/types/utils/subscribe.d.ts +10 -0
  93. package/dist/types/utils/thread.d.ts +6 -0
  94. package/dist/types/utils/urls.d.ts +26 -0
  95. package/dist/types/utils/utils.d.ts +26 -0
  96. package/dist/types/utils/version.d.ts +2 -0
  97. package/dist/types/utils/worker-types.d.ts +68 -0
  98. package/dist/types/utils/worker_broker.d.ts +3 -0
  99. package/package.json +103 -3
  100. package/src/builders/common.ts +41 -0
  101. package/src/builders/earcut.d.ts +15 -0
  102. package/src/builders/geometry-types.ts +60 -0
  103. package/src/builders/points.ts +115 -0
  104. package/src/builders/polygons.ts +225 -0
  105. package/src/builders/polylines.ts +682 -0
  106. package/src/builders/wireframe.ts +31 -0
  107. package/src/core.d.ts +29 -0
  108. package/src/core.ts +33 -0
  109. package/src/experimental/loaders-gl-worker.ts +19 -0
  110. package/src/experimental/projected-basemaps-worker.ts +13 -0
  111. package/src/experimental/projected-mesh-cache.ts +137 -0
  112. package/src/experimental/projected-mesh-domain.ts +110 -0
  113. package/src/experimental/projected-mesh-refinement.ts +193 -0
  114. package/src/experimental/projected-mesh.ts +399 -0
  115. package/src/experimental/projected-normal.ts +26 -0
  116. package/src/experimental/projected-symbol-mesh.ts +74 -0
  117. package/src/gl/constants.ts +18 -0
  118. package/src/gl/context.ts +103 -0
  119. package/src/gl/extensions.ts +30 -0
  120. package/src/gl/globe_mesh.ts +285 -0
  121. package/src/gl/glsl.ts +257 -0
  122. package/src/gl/mesh-types.ts +56 -0
  123. package/src/gl/render_state.ts +111 -0
  124. package/src/gl/shader_program.ts +1310 -0
  125. package/src/gl/texture.ts +814 -0
  126. package/src/gl/uniform_buffer.ts +340 -0
  127. package/src/gl/vao.ts +154 -0
  128. package/src/gl/vbo_mesh.ts +349 -0
  129. package/src/gl/vertex-constants.ts +19 -0
  130. package/src/gl/vertex-types.ts +35 -0
  131. package/src/gl/vertex_data.ts +126 -0
  132. package/src/gl/vertex_elements.ts +54 -0
  133. package/src/gl/vertex_layout.ts +241 -0
  134. package/src/glsl.d.ts +14 -0
  135. package/src/gpu/luma_device_renderer.ts +579 -0
  136. package/src/gpu/pixel_readback.ts +51 -0
  137. package/src/gpu/resource_lifecycle.ts +32 -0
  138. package/src/gpu/tangram_gpu_backend.ts +195 -0
  139. package/src/index.d.ts +155 -0
  140. package/src/index.ts +105 -0
  141. package/src/labels/collision-types.ts +94 -0
  142. package/src/labels/collision.ts +273 -0
  143. package/src/labels/collision_grid.ts +61 -0
  144. package/src/labels/intersect.ts +30 -0
  145. package/src/labels/label-types.ts +91 -0
  146. package/src/labels/label.ts +207 -0
  147. package/src/labels/label_line.ts +801 -0
  148. package/src/labels/label_point.ts +131 -0
  149. package/src/labels/main-pass-types.ts +73 -0
  150. package/src/labels/main_pass.ts +221 -0
  151. package/src/labels/point_anchor.ts +100 -0
  152. package/src/labels/point_placement.ts +150 -0
  153. package/src/labels/projected-pass.ts +259 -0
  154. package/src/labels/repeat_group.ts +72 -0
  155. package/src/lights/ambient_light.glsl +18 -0
  156. package/src/lights/directional_light.glsl +39 -0
  157. package/src/lights/geographic-lights.ts +21 -0
  158. package/src/lights/light-definitions.ts +285 -0
  159. package/src/lights/light.ts +590 -0
  160. package/src/lights/lighting-uniforms.ts +80 -0
  161. package/src/lights/lighting-wgsl.ts +116 -0
  162. package/src/lights/material.glsl +237 -0
  163. package/src/lights/material.ts +145 -0
  164. package/src/lights/native-falloff.ts +37 -0
  165. package/src/lights/point_light.glsl +96 -0
  166. package/src/lights/spot_light.glsl +111 -0
  167. package/src/map-logic/draped-terrain-bounds.ts +71 -0
  168. package/src/map-logic/globe-terrain-preparation.ts +217 -0
  169. package/src/map-logic/globe-terrain.ts +296 -0
  170. package/src/map-logic/index.ts +37 -0
  171. package/src/map-logic/label-identity.ts +36 -0
  172. package/src/map-logic/label-placement.ts +117 -0
  173. package/src/map-logic/screen-bounds.ts +34 -0
  174. package/src/map-logic/terrain-data.ts +107 -0
  175. package/src/map-logic/terrain-error.ts +134 -0
  176. package/src/map-logic/terrain-ground-topology.ts +164 -0
  177. package/src/map-logic/terrain-height-field.ts +254 -0
  178. package/src/map-logic/terrain-navigation.ts +50 -0
  179. package/src/map-logic/terrain-neighborhood.ts +43 -0
  180. package/src/map-logic/terrain-query.ts +51 -0
  181. package/src/map-logic/terrain-resource-budget.ts +124 -0
  182. package/src/map-logic/terrain-transition-topology.ts +164 -0
  183. package/src/map-logic/tile-build-queue.ts +110 -0
  184. package/src/map-logic/tile-cache-policy.ts +89 -0
  185. package/src/map-logic/tile-residency.ts +50 -0
  186. package/src/map-logic/triangle-query-index.ts +265 -0
  187. package/src/procedures/js-yaml.d.ts +15 -0
  188. package/src/procedures/mesh-projector.ts +191 -0
  189. package/src/procedures/mlt-loaders.ts +55 -0
  190. package/src/procedures/mvt-dependencies.d.ts +20 -0
  191. package/src/procedures/mvt-legacy.ts +150 -0
  192. package/src/procedures/mvt-loaders.ts +53 -0
  193. package/src/procedures/mvt-parser.ts +48 -0
  194. package/src/procedures/mvt-properties.ts +36 -0
  195. package/src/procedures/mvt-tile-provider.ts +72 -0
  196. package/src/procedures/pmtiles-loader.ts +75 -0
  197. package/src/procedures/projected-coordinate-transform.ts +79 -0
  198. package/src/procedures/projection-batch-executor.ts +140 -0
  199. package/src/procedures/scene-yaml-legacy.ts +16 -0
  200. package/src/procedures/scene-yaml-loaders.ts +10 -0
  201. package/src/procedures/terrain-draping.ts +713 -0
  202. package/src/procedures/terrain-globe.ts +32 -0
  203. package/src/procedures/terrain-styled-topology.ts +184 -0
  204. package/src/procedures/web-mercator-legacy.ts +24 -0
  205. package/src/procedures/web-mercator-math.ts +50 -0
  206. package/src/scene/camera.ts +298 -0
  207. package/src/scene/camera_base.ts +116 -0
  208. package/src/scene/classic_scene.ts +20 -0
  209. package/src/scene/external_camera.ts +101 -0
  210. package/src/scene/globals.ts +120 -0
  211. package/src/scene/ground_footprint.ts +139 -0
  212. package/src/scene/host_frame.ts +326 -0
  213. package/src/scene/projected_tile_lod.ts +125 -0
  214. package/src/scene/projection_math.ts +142 -0
  215. package/src/scene/projection_shaders.ts +183 -0
  216. package/src/scene/renderer.ts +516 -0
  217. package/src/scene/scene-resource-types.ts +174 -0
  218. package/src/scene/scene.ts +2378 -0
  219. package/src/scene/scene_bundle.ts +304 -0
  220. package/src/scene/scene_debug.ts +129 -0
  221. package/src/scene/scene_loader.ts +402 -0
  222. package/src/scene/scene_worker.ts +528 -0
  223. package/src/scene/view.ts +683 -0
  224. package/src/scene/visibility_adapter.ts +319 -0
  225. package/src/scene/worker_url.ts +15 -0
  226. package/src/selection/draped-terrain-surface.ts +377 -0
  227. package/src/selection/selection-types.ts +79 -0
  228. package/src/selection/selection.ts +542 -0
  229. package/src/selection/selection_fragment.glsl +18 -0
  230. package/src/selection/selection_globals.glsl +9 -0
  231. package/src/selection/selection_pixels.ts +59 -0
  232. package/src/selection/selection_vertex.glsl +15 -0
  233. package/src/selection/terrain_surface.ts +298 -0
  234. package/src/shader-modules/globe-horizon.ts +52 -0
  235. package/src/shader-modules/height-decode.ts +41 -0
  236. package/src/shader-modules/hillshade.ts +70 -0
  237. package/src/shader-modules/index.ts +10 -0
  238. package/src/shader-modules/planar.ts +24 -0
  239. package/src/shader-modules/sphere-map.ts +38 -0
  240. package/src/shader-modules/triplanar.ts +45 -0
  241. package/src/sources/aligned_tile_source.ts +122 -0
  242. package/src/sources/data_source.ts +655 -0
  243. package/src/sources/decoded_tile_store.ts +245 -0
  244. package/src/sources/geojson.ts +300 -0
  245. package/src/sources/mvt.ts +247 -0
  246. package/src/sources/raster.ts +341 -0
  247. package/src/sources/shared_tile_source_adapter.ts +117 -0
  248. package/src/sources/sources.ts +10 -0
  249. package/src/sources/tile_source_adapter.ts +84 -0
  250. package/src/sources/tile_source_metadata.ts +65 -0
  251. package/src/sources/tile_source_state.ts +112 -0
  252. package/src/sources/topojson.ts +90 -0
  253. package/src/styles/feature_annotations.ts +16 -0
  254. package/src/styles/filter.ts +190 -0
  255. package/src/styles/geometry-style-types.ts +209 -0
  256. package/src/styles/globe_visibility_wgsl.ts +22 -0
  257. package/src/styles/layer-types.ts +45 -0
  258. package/src/styles/layer.ts +586 -0
  259. package/src/styles/lines/dasharray.ts +49 -0
  260. package/src/styles/lines/lines.ts +707 -0
  261. package/src/styles/lines/lines_wgsl.ts +224 -0
  262. package/src/styles/points/point-runtime-types.ts +125 -0
  263. package/src/styles/points/points.ts +1079 -0
  264. package/src/styles/points/points_fragment.glsl +126 -0
  265. package/src/styles/points/points_vertex.glsl +230 -0
  266. package/src/styles/points/points_wgsl.ts +189 -0
  267. package/src/styles/polygons/polygons.ts +268 -0
  268. package/src/styles/polygons/polygons_fragment.glsl +173 -0
  269. package/src/styles/polygons/polygons_vertex.glsl +213 -0
  270. package/src/styles/polygons/polygons_wgsl.ts +127 -0
  271. package/src/styles/property-types.ts +125 -0
  272. package/src/styles/raster/raster.ts +33 -0
  273. package/src/styles/raster/raster_globals.glsl +46 -0
  274. package/src/styles/style-mixing-types.ts +101 -0
  275. package/src/styles/style-runtime-types.ts +220 -0
  276. package/src/styles/style-schema.ts +133 -0
  277. package/src/styles/style.ts +1033 -0
  278. package/src/styles/style_globals.glsl +69 -0
  279. package/src/styles/style_manager.ts +464 -0
  280. package/src/styles/style_parser.ts +620 -0
  281. package/src/styles/text/font_manager.ts +180 -0
  282. package/src/styles/text/fontfaceobserver.d.ts +10 -0
  283. package/src/styles/text/text-types.ts +220 -0
  284. package/src/styles/text/text.ts +378 -0
  285. package/src/styles/text/text_canvas.ts +773 -0
  286. package/src/styles/text/text_labels.ts +436 -0
  287. package/src/styles/text/text_segments.ts +142 -0
  288. package/src/styles/text/text_settings.ts +228 -0
  289. package/src/styles/text/text_wgsl.ts +159 -0
  290. package/src/styles/text/text_wrap.ts +194 -0
  291. package/src/tile/globe_tile_preload.ts +40 -0
  292. package/src/tile/tangram_tileset_2d.ts +108 -0
  293. package/src/tile/tile-build-types.ts +155 -0
  294. package/src/tile/tile.ts +807 -0
  295. package/src/tile/tile_id.ts +172 -0
  296. package/src/tile/tile_manager.ts +889 -0
  297. package/src/tile/tile_pyramid.ts +119 -0
  298. package/src/tile/tile_resource_cache.ts +91 -0
  299. package/src/tile/tile_traversal_adapter.ts +132 -0
  300. package/src/types.ts +332 -0
  301. package/src/utils/debounce.ts +17 -0
  302. package/src/utils/debug_settings.ts +43 -0
  303. package/src/utils/errors.ts +12 -0
  304. package/src/utils/functions.ts +95 -0
  305. package/src/utils/geo.ts +364 -0
  306. package/src/utils/hash.ts +14 -0
  307. package/src/utils/log.ts +108 -0
  308. package/src/utils/media_capture.ts +193 -0
  309. package/src/utils/merge.ts +44 -0
  310. package/src/utils/obb.ts +134 -0
  311. package/src/utils/props.ts +43 -0
  312. package/src/utils/slice.ts +14 -0
  313. package/src/utils/subscribe.ts +58 -0
  314. package/src/utils/task.ts +154 -0
  315. package/src/utils/thread.ts +26 -0
  316. package/src/utils/urls.ts +223 -0
  317. package/src/utils/utils.ts +310 -0
  318. package/src/utils/vector.ts +197 -0
  319. package/src/utils/version.ts +8 -0
  320. package/src/utils/worker-types.ts +79 -0
  321. package/src/utils/worker_broker.ts +523 -0
@@ -0,0 +1,378 @@
1
+ // Tangram
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2013-2016 Brett Camper and Mapzen
4
+ // Copyright (c) 2026 vis.gl contributors
5
+
6
+ // Text rendering style
7
+
8
+
9
+ import type {TextLabelRuntime} from './text_labels';
10
+ import type {TextTile, TextFeature, TextContext, TextLabelDraw, TextFeatureQueue, TextLabelCandidate, TextGeometry, TextRenderLabel, TextSprite} from './text-types';
11
+ import type {LabelLayout, LabelPointCoordinate} from '../../labels/label-types';
12
+ import Geo from '../../utils/geo';
13
+ import {Style} from '../style';
14
+ import {Points} from '../points/points';
15
+ import Collision from '../../labels/collision';
16
+ import LabelPoint from '../../labels/label_point';
17
+ import LabelLine from '../../labels/label_line';
18
+ import gl from '../../gl/constants'; // web workers don't have access to GL context, so import all GL constants
19
+ import VertexLayout from '../../gl/vertex_layout';
20
+ import {buildTextWGSL} from './text_wgsl';
21
+ import StyleParser from '../style_parser';
22
+ import {PACKED_HEIGHT_SCALE, packProjectedAnnotationHeight} from '../../gl/vertex-constants';
23
+
24
+ /** Mesh variant controlling static attributes and point/text shader layout. */
25
+ interface TextMeshVariant {
26
+ shader_point: boolean;
27
+ selection: boolean;
28
+ }
29
+ /** Mutable feature styling consumed by the inherited point quad builder. */
30
+ interface TextFeatureStyle {
31
+ /** Projected signed-short height, captured independently for each queued feature. */
32
+ z?: number;
33
+ label?: TextRenderLabel;
34
+ size?: LabelPointCoordinate | {straight?: LabelPointCoordinate; curved?: LabelPointCoordinate[]};
35
+ texcoords?: number[] | {straight?: TextSprite; curved?: TextSprite[]};
36
+ texcoords_stroke?: number[][];
37
+ label_texture?: string;
38
+ label_textures?: string[];
39
+ blend_order?: number;
40
+ }
41
+ /** Inherited mesh surface needed to populate a text vertex template. */
42
+ interface TextBuildMesh {
43
+ vertex_data: {vertex_layout: VertexLayout};
44
+ variant: import('../points/point-runtime-types').PointTemplateMesh['variant'];
45
+ }
46
+ /** Checked standalone-text style, extending only the point/style capabilities it consumes. */
47
+ export interface TextStyleRuntime extends TextLabelRuntime {
48
+ /** Optional worker terrain height field for geographic glyph anchors. */
49
+ terrain?: import('../../procedures/terrain-draping').TerrainDrapingSnapshot;
50
+ /** Optional anchor projection; screen-space glyph geometry remains unchanged. */
51
+ cpu_projection?: import('../../procedures/mesh-projector').ProjectedBasemapOptions;
52
+ /** Whether this is a built-in renderer style. */
53
+ built_in: boolean;
54
+ super: {makeVertexTemplate(this: TextStyleRuntime, style: TextFeatureStyle, mesh: TextBuildMesh, addCustom: boolean): number[]};
55
+ generation: number;
56
+ defines: Record<string, boolean | number | string>;
57
+ queues: Record<string, TextFeatureQueue[]>;
58
+ feature_style: TextFeatureStyle;
59
+ vertex_template: number[];
60
+ vertex_layouts: Record<string, VertexLayout>;
61
+ texture_id: number;
62
+ setupDefines(): void;
63
+ reset(): void;
64
+ queueFeature(feature: TextFeatureQueue, tile: TextTile): void;
65
+ addCustomAttributesToVertexTemplate(style: TextFeatureStyle, index: number): void;
66
+ addCustomAttributesToAttributeList(attributes: ConstructorParameters<typeof VertexLayout>[0]): void;
67
+ getBlendOrderForDraw(draw: TextLabelDraw): number;
68
+ buildLabels(size: LabelPointCoordinate | LabelPointCoordinate[], geometry: TextGeometry, layout: LabelLayout, totalSize?: LabelPointCoordinate): TextRenderLabel[];
69
+ buildLineLabels(line: LabelPointCoordinate[], size: LabelPointCoordinate | LabelPointCoordinate[], layout: LabelLayout, totalSize?: LabelPointCoordinate): TextRenderLabel[];
70
+ init(options?: import('../style-runtime-types').StyleInitOptions): void;
71
+ getWGSLShaderSource(selection?: boolean): string;
72
+ makeVertexTemplate(style: TextFeatureStyle, mesh: TextBuildMesh): number[];
73
+ addFeature(feature: TextFeature, draw: TextLabelDraw, context: TextContext): void;
74
+ endData(tile: TextTile): Promise<TextTileData | null>;
75
+ _preprocess(draw: TextLabelDraw): TextLabelDraw | undefined;
76
+ vertexLayoutForMeshVariant(variant: TextMeshVariant): VertexLayout;
77
+ }
78
+ /** Completed text tile mesh and texture ownership records. */
79
+ type TextTileData = import('../style-runtime-types').BuildTileData<Uint8Array>;
80
+ /** Existing prototype/mixin factory: inherited methods remain implemented by Points. */
81
+ export let TextStyle: TextStyleRuntime = Object.create(Points);
82
+
83
+ Object.assign(TextStyle, {
84
+ name: 'text',
85
+ super: Points,
86
+ built_in: true,
87
+
88
+ getWGSLShaderSource(this: TextStyleRuntime, selection = false) {
89
+ return buildTextWGSL(Boolean(this.cpu_projection), selection, Boolean(this.terrain));
90
+ },
91
+
92
+ init(this: TextStyleRuntime, options = {}) {
93
+ Style.init.call(this, options);
94
+
95
+ // Shader defines
96
+ this.setupDefines();
97
+
98
+ // Omit some code for SDF-drawn shader points
99
+ this.defines.TANGRAM_HAS_SHADER_POINTS = false;
100
+
101
+ // Indicate vertex shader should apply zoom-interpolated offsets and angles for curved labels
102
+ this.defines.TANGRAM_CURVED_LABEL = true;
103
+
104
+ this.reset();
105
+ },
106
+
107
+ /**
108
+ * A "template" that sets constant attibutes for each vertex, which is then modified per vertex or per feature.
109
+ * A plain JS array matching the order of the vertex layout.
110
+ */
111
+ makeVertexTemplate(this: TextStyleRuntime, style: TextFeatureStyle, mesh: TextBuildMesh) {
112
+ this.super.makeVertexTemplate.call(this, style, mesh, /* add_custom_attribs */ false);
113
+ let vertex_layout = mesh.vertex_data.vertex_layout;
114
+ let i = vertex_layout.index.a_pre_angles;
115
+
116
+ // a_pre_angles.xyzw - rotation of entire curved label
117
+ // a_angles.xyzw - angle of each curved label segment
118
+ // a_offsets.xyzw - offset of each curved label segment
119
+ for (let j=0; j < 12; j++) {
120
+ this.vertex_template[i++] = 0;
121
+ }
122
+
123
+ this.addCustomAttributesToVertexTemplate(style, i);
124
+ return this.vertex_template;
125
+ },
126
+
127
+ reset(this: TextStyleRuntime) {
128
+ this.queues = {};
129
+ this.resetText();
130
+ },
131
+
132
+ // Override to queue features instead of processing immediately
133
+ addFeature (this: TextStyleRuntime, feature: TextFeature, draw: TextLabelDraw, context: TextContext) {
134
+ let tile = context.tile;
135
+ if (tile.generation !== this.generation) {
136
+ return;
137
+ }
138
+ if (this.cpu_projection && !['Point', 'MultiPoint'].includes(feature.geometry.type)) {
139
+ throw new Error('Projected annotations require Point or MultiPoint source geometry');
140
+ }
141
+
142
+ let type = feature.geometry.type;
143
+ draw.can_articulate = (type === 'LineString' || type === 'MultiLineString');
144
+
145
+ // supersample text rendering for angled labels, to improve clarity
146
+ draw.supersample_text = (type === 'LineString' || type === 'MultiLineString');
147
+
148
+ let q = this.parseTextFeature(feature, draw, context, tile);
149
+ if (!q) {
150
+ return;
151
+ }
152
+ if (this.cpu_projection) {
153
+ const height = packProjectedAnnotationHeight(StyleParser.evalProjectedHeightProperty(draw.z, context),
154
+ this.cpu_projection.allowElevation) / PACKED_HEIGHT_SCALE;
155
+ for (const candidate of Array.isArray(q) ? q : [q]) candidate.layout.projected_height = height;
156
+ }
157
+
158
+ // text can be an array if a `left` or `right` orientation key is defined for the text source
159
+ // in which case, push both text sources to the queue
160
+ if (q instanceof Array){
161
+ q.forEach(q => {
162
+ q.feature = feature;
163
+ q.context = context;
164
+ q.layout.vertex = false; // vertex placement option not applicable to standalone labels
165
+ this.queueFeature(q as TextFeatureQueue, tile); // queue the feature for later processing
166
+ });
167
+ }
168
+ else {
169
+ q.feature = feature;
170
+ q.context = context;
171
+ q.layout.vertex = false; // vertex placement option not applicable to standalone labels
172
+ this.queueFeature(q as TextFeatureQueue, tile); // queue the feature for later processing
173
+ }
174
+
175
+ // Register with collision manager
176
+ Collision.addStyle(this.name, tile.id);
177
+ },
178
+
179
+ // Override
180
+ async endData (this: TextStyleRuntime, tile: TextTile) {
181
+ let queue = this.queues[tile.id];
182
+ delete this.queues[tile.id];
183
+
184
+ const { labels, texts, textures } = await this.collideAndRenderTextLabels(tile, this.name, queue);
185
+
186
+ if (labels && texts) {
187
+ this.texts[tile.id] = texts;
188
+
189
+ // Build queued features
190
+ labels.forEach(q => {
191
+ let text_settings_key = q.text_settings_key;
192
+ let text_info =
193
+ this.texts[tile.id][text_settings_key] &&
194
+ this.texts[tile.id][text_settings_key][q.text];
195
+
196
+ // setup styling object expected by Style class
197
+ let style = this.feature_style;
198
+ style.label = q.label;
199
+ if (this.cpu_projection) style.z = (q.layout.projected_height ?? 0) * PACKED_HEIGHT_SCALE;
200
+
201
+ if (text_info.text_settings.can_articulate){
202
+ // unpack logical sizes of each segment into an array for the style
203
+ style.size = {};
204
+ style.texcoords = {};
205
+
206
+ if (q.label.type === 'straight'){
207
+ style.size.straight = text_info.size!.logical_size;
208
+ style.texcoords.straight = text_info.texcoords!.straight!;
209
+ style.label_texture = textures![text_info.texcoords!.straight!.texture_id];
210
+ }
211
+ else{
212
+ style.size.curved = text_info.segment_sizes!.map(function(size){ return size.logical_size; });
213
+ style.texcoords_stroke = text_info.texcoords_stroke;
214
+ style.texcoords.curved = text_info.texcoords!.curved!;
215
+ style.label_textures = text_info.texcoords!.curved!.map(t => textures![t.texture_id]);
216
+ }
217
+ }
218
+ else {
219
+ style.size = text_info.size!.logical_size;
220
+ style.texcoords = text_info.align![q.label.align!].texcoords;
221
+ style.label_texture = textures![text_info.align![q.label.align!].texture_id!];
222
+ }
223
+
224
+ style.blend_order = q.draw.blend_order; // copy pre-computed blend order
225
+ Style.addFeature.call(this, q.feature, q.draw, q.context);
226
+ });
227
+ }
228
+ this.freeText(tile);
229
+
230
+ // Finish tile mesh
231
+ const tile_data = await Style.endData.call(this, tile);
232
+ if (tile_data) {
233
+ // Attach tile-specific label atlas to mesh as a texture uniform
234
+ if (textures && textures.length) {
235
+ tile_data.textures.push(...textures); // assign texture ownership to tile
236
+ }
237
+
238
+ // Always apply shader blocks to standalone text
239
+ for (let m in tile_data.meshes) {
240
+ const mesh = tile_data.meshes[m];
241
+ mesh.uniforms = mesh.uniforms || {};
242
+ mesh.uniforms.u_apply_color_blocks = true;
243
+ }
244
+ }
245
+
246
+ return tile_data;
247
+ },
248
+
249
+ // Sets up caching for draw properties
250
+ _preprocess (this: TextStyleRuntime, draw: TextLabelDraw) {
251
+ draw.blend_order = this.getBlendOrderForDraw(draw); // from draw block, or fall back on default style blend order
252
+ if (this.cpu_projection) draw.z = StyleParser.createProjectedHeightPropertyCache(draw.z);
253
+ return this.preprocessText(draw);
254
+ },
255
+
256
+ // Implements label building for TextLabels mixin
257
+ buildTextLabels (this: TextStyleRuntime, tile: TextTile, feature_queue: TextFeatureQueue[]): TextLabelCandidate[] {
258
+ let labels: TextLabelCandidate[] = [];
259
+ for (let f=0; f < feature_queue.length; f++) {
260
+ let fq = feature_queue[f];
261
+ let text_info = this.texts[tile.id][fq.text_settings_key][fq.text];
262
+ let feature_labels;
263
+
264
+ fq.layout.vertical_buffer = text_info.vertical_buffer!;
265
+
266
+ if (text_info.text_settings.can_articulate){
267
+ var sizes = text_info.segment_sizes!.map(size => size.collision_size);
268
+ fq.layout.no_curving = text_info.no_curving;
269
+ feature_labels = this.buildLabels(sizes, fq.feature.geometry, fq.layout, text_info.size!.collision_size);
270
+ }
271
+ else {
272
+ feature_labels = this.buildLabels(text_info.size!.collision_size, fq.feature.geometry, fq.layout);
273
+ }
274
+ for (let i = 0; i < feature_labels.length; i++) {
275
+ let fql: TextLabelCandidate = Object.create(fq);
276
+ fql.label = feature_labels[i];
277
+ labels.push(fql);
278
+ }
279
+ }
280
+ return labels;
281
+ },
282
+
283
+ // Builds one or more labels for a geometry
284
+ buildLabels (this: TextStyleRuntime, size: LabelPointCoordinate | LabelPointCoordinate[], geometry: TextGeometry, layout: LabelLayout, total_size?: LabelPointCoordinate): TextRenderLabel[] {
285
+ let labels: TextRenderLabel[] = [];
286
+
287
+ if (geometry.type === 'LineString') {
288
+ Array.prototype.push.apply(labels, this.buildLineLabels(geometry.coordinates, size, layout, total_size));
289
+ } else if (geometry.type === 'MultiLineString') {
290
+ let lines = geometry.coordinates;
291
+ for (let i = 0; i < lines.length; ++i) {
292
+ Array.prototype.push.apply(labels, this.buildLineLabels(lines[i], size, layout, total_size));
293
+ }
294
+ } else if (geometry.type === 'Point') {
295
+ labels.push(new LabelPoint(geometry.coordinates, size as LabelPointCoordinate, layout));
296
+ } else if (geometry.type === 'MultiPoint') {
297
+ let points = geometry.coordinates;
298
+ for (let i = 0; i < points.length; ++i) {
299
+ labels.push(new LabelPoint(points[i], size as LabelPointCoordinate, layout));
300
+ }
301
+ } else if (geometry.type === 'Polygon') {
302
+ let centroid = Geo.centroid(geometry.coordinates);
303
+ if (centroid) { // skip degenerate polygons
304
+ labels.push(new LabelPoint(centroid as LabelPointCoordinate, size as LabelPointCoordinate, layout));
305
+ }
306
+ } else if (geometry.type === 'MultiPolygon') {
307
+ let centroid = Geo.multiCentroid(geometry.coordinates);
308
+ if (centroid) { // skip degenerate polygons
309
+ labels.push(new LabelPoint(centroid as LabelPointCoordinate, size as LabelPointCoordinate, layout));
310
+ }
311
+ }
312
+
313
+ return labels;
314
+ },
315
+
316
+ // Build one or more labels for a line geometry
317
+ buildLineLabels (this: TextStyleRuntime, line: LabelPointCoordinate[], size: LabelPointCoordinate | LabelPointCoordinate[], layout: LabelLayout, total_size?: LabelPointCoordinate): TextRenderLabel[] {
318
+ let labels: TextRenderLabel[] = [];
319
+ let subdiv = Math.min(Number(layout.subdiv), line.length - 1);
320
+ if (subdiv > 1) {
321
+ // Create multiple labels for line, with each allotted a range of segments
322
+ // in which it will attempt to place
323
+ let seg_per_div = (line.length - 1) / subdiv;
324
+ for (let i = 0; i < subdiv; i++) {
325
+ let start = Math.floor(i * seg_per_div);
326
+ let end = Math.floor((i + 1) * seg_per_div) + 1;
327
+ let line_segment = line.slice(start, end);
328
+
329
+ let label = LabelLine.create(size, total_size, line_segment, layout);
330
+ if (label){
331
+ labels.push(label);
332
+ }
333
+ }
334
+ }
335
+
336
+ // Consider full line for label placement if no subdivisions requested, or as last resort if not enough
337
+ // labels placed (e.g. fewer than requested subdivisions)
338
+ // TODO: refactor multiple label placements per line / move into label placement class for better effectiveness
339
+ if (labels.length < subdiv) {
340
+ let label = LabelLine.create(size, total_size, line, layout);
341
+ if (label){
342
+ labels.push(label);
343
+ }
344
+ }
345
+ return labels;
346
+ },
347
+
348
+ // Override
349
+ // Create or return vertex layout
350
+ vertexLayoutForMeshVariant(this: TextStyleRuntime, variant: TextMeshVariant): VertexLayout {
351
+ // Vertex layout only depends on shader point flag, so using it as layout key to avoid duplicate layouts
352
+ if (this.vertex_layouts[variant.shader_point as unknown as string] == null) {
353
+ // TODO: could make selection, offset, and curved label attribs optional, but may not be worth it
354
+ // since text points generally don't consume much memory anyway
355
+ const attribs: ConstructorParameters<typeof VertexLayout>[0] = [
356
+ { name: 'a_position', size: 4, type: gl.SHORT, normalized: false },
357
+ { name: 'a_shape', size: 4, type: gl.SHORT, normalized: false },
358
+ { name: 'a_texcoord', size: 2, type: gl.UNSIGNED_SHORT, normalized: true },
359
+ { name: 'a_offset', size: 2, type: gl.SHORT, normalized: false },
360
+ { name: 'a_color', size: 4, type: gl.UNSIGNED_BYTE, normalized: true },
361
+ { name: 'a_selection_color', size: 4, type: gl.UNSIGNED_BYTE, normalized: true, static: (variant.selection ? null! : [0, 0, 0, 0]) },
362
+ { name: 'a_pre_angles', size: 4, type: gl.BYTE, normalized: false },
363
+ { name: 'a_angles', size: 4, type: gl.SHORT, normalized: false },
364
+ { name: 'a_offsets', size: 4, type: gl.UNSIGNED_SHORT, normalized: false },
365
+ ];
366
+
367
+ this.addCustomAttributesToAttributeList(attribs);
368
+ if (this.cpu_projection) attribs.push({name: 'a_projected_position', size: 3, type: gl.FLOAT, normalized: false});
369
+ this.vertex_layouts[variant.shader_point as unknown as string] = new VertexLayout(attribs);
370
+ }
371
+ return this.vertex_layouts[variant.shader_point as unknown as string];
372
+ },
373
+ } satisfies Pick<TextStyleRuntime,
374
+ 'name' | 'super' | 'built_in' | 'getWGSLShaderSource' | 'init' | 'makeVertexTemplate' |
375
+ 'reset' | 'addFeature' | 'endData' | '_preprocess' | 'buildTextLabels' | 'buildLabels' |
376
+ 'buildLineLabels' | 'vertexLayoutForMeshVariant'>);
377
+
378
+ TextStyle.texture_id = 0; // namespaces per-tile label textures