@react-x11/components 0.8.0 → 0.9.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 (323) hide show
  1. package/README.md +95 -34
  2. package/dist/charts/node.d.ts +1 -1
  3. package/dist/charts/node.d.ts.map +1 -1
  4. package/dist/charts/node.js +6 -2
  5. package/dist/charts/node.js.map +1 -1
  6. package/dist/embed/client.d.ts +48 -3
  7. package/dist/embed/client.d.ts.map +1 -1
  8. package/dist/embed/client.js +79 -5
  9. package/dist/embed/client.js.map +1 -1
  10. package/dist/embed/index.d.ts +1 -1
  11. package/dist/embed/index.d.ts.map +1 -1
  12. package/dist/embed/index.js +1 -1
  13. package/dist/embed/index.js.map +1 -1
  14. package/dist/html/node.d.ts +3 -1
  15. package/dist/html/node.d.ts.map +1 -1
  16. package/dist/html/node.js +7 -5
  17. package/dist/html/node.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/{markdown → internal/markdown}/ast.d.ts +12 -0
  23. package/dist/internal/markdown/ast.d.ts.map +1 -0
  24. package/dist/internal/markdown/ast.js +22 -0
  25. package/dist/internal/markdown/ast.js.map +1 -0
  26. package/dist/internal/markdown/parse.d.ts.map +1 -0
  27. package/dist/{markdown → internal/markdown}/parse.js +112 -22
  28. package/dist/internal/markdown/parse.js.map +1 -0
  29. package/dist/internal/markdown/stringify.d.ts +4 -0
  30. package/dist/internal/markdown/stringify.d.ts.map +1 -0
  31. package/dist/internal/markdown/stringify.js +684 -0
  32. package/dist/internal/markdown/stringify.js.map +1 -0
  33. package/dist/internal/markdown/tags.d.ts.map +1 -0
  34. package/dist/internal/markdown/tags.js.map +1 -0
  35. package/dist/internal/scroll.d.ts +3 -2
  36. package/dist/internal/scroll.d.ts.map +1 -1
  37. package/dist/internal/scroll.js +1 -0
  38. package/dist/internal/scroll.js.map +1 -1
  39. package/dist/maps/anchors.d.ts +98 -0
  40. package/dist/maps/anchors.d.ts.map +1 -0
  41. package/dist/maps/anchors.js +531 -0
  42. package/dist/maps/anchors.js.map +1 -0
  43. package/dist/maps/controller.d.ts +283 -0
  44. package/dist/maps/controller.d.ts.map +1 -0
  45. package/dist/maps/controller.js +743 -0
  46. package/dist/maps/controller.js.map +1 -0
  47. package/dist/maps/gl/buckets.d.ts +95 -0
  48. package/dist/maps/gl/buckets.d.ts.map +1 -0
  49. package/dist/maps/gl/buckets.js +362 -0
  50. package/dist/maps/gl/buckets.js.map +1 -0
  51. package/dist/maps/gl/build-worker.d.ts +13 -0
  52. package/dist/maps/gl/build-worker.d.ts.map +1 -0
  53. package/dist/maps/gl/build-worker.js +44 -0
  54. package/dist/maps/gl/build-worker.js.map +1 -0
  55. package/dist/maps/gl/color.d.ts +8 -0
  56. package/dist/maps/gl/color.d.ts.map +1 -0
  57. package/dist/maps/gl/color.js +57 -0
  58. package/dist/maps/gl/color.js.map +1 -0
  59. package/dist/maps/gl/cover.d.ts +51 -0
  60. package/dist/maps/gl/cover.d.ts.map +1 -0
  61. package/dist/maps/gl/cover.js +124 -0
  62. package/dist/maps/gl/cover.js.map +1 -0
  63. package/dist/maps/gl/index.d.ts +3 -0
  64. package/dist/maps/gl/index.d.ts.map +1 -0
  65. package/dist/maps/gl/index.js +20 -0
  66. package/dist/maps/gl/index.js.map +1 -0
  67. package/dist/maps/gl/markers.d.ts +28 -0
  68. package/dist/maps/gl/markers.d.ts.map +1 -0
  69. package/dist/maps/gl/markers.js +60 -0
  70. package/dist/maps/gl/markers.js.map +1 -0
  71. package/dist/maps/gl/overlays.d.ts +68 -0
  72. package/dist/maps/gl/overlays.d.ts.map +1 -0
  73. package/dist/maps/gl/overlays.js +300 -0
  74. package/dist/maps/gl/overlays.js.map +1 -0
  75. package/dist/maps/gl/pane.d.ts +12 -0
  76. package/dist/maps/gl/pane.d.ts.map +1 -0
  77. package/dist/maps/gl/pane.js +37 -0
  78. package/dist/maps/gl/pane.js.map +1 -0
  79. package/dist/maps/gl/placement.d.ts +111 -0
  80. package/dist/maps/gl/placement.d.ts.map +1 -0
  81. package/dist/maps/gl/placement.js +567 -0
  82. package/dist/maps/gl/placement.js.map +1 -0
  83. package/dist/maps/gl/renderer.d.ts +352 -0
  84. package/dist/maps/gl/renderer.d.ts.map +1 -0
  85. package/dist/maps/gl/renderer.js +1127 -0
  86. package/dist/maps/gl/renderer.js.map +1 -0
  87. package/dist/maps/gl/shaders.d.ts +120 -0
  88. package/dist/maps/gl/shaders.d.ts.map +1 -0
  89. package/dist/maps/gl/shaders.js +451 -0
  90. package/dist/maps/gl/shaders.js.map +1 -0
  91. package/dist/maps/gl/store.d.ts +115 -0
  92. package/dist/maps/gl/store.d.ts.map +1 -0
  93. package/dist/maps/gl/store.js +469 -0
  94. package/dist/maps/gl/store.js.map +1 -0
  95. package/dist/maps/gl/text.d.ts +154 -0
  96. package/dist/maps/gl/text.d.ts.map +1 -0
  97. package/dist/maps/gl/text.js +382 -0
  98. package/dist/maps/gl/text.js.map +1 -0
  99. package/dist/maps/gl/view.d.ts +54 -0
  100. package/dist/maps/gl/view.d.ts.map +1 -0
  101. package/dist/maps/gl/view.js +974 -0
  102. package/dist/maps/gl/view.js.map +1 -0
  103. package/dist/maps/index.d.ts +1 -1
  104. package/dist/maps/index.d.ts.map +1 -1
  105. package/dist/maps/index.js +216 -52
  106. package/dist/maps/index.js.map +1 -1
  107. package/dist/maps/labels.d.ts +37 -16
  108. package/dist/maps/labels.d.ts.map +1 -1
  109. package/dist/maps/labels.js +188 -119
  110. package/dist/maps/labels.js.map +1 -1
  111. package/dist/maps/node.d.ts +162 -56
  112. package/dist/maps/node.d.ts.map +1 -1
  113. package/dist/maps/node.js +607 -515
  114. package/dist/maps/node.js.map +1 -1
  115. package/dist/maps/overlay.d.ts +72 -9
  116. package/dist/maps/overlay.d.ts.map +1 -1
  117. package/dist/maps/overlay.js +108 -28
  118. package/dist/maps/overlay.js.map +1 -1
  119. package/dist/maps/paint.d.ts +3 -0
  120. package/dist/maps/paint.d.ts.map +1 -1
  121. package/dist/maps/paint.js.map +1 -1
  122. package/dist/maps/proj.d.ts +14 -0
  123. package/dist/maps/proj.d.ts.map +1 -1
  124. package/dist/maps/proj.js +28 -0
  125. package/dist/maps/proj.js.map +1 -1
  126. package/dist/maps/renderer.d.ts +69 -0
  127. package/dist/maps/renderer.d.ts.map +1 -0
  128. package/dist/maps/renderer.js +66 -0
  129. package/dist/maps/renderer.js.map +1 -0
  130. package/dist/maps/sources.d.ts +25 -3
  131. package/dist/maps/sources.d.ts.map +1 -1
  132. package/dist/maps/sources.js +17 -0
  133. package/dist/maps/sources.js.map +1 -1
  134. package/dist/maps/theme.d.ts +19 -0
  135. package/dist/maps/theme.d.ts.map +1 -0
  136. package/dist/maps/theme.js +44 -0
  137. package/dist/maps/theme.js.map +1 -0
  138. package/dist/maps/tiles.d.ts +117 -17
  139. package/dist/maps/tiles.d.ts.map +1 -1
  140. package/dist/maps/tiles.js +163 -30
  141. package/dist/maps/tiles.js.map +1 -1
  142. package/dist/maps/types.d.ts +188 -20
  143. package/dist/maps/types.d.ts.map +1 -1
  144. package/dist/markdown/expressions.d.ts +1 -1
  145. package/dist/markdown/expressions.d.ts.map +1 -1
  146. package/dist/markdown/expressions.js.map +1 -1
  147. package/dist/markdown/index.d.ts +7 -6
  148. package/dist/markdown/index.d.ts.map +1 -1
  149. package/dist/markdown/index.js +9 -7
  150. package/dist/markdown/index.js.map +1 -1
  151. package/dist/markdown/spans.d.ts +1 -1
  152. package/dist/markdown/spans.d.ts.map +1 -1
  153. package/dist/media-player/index.d.ts +11 -3
  154. package/dist/media-player/index.d.ts.map +1 -1
  155. package/dist/media-player/index.js +13 -2
  156. package/dist/media-player/index.js.map +1 -1
  157. package/dist/rich-text-editor/clipboard.d.ts +23 -0
  158. package/dist/rich-text-editor/clipboard.d.ts.map +1 -0
  159. package/dist/rich-text-editor/clipboard.js +307 -0
  160. package/dist/rich-text-editor/clipboard.js.map +1 -0
  161. package/dist/rich-text-editor/collab.d.ts +32 -0
  162. package/dist/rich-text-editor/collab.d.ts.map +1 -0
  163. package/dist/rich-text-editor/collab.js +55 -0
  164. package/dist/rich-text-editor/collab.js.map +1 -0
  165. package/dist/rich-text-editor/commands.d.ts +50 -0
  166. package/dist/rich-text-editor/commands.d.ts.map +1 -0
  167. package/dist/rich-text-editor/commands.js +376 -0
  168. package/dist/rich-text-editor/commands.js.map +1 -0
  169. package/dist/rich-text-editor/drag.d.ts +68 -0
  170. package/dist/rich-text-editor/drag.d.ts.map +1 -0
  171. package/dist/rich-text-editor/drag.js +148 -0
  172. package/dist/rich-text-editor/drag.js.map +1 -0
  173. package/dist/rich-text-editor/html.d.ts +145 -0
  174. package/dist/rich-text-editor/html.d.ts.map +1 -0
  175. package/dist/rich-text-editor/html.js +516 -0
  176. package/dist/rich-text-editor/html.js.map +1 -0
  177. package/dist/rich-text-editor/index.d.ts +263 -0
  178. package/dist/rich-text-editor/index.d.ts.map +1 -0
  179. package/dist/rich-text-editor/index.js +822 -0
  180. package/dist/rich-text-editor/index.js.map +1 -0
  181. package/dist/rich-text-editor/inline.d.ts +94 -0
  182. package/dist/rich-text-editor/inline.d.ts.map +1 -0
  183. package/dist/rich-text-editor/inline.js +252 -0
  184. package/dist/rich-text-editor/inline.js.map +1 -0
  185. package/dist/rich-text-editor/keymap.d.ts +71 -0
  186. package/dist/rich-text-editor/keymap.d.ts.map +1 -0
  187. package/dist/rich-text-editor/keymap.js +393 -0
  188. package/dist/rich-text-editor/keymap.js.map +1 -0
  189. package/dist/rich-text-editor/keys.d.ts +29 -0
  190. package/dist/rich-text-editor/keys.d.ts.map +1 -0
  191. package/dist/rich-text-editor/keys.js +93 -0
  192. package/dist/rich-text-editor/keys.js.map +1 -0
  193. package/dist/rich-text-editor/look.d.ts +71 -0
  194. package/dist/rich-text-editor/look.d.ts.map +1 -0
  195. package/dist/rich-text-editor/look.js +342 -0
  196. package/dist/rich-text-editor/look.js.map +1 -0
  197. package/dist/rich-text-editor/markdown.d.ts +18 -0
  198. package/dist/rich-text-editor/markdown.d.ts.map +1 -0
  199. package/dist/rich-text-editor/markdown.js +496 -0
  200. package/dist/rich-text-editor/markdown.js.map +1 -0
  201. package/dist/rich-text-editor/nodes.d.ts +135 -0
  202. package/dist/rich-text-editor/nodes.d.ts.map +1 -0
  203. package/dist/rich-text-editor/nodes.js +397 -0
  204. package/dist/rich-text-editor/nodes.js.map +1 -0
  205. package/dist/rich-text-editor/render.d.ts +68 -0
  206. package/dist/rich-text-editor/render.d.ts.map +1 -0
  207. package/dist/rich-text-editor/render.js +500 -0
  208. package/dist/rich-text-editor/render.js.map +1 -0
  209. package/dist/rich-text-editor/schema.d.ts +16 -0
  210. package/dist/rich-text-editor/schema.d.ts.map +1 -0
  211. package/dist/rich-text-editor/schema.js +386 -0
  212. package/dist/rich-text-editor/schema.js.map +1 -0
  213. package/dist/rich-text-editor/store.d.ts +11 -0
  214. package/dist/rich-text-editor/store.d.ts.map +1 -0
  215. package/dist/rich-text-editor/store.js +43 -0
  216. package/dist/rich-text-editor/store.js.map +1 -0
  217. package/dist/rich-text-editor/suggest.d.ts +127 -0
  218. package/dist/rich-text-editor/suggest.d.ts.map +1 -0
  219. package/dist/rich-text-editor/suggest.js +0 -0
  220. package/dist/rich-text-editor/suggest.js.map +1 -0
  221. package/dist/rich-text-editor/tables.d.ts +41 -0
  222. package/dist/rich-text-editor/tables.d.ts.map +1 -0
  223. package/dist/rich-text-editor/tables.js +204 -0
  224. package/dist/rich-text-editor/tables.js.map +1 -0
  225. package/dist/rich-text-editor/toolbar.d.ts +58 -0
  226. package/dist/rich-text-editor/toolbar.d.ts.map +1 -0
  227. package/dist/rich-text-editor/toolbar.js +548 -0
  228. package/dist/rich-text-editor/toolbar.js.map +1 -0
  229. package/dist/rich-text-editor/view.d.ts +368 -0
  230. package/dist/rich-text-editor/view.d.ts.map +1 -0
  231. package/dist/rich-text-editor/view.js +1968 -0
  232. package/dist/rich-text-editor/view.js.map +1 -0
  233. package/dist/rich-text-editor/virtual.d.ts +54 -0
  234. package/dist/rich-text-editor/virtual.d.ts.map +1 -0
  235. package/dist/rich-text-editor/virtual.js +262 -0
  236. package/dist/rich-text-editor/virtual.js.map +1 -0
  237. package/dist/richtext/node.d.ts +25 -2
  238. package/dist/richtext/node.d.ts.map +1 -1
  239. package/dist/richtext/node.js +46 -24
  240. package/dist/richtext/node.js.map +1 -1
  241. package/dist/terminal/backends.d.ts +4 -1
  242. package/dist/terminal/backends.d.ts.map +1 -1
  243. package/dist/terminal/backends.js.map +1 -1
  244. package/dist/terminal/index.d.ts +18 -7
  245. package/dist/terminal/index.d.ts.map +1 -1
  246. package/dist/terminal/index.js +28 -11
  247. package/dist/terminal/index.js.map +1 -1
  248. package/package.json +23 -4
  249. package/src/charts/node.ts +6 -2
  250. package/src/embed/client.ts +102 -8
  251. package/src/embed/index.ts +2 -0
  252. package/src/html/node.ts +7 -5
  253. package/src/index.ts +2 -0
  254. package/src/{markdown → internal/markdown}/ast.ts +24 -7
  255. package/src/{markdown → internal/markdown}/parse.ts +134 -24
  256. package/src/internal/markdown/stringify.ts +772 -0
  257. package/src/internal/scroll.ts +5 -3
  258. package/src/maps/anchors.ts +607 -0
  259. package/src/maps/controller.ts +999 -0
  260. package/src/maps/gl/buckets.ts +457 -0
  261. package/src/maps/gl/build-worker.ts +55 -0
  262. package/src/maps/gl/color.ts +62 -0
  263. package/src/maps/gl/cover.ts +170 -0
  264. package/src/maps/gl/index.ts +23 -0
  265. package/src/maps/gl/markers.ts +83 -0
  266. package/src/maps/gl/overlays.ts +379 -0
  267. package/src/maps/gl/pane.ts +42 -0
  268. package/src/maps/gl/placement.ts +816 -0
  269. package/src/maps/gl/renderer.ts +1576 -0
  270. package/src/maps/gl/shaders.ts +486 -0
  271. package/src/maps/gl/store.ts +566 -0
  272. package/src/maps/gl/text.ts +495 -0
  273. package/src/maps/gl/view.ts +1224 -0
  274. package/src/maps/index.ts +270 -81
  275. package/src/maps/labels.ts +214 -121
  276. package/src/maps/node.ts +763 -629
  277. package/src/maps/overlay.ts +148 -43
  278. package/src/maps/paint.ts +3 -0
  279. package/src/maps/proj.ts +31 -0
  280. package/src/maps/renderer.ts +155 -0
  281. package/src/maps/sources.ts +38 -3
  282. package/src/maps/theme.ts +51 -0
  283. package/src/maps/tiles.ts +191 -33
  284. package/src/maps/types.ts +188 -20
  285. package/src/markdown/expressions.ts +5 -1
  286. package/src/markdown/index.ts +14 -11
  287. package/src/markdown/spans.ts +1 -1
  288. package/src/media-player/index.ts +18 -4
  289. package/src/rich-text-editor/clipboard.ts +439 -0
  290. package/src/rich-text-editor/collab.ts +91 -0
  291. package/src/rich-text-editor/commands.ts +448 -0
  292. package/src/rich-text-editor/dom-globals.d.ts +23 -0
  293. package/src/rich-text-editor/drag.ts +211 -0
  294. package/src/rich-text-editor/html.ts +619 -0
  295. package/src/rich-text-editor/index.ts +1331 -0
  296. package/src/rich-text-editor/inline.ts +345 -0
  297. package/src/rich-text-editor/keymap.ts +510 -0
  298. package/src/rich-text-editor/keys.ts +119 -0
  299. package/src/rich-text-editor/look.ts +427 -0
  300. package/src/rich-text-editor/markdown.ts +653 -0
  301. package/src/rich-text-editor/nodes.ts +497 -0
  302. package/src/rich-text-editor/render.ts +800 -0
  303. package/src/rich-text-editor/schema.ts +431 -0
  304. package/src/rich-text-editor/store.ts +39 -0
  305. package/src/rich-text-editor/suggest.ts +597 -0
  306. package/src/rich-text-editor/tables.ts +272 -0
  307. package/src/rich-text-editor/toolbar.ts +724 -0
  308. package/src/rich-text-editor/view.ts +2287 -0
  309. package/src/rich-text-editor/virtual.ts +347 -0
  310. package/src/richtext/node.ts +59 -30
  311. package/src/terminal/backends.ts +4 -1
  312. package/src/terminal/index.ts +43 -15
  313. package/dist/markdown/ast.d.ts.map +0 -1
  314. package/dist/markdown/ast.js +0 -17
  315. package/dist/markdown/ast.js.map +0 -1
  316. package/dist/markdown/parse.d.ts.map +0 -1
  317. package/dist/markdown/parse.js.map +0 -1
  318. package/dist/markdown/tags.d.ts.map +0 -1
  319. package/dist/markdown/tags.js.map +0 -1
  320. /package/dist/{markdown → internal/markdown}/parse.d.ts +0 -0
  321. /package/dist/{markdown → internal/markdown}/tags.d.ts +0 -0
  322. /package/dist/{markdown → internal/markdown}/tags.js +0 -0
  323. /package/src/{markdown → internal/markdown}/tags.ts +0 -0
