@tangram.gl/tangram-renderer 0.0.0-stage → 0.0.1

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 +60 -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,304 @@
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
+ import Utils from '../utils/utils';
7
+ import * as URLs from '../utils/urls';
8
+ import { isGlobalReference } from './globals';
9
+
10
+ import JSZip from 'jszip';
11
+ import {parseSceneYamlLegacy} from '../procedures/scene-yaml-legacy';
12
+ import type {SceneDefinition, SceneInput, SceneResourceDescriptor} from './scene-resource-types';
13
+
14
+ /** Extracted archive member and its lazily created browser URL. */
15
+ type SceneBundleFile = {data: ArrayBuffer; type: string | undefined; depth: number; url?: string};
16
+ type SceneBundleParent = SceneBundle | ZipSceneBundle | null;
17
+
18
+ /** Resolve resources relative to an authored scene, including nested archive imports. */
19
+ export class SceneBundle {
20
+
21
+ /** Scene URL or reusable in-memory definition. */
22
+ url: SceneInput;
23
+ /** Resource directory for this scene. */
24
+ path: string;
25
+ /** Authored directory used to resolve within an ancestor archive. */
26
+ path_for_parent: string;
27
+ /** Importing scene, if present. */
28
+ parent: SceneBundleParent;
29
+ /** Archive ancestor responsible for relative resources. */
30
+ container: SceneBundle | ZipSceneBundle | null;
31
+
32
+ /** Create a resource resolver without loading or validating its scene. */
33
+ constructor (url: SceneInput, path?: string | null, parent: SceneBundleParent = null) {
34
+ this.url = url;
35
+
36
+ // If a base path was provided, use it for resolving local bundle resources only if
37
+ // the base path is absolute, or this bundle's path is relative
38
+ if (path && (!URLs.isRelativeURL(path) || URLs.isRelativeURL(this.url))) {
39
+ this.path = path;
40
+ }
41
+ else {
42
+ this.path = URLs.pathForURL(this.url);
43
+ }
44
+
45
+ this.path_for_parent = path || this.path; // for resolving paths relative to a parent bundle
46
+ this.parent = parent;
47
+
48
+ // An ancestor bundle may be a container (e.g. zip file) that needs to resolve relative paths
49
+ // for any scenes it contains, e.g. `root.zip` has a `root.yaml` that includes a `folder/child.yaml`:
50
+ // resources within `child.yaml` must be resolved through the bundle for `root.zip`
51
+ this.container = null;
52
+ // Absolute imports leave the archive. Their own relative resources must
53
+ // resolve on the network, not through the importing ZIP container.
54
+ if (this.parent && URLs.isRelativeURL(this.path_for_parent)) {
55
+ if (this.parent.container) {
56
+ this.container = this.parent.container;
57
+ }
58
+ else if (this.parent.isContainer()) {
59
+ this.container = this.parent;
60
+ }
61
+ }
62
+ }
63
+
64
+ /** Load and parse URL data, or snapshot reusable object scene data. */
65
+ load (): Promise<SceneDefinition> {
66
+ return loadResource(this.url);
67
+ }
68
+
69
+ // Info for retrieving a specific resource from this bundle
70
+ // url: fully qualified URL to retrieve the content of the resource (e.g. zips will transform this to blob URL)
71
+ // path: original path of the resource within the bundle (for resolving paths up the bundle tree)
72
+ // type: file extension (used for determining bundle type, `yaml` or `zip`)
73
+ /** Return the network/blob URL and authored directory/format for an import. */
74
+ resourceFor (url: string): SceneResourceDescriptor {
75
+ return {
76
+ url: this.urlFor(url),
77
+ path: this.pathFor(url),
78
+ type: this.typeFor(url)
79
+ };
80
+ }
81
+
82
+ /** Resolve a resource URL, retaining globals and omitted URLs. */
83
+ urlFor (url: string | undefined): string | undefined {
84
+ if (isGlobalReference(url)) {
85
+ return url;
86
+ }
87
+
88
+ if (URLs.isRelativeURL(url) && this.container) {
89
+ return this.parent!.urlFor(this.path_for_parent + url);
90
+ }
91
+ return URLs.addBaseURL(url, this.path);
92
+ }
93
+
94
+ /** Return the authored directory before archive resolution changes the URL. */
95
+ pathFor (url: string): string {
96
+ return URLs.pathForURL(url);
97
+ }
98
+
99
+ /** Infer the resource format from its authored extension. */
100
+ typeFor (url: string): string | undefined {
101
+ return URLs.extensionForURL(url);
102
+ }
103
+
104
+ /** Ordinary scene files do not own an archive of resources. */
105
+ isContainer (): boolean {
106
+ return false;
107
+ }
108
+
109
+ }
110
+
111
+ /** ZIP scene with one root YAML member and lazy blob URLs for its resources. */
112
+ export class ZipSceneBundle extends SceneBundle {
113
+
114
+ /** Archive parser, initialized only when loading starts. */
115
+ zip: JSZip | null;
116
+ /** Non-directory members indexed by authored archive path. */
117
+ files: Record<string, SceneBundleFile>;
118
+ /** Root YAML path selected after archive inspection. */
119
+ root: string | null;
120
+
121
+ /** Create an archive resolver; loading remains explicit. */
122
+ constructor (url: SceneInput, path?: string | null, parent: SceneBundleParent = null) {
123
+ super(url, path, parent);
124
+ this.zip = null;
125
+ this.files = {};
126
+ this.root = null;
127
+ this.path = '';
128
+ }
129
+
130
+ /** Archive scenes own their relative resources. */
131
+ isContainer (): boolean {
132
+ return true;
133
+ }
134
+
135
+ /** Extract an URL-backed archive, retaining the legacy object-input fallback. */
136
+ async load (): Promise<SceneDefinition> {
137
+ this.zip = new JSZip();
138
+
139
+ if (typeof this.url === 'string') {
140
+ const { body } = await Utils.io(this.url, 60000, 'arraybuffer');
141
+ await this.zip.loadAsync(body as ArrayBuffer);
142
+ await this.parseZipFiles();
143
+ return this.loadRoot();
144
+ } else {
145
+ return this as unknown as SceneDefinition;
146
+ }
147
+ }
148
+
149
+ /** Resolve relative resources within the archive, or delegate external URLs. */
150
+ urlFor (url: string | undefined): string | undefined {
151
+ if (isGlobalReference(url)) {
152
+ return url;
153
+ }
154
+
155
+ if (URLs.isRelativeURL(url)) {
156
+ return this.urlForZipFile(URLs.flattenRelativeURL(url!));
157
+ }
158
+ return super.urlFor(url);
159
+ }
160
+
161
+ /** Infer an archive member's format without opening its blob URL. */
162
+ typeFor (url: string): string | undefined {
163
+ if (URLs.isRelativeURL(url)) {
164
+ return this.typeForZipFile(url);
165
+ }
166
+ return super.typeFor(url);
167
+ }
168
+
169
+ /** Load the unique root YAML file selected by findRoot. */
170
+ loadRoot (): Promise<SceneDefinition> {
171
+ this.findRoot();
172
+ return loadResource(this.urlForZipFile(this.root as string));
173
+ }
174
+
175
+ /** Select the unique root YAML file, rejecting missing or ambiguous roots. */
176
+ findRoot (): void {
177
+ // There must be a single YAML file at the top level of the zip
178
+ const yamls = Object.keys(this.files)
179
+ .filter(path => this.files[path].depth === 0)
180
+ .filter(path => URLs.extensionForURL(path) === 'yaml');
181
+
182
+ if (yamls.length === 1) {
183
+ this.root = yamls[0];
184
+ }
185
+
186
+ // No root found
187
+ if (!this.root) {
188
+ let msg = `Could not find root scene for bundle '${this.url}': `;
189
+ msg += 'The zip archive\'s root level must contain a single scene file with the \'.yaml\' extension. ';
190
+ if (yamls.length > 0) {
191
+ msg += `Found multiple YAML files at the root level: ${yamls.map(r => '\'' + r + '\'' ).join(', ')}.`;
192
+ }
193
+ else {
194
+ msg += 'Found NO YAML files at the root level.';
195
+ }
196
+ throw Error(msg);
197
+ }
198
+ }
199
+
200
+ /** Extract non-directory members while retaining depth and format metadata. */
201
+ async parseZipFiles (): Promise<void> {
202
+ let paths: string[] = [];
203
+ let queue: Promise<ArrayBuffer>[] = [];
204
+ this.zip!.forEach((path, file) => {
205
+ if (!file.dir) {
206
+ paths.push(path);
207
+ queue.push(file.async('arraybuffer'));
208
+ }
209
+ });
210
+
211
+ const data = await Promise.all(queue);
212
+ for (let i = 0; i < data.length; i++) {
213
+ let path = paths[i];
214
+ let depth = path.split('/').length - 1;
215
+ this.files[path] = {
216
+ data: data[i],
217
+ type: URLs.extensionForURL(path),
218
+ depth
219
+ };
220
+ }
221
+ }
222
+
223
+ /** Create or reuse a member's blob URL; missing members return undefined. */
224
+ urlForZipFile (file: string): string | undefined {
225
+ if (this.files[file]) {
226
+ if (!this.files[file].url) {
227
+ this.files[file].url = URLs.createObjectURL(new Blob([this.files[file].data])) as string;
228
+ }
229
+
230
+ return this.files[file].url;
231
+ }
232
+ }
233
+
234
+ /** Return a member's format, or undefined when the member is absent. */
235
+ typeForZipFile (file: string): string | undefined {
236
+ return this.files[file] && this.files[file].type;
237
+ }
238
+
239
+ }
240
+
241
+ /** Create a scene or zip bundle, inferring its path and parent when omitted. */
242
+ export function createSceneBundle (url: SceneInput, path?: string | null, parent: SceneBundleParent = null, type: string | null = null): SceneBundle | ZipSceneBundle {
243
+ if ((type != null && type === 'zip') ||
244
+ (typeof url === 'string' && !URLs.isLocalURL(url) && URLs.extensionForURL(url) === 'zip')) {
245
+ return new ZipSceneBundle(url, path, parent);
246
+ }
247
+ return new SceneBundle(url, path, parent);
248
+ }
249
+
250
+ /** Interpret parser output as scene data; this boundary does not add schema validation. */
251
+ function parseResource (body: string): SceneDefinition {
252
+ return parseSceneYamlLegacy(body) as SceneDefinition;
253
+ }
254
+
255
+ /** Load authored YAML or snapshot object definitions before mutating their resource paths. */
256
+ function loadResource (source: SceneInput | undefined): Promise<SceneDefinition> {
257
+ return new Promise((resolve, reject) => {
258
+ if (typeof source === 'string') {
259
+ Utils.io(source).then(({ body }) => {
260
+ try {
261
+ resolve(parseResource(body as string));
262
+ }
263
+ catch(e) {
264
+ reject(e);
265
+ }
266
+ }, reject);
267
+ } else {
268
+ // Normalization changes nested URLs and globals, not just the root.
269
+ // Keep editor documents reusable across loads with different bases.
270
+ resolve(cloneSceneValue(source) as SceneDefinition);
271
+ }
272
+ });
273
+ }
274
+
275
+ /** Snapshot enumerable scene data and URL accessors, leaving unrelated class internals alone. */
276
+ function cloneSceneValue(value: unknown, copies = new WeakMap<object, object>()): unknown {
277
+ if (!value || (!Array.isArray(value) && Object.prototype.toString.call(value) !== '[object Object]')) {
278
+ return value;
279
+ }
280
+ const original = value as object; // Arrays and object-tag records passed the snapshot boundary above.
281
+ if (copies.has(original)) return copies.get(original);
282
+
283
+ // Class definitions become writable scene data. Keeping their prototype
284
+ // would attach getters to an instance with no private fields. Read scene
285
+ // accessors on the original without invoking its setters. URL getters are
286
+ // supported even when non-enumerable; arbitrary non-enumerable accessors
287
+ // are application internals, not scene data, and must not be evaluated.
288
+ const copy: object = Array.isArray(value) ? new Array<unknown>(value.length) :
289
+ Object.create(Object.getPrototypeOf(value) === null ? null : Object.prototype);
290
+ copies.set(original, copy);
291
+ const keys = new Set<string>();
292
+ for (const key in original) keys.add(key);
293
+ for (let owner = original; owner && owner !== Object.prototype; owner = Object.getPrototypeOf(owner)) {
294
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(owner))) {
295
+ if (descriptor.get && (descriptor.enumerable || key === 'url')) keys.add(key);
296
+ }
297
+ }
298
+ for (const key of keys) {
299
+ Object.defineProperty(copy, key, {
300
+ value: cloneSceneValue((value as Record<string, unknown>)[key], copies), enumerable: true, writable: true, configurable: true
301
+ });
302
+ }
303
+ return copy;
304
+ }
@@ -0,0 +1,129 @@
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
+ import log from '../utils/log';
7
+ import WorkerBroker from '../utils/worker_broker';
8
+ import debugSettings from '../utils/debug_settings';
9
+ import { debugSumLayerStats } from '../tile/tile';
10
+ import Texture from '../gl/texture';
11
+
12
+ // Debug config and functions
13
+ export default function setupSceneDebug (scene: any): void {
14
+ scene.debug = {
15
+ // Profile helpers, issues a profile on main thread & all workers
16
+ profile(name: string): void {
17
+ console.profile(`main thread: ${name}`); // eslint-disable-line no-console
18
+ WorkerBroker.postMessage(scene.workers, 'self.profile', name);
19
+ },
20
+
21
+ profileEnd(name: string): void {
22
+ console.profileEnd(`main thread: ${name}`); // eslint-disable-line no-console
23
+ WorkerBroker.postMessage(scene.workers, 'self.profileEnd', name);
24
+ },
25
+
26
+ // Rebuild geometry a given # of times and print average, min, max timings
27
+ timeRebuild (num = 1, options: any = {}): void {
28
+ const times: number[] = [];
29
+ const cycle = (): void => {
30
+ let start = +new Date();
31
+ scene.rebuild(options).then(() => {
32
+ times.push(+new Date() - start);
33
+
34
+ if (times.length < num) {
35
+ cycle();
36
+ }
37
+ else {
38
+ let avg = ~~(times.reduce((a, b) => a + b) / times.length);
39
+ log('info', `Profiled rebuild ${num} times: ${avg} avg (${Math.min(...times)} min, ${Math.max(...times)} max)`);
40
+ }
41
+ });
42
+ };
43
+ cycle();
44
+ },
45
+
46
+ // Return geometry counts of visible tiles, grouped by style name
47
+ geometryCountByStyle (): Record<string, number> {
48
+ const counts: Record<string, number> = {};
49
+ scene.tile_manager.getRenderableTiles().forEach((tile: any) => {
50
+ for (let style in tile.meshes) {
51
+ counts[style] = counts[style] || 0;
52
+ tile.meshes[style].forEach((mesh: any) => {
53
+ counts[style] += mesh.geometry_count;
54
+ });
55
+ }
56
+ });
57
+ return counts;
58
+ },
59
+
60
+ // Return geometry counts of visible tiles, grouped by base style name
61
+ geometryCountByBaseStyle (): Record<string, number> {
62
+ let style_counts = scene.debug.geometryCountByStyle();
63
+ const counts: Record<string, number> = {};
64
+ for (let style in style_counts) {
65
+ let base = scene.styles[style].baseStyle();
66
+ counts[base] = counts[base] || 0;
67
+ counts[base] += style_counts[style];
68
+ }
69
+ return counts;
70
+ },
71
+
72
+ // Return sum of all geometry counts for visible tiles
73
+ geometryCountTotal () {
74
+ const styles = scene.debug.geometryCountByStyle();
75
+ return Object.keys(styles).reduce((p, c) => styles[c] + p, 0);
76
+ },
77
+
78
+ // Return geometry GL buffer sizes for visible tiles, grouped by style name
79
+ geometrySizeByStyle (): Record<string, number> {
80
+ const sizes: Record<string, number> = {};
81
+ scene.tile_manager.getRenderableTiles().forEach((tile: any) => {
82
+ for (let style in tile.meshes) {
83
+ sizes[style] = sizes[style] || 0;
84
+ tile.meshes[style].forEach((mesh: any) => {
85
+ sizes[style] += mesh.buffer_size;
86
+ });
87
+ }
88
+ });
89
+ return sizes;
90
+ },
91
+
92
+ // Return geometry GL buffer sizes for visible tiles, grouped by base style name
93
+ geometrySizeByBaseStyle (): Record<string, number> {
94
+ let style_sizes = scene.debug.geometrySizeByStyle();
95
+ const sizes: Record<string, number> = {};
96
+ for (let style in style_sizes) {
97
+ let base = scene.styles[style].baseStyle();
98
+ sizes[base] = sizes[base] || 0;
99
+ sizes[base] += style_sizes[style];
100
+ }
101
+ return sizes;
102
+ },
103
+
104
+ // Return sum of all geometry GL buffer sizes for visible tiles
105
+ geometrySizeTotal () {
106
+ const styles = scene.debug.geometrySizeByStyle();
107
+ return Object.keys(styles).reduce((p, c) => styles[c] + p, 0);
108
+ },
109
+
110
+ // Return sum of all texture memory usage
111
+ textureSizeTotal() {
112
+ return Object.values((Texture as any).textures).map((t: any) => t.byteSize()).reduce((p, c) => p + c);
113
+ },
114
+
115
+ layerStats (): Record<string, any> {
116
+ if (debugSettings.layer_stats) {
117
+ return debugSumLayerStats(scene.tile_manager.getRenderableTiles());
118
+ }
119
+ else {
120
+ log('warn', 'Enable the \'layer_stats\' debug setting to collect layer stats');
121
+ return {};
122
+ }
123
+ },
124
+
125
+ renderableTilesCount (): number {
126
+ return scene.tile_manager.getRenderableTiles().length;
127
+ }
128
+ };
129
+ }