@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,486 @@
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
+
25
+ /** Where each attribute lives, shared by every program. Locations 5-9 are
26
+ * the label program's, one label per instance (see {@link LABEL_VERTEX}). */
27
+ export const ATTRIBUTES = {
28
+ a_corner: 0,
29
+ a_p0: 1,
30
+ a_p1: 2,
31
+ a_x: 3,
32
+ a_d1: 4,
33
+ a_anchor: 5,
34
+ a_rect: 6,
35
+ a_ink: 7,
36
+ a_halo: 8,
37
+ a_params: 9,
38
+ } as const;
39
+
40
+ const PRELUDE = `precision highp float;
41
+ attribute vec2 a_corner;
42
+ attribute vec2 a_p0;
43
+ attribute vec2 a_p1;
44
+ attribute vec2 a_x;
45
+ attribute float a_d1;
46
+ // device pixels per tile unit, then the tile's origin in device pixels
47
+ uniform vec3 u_tile;
48
+ uniform vec2 u_viewport;
49
+ vec4 clip(vec2 p) {
50
+ return vec4(p.x / u_viewport.x * 2.0 - 1.0, 1.0 - p.y / u_viewport.y * 2.0, 0.0, 1.0);
51
+ }
52
+ bool broken() {
53
+ return a_p0.x < -32767.5 || a_p1.x < -32767.5;
54
+ }
55
+ `;
56
+
57
+ /**
58
+ * A segment as a capsule: the quad around it, widened by half the line
59
+ * width plus a pixel of fringe, and shaded by distance to the segment.
60
+ *
61
+ * The distance function is what makes this worth doing on the GPU rather
62
+ * than extruding on the CPU: clamping the pixel's position along the
63
+ * segment before measuring gives **round caps and round joins for free** —
64
+ * two consecutive capsules overlap in exactly the disc a round join is —
65
+ * and the same number is the antialiasing ramp. Nothing about a join is
66
+ * computed anywhere, so a road network costs its points and nothing else.
67
+ *
68
+ * What that costs is a translucent line: where two capsules overlap at a
69
+ * join the colour would be laid down twice, a darker bead at every vertex.
70
+ * So a translucent stroke is drawn a pixel at a time under the stencil, in
71
+ * two parts (`u_part`): the pixels a capsule covers wholly, the first
72
+ * capsule to reach one taking it, and then the antialiased fringe where
73
+ * nothing has been drawn yet.
74
+ */
75
+ export const LINE_VERTEX = `${PRELUDE}
76
+ uniform float u_half;
77
+ varying vec2 v_local;
78
+ varying float v_len;
79
+ varying float v_dist;
80
+ void main() {
81
+ if (broken()) {
82
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
83
+ return;
84
+ }
85
+ vec2 a = a_p0 * u_tile.x + u_tile.yz;
86
+ vec2 b = a_p1 * u_tile.x + u_tile.yz;
87
+ vec2 d = b - a;
88
+ float len = length(d);
89
+ vec2 t = len > 0.0001 ? d / len : vec2(1.0, 0.0);
90
+ vec2 n = vec2(-t.y, t.x);
91
+ float e = u_half + 1.0;
92
+ float along = mix(-e, len + e, a_corner.x);
93
+ float across = a_corner.y * e;
94
+ v_local = vec2(along, across);
95
+ v_len = len;
96
+ v_dist = a_x.x * u_tile.x + along;
97
+ gl_Position = clip(a + t * along + n * across);
98
+ }
99
+ `;
100
+
101
+ export const LINE_FRAGMENT = `precision highp float;
102
+ uniform vec4 u_color;
103
+ uniform float u_half;
104
+ // up to four dashes, on and off in turn, and the pattern's length — device
105
+ // pixels; a length of 0 is a solid line
106
+ uniform vec4 u_dash_a;
107
+ uniform vec4 u_dash_b;
108
+ uniform float u_period;
109
+ // 0: every pixel; 1: only those the capsule covers wholly; 2: only the rest
110
+ uniform float u_part;
111
+ varying vec2 v_local;
112
+ varying float v_len;
113
+ varying float v_dist;
114
+ // How much of the pixel at \`m\` along the pattern the dash from \`s\`, \`on\`
115
+ // long, covers — or its copy a pattern later, which the last pixels of a
116
+ // pattern are nearest to.
117
+ float dash(float m, float s, float on) {
118
+ if (on <= 0.0) return 0.0;
119
+ float here = min(m - s, s + on - m);
120
+ float next = min(m - u_period - s, s + on - m + u_period);
121
+ return clamp(max(here, next) + 0.5, 0.0, 1.0);
122
+ }
123
+ void main() {
124
+ float x = clamp(v_local.x, 0.0, v_len);
125
+ float dist = length(vec2(v_local.x - x, v_local.y));
126
+ float alpha = clamp(u_half - dist + 0.5, 0.0, 1.0);
127
+ if (u_period > 0.0) {
128
+ float m = mod(v_dist, u_period);
129
+ float s1 = u_dash_a.x + u_dash_a.y;
130
+ float s2 = s1 + u_dash_a.z + u_dash_a.w;
131
+ float s3 = s2 + u_dash_b.x + u_dash_b.y;
132
+ alpha *= max(
133
+ max(dash(m, 0.0, u_dash_a.x), dash(m, s1, u_dash_a.z)),
134
+ max(dash(m, s2, u_dash_b.x), dash(m, s3, u_dash_b.z))
135
+ );
136
+ }
137
+ if (u_part > 0.5 && (alpha < 1.0) == (u_part < 1.5)) discard;
138
+ if (alpha <= 0.0) discard;
139
+ gl_FragColor = u_color * alpha;
140
+ }
141
+ `;
142
+
143
+ /**
144
+ * A fill edge as one triangle of its ring's fan: apex, p0, p1.
145
+ *
146
+ * Drawn into the stencil buffer only. A fan per ring, apex anywhere, covers
147
+ * each pixel as many times as the ring winds around it, so incrementing on
148
+ * one facing and decrementing on the other leaves the winding number behind
149
+ * — non-zero is inside, which is a polygon with its holes cut, with no
150
+ * triangulation anywhere. The quad corner picks the vertex: `(0,-1)` is the
151
+ * apex, `(1,-1)` is p0 and `(0,1)` is p1.
152
+ */
153
+ export const FAN_VERTEX = `${PRELUDE}
154
+ void main() {
155
+ if (broken()) {
156
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
157
+ return;
158
+ }
159
+ float which = a_corner.x + a_corner.y + 1.0;
160
+ vec2 q = which < 0.5 ? a_x : (which < 1.5 ? a_p0 : a_p1);
161
+ gl_Position = clip(q * u_tile.x + u_tile.yz);
162
+ }
163
+ `;
164
+
165
+ export const FAN_FRAGMENT = `precision mediump float;
166
+ void main() {
167
+ gl_FragColor = vec4(0.0);
168
+ }
169
+ `;
170
+
171
+ /** The viewport, filled where the stencil says a polygon is. */
172
+ export const COVER_VERTEX = `precision highp float;
173
+ attribute vec2 a_corner;
174
+ void main() {
175
+ gl_Position = vec4(a_corner.x * 2.0 - 1.0, a_corner.y, 0.0, 1.0);
176
+ }
177
+ `;
178
+
179
+ export const COVER_FRAGMENT = `precision mediump float;
180
+ uniform vec4 u_color;
181
+ void main() {
182
+ gl_FragColor = u_color;
183
+ }
184
+ `;
185
+
186
+ /** The offscreen frame, copied to the surface — only where the surface has
187
+ * no stencil buffer of its own. */
188
+ export const BLIT_VERTEX = `precision highp float;
189
+ attribute vec2 a_corner;
190
+ varying vec2 v_uv;
191
+ void main() {
192
+ v_uv = vec2(a_corner.x, a_corner.y * 0.5 + 0.5);
193
+ gl_Position = vec4(a_corner.x * 2.0 - 1.0, a_corner.y, 0.0, 1.0);
194
+ }
195
+ `;
196
+
197
+ export const BLIT_FRAGMENT = `precision mediump float;
198
+ uniform sampler2D u_image;
199
+ // 1 copies the frame; below 1 it is a level fading in over the one leaving,
200
+ // premultiplied for the ONE, ONE_MINUS_SRC_ALPHA blend
201
+ uniform float u_alpha;
202
+ varying vec2 v_uv;
203
+ void main() {
204
+ gl_FragColor = texture2D(u_image, v_uv) * u_alpha;
205
+ }
206
+ `;
207
+
208
+ /**
209
+ * A label: its raster from the atlas as one quad, centred on the anchor and
210
+ * turned to the baseline — which is all a label needs, because placement
211
+ * only ever sets a line label on a straight stretch.
212
+ *
213
+ * A level label is set on **whole pixels**, texel for pixel, so the text is
214
+ * exactly as crisp as the text engine made it; a slanted one is sampled
215
+ * bilinearly, as rotated type always is. The quad is the raster less an
216
+ * inset (`u_inset`): the raster's clear margin is wide enough for a halo to
217
+ * grow into, and the inset is what keeps the halo's samples from reaching
218
+ * past the margin into a neighbouring label.
219
+ */
220
+ export const LABEL_VERTEX = `precision highp float;
221
+ attribute vec2 a_corner;
222
+ // centre (device pixels), then cos and sin of the baseline
223
+ attribute vec4 a_anchor;
224
+ // the raster in the atlas: x, y, width, height in texels, margin included
225
+ attribute vec4 a_rect;
226
+ attribute vec4 a_ink;
227
+ attribute vec4 a_halo;
228
+ // halo radius in pixels, and 1 to set the label on whole pixels
229
+ attribute vec2 a_params;
230
+ uniform vec2 u_viewport;
231
+ uniform vec2 u_atlas;
232
+ uniform float u_inset;
233
+ varying vec2 v_uv;
234
+ varying vec4 v_ink;
235
+ varying vec4 v_halo;
236
+ varying float v_radius;
237
+ void main() {
238
+ vec2 corner = vec2(a_corner.x, a_corner.y * 0.5 + 0.5);
239
+ vec2 size = a_rect.zw - 2.0 * u_inset;
240
+ vec2 p;
241
+ if (a_params.y > 0.5) {
242
+ p = floor(a_anchor.xy - size * 0.5 + 0.5) + corner * size;
243
+ } else {
244
+ vec2 local = (corner - 0.5) * size;
245
+ vec2 axis = a_anchor.zw;
246
+ p = a_anchor.xy + vec2(local.x * axis.x - local.y * axis.y,
247
+ local.x * axis.y + local.y * axis.x);
248
+ }
249
+ v_uv = (a_rect.xy + u_inset + corner * size) / u_atlas;
250
+ v_ink = a_ink;
251
+ v_halo = a_halo;
252
+ v_radius = a_params.x;
253
+ 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);
254
+ }
255
+ `;
256
+
257
+ /**
258
+ * Coverage in, colour out: the ink where the glyphs are, and under it a
259
+ * halo — the coverage *dilated* by the halo's radius, as the greatest
260
+ * coverage on two rings of samples around the pixel. Dilating here rather
261
+ * than when rasterizing is what lets one raster serve every halo width and
262
+ * colour a style asks for; the samples cost nothing next to the few
263
+ * thousand pixels a frame's labels cover.
264
+ */
265
+ export const LABEL_FRAGMENT = `precision highp float;
266
+ uniform sampler2D u_image;
267
+ uniform vec2 u_atlas;
268
+ varying vec2 v_uv;
269
+ varying vec4 v_ink;
270
+ varying vec4 v_halo;
271
+ varying float v_radius;
272
+ void main() {
273
+ float ink = texture2D(u_image, v_uv).a;
274
+ float halo = ink;
275
+ if (v_radius > 0.0) {
276
+ vec2 reach = vec2(v_radius) / u_atlas;
277
+ for (int i = 0; i < 16; i++) {
278
+ float a = float(i) * 0.3926991;
279
+ vec2 d = vec2(cos(a), sin(a)) * reach;
280
+ halo = max(halo, texture2D(u_image, v_uv + d).a);
281
+ halo = max(halo, texture2D(u_image, v_uv + d * 0.5).a);
282
+ }
283
+ }
284
+ vec4 color = v_ink * ink + v_halo * (halo * (1.0 - ink));
285
+ if (color.a <= 0.0) discard;
286
+ gl_FragColor = color;
287
+ }
288
+ `;
289
+
290
+ /**
291
+ * A marker: a quad around it, instanced. Its outline is computed per pixel
292
+ * (`MARKER_FRAGMENT`), so the quad is only big enough to hold the shape, its
293
+ * ring and a pixel of coverage.
294
+ */
295
+ export const MARKER_VERTEX = `precision highp float;
296
+ attribute vec2 a_corner;
297
+ // the point marked (device pixels) — a pin's tip, a disc's centre — the
298
+ // head's radius, and how far above the point the head's centre is: 0 for a
299
+ // disc
300
+ attribute vec4 a_anchor;
301
+ // the fill and the ring, premultiplied
302
+ attribute vec4 a_ink;
303
+ attribute vec4 a_halo;
304
+ // the ring's width in pixels
305
+ attribute vec2 a_params;
306
+ uniform vec2 u_viewport;
307
+ varying vec2 v_local;
308
+ varying vec4 v_fill;
309
+ varying vec4 v_ring;
310
+ varying vec3 v_shape;
311
+ void main() {
312
+ float r = a_anchor.z;
313
+ float d = a_anchor.w;
314
+ vec2 centre = a_anchor.xy - vec2(0.0, d);
315
+ float m = a_params.x * 0.5 + 1.0;
316
+ vec2 lo = centre - vec2(r + m);
317
+ vec2 hi = centre + vec2(r + m, max(r, d) + m);
318
+ vec2 p = mix(lo, hi, vec2(a_corner.x, a_corner.y * 0.5 + 0.5));
319
+ v_local = p - centre;
320
+ v_fill = a_ink;
321
+ v_ring = a_halo;
322
+ v_shape = vec3(r, d, a_params.x * 0.5);
323
+ 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);
324
+ }
325
+ `;
326
+
327
+ /**
328
+ * A marker's pixels: the signed distance to its outline, and from it the
329
+ * fill inside and the ring over it — a stroke centred on the outline, which
330
+ * is how the retained renderer fills its path and then strokes it. The
331
+ * outline is a disc, or a pin's teardrop: the hull of the head and a point
332
+ * below it, which is Inigo Quilez's uneven capsule with a second radius of
333
+ * zero — its straight sides tangent to the head where the retained
334
+ * renderer's are.
335
+ */
336
+ export const MARKER_FRAGMENT = `precision highp float;
337
+ varying vec2 v_local;
338
+ varying vec4 v_fill;
339
+ varying vec4 v_ring;
340
+ varying vec3 v_shape;
341
+ float outline(vec2 p, float r, float d) {
342
+ if (d <= r) return length(p) - r;
343
+ p.x = abs(p.x);
344
+ float b = r / d;
345
+ float a = sqrt(1.0 - b * b);
346
+ float k = dot(p, vec2(-b, a));
347
+ if (k < 0.0) return length(p) - r;
348
+ if (k > a * d) return length(p - vec2(0.0, d));
349
+ return dot(p, vec2(a, b)) - r;
350
+ }
351
+ void main() {
352
+ float dist = outline(v_local, v_shape.x, v_shape.y);
353
+ float fill = clamp(0.5 - dist, 0.0, 1.0);
354
+ float ring = clamp(v_shape.z + 0.5 - abs(dist), 0.0, 1.0);
355
+ vec4 stroke = v_ring * ring;
356
+ vec4 color = stroke + v_fill * (fill * (1.0 - stroke.a));
357
+ if (color.a <= 0.0) discard;
358
+ gl_FragColor = color;
359
+ }
360
+ `;
361
+
362
+ /**
363
+ * A circle layer's point as a disc: a quad around it, instanced over the
364
+ * layer's records. Only `a_p0` is read — a point is one record, and the
365
+ * sentinel after a range's last point is `a_p1` of nothing drawn.
366
+ */
367
+ export const CIRCLE_VERTEX = `${PRELUDE}
368
+ uniform float u_radius;
369
+ uniform float u_stroke;
370
+ varying vec2 v_local;
371
+ void main() {
372
+ if (a_p0.x < -32767.5) {
373
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
374
+ return;
375
+ }
376
+ vec2 centre = a_p0 * u_tile.x + u_tile.yz;
377
+ float e = u_radius + u_stroke * 0.5 + 1.0;
378
+ v_local = vec2(a_corner.x * 2.0 - 1.0, a_corner.y) * e;
379
+ gl_Position = clip(centre + v_local);
380
+ }
381
+ `;
382
+
383
+ /** The disc's pixels: the fill inside, and a stroke centred on the edge
384
+ * over it — `paint.ts` fills a circle's path and then strokes it. */
385
+ export const CIRCLE_FRAGMENT = `precision highp float;
386
+ uniform vec4 u_color;
387
+ uniform vec4 u_stroke_color;
388
+ uniform float u_radius;
389
+ uniform float u_stroke;
390
+ varying vec2 v_local;
391
+ void main() {
392
+ float dist = length(v_local) - u_radius;
393
+ float fill = clamp(0.5 - dist, 0.0, 1.0);
394
+ float ring = u_stroke > 0.0
395
+ ? clamp(u_stroke * 0.5 + 0.5 - abs(dist), 0.0, 1.0)
396
+ : 0.0;
397
+ vec4 stroke = u_stroke_color * ring;
398
+ vec4 color = stroke + u_color * (fill * (1.0 - stroke.a));
399
+ if (color.a <= 0.0) discard;
400
+ gl_FragColor = color;
401
+ }
402
+ `;
403
+
404
+ /**
405
+ * A raster tile: its image over its square — the data tile's, which past
406
+ * the source's depth is larger than the cell it is drawn for — and a
407
+ * scissor clipping it to that cell. A pixel past every edge, so two squares
408
+ * that share an edge leave no gap; the scissor crops it and the image
409
+ * clamps to it.
410
+ */
411
+ export const RASTER_VERTEX = `precision highp float;
412
+ attribute vec2 a_corner;
413
+ // the square's size, then its top-left corner — device pixels
414
+ uniform vec3 u_tile;
415
+ uniform vec2 u_viewport;
416
+ varying vec2 v_uv;
417
+ void main() {
418
+ vec2 corner = vec2(a_corner.x, a_corner.y * 0.5 + 0.5);
419
+ vec2 p = u_tile.yz - 1.0 + corner * (u_tile.x + 2.0);
420
+ v_uv = (p - u_tile.yz) / u_tile.x;
421
+ 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);
422
+ }
423
+ `;
424
+
425
+ /** An image as a source decodes one — not premultiplied — onto a frame
426
+ * that is. */
427
+ export const RASTER_FRAGMENT = `precision mediump float;
428
+ uniform sampler2D u_image;
429
+ varying vec2 v_uv;
430
+ void main() {
431
+ vec4 c = texture2D(u_image, v_uv);
432
+ gl_FragColor = vec4(c.rgb * c.a, c.a);
433
+ }
434
+ `;
435
+
436
+ /* The GL table is WebGL-shaped (x11-dri's camelCase), typed loosely on
437
+ * purpose — the same reason `src/three/renderer-direct.ts` gives. */
438
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
439
+ export type GL = any;
440
+
441
+ /** A linked program and its uniform locations, looked up once. */
442
+ export interface Program {
443
+ program: unknown;
444
+ uniforms: Record<string, unknown>;
445
+ }
446
+
447
+ function compileShader(gl: GL, type: number, source: string): unknown {
448
+ const shader = gl.createShader(type);
449
+ gl.shaderSource(shader, source);
450
+ gl.compileShader(shader);
451
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
452
+ const log = gl.getShaderInfoLog(shader);
453
+ gl.deleteShader(shader);
454
+ throw new Error(`@react-x11/components maps/gl: shader failed: ${log}`);
455
+ }
456
+ return shader;
457
+ }
458
+
459
+ /** Compile, bind the shared locations, link, and look the uniforms up. */
460
+ export function linkProgram(
461
+ gl: GL,
462
+ vertex: string,
463
+ fragment: string,
464
+ uniforms: readonly string[],
465
+ ): Program {
466
+ const program = gl.createProgram();
467
+ const vs = compileShader(gl, gl.VERTEX_SHADER, vertex);
468
+ const fs = compileShader(gl, gl.FRAGMENT_SHADER, fragment);
469
+ gl.attachShader(program, vs);
470
+ gl.attachShader(program, fs);
471
+ for (const [name, location] of Object.entries(ATTRIBUTES)) {
472
+ gl.bindAttribLocation(program, location, name);
473
+ }
474
+ gl.linkProgram(program);
475
+ gl.deleteShader(vs);
476
+ gl.deleteShader(fs);
477
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
478
+ const log = gl.getProgramInfoLog(program);
479
+ gl.deleteProgram(program);
480
+ throw new Error(`@react-x11/components maps/gl: link failed: ${log}`);
481
+ }
482
+ const found: Record<string, unknown> = {};
483
+ for (const name of uniforms)
484
+ found[name] = gl.getUniformLocation(program, name);
485
+ return { program, uniforms: found };
486
+ }