@@ -0,0 +1,451 @@
1
+ // The GL renderer's four programs, and the one decision they share.
2
+ //
3
+ // Everything is **GLSL ES 1.00**: it is the one dialect both direct backends
4
+ // compile — Apple's GL 4.1 core accepts it through ARB_ES2_compatibility
5
+ // (x11-dri prepends the `#version 100` a core profile insists on), and every
6
+ // Linux GLES driver speaks it — so one source serves the Cocoa backend,
7
+ // XQuartz's Apple-DRI flavor and DRI3 alike.
8
+ //
9
+ // The shared decision is the vertex layout. Every program binds its
10
+ // attributes to the same five locations, so one vertex array object per
11
+ // *range of records* can feed whichever program draws that range:
12
+ //
13
+ // 0 a_corner the static quad corner — `(0|1, -1|1)`, per vertex
14
+ // 1 a_p0 record i: x, y (int16 × 2)
15
+ // 2 a_p1 record i + 1: x, y (int16 × 2)
16
+ // 3 a_x record i: the fan apex (fill stream, int16 × 2)
17
+ // or the distance along the line (float)
18
+ // 4 a_d1 record i + 1: the distance along the line (float)
19
+ //
20
+ // Locations 1-4 advance once per *instance* (divisor 1), so instance i is
21
+ // segment i of the stream and a polyline costs no memory beyond its points.
22
+ // A segment that touches a sentinel collapses to a point outside the clip
23
+ // volume — see `buckets.ts` for why sentinels beat an index buffer.
24
+ /** Where each attribute lives, shared by every program. Locations 5-9 are
25
+ * the label program's, one label per instance (see {@link LABEL_VERTEX}). */
26
+ export const ATTRIBUTES = {
27
+ a_corner: 0,
28
+ a_p0: 1,
29
+ a_p1: 2,
30
+ a_x: 3,
31
+ a_d1: 4,
32
+ a_anchor: 5,
33
+ a_rect: 6,
34
+ a_ink: 7,
35
+ a_halo: 8,
36
+ a_params: 9,
37
+ };
38
+ const PRELUDE = `precision highp float;
39
+ attribute vec2 a_corner;
40
+ attribute vec2 a_p0;
41
+ attribute vec2 a_p1;
42
+ attribute vec2 a_x;
43
+ attribute float a_d1;
44
+ // device pixels per tile unit, then the tile's origin in device pixels
45
+ uniform vec3 u_tile;
46
+ uniform vec2 u_viewport;
47
+ vec4 clip(vec2 p) {
48
+ return vec4(p.x / u_viewport.x * 2.0 - 1.0, 1.0 - p.y / u_viewport.y * 2.0, 0.0, 1.0);
49
+ }
50
+ bool broken() {
51
+ return a_p0.x < -32767.5 || a_p1.x < -32767.5;
52
+ }
53
+ `;
54
+ /**
55
+ * A segment as a capsule: the quad around it, widened by half the line
56
+ * width plus a pixel of fringe, and shaded by distance to the segment.
57
+ *
58
+ * The distance function is what makes this worth doing on the GPU rather
59
+ * than extruding on the CPU: clamping the pixel's position along the
60
+ * segment before measuring gives **round caps and round joins for free** —
61
+ * two consecutive capsules overlap in exactly the disc a round join is —
62
+ * and the same number is the antialiasing ramp. Nothing about a join is
63
+ * computed anywhere, so a road network costs its points and nothing else.
64
+ *
65
+ * What that costs is a translucent line: where two capsules overlap at a
66
+ * join the colour would be laid down twice, a darker bead at every vertex.
67
+ * So a translucent stroke is drawn a pixel at a time under the stencil, in
68
+ * two parts (`u_part`): the pixels a capsule covers wholly, the first
69
+ * capsule to reach one taking it, and then the antialiased fringe where
70
+ * nothing has been drawn yet.
71
+ */
72
+ export const LINE_VERTEX = `${PRELUDE}
73
+ uniform float u_half;
74
+ varying vec2 v_local;
75
+ varying float v_len;
76
+ varying float v_dist;
77
+ void main() {
78
+ if (broken()) {
79
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
80
+ return;
81
+ }
82
+ vec2 a = a_p0 * u_tile.x + u_tile.yz;
83
+ vec2 b = a_p1 * u_tile.x + u_tile.yz;
84
+ vec2 d = b - a;
85
+ float len = length(d);
86
+ vec2 t = len > 0.0001 ? d / len : vec2(1.0, 0.0);
87
+ vec2 n = vec2(-t.y, t.x);
88
+ float e = u_half + 1.0;
89
+ float along = mix(-e, len + e, a_corner.x);
90
+ float across = a_corner.y * e;
91
+ v_local = vec2(along, across);
92
+ v_len = len;
93
+ v_dist = a_x.x * u_tile.x + along;
94
+ gl_Position = clip(a + t * along + n * across);
95
+ }
96
+ `;
97
+ export const LINE_FRAGMENT = `precision highp float;
98
+ uniform vec4 u_color;
99
+ uniform float u_half;
100
+ // up to four dashes, on and off in turn, and the pattern's length — device
101
+ // pixels; a length of 0 is a solid line
102
+ uniform vec4 u_dash_a;
103
+ uniform vec4 u_dash_b;
104
+ uniform float u_period;
105
+ // 0: every pixel; 1: only those the capsule covers wholly; 2: only the rest
106
+ uniform float u_part;
107
+ varying vec2 v_local;
108
+ varying float v_len;
109
+ varying float v_dist;
110
+ // How much of the pixel at \`m\` along the pattern the dash from \`s\`, \`on\`
111
+ // long, covers — or its copy a pattern later, which the last pixels of a
112
+ // pattern are nearest to.
113
+ float dash(float m, float s, float on) {
114
+ if (on <= 0.0) return 0.0;
115
+ float here = min(m - s, s + on - m);
116
+ float next = min(m - u_period - s, s + on - m + u_period);
117
+ return clamp(max(here, next) + 0.5, 0.0, 1.0);
118
+ }
119
+ void main() {
120
+ float x = clamp(v_local.x, 0.0, v_len);
121
+ float dist = length(vec2(v_local.x - x, v_local.y));
122
+ float alpha = clamp(u_half - dist + 0.5, 0.0, 1.0);
123
+ if (u_period > 0.0) {
124
+ float m = mod(v_dist, u_period);
125
+ float s1 = u_dash_a.x + u_dash_a.y;
126
+ float s2 = s1 + u_dash_a.z + u_dash_a.w;
127
+ float s3 = s2 + u_dash_b.x + u_dash_b.y;
128
+ alpha *= max(
129
+ max(dash(m, 0.0, u_dash_a.x), dash(m, s1, u_dash_a.z)),
130
+ max(dash(m, s2, u_dash_b.x), dash(m, s3, u_dash_b.z))
131
+ );
132
+ }
133
+ if (u_part > 0.5 && (alpha < 1.0) == (u_part < 1.5)) discard;
134
+ if (alpha <= 0.0) discard;
135
+ gl_FragColor = u_color * alpha;
136
+ }
137
+ `;
138
+ /**
139
+ * A fill edge as one triangle of its ring's fan: apex, p0, p1.
140
+ *
141
+ * Drawn into the stencil buffer only. A fan per ring, apex anywhere, covers
142
+ * each pixel as many times as the ring winds around it, so incrementing on
143
+ * one facing and decrementing on the other leaves the winding number behind
144
+ * — non-zero is inside, which is a polygon with its holes cut, with no
145
+ * triangulation anywhere. The quad corner picks the vertex: `(0,-1)` is the
146
+ * apex, `(1,-1)` is p0 and `(0,1)` is p1.
147
+ */
148
+ export const FAN_VERTEX = `${PRELUDE}
149
+ void main() {
150
+ if (broken()) {
151
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
152
+ return;
153
+ }
154
+ float which = a_corner.x + a_corner.y + 1.0;
155
+ vec2 q = which < 0.5 ? a_x : (which < 1.5 ? a_p0 : a_p1);
156
+ gl_Position = clip(q * u_tile.x + u_tile.yz);
157
+ }
158
+ `;
159
+ export const FAN_FRAGMENT = `precision mediump float;
160
+ void main() {
161
+ gl_FragColor = vec4(0.0);
162
+ }
163
+ `;
164
+ /** The viewport, filled where the stencil says a polygon is. */
165
+ export const COVER_VERTEX = `precision highp float;
166
+ attribute vec2 a_corner;
167
+ void main() {
168
+ gl_Position = vec4(a_corner.x * 2.0 - 1.0, a_corner.y, 0.0, 1.0);
169
+ }
170
+ `;
171
+ export const COVER_FRAGMENT = `precision mediump float;
172
+ uniform vec4 u_color;
173
+ void main() {
174
+ gl_FragColor = u_color;
175
+ }
176
+ `;
177
+ /** The offscreen frame, copied to the surface — only where the surface has
178
+ * no stencil buffer of its own. */
179
+ export const BLIT_VERTEX = `precision highp float;
180
+ attribute vec2 a_corner;
181
+ varying vec2 v_uv;
182
+ void main() {
183
+ v_uv = vec2(a_corner.x, a_corner.y * 0.5 + 0.5);
184
+ gl_Position = vec4(a_corner.x * 2.0 - 1.0, a_corner.y, 0.0, 1.0);
185
+ }
186
+ `;
187
+ export const BLIT_FRAGMENT = `precision mediump float;
188
+ uniform sampler2D u_image;
189
+ // 1 copies the frame; below 1 it is a level fading in over the one leaving,
190
+ // premultiplied for the ONE, ONE_MINUS_SRC_ALPHA blend
191
+ uniform float u_alpha;
192
+ varying vec2 v_uv;
193
+ void main() {
194
+ gl_FragColor = texture2D(u_image, v_uv) * u_alpha;
195
+ }
196
+ `;
197
+ /**
198
+ * A label: its raster from the atlas as one quad, centred on the anchor and
199
+ * turned to the baseline — which is all a label needs, because placement
200
+ * only ever sets a line label on a straight stretch.
201
+ *
202
+ * A level label is set on **whole pixels**, texel for pixel, so the text is
203
+ * exactly as crisp as the text engine made it; a slanted one is sampled
204
+ * bilinearly, as rotated type always is. The quad is the raster less an
205
+ * inset (`u_inset`): the raster's clear margin is wide enough for a halo to
206
+ * grow into, and the inset is what keeps the halo's samples from reaching
207
+ * past the margin into a neighbouring label.
208
+ */
209
+ export const LABEL_VERTEX = `precision highp float;
210
+ attribute vec2 a_corner;
211
+ // centre (device pixels), then cos and sin of the baseline
212
+ attribute vec4 a_anchor;
213
+ // the raster in the atlas: x, y, width, height in texels, margin included
214
+ attribute vec4 a_rect;
215
+ attribute vec4 a_ink;
216
+ attribute vec4 a_halo;
217
+ // halo radius in pixels, and 1 to set the label on whole pixels
218
+ attribute vec2 a_params;
219
+ uniform vec2 u_viewport;
220
+ uniform vec2 u_atlas;
221
+ uniform float u_inset;
222
+ varying vec2 v_uv;
223
+ varying vec4 v_ink;
224
+ varying vec4 v_halo;
225
+ varying float v_radius;
226
+ void main() {
227
+ vec2 corner = vec2(a_corner.x, a_corner.y * 0.5 + 0.5);
228
+ vec2 size = a_rect.zw - 2.0 * u_inset;
229
+ vec2 p;
230
+ if (a_params.y > 0.5) {
231
+ p = floor(a_anchor.xy - size * 0.5 + 0.5) + corner * size;
232
+ } else {
233
+ vec2 local = (corner - 0.5) * size;
234
+ vec2 axis = a_anchor.zw;
235
+ p = a_anchor.xy + vec2(local.x * axis.x - local.y * axis.y,
236
+ local.x * axis.y + local.y * axis.x);
237
+ }
238
+ v_uv = (a_rect.xy + u_inset + corner * size) / u_atlas;
239
+ v_ink = a_ink;
240
+ v_halo = a_halo;
241
+ v_radius = a_params.x;
242
+ gl_Position = vec4(p.x / u_viewport.x * 2.0 - 1.0, 1.0 - p.y / u_viewport.y * 2.0, 0.0, 1.0);
243
+ }
244
+ `;
245
+ /**
246
+ * Coverage in, colour out: the ink where the glyphs are, and under it a
247
+ * halo — the coverage *dilated* by the halo's radius, as the greatest
248
+ * coverage on two rings of samples around the pixel. Dilating here rather
249
+ * than when rasterizing is what lets one raster serve every halo width and
250
+ * colour a style asks for; the samples cost nothing next to the few
251
+ * thousand pixels a frame's labels cover.
252
+ */
253
+ export const LABEL_FRAGMENT = `precision highp float;
254
+ uniform sampler2D u_image;
255
+ uniform vec2 u_atlas;
256
+ varying vec2 v_uv;
257
+ varying vec4 v_ink;
258
+ varying vec4 v_halo;
259
+ varying float v_radius;
260
+ void main() {
261
+ float ink = texture2D(u_image, v_uv).a;
262
+ float halo = ink;
263
+ if (v_radius > 0.0) {
264
+ vec2 reach = vec2(v_radius) / u_atlas;
265
+ for (int i = 0; i < 16; i++) {
266
+ float a = float(i) * 0.3926991;
267
+ vec2 d = vec2(cos(a), sin(a)) * reach;
268
+ halo = max(halo, texture2D(u_image, v_uv + d).a);
269
+ halo = max(halo, texture2D(u_image, v_uv + d * 0.5).a);
270
+ }
271
+ }
272
+ vec4 color = v_ink * ink + v_halo * (halo * (1.0 - ink));
273
+ if (color.a <= 0.0) discard;
274
+ gl_FragColor = color;
275
+ }
276
+ `;
277
+ /**
278
+ * A marker: a quad around it, instanced. Its outline is computed per pixel
279
+ * (`MARKER_FRAGMENT`), so the quad is only big enough to hold the shape, its
280
+ * ring and a pixel of coverage.
281
+ */
282
+ export const MARKER_VERTEX = `precision highp float;
283
+ attribute vec2 a_corner;
284
+ // the point marked (device pixels) — a pin's tip, a disc's centre — the
285
+ // head's radius, and how far above the point the head's centre is: 0 for a
286
+ // disc
287
+ attribute vec4 a_anchor;
288
+ // the fill and the ring, premultiplied
289
+ attribute vec4 a_ink;
290
+ attribute vec4 a_halo;
291
+ // the ring's width in pixels
292
+ attribute vec2 a_params;
293
+ uniform vec2 u_viewport;
294
+ varying vec2 v_local;
295
+ varying vec4 v_fill;
296
+ varying vec4 v_ring;
297
+ varying vec3 v_shape;
298
+ void main() {
299
+ float r = a_anchor.z;
300
+ float d = a_anchor.w;
301
+ vec2 centre = a_anchor.xy - vec2(0.0, d);
302
+ float m = a_params.x * 0.5 + 1.0;
303
+ vec2 lo = centre - vec2(r + m);
304
+ vec2 hi = centre + vec2(r + m, max(r, d) + m);
305
+ vec2 p = mix(lo, hi, vec2(a_corner.x, a_corner.y * 0.5 + 0.5));
306
+ v_local = p - centre;
307
+ v_fill = a_ink;
308
+ v_ring = a_halo;
309
+ v_shape = vec3(r, d, a_params.x * 0.5);
310
+ gl_Position = vec4(p.x / u_viewport.x * 2.0 - 1.0, 1.0 - p.y / u_viewport.y * 2.0, 0.0, 1.0);
311
+ }
312
+ `;
313
+ /**
314
+ * A marker's pixels: the signed distance to its outline, and from it the
315
+ * fill inside and the ring over it — a stroke centred on the outline, which
316
+ * is how the retained renderer fills its path and then strokes it. The
317
+ * outline is a disc, or a pin's teardrop: the hull of the head and a point
318
+ * below it, which is Inigo Quilez's uneven capsule with a second radius of
319
+ * zero — its straight sides tangent to the head where the retained
320
+ * renderer's are.
321
+ */
322
+ export const MARKER_FRAGMENT = `precision highp float;
323
+ varying vec2 v_local;
324
+ varying vec4 v_fill;
325
+ varying vec4 v_ring;
326
+ varying vec3 v_shape;
327
+ float outline(vec2 p, float r, float d) {
328
+ if (d <= r) return length(p) - r;
329
+ p.x = abs(p.x);
330
+ float b = r / d;
331
+ float a = sqrt(1.0 - b * b);
332
+ float k = dot(p, vec2(-b, a));
333
+ if (k < 0.0) return length(p) - r;
334
+ if (k > a * d) return length(p - vec2(0.0, d));
335
+ return dot(p, vec2(a, b)) - r;
336
+ }
337
+ void main() {
338
+ float dist = outline(v_local, v_shape.x, v_shape.y);
339
+ float fill = clamp(0.5 - dist, 0.0, 1.0);
340
+ float ring = clamp(v_shape.z + 0.5 - abs(dist), 0.0, 1.0);
341
+ vec4 stroke = v_ring * ring;
342
+ vec4 color = stroke + v_fill * (fill * (1.0 - stroke.a));
343
+ if (color.a <= 0.0) discard;
344
+ gl_FragColor = color;
345
+ }
346
+ `;
347
+ /**
348
+ * A circle layer's point as a disc: a quad around it, instanced over the
349
+ * layer's records. Only `a_p0` is read — a point is one record, and the
350
+ * sentinel after a range's last point is `a_p1` of nothing drawn.
351
+ */
352
+ export const CIRCLE_VERTEX = `${PRELUDE}
353
+ uniform float u_radius;
354
+ uniform float u_stroke;
355
+ varying vec2 v_local;
356
+ void main() {
357
+ if (a_p0.x < -32767.5) {
358
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
359
+ return;
360
+ }
361
+ vec2 centre = a_p0 * u_tile.x + u_tile.yz;
362
+ float e = u_radius + u_stroke * 0.5 + 1.0;
363
+ v_local = vec2(a_corner.x * 2.0 - 1.0, a_corner.y) * e;
364
+ gl_Position = clip(centre + v_local);
365
+ }
366
+ `;
367
+ /** The disc's pixels: the fill inside, and a stroke centred on the edge
368
+ * over it — `paint.ts` fills a circle's path and then strokes it. */
369
+ export const CIRCLE_FRAGMENT = `precision highp float;
370
+ uniform vec4 u_color;
371
+ uniform vec4 u_stroke_color;
372
+ uniform float u_radius;
373
+ uniform float u_stroke;
374
+ varying vec2 v_local;
375
+ void main() {
376
+ float dist = length(v_local) - u_radius;
377
+ float fill = clamp(0.5 - dist, 0.0, 1.0);
378
+ float ring = u_stroke > 0.0
379
+ ? clamp(u_stroke * 0.5 + 0.5 - abs(dist), 0.0, 1.0)
380
+ : 0.0;
381
+ vec4 stroke = u_stroke_color * ring;
382
+ vec4 color = stroke + u_color * (fill * (1.0 - stroke.a));
383
+ if (color.a <= 0.0) discard;
384
+ gl_FragColor = color;
385
+ }
386
+ `;
387
+ /**
388
+ * A raster tile: its image over its square — the data tile's, which past
389
+ * the source's depth is larger than the cell it is drawn for — and a
390
+ * scissor clipping it to that cell. A pixel past every edge, so two squares
391
+ * that share an edge leave no gap; the scissor crops it and the image
392
+ * clamps to it.
393
+ */
394
+ export const RASTER_VERTEX = `precision highp float;
395
+ attribute vec2 a_corner;
396
+ // the square's size, then its top-left corner — device pixels
397
+ uniform vec3 u_tile;
398
+ uniform vec2 u_viewport;
399
+ varying vec2 v_uv;
400
+ void main() {
401
+ vec2 corner = vec2(a_corner.x, a_corner.y * 0.5 + 0.5);
402
+ vec2 p = u_tile.yz - 1.0 + corner * (u_tile.x + 2.0);
403
+ v_uv = (p - u_tile.yz) / u_tile.x;
404
+ gl_Position = vec4(p.x / u_viewport.x * 2.0 - 1.0, 1.0 - p.y / u_viewport.y * 2.0, 0.0, 1.0);
405
+ }
406
+ `;
407
+ /** An image as a source decodes one — not premultiplied — onto a frame
408
+ * that is. */
409
+ export const RASTER_FRAGMENT = `precision mediump float;
410
+ uniform sampler2D u_image;
411
+ varying vec2 v_uv;
412
+ void main() {
413
+ vec4 c = texture2D(u_image, v_uv);
414
+ gl_FragColor = vec4(c.rgb * c.a, c.a);
415
+ }
416
+ `;
417
+ function compileShader(gl, type, source) {
418
+ const shader = gl.createShader(type);
419
+ gl.shaderSource(shader, source);
420
+ gl.compileShader(shader);
421
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
422
+ const log = gl.getShaderInfoLog(shader);
423
+ gl.deleteShader(shader);
424
+ throw new Error(`@react-x11/components maps/gl: shader failed: ${log}`);
425
+ }
426
+ return shader;
427
+ }
428
+ /** Compile, bind the shared locations, link, and look the uniforms up. */
429
+ export function linkProgram(gl, vertex, fragment, uniforms) {
430
+ const program = gl.createProgram();
431
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertex);
432
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
433
+ gl.attachShader(program, vs);
434
+ gl.attachShader(program, fs);
435
+ for (const [name, location] of Object.entries(ATTRIBUTES)) {
436
+ gl.bindAttribLocation(program, location, name);
437
+ }
438
+ gl.linkProgram(program);
439
+ gl.deleteShader(vs);
440
+ gl.deleteShader(fs);
441
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
442
+ const log = gl.getProgramInfoLog(program);
443
+ gl.deleteProgram(program);
444
+ throw new Error(`@react-x11/components maps/gl: link failed: ${log}`);
445
+ }
446
+ const found = {};
447
+ for (const name of uniforms)
448
+ found[name] = gl.getUniformLocation(program, name);
449
+ return { program, uniforms: found };
450
+ }
451
+ //# sourceMappingURL=shaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shaders.js","sourceRoot":"","sources":["../../../src/maps/gl/shaders.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AACzE,6EAA6E;AAC7E,wEAAwE;AACxE,6CAA6C;AAC7C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AACxE,kEAAkE;AAClE,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,sEAAsE;AACtE,qEAAqE;AACrE,sEAAsE;AACtE,mEAAmE;AACnE,EAAE;AACF,0EAA0E;AAC1E,4EAA4E;AAC5E,0EAA0E;AAC1E,oEAAoE;AAEpE;8EAC8E;AAC9E,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;CACH,CAAC;AAEX,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;CAef,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,OAAO;;;;;;;;;;;;;;;;;;;;;;;;CAwBpC,C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EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACpB,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACpB,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;QACrD,MAAM,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC1C,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,+CAA+C,GAAG,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,QAAQ;QACzB,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,115 @@
1
+ import type { MapSource } from '../sources.js';
2
+ import type { TileId } from '../proj.js';
3
+ import type { PreparedStyle } from '../paint.js';
4
+ import type { GlTileData } from './buckets.js';
5
+ import type { TileLookup } from './cover.js';
6
+ export interface GlTileStoreOptions {
7
+ source: MapSource;
8
+ /** What the source is called in its requests and its errors —
9
+ * `source-<index>` when it has no `id`. */
10
+ sourceId?: string;
11
+ prepared: PreparedStyle;
12
+ /**
13
+ * Called once per failed load, with whatever the source threw — what
14
+ * `<Map onTileError>` hears. A load aborted because the map stopped
15
+ * wanting the tile is not a failure, whatever it answers after that.
16
+ */
17
+ onError?: (error: unknown, tile: TileId & {
18
+ sourceId: string;
19
+ }) => void;
20
+ /** A load landed or a build finished: a frame is worth drawing. */
21
+ onChange: () => void;
22
+ /** Loads in flight at once. 8 by default. */
23
+ concurrency?: number;
24
+ /** Tiles kept, bytes and buckets both. 256 by default. */
25
+ capacity?: number;
26
+ /**
27
+ * Build buckets on this many worker threads. `0` (the default) builds on
28
+ * this thread under `pump`'s budget. Falls back to that when the runtime
29
+ * has no `worker_threads`.
30
+ */
31
+ workers?: number;
32
+ }
33
+ export declare class GlTileStore implements TileLookup {
34
+ private readonly _source;
35
+ private readonly _sourceId;
36
+ private readonly _onError;
37
+ private _prepared;
38
+ private _style;
39
+ private readonly _onChange;
40
+ private readonly _concurrency;
41
+ private readonly _capacity;
42
+ private readonly _entries;
43
+ /** Loaded tiles waiting for a build, oldest first. */
44
+ private _queue;
45
+ private _waiting;
46
+ private _inFlight;
47
+ private _frame;
48
+ private _disposed;
49
+ private readonly _pool;
50
+ /** Bucket builds and their cost on this thread, for a HUD. */
51
+ built: number;
52
+ buildMs: number;
53
+ constructor(options: GlTileStoreOptions);
54
+ get source(): MapSource;
55
+ /** Tiles loaded and waiting for (or in) a build. */
56
+ get building(): number;
57
+ /** Tiles asked for and not yet answered. */
58
+ get loading(): number;
59
+ /** Whether builds happen off this thread. */
60
+ get threaded(): boolean;
61
+ get(tile: TileId): GlTileData | null | undefined;
62
+ /** A new frame: what the cover asks for from here on is this frame's. */
63
+ tick(): void;
64
+ /** Ask for tiles, centre-out. Already-known tiles cost a lookup. */
65
+ want(tiles: readonly TileId[]): void;
66
+ private _drain;
67
+ private _load;
68
+ /**
69
+ * How many of `tiles` failed to load and are waiting on a retry — the
70
+ * frame's `errors`.
71
+ */
72
+ failedAmong(tiles: readonly TileId[]): number;
73
+ /**
74
+ * Stop loading: every load in flight is aborted and forgotten, and nothing
75
+ * waiting is started. For a source taken off the map, whose tiles that
76
+ * have arrived stay, so switching back to it is free — the retained
77
+ * cache's rule.
78
+ */
79
+ abortLoads(): void;
80
+ /** Build every tile again from its bytes — `refresh()`, after a style
81
+ * the application edited in place. The old buckets draw until then. */
82
+ rebuild(): void;
83
+ /**
84
+ * Work through the loaded tiles. Answers whether more are waiting on this
85
+ * thread, which is the caller's cue for another frame.
86
+ *
87
+ * With workers, everything waiting is dispatched and nothing is built
88
+ * here: a finished build calls `onChange` like a finished load does. On
89
+ * this thread, tiles are built until `deadline` — always at least one, or
90
+ * a budget smaller than one tile would build nothing forever.
91
+ */
92
+ pump(deadline: number): boolean;
93
+ /**
94
+ * A new style. Buckets are rebuilt only if the new one would select
95
+ * different features — a different layer list or different filters —
96
+ * and until a tile is rebuilt its old buckets keep drawing.
97
+ */
98
+ setStyle(prepared: PreparedStyle): void;
99
+ /** Every tile with bytes back on the build queue, most recently drawn
100
+ * first; each keeps drawing its old buckets until its new ones exist. */
101
+ private _requeue;
102
+ /**
103
+ * The end of a frame: cancel every load it did not want, and let go of the
104
+ * least recently drawn tiles past capacity.
105
+ *
106
+ * A tile panned or zoomed out of the cover — and the ring around it the
107
+ * cover keeps warm — would otherwise load to the end: a request nobody is
108
+ * waiting for, pointed at somebody else's servers. That is the contract
109
+ * the docs make for `request.signal`, on either renderer. A tile that
110
+ * comes back is asked for again, with a new signal.
111
+ */
112
+ evict(release: (data: GlTileData) => void): void;
113
+ dispose(release: (data: GlTileData) => void): void;
114
+ }
115
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/maps/gl/store.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAoB7C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,CAAC;IAClB;gDAC4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAA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