@arraypress/effects-astro 0.0.0-stage → 0.1.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 (314) hide show
  1. package/AGENTS.md +85 -0
  2. package/COMPONENTS.md +1264 -0
  3. package/LICENSE +139 -0
  4. package/README.md +197 -2
  5. package/package.json +60 -4
  6. package/src/components/AsciiRain.astro +36 -0
  7. package/src/components/BorderSweep.astro +39 -0
  8. package/src/components/Caustics.astro +39 -0
  9. package/src/components/ColorPanels.astro +62 -0
  10. package/src/components/Cursor.astro +97 -0
  11. package/src/components/DotGrid.astro +34 -0
  12. package/src/components/DotSurface.astro +35 -0
  13. package/src/components/EffectCanvas.astro +152 -0
  14. package/src/components/FitText.astro +35 -0
  15. package/src/components/FlutedGlass.astro +36 -0
  16. package/src/components/Glass.astro +69 -0
  17. package/src/components/GlassGlyph.astro +38 -0
  18. package/src/components/GlowField.astro +177 -0
  19. package/src/components/Grain.astro +98 -0
  20. package/src/components/HaloRing.astro +38 -0
  21. package/src/components/HighlightSweep.astro +74 -0
  22. package/src/components/ImageRipple.astro +56 -0
  23. package/src/components/Ink.astro +37 -0
  24. package/src/components/InkField.astro +45 -0
  25. package/src/components/IsoCity.astro +54 -0
  26. package/src/components/LightField.astro +40 -0
  27. package/src/components/LiquidMetal.astro +41 -0
  28. package/src/components/Magnetic.astro +52 -0
  29. package/src/components/Marquee.astro +216 -0
  30. package/src/components/MosaicReveal.astro +196 -0
  31. package/src/components/NebulaLogo.astro +38 -0
  32. package/src/components/NeonSwarm.astro +38 -0
  33. package/src/components/Ocean.astro +40 -0
  34. package/src/components/OutlineWordmark.astro +222 -0
  35. package/src/components/PaperBackground.astro +40 -0
  36. package/src/components/PaperShader.astro +55 -0
  37. package/src/components/Parallax.astro +49 -0
  38. package/src/components/ParticleLogo.astro +37 -0
  39. package/src/components/PixelGlitchText.astro +70 -0
  40. package/src/components/PointCloud.astro +37 -0
  41. package/src/components/ProductStack.astro +298 -0
  42. package/src/components/PulseMark.astro +189 -0
  43. package/src/components/RadiantGlass.astro +38 -0
  44. package/src/components/RainOnGlass.astro +71 -0
  45. package/src/components/Reveal.astro +115 -0
  46. package/src/components/ScrambleText.astro +52 -0
  47. package/src/components/ScrollReveal.astro +38 -0
  48. package/src/components/ShaderBackground.astro +55 -0
  49. package/src/components/SignalLines.astro +41 -0
  50. package/src/components/SilkRibbon.astro +37 -0
  51. package/src/components/SpotlightText.astro +131 -0
  52. package/src/components/Tilt.astro +79 -0
  53. package/src/components/Topography.astro +38 -0
  54. package/src/components/Typewriter.astro +66 -0
  55. package/src/components/VariableType.astro +59 -0
  56. package/src/components/VoxelLogo.astro +46 -0
  57. package/src/components/WaveBars.astro +41 -0
  58. package/src/components/WorldRoutes.astro +41 -0
  59. package/src/components/style.js +19 -0
  60. package/src/index.d.ts +143 -0
  61. package/src/index.js +105 -0
  62. package/src/runtime/ascii-rain.d.ts +53 -0
  63. package/src/runtime/ascii-rain.js +355 -0
  64. package/src/runtime/audio-meter.d.ts +65 -0
  65. package/src/runtime/audio-meter.js +282 -0
  66. package/src/runtime/audio.d.ts +26 -0
  67. package/src/runtime/audio.js +453 -0
  68. package/src/runtime/blur.d.ts +2 -0
  69. package/src/runtime/blur.js +56 -0
  70. package/src/runtime/canvas2d.d.ts +23 -0
  71. package/src/runtime/canvas2d.js +105 -0
  72. package/src/runtime/caustics.d.ts +40 -0
  73. package/src/runtime/caustics.js +286 -0
  74. package/src/runtime/color.d.ts +33 -0
  75. package/src/runtime/color.js +213 -0
  76. package/src/runtime/curl.d.ts +5 -0
  77. package/src/runtime/curl.js +81 -0
  78. package/src/runtime/cursor.d.ts +9 -0
  79. package/src/runtime/cursor.js +80 -0
  80. package/src/runtime/device.d.ts +14 -0
  81. package/src/runtime/device.js +73 -0
  82. package/src/runtime/dot-grid.d.ts +27 -0
  83. package/src/runtime/dot-grid.js +245 -0
  84. package/src/runtime/dot-surface.d.ts +46 -0
  85. package/src/runtime/dot-surface.js +429 -0
  86. package/src/runtime/feedback.d.ts +18 -0
  87. package/src/runtime/feedback.js +131 -0
  88. package/src/runtime/fit-text.d.ts +5 -0
  89. package/src/runtime/fit-text.js +60 -0
  90. package/src/runtime/fluid.d.ts +55 -0
  91. package/src/runtime/fluid.js +504 -0
  92. package/src/runtime/fluted-glass.d.ts +27 -0
  93. package/src/runtime/fluted-glass.js +157 -0
  94. package/src/runtime/gl.d.ts +19 -0
  95. package/src/runtime/gl.js +104 -0
  96. package/src/runtime/glass-glyph.d.ts +49 -0
  97. package/src/runtime/glass-glyph.js +355 -0
  98. package/src/runtime/glass-sheen.d.ts +2 -0
  99. package/src/runtime/glass-sheen.js +30 -0
  100. package/src/runtime/glsl.d.ts +17 -0
  101. package/src/runtime/glsl.js +78 -0
  102. package/src/runtime/glyphs.d.ts +22 -0
  103. package/src/runtime/glyphs.js +107 -0
  104. package/src/runtime/halo-ring.d.ts +47 -0
  105. package/src/runtime/halo-ring.js +334 -0
  106. package/src/runtime/height-field.d.ts +50 -0
  107. package/src/runtime/height-field.js +176 -0
  108. package/src/runtime/image-ripple.d.ts +25 -0
  109. package/src/runtime/image-ripple.js +353 -0
  110. package/src/runtime/image.d.ts +11 -0
  111. package/src/runtime/image.js +81 -0
  112. package/src/runtime/in-view.d.ts +6 -0
  113. package/src/runtime/in-view.js +36 -0
  114. package/src/runtime/ink-field/shaders.js +258 -0
  115. package/src/runtime/ink-field/sim.js +582 -0
  116. package/src/runtime/ink-field.d.ts +39 -0
  117. package/src/runtime/ink-field.js +311 -0
  118. package/src/runtime/ink.d.ts +31 -0
  119. package/src/runtime/ink.js +109 -0
  120. package/src/runtime/instancing.d.ts +12 -0
  121. package/src/runtime/instancing.js +37 -0
  122. package/src/runtime/iso-camera.d.ts +35 -0
  123. package/src/runtime/iso-camera.js +85 -0
  124. package/src/runtime/iso-city/figures.d.ts +30 -0
  125. package/src/runtime/iso-city/figures.js +136 -0
  126. package/src/runtime/iso-city/look.d.ts +34 -0
  127. package/src/runtime/iso-city/look.js +105 -0
  128. package/src/runtime/iso-city/plan.d.ts +59 -0
  129. package/src/runtime/iso-city/plan.js +463 -0
  130. package/src/runtime/iso-city/roads.d.ts +64 -0
  131. package/src/runtime/iso-city/roads.js +320 -0
  132. package/src/runtime/iso-city/scene.d.ts +27 -0
  133. package/src/runtime/iso-city/scene.js +432 -0
  134. package/src/runtime/iso-city/shaders.d.ts +6 -0
  135. package/src/runtime/iso-city/shaders.js +233 -0
  136. package/src/runtime/iso-city/shadows.d.ts +13 -0
  137. package/src/runtime/iso-city/shadows.js +148 -0
  138. package/src/runtime/iso-city/traffic.d.ts +80 -0
  139. package/src/runtime/iso-city/traffic.js +457 -0
  140. package/src/runtime/iso-city.d.ts +37 -0
  141. package/src/runtime/iso-city.js +458 -0
  142. package/src/runtime/lens-map.d.ts +11 -0
  143. package/src/runtime/lens-map.js +146 -0
  144. package/src/runtime/light-field.d.ts +29 -0
  145. package/src/runtime/light-field.js +292 -0
  146. package/src/runtime/liquid-glass.d.ts +48 -0
  147. package/src/runtime/liquid-glass.js +423 -0
  148. package/src/runtime/liquid-metal/beads.js +217 -0
  149. package/src/runtime/liquid-metal/field.js +88 -0
  150. package/src/runtime/liquid-metal/look.js +64 -0
  151. package/src/runtime/liquid-metal/shaders.js +255 -0
  152. package/src/runtime/liquid-metal/wave.js +53 -0
  153. package/src/runtime/liquid-metal.d.ts +46 -0
  154. package/src/runtime/liquid-metal.js +366 -0
  155. package/src/runtime/loop.d.ts +7 -0
  156. package/src/runtime/loop.js +112 -0
  157. package/src/runtime/magnetic.d.ts +9 -0
  158. package/src/runtime/magnetic.js +46 -0
  159. package/src/runtime/marquee.d.ts +2 -0
  160. package/src/runtime/marquee.js +27 -0
  161. package/src/runtime/mesh.d.ts +30 -0
  162. package/src/runtime/mesh.js +217 -0
  163. package/src/runtime/mosaic-reveal.d.ts +34 -0
  164. package/src/runtime/mosaic-reveal.js +504 -0
  165. package/src/runtime/motion.d.ts +2 -0
  166. package/src/runtime/motion.js +21 -0
  167. package/src/runtime/mount.d.ts +13 -0
  168. package/src/runtime/mount.js +120 -0
  169. package/src/runtime/nebula-logo.d.ts +31 -0
  170. package/src/runtime/nebula-logo.js +282 -0
  171. package/src/runtime/neon-swarm.d.ts +31 -0
  172. package/src/runtime/neon-swarm.js +258 -0
  173. package/src/runtime/ocean/presets.d.ts +54 -0
  174. package/src/runtime/ocean/presets.js +184 -0
  175. package/src/runtime/ocean/shader.d.ts +14 -0
  176. package/src/runtime/ocean/shader.js +389 -0
  177. package/src/runtime/ocean/view.d.ts +24 -0
  178. package/src/runtime/ocean/view.js +98 -0
  179. package/src/runtime/ocean/waves.d.ts +29 -0
  180. package/src/runtime/ocean/waves.js +119 -0
  181. package/src/runtime/ocean.d.ts +31 -0
  182. package/src/runtime/ocean.js +173 -0
  183. package/src/runtime/palettes.d.ts +37 -0
  184. package/src/runtime/palettes.js +75 -0
  185. package/src/runtime/paper-look.d.ts +42 -0
  186. package/src/runtime/paper-look.js +91 -0
  187. package/src/runtime/paper-looks.d.ts +17 -0
  188. package/src/runtime/paper-looks.js +21 -0
  189. package/src/runtime/paper.d.ts +37 -0
  190. package/src/runtime/paper.js +303 -0
  191. package/src/runtime/particle-logo.d.ts +31 -0
  192. package/src/runtime/particle-logo.js +196 -0
  193. package/src/runtime/ping-pong.d.ts +43 -0
  194. package/src/runtime/ping-pong.js +175 -0
  195. package/src/runtime/pixel-glitch.d.ts +17 -0
  196. package/src/runtime/pixel-glitch.js +287 -0
  197. package/src/runtime/point-cloud.d.ts +33 -0
  198. package/src/runtime/point-cloud.js +287 -0
  199. package/src/runtime/pointer.d.ts +27 -0
  200. package/src/runtime/pointer.js +128 -0
  201. package/src/runtime/points.d.ts +25 -0
  202. package/src/runtime/points.js +130 -0
  203. package/src/runtime/pools.d.ts +2 -0
  204. package/src/runtime/pools.js +25 -0
  205. package/src/runtime/product-stack.d.ts +24 -0
  206. package/src/runtime/product-stack.js +210 -0
  207. package/src/runtime/radiant-glass.d.ts +29 -0
  208. package/src/runtime/radiant-glass.js +282 -0
  209. package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
  210. package/src/runtime/rain-on-glass/backdrop.js +185 -0
  211. package/src/runtime/rain-on-glass/shader.d.ts +2 -0
  212. package/src/runtime/rain-on-glass/shader.js +168 -0
  213. package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
  214. package/src/runtime/rain-on-glass/wipe.js +65 -0
  215. package/src/runtime/rain-on-glass.d.ts +27 -0
  216. package/src/runtime/rain-on-glass.js +210 -0
  217. package/src/runtime/ramp.d.ts +2 -0
  218. package/src/runtime/ramp.js +30 -0
  219. package/src/runtime/random.d.ts +2 -0
  220. package/src/runtime/random.js +22 -0
  221. package/src/runtime/scroll-reveal.d.ts +22 -0
  222. package/src/runtime/scroll-reveal.js +73 -0
  223. package/src/runtime/shader-background.d.ts +42 -0
  224. package/src/runtime/shader-background.js +261 -0
  225. package/src/runtime/shader-backgrounds/band-lens.js +72 -0
  226. package/src/runtime/shader-backgrounds/common.js +53 -0
  227. package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
  228. package/src/runtime/shader-backgrounds/grid.js +33 -0
  229. package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
  230. package/src/runtime/shader-backgrounds/silk.js +57 -0
  231. package/src/runtime/shader-backgrounds/waves.js +31 -0
  232. package/src/runtime/shape.d.ts +42 -0
  233. package/src/runtime/shape.js +313 -0
  234. package/src/runtime/silk-ribbon.d.ts +23 -0
  235. package/src/runtime/silk-ribbon.js +206 -0
  236. package/src/runtime/slideshow.d.ts +27 -0
  237. package/src/runtime/slideshow.js +234 -0
  238. package/src/runtime/spotlight.d.ts +9 -0
  239. package/src/runtime/spotlight.js +97 -0
  240. package/src/runtime/stack-poses.d.ts +53 -0
  241. package/src/runtime/stack-poses.js +273 -0
  242. package/src/runtime/stage.d.ts +47 -0
  243. package/src/runtime/stage.js +187 -0
  244. package/src/runtime/swarm.d.ts +49 -0
  245. package/src/runtime/swarm.js +199 -0
  246. package/src/runtime/text-motion.d.ts +41 -0
  247. package/src/runtime/text-motion.js +165 -0
  248. package/src/runtime/text.d.ts +11 -0
  249. package/src/runtime/text.js +90 -0
  250. package/src/runtime/tilt.d.ts +19 -0
  251. package/src/runtime/tilt.js +116 -0
  252. package/src/runtime/topography.d.ts +71 -0
  253. package/src/runtime/topography.js +650 -0
  254. package/src/runtime/trackers.d.ts +21 -0
  255. package/src/runtime/trackers.js +76 -0
  256. package/src/runtime/variable-type.d.ts +43 -0
  257. package/src/runtime/variable-type.js +358 -0
  258. package/src/runtime/voxel-logo.d.ts +31 -0
  259. package/src/runtime/voxel-logo.js +237 -0
  260. package/src/runtime/waves.d.ts +70 -0
  261. package/src/runtime/waves.js +799 -0
  262. package/src/runtime/world-labels.d.ts +29 -0
  263. package/src/runtime/world-labels.js +59 -0
  264. package/src/runtime/world-land.d.ts +8 -0
  265. package/src/runtime/world-land.js +105 -0
  266. package/src/runtime/world-map.d.ts +69 -0
  267. package/src/runtime/world-map.js +308 -0
  268. package/src/runtime/world-plan.d.ts +101 -0
  269. package/src/runtime/world-plan.js +333 -0
  270. package/src/runtime/world-routes.d.ts +75 -0
  271. package/src/runtime/world-routes.js +673 -0
  272. package/src/styles/border-sweep.css +82 -0
  273. package/src/styles/glass.css +104 -0
  274. package/src/styles/motion.css +218 -0
  275. package/src/styles/reveal.css +51 -0
  276. package/src/vendor/paper/LICENSE +201 -0
  277. package/src/vendor/paper/NOTICE +5 -0
  278. package/src/vendor/paper/README.md +8 -0
  279. package/src/vendor/paper/get-shader-color-from-string.js +100 -0
  280. package/src/vendor/paper/get-shader-noise-texture.js +17 -0
  281. package/src/vendor/paper/presets.js +3678 -0
  282. package/src/vendor/paper/shader-sizing.js +37 -0
  283. package/src/vendor/paper/shader-utils.js +130 -0
  284. package/src/vendor/paper/shaders/color-panels.js +223 -0
  285. package/src/vendor/paper/shaders/dithering.js +270 -0
  286. package/src/vendor/paper/shaders/dot-grid.js +109 -0
  287. package/src/vendor/paper/shaders/dot-orbit.js +122 -0
  288. package/src/vendor/paper/shaders/fluted-glass.js +360 -0
  289. package/src/vendor/paper/shaders/gem-smoke.js +572 -0
  290. package/src/vendor/paper/shaders/god-rays.js +132 -0
  291. package/src/vendor/paper/shaders/grain-gradient.js +300 -0
  292. package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
  293. package/src/vendor/paper/shaders/halftone-dots.js +320 -0
  294. package/src/vendor/paper/shaders/heatmap.js +383 -0
  295. package/src/vendor/paper/shaders/image-dithering.js +198 -0
  296. package/src/vendor/paper/shaders/lens-distortion.js +275 -0
  297. package/src/vendor/paper/shaders/liquid-metal.js +632 -0
  298. package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
  299. package/src/vendor/paper/shaders/metaballs.js +110 -0
  300. package/src/vendor/paper/shaders/neuro-noise.js +76 -0
  301. package/src/vendor/paper/shaders/paper-texture.js +526 -0
  302. package/src/vendor/paper/shaders/perlin-noise.js +166 -0
  303. package/src/vendor/paper/shaders/pulsing-border.js +238 -0
  304. package/src/vendor/paper/shaders/simplex-noise.js +91 -0
  305. package/src/vendor/paper/shaders/smoke-ring.js +132 -0
  306. package/src/vendor/paper/shaders/spiral.js +82 -0
  307. package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
  308. package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
  309. package/src/vendor/paper/shaders/swirl.js +103 -0
  310. package/src/vendor/paper/shaders/voronoi.js +138 -0
  311. package/src/vendor/paper/shaders/warp.js +129 -0
  312. package/src/vendor/paper/shaders/water.js +121 -0
  313. package/src/vendor/paper/shaders/waves.js +65 -0
  314. package/src/vendor/paper/vertex-shader.js +159 -0
@@ -0,0 +1,29 @@
1
+ /** A name to place beside its city. */
2
+ export interface LabelItem {
3
+ /** The city, CSS px. */
4
+ x: number;
5
+ y: number;
6
+ /** The name's size, CSS px. */
7
+ w: number;
8
+ h: number;
9
+ /** Space between the city's centre and its name. */
10
+ gap: number;
11
+ /** Show it even where it overlaps. */
12
+ force?: boolean;
13
+ }
14
+
15
+ /** A box: its top left and size. */
16
+ export interface Rect {
17
+ x: number;
18
+ y: number;
19
+ w: number;
20
+ h: number;
21
+ }
22
+
23
+ /**
24
+ * Places names beside their cities, most important first: right, left,
25
+ * above or below, whichever first covers no placed name and no obstacle
26
+ * and stays in `bounds` (null for anywhere). A name with nowhere to go is
27
+ * null, unless `force` puts it on the first side that fits the bounds.
28
+ */
29
+ export function placeLabels(items: LabelItem[], obstacles: Rect[], bounds: { width: number; height: number } | null): (Rect | null)[];
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/world-labels
3
+ *
4
+ * Where <WorldRoutes> puts the cities' names: beside each city, trying
5
+ * the right, the left, above and below in turn, and leaving a name out
6
+ * rather than letting it cover another or another city's dot. Names that
7
+ * must show (the home city's, the one under the pointer) take the first
8
+ * side that fits the box whatever they cover.
9
+ */
10
+
11
+ /**
12
+ * @typedef {object} LabelItem
13
+ * @property {number} x The city, CSS px across.
14
+ * @property {number} y The city, CSS px down.
15
+ * @property {number} w The name's width, CSS px.
16
+ * @property {number} h The name's height, CSS px.
17
+ * @property {number} gap Space between the city's centre and its name.
18
+ * @property {boolean} [force] Show it even where it overlaps.
19
+ */
20
+
21
+ /** @typedef {{ x: number, y: number, w: number, h: number }} Rect A box, its top left and size. */
22
+
23
+ /**
24
+ * Do two boxes overlap?
25
+ *
26
+ * @param {Rect} a One.
27
+ * @param {Rect} b The other.
28
+ * @returns {boolean} True when they share any area.
29
+ */
30
+ const overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
31
+
32
+ /**
33
+ * Places names beside their cities, first come first served: pass the
34
+ * ones that matter most first.
35
+ *
36
+ * @param {LabelItem[]} items The names, in order of importance.
37
+ * @param {Rect[]} obstacles What names must not cover (the cities' dots), each item's own city included.
38
+ * @param {{ width: number, height: number } | null} bounds The box names must stay in, or null for anywhere.
39
+ * @returns {(Rect | null)[]} Each name's box, or null where it is left out.
40
+ */
41
+ export function placeLabels(items, obstacles, bounds) {
42
+ /** @type {Rect[]} */
43
+ const placed = [];
44
+ return items.map((item) => {
45
+ const { x, y, w, h, gap } = item;
46
+ /** @type {Rect[]} */
47
+ const sides = [
48
+ { x: x + gap, y: y - h / 2, w, h },
49
+ { x: x - gap - w, y: y - h / 2, w, h },
50
+ { x: x - w / 2, y: y - gap - h, w, h },
51
+ { x: x - w / 2, y: y + gap, w, h },
52
+ ];
53
+ const inside = sides.filter((r) => !bounds || (r.x >= 0 && r.y >= 0 && r.x + r.w <= bounds.width && r.y + r.h <= bounds.height));
54
+ const free = inside.find((r) => !placed.some((p) => overlaps(p, r)) && !obstacles.some((o) => overlaps(o, r)));
55
+ const box = free ?? (item.force ? (inside[0] ?? sides[0]) : null);
56
+ if (box) placed.push(box);
57
+ return box;
58
+ });
59
+ }
@@ -0,0 +1,8 @@
1
+ /** Natural Earth's land on a 1.5° grid from 84°N to 60°S, as alternating sea and land runs in base 36. */
2
+ export const LAND: { cols: number; rows: number; step: number; top: number; runs: string };
3
+
4
+ /** Whether a point (degrees north, degrees east) is on land. */
5
+ export function isLand(lat: number, lon: number): boolean;
6
+
7
+ /** How much land is at a point, 0–1, blended between the four nearest cells: above 0.5 is land, with rounded coasts. */
8
+ export function landAt(lat: number, lon: number): number;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/world-land
3
+ *
4
+ * Where the land is, at 1.5° a cell, for drawing a world map without
5
+ * shipping one: Natural Earth's 1:110m land (public domain), sampled on
6
+ * an equirectangular grid from 84°N to 60°S (Antarctica left out), and
7
+ * stored as runs of sea and land, alternately, in base 36.
8
+ */
9
+
10
+ /** The grid: columns from 180°W, rows from 84°N, each `step` degrees. */
11
+ export const LAND = {
12
+ cols: 240,
13
+ rows: 96,
14
+ step: 1.5,
15
+ top: 84,
16
+ runs:
17
+ '2m,9,5g,h,2,r,3,3,55,6,3,8,2,x,o,6,d,2,s,5,2r,1,4,3,1,2,1,4,1,7,4,y,l,5,1i,3,2i,2,j,6,7,x,m,3,1k,2,2k,4,1,2,3,' +
18
+ '3,3,2,4,1,f,r,1g,4,j,e,g,4,1p,3,16,o,1f,2,j,f,2c,4,1,3,1,1,1,2,2,3,1,2,2,6,h,m,1e,2,9,2,6,w,7,2,p,2,d,1,m,1,3,' +
19
+ '8,6,2,2,c,d,8,c,1b,3,3,7,3,1,11,2,d,u,f,6,4,2,1,3,b,1,1,1,2,5,1,4,7,9,k,t,9,i,1,4,3,1,1l,7,5,4,7,z,4,2,4,2,1,4' +
20
+ ',2,2,6,4,a,f,u,g,3,2,3,2,1,8,1,3,1,21,1,2,6,1h,6,8,5,d,w,i,3,i,1,1z,3,2,4,1h,1,1,4,7,2,1,7,8,c,6,h,6,3,6,4,2y,' +
21
+ '1b,2,2,1,2,5,5,9,7,d,2,i,7,2,2w,b,1c,6,1,3,3,3,2,b,5,w,8,2,2n,1,8,c,b,1,z,b,6,f,2,w,9,2,2i,5,5,i,5,a,u,b,6,2,2' +
22
+ ',1a,8,4,28,2,1,2,2,4,2,q,1,1,1,d,r,b,a,11,1,b,3,5,25,c,3,p,1,i,u,7,a,11,2,7,2,1,3,3,26,c,5,l,1,m,w,2,f,x,1,1,2' +
23
+ ',7,1,4,1,1,25,e,4,17,1,2,v,2,g,v,2,1,3,3,2k,9,3,1c,v,1,f,z,4,2,2k,9,1,1e,15,2,2,10,2,3,2l,1,1,1o,12,1,2,4,3,x,' +
24
+ '1,1,2m,1s,14,7,1,x,2n,1s,17,13,l,2,1,2,7,3,1l,1t,11,2,1,16,9,2,9,7,5,3,1l,3,2,1p,10,15,8,5,2,3,7,9,4,3,1h,5,3,' +
25
+ '1p,z,16,7,8,2,2,6,2,4,2,6,3,1e,1z,y,17,6,a,1,2,2,3,f,3,18,1,1,1,2,8,2,1r,w,18,6,a,1,3,2,2,f,3,17,4,3,7,1,1t,u,' +
26
+ '1b,3,3,1,1,3,b,1r,3,2,5,3,1t,u,1b,2,1,8,9,2,4,1,1,1k,4,2,2,6,1v,r,1b,c,h,1k,8,3,1z,o,1c,g,3,2,8,1m,6,1,23,1,1,' +
27
+ 'l,1c,i,1,1w,2a,1,1,c,2,1,5,1,1b,13,2,1b,2a,2,1,9,a,1,19,v,2,9,2,1a,2c,1,1,8,a,2,1,1,15,x,1,9,4,17,2d,1,2,7,1j,' +
28
+ 'x,2,9,2,2,7,y,2i,6,1i,z,2,d,7,w,2,1,2h,5,c,1,15,10,1,e,6,d,2,e,2n,5,5,2,6,3,12,10,2,c,a,9,4,9,2s,5,3,3,a,2,z,1' +
29
+ '0,2,b,b,7,7,8,1,2,2r,8,1c,11,2,9,c,6,8,8,9,2,2l,1,2,6,19,11,2,7,e,5,9,1,1,7,8,1,2q,6,18,13,1,4,h,3,c,8,7,1,2t,' +
30
+ '2,19,15,k,3,d,7,9,1,2s,1,7,1,1,1,10,13,3,2,h,2,g,3,9,1,1,1,2s,1,5,2,1,6,w,17,h,2,h,1,36,1,2,c,v,16,k,1,b,2,f,2' +
31
+ ',2w,d,v,15,k,1,d,1,f,1,2w,h,t,6,3,t,w,1,2,2,8,2,32,h,14,q,w,2,1,2,7,2,32,i,14,p,y,2,1,1,5,5,30,k,13,n,11,3,4,6' +
32
+ ',1,3,2,1,2s,n,11,m,13,2,4,5,7,1,2,1,2p,o,10,l,14,3,3,5,1,2,8,1,1,2,2l,s,x,k,15,3,5,1,4,1,2,1,4,7,2i,u,w,i,17,2' +
33
+ ',l,5,2h,v,v,i,18,2,2,1,e,1,2,6,6,1,2a,u,w,h,1c,3,f,4,1,2,7,1,29,s,x,i,1j,1,f,2,2g,r,y,i,4i,q,y,i,1o,4,4,1,2l,p' +
34
+ ',y,j,5,1,1f,1,1,5,3,2,2m,o,y,j,4,3,1d,8,3,3,2n,m,y,h,4,4,1d,b,1,3,2o,l,y,g,5,4,1c,h,2n,k,10,e,7,2,1b,k,a,1,2b,' +
35
+ 'k,10,f,5,3,19,n,a,1,2a,i,13,e,5,3,18,p,2k,f,16,d,6,2,19,q,2j,f,16,c,1i,q,2j,f,16,c,1i,q,2i,f,18,a,1k,p,2i,e,1a' +
36
+ ',8,1l,p,2i,d,1b,7,1m,8,4,d,2i,c,1c,5,1o,6,7,1,1,9,2j,a,3m,8,f,1,23,b,3n,7,g,1,22,a,3p,2,1,1,i,3,20,8,4d,2,21,6' +
37
+ ',3w,2,h,1,22,6,3w,2,f,2,22,6,4c,2,24,5,4c,3,24,6,6i,5,6j,4,6k,4,5,2,6e,4,6l,5,oj',
38
+ };
39
+
40
+ /** @type {Uint8Array | null} */
41
+ let cells = null;
42
+
43
+ /**
44
+ * The grid decoded, once: 1 for land, 0 for sea, row by row from 84°N.
45
+ *
46
+ * @returns {Uint8Array} The cells.
47
+ */
48
+ function grid() {
49
+ if (!cells) {
50
+ const decoded = new Uint8Array(LAND.cols * LAND.rows);
51
+ let at = 0;
52
+ LAND.runs.split(',').forEach((run, i) => {
53
+ const length = parseInt(run, 36);
54
+ if (i % 2) decoded.fill(1, at, at + length);
55
+ at += length;
56
+ });
57
+ cells = decoded;
58
+ }
59
+ return cells;
60
+ }
61
+
62
+ /**
63
+ * One cell, with longitude wrapping round the world and anything off the
64
+ * grid's top or bottom counted as sea.
65
+ *
66
+ * @param {number} row The row, from 84°N.
67
+ * @param {number} col The column, from 180°W (any whole number).
68
+ * @returns {number} 1 for land, 0 for sea.
69
+ */
70
+ function cell(row, col) {
71
+ if (row < 0 || row >= LAND.rows) return 0;
72
+ return grid()[row * LAND.cols + (((col % LAND.cols) + LAND.cols) % LAND.cols)];
73
+ }
74
+
75
+ /**
76
+ * Whether a point is on land.
77
+ *
78
+ * @param {number} lat Latitude, degrees north.
79
+ * @param {number} lon Longitude, degrees east.
80
+ * @returns {boolean} True on land.
81
+ */
82
+ export function isLand(lat, lon) {
83
+ return cell(Math.floor((LAND.top - lat) / LAND.step), Math.floor((lon + 180) / LAND.step)) === 1;
84
+ }
85
+
86
+ /**
87
+ * How much of the land is at a point, blended between the four nearest
88
+ * cell centres. Above one half is land: a map zoomed in far enough that a
89
+ * cell spans several dots gets rounded coasts rather than 1.5° steps.
90
+ *
91
+ * @param {number} lat Latitude, degrees north.
92
+ * @param {number} lon Longitude, degrees east.
93
+ * @returns {number} 0 (open sea) to 1 (inland).
94
+ */
95
+ export function landAt(lat, lon) {
96
+ const y = (LAND.top - lat) / LAND.step - 0.5;
97
+ const x = (lon + 180) / LAND.step - 0.5;
98
+ const row = Math.floor(y);
99
+ const col = Math.floor(x);
100
+ const fy = y - row;
101
+ const fx = x - col;
102
+ const top = cell(row, col) * (1 - fx) + cell(row, col + 1) * fx;
103
+ const bottom = cell(row + 1, col) * (1 - fx) + cell(row + 1, col + 1) * fx;
104
+ return top * (1 - fy) + bottom * fy;
105
+ }
@@ -0,0 +1,69 @@
1
+ /** Two corners, [[south, west], [north, east]], in degrees. */
2
+ export type Bounds = [[number, number], [number, number]];
3
+
4
+ /** Bounds with `east` past `west` (above 180 when crossing the date line). */
5
+ export interface Box {
6
+ south: number;
7
+ west: number;
8
+ north: number;
9
+ east: number;
10
+ }
11
+
12
+ /** A region the map can show by name. */
13
+ export type RegionName = 'world' | 'europe' | 'north-america' | 'south-america' | 'africa' | 'middle-east' | 'asia' | 'oceania';
14
+
15
+ /** Named regions, as [[south, west], [north, east]]. */
16
+ export const REGIONS: Record<RegionName, Bounds>;
17
+
18
+ /** A longitude brought into [-180, 180). */
19
+ export function wrapLon(lon: number): number;
20
+
21
+ /** The box a region names (unknown names are the world), or with `routes` the smallest round `places`, the short way round. */
22
+ export function regionBounds(region: RegionName | 'routes' | Bounds | undefined, places?: [number, number][]): Box;
23
+
24
+ /** A box fitted into a width and height. */
25
+ export interface MapView {
26
+ width: number;
27
+ height: number;
28
+ /** CSS px a degree of latitude. */
29
+ scale: number;
30
+ /** cos(standard parallel): a degree of longitude is `scale * squash` px. */
31
+ squash: number;
32
+ /** The place at the box's middle. */
33
+ lat: number;
34
+ lon: number;
35
+ /** CSS px once round the world. */
36
+ period: number;
37
+ /** Where the region's north edge falls, CSS px down. */
38
+ top: number;
39
+ }
40
+
41
+ /** Fits a box into a width and height: all of it (`contain`, the default) or filling it (`cover`). */
42
+ export function fitView(box: Box, width: number, height: number, fit?: 'contain' | 'cover'): MapView;
43
+
44
+ /** Where a place falls on the unpanned map, CSS px: on the turn of the world centred on the view. */
45
+ export function project(view: MapView, lat: number, lon: number): [number, number];
46
+
47
+ /** The place at a point on the unpanned map, [lat, lon] (longitude not wrapped). */
48
+ export function unproject(view: MapView, x: number, y: number): [number, number];
49
+
50
+ /** `steps + 1` points [lat, lon] along the great circle between two places, longitudes unbroken from the first. */
51
+ export function greatCircle(from: [number, number], to: [number, number], steps: number): [number, number][];
52
+
53
+ /** How the land is painted. */
54
+ export interface LandStyle {
55
+ color: string;
56
+ opacity: number;
57
+ /** Space between dots, CSS px. */
58
+ pitch: number;
59
+ /** A dot's radius (half its side, square), CSS px. */
60
+ dot: number;
61
+ shape: 'round' | 'square';
62
+ /** Degrees between graticule lines, 0 for none. */
63
+ graticule: number;
64
+ /** Repeat the world round, rather than one turn of it. */
65
+ wrap: boolean;
66
+ }
67
+
68
+ /** Paints the land dots (and graticule) for the strip of the unpanned map from `left`, `width` CSS px wide, into `ctx` at 0. */
69
+ export function paintLand(ctx: CanvasRenderingContext2D, view: MapView, style: LandStyle, left: number, width: number): void;
@@ -0,0 +1,308 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/world-map
3
+ *
4
+ * The map under <WorldRoutes>: named regions, fitting one into a box
5
+ * (contain or cover), the projection between degrees and CSS px, great-
6
+ * circle paths, and painting the land dots and a graticule into tiles.
7
+ *
8
+ * The projection is equirectangular. A view of the whole world is the
9
+ * plain plate carrée; a region takes its middle latitude as the standard
10
+ * parallel, so Europe is not stretched wide. Positions are CSS px in the
11
+ * box with the map unpanned; one turn of the world is `period` px across,
12
+ * and the band one turn wide centred on the view is the map that shows
13
+ * when it does not drift.
14
+ */
15
+
16
+ import { LAND, isLand, landAt } from './world-land.js';
17
+
18
+ /** @typedef {[[number, number], [number, number]]} Bounds Two corners, [[south, west], [north, east]], in degrees. */
19
+ /** @typedef {{ south: number, west: number, north: number, east: number }} Box Bounds with `east` past `west` (above 180 when crossing the date line). */
20
+
21
+ /** Named regions, as [[south, west], [north, east]]. */
22
+ export const REGIONS = /** @type {const} */ ({
23
+ world: [[LAND.top - LAND.rows * LAND.step, -180], [LAND.top, 180]],
24
+ europe: [[35, -12], [66, 36]],
25
+ 'north-america': [[12, -138], [62, -52]],
26
+ 'south-america': [[-56, -84], [13, -32]],
27
+ africa: [[-36, -19], [38, 53]],
28
+ 'middle-east': [[11, 24], [43, 64]],
29
+ asia: [[-11, 60], [56, 150]],
30
+ oceania: [[-48, 110], [-5, 180]],
31
+ });
32
+
33
+ /** @typedef {keyof typeof REGIONS} RegionName A region the map can show by name. */
34
+
35
+ /** Degrees of the world's land latitude the map covers: 84°N to 60°S. */
36
+ const NORTH = LAND.top;
37
+ const SOUTH = LAND.top - LAND.rows * LAND.step;
38
+
39
+ /**
40
+ * A longitude brought into [-180, 180).
41
+ *
42
+ * @param {number} lon Degrees east.
43
+ * @returns {number} The same meridian, in [-180, 180).
44
+ */
45
+ export const wrapLon = (lon) => ((((lon + 180) % 360) + 360) % 360) - 180;
46
+
47
+ /**
48
+ * The bounds a region names, or that fit a set of places.
49
+ *
50
+ * @param {keyof typeof REGIONS | 'routes' | Bounds | undefined} region A name, `routes`, or [[south, west], [north, east]].
51
+ * @param {[number, number][]} [places=[]] [lat, lon] of every city, for `routes`.
52
+ * @returns {Box} The box, `east` past `west`. Unknown names, and `routes` with no places, are the world.
53
+ */
54
+ export function regionBounds(region, places = []) {
55
+ if (Array.isArray(region)) {
56
+ const [[south, west], [north, east]] = region;
57
+ return { south: Math.min(south, north), north: Math.max(south, north), west, east: east > west ? east : east + 360 };
58
+ }
59
+ if (region === 'routes' && places.length) return fitPlaces(places);
60
+ const [[south, west], [north, east]] = REGIONS[/** @type {keyof typeof REGIONS} */ (region)] ?? REGIONS.world;
61
+ return { south, west, north, east };
62
+ }
63
+
64
+ /**
65
+ * The smallest box round some places, with a margin: across the date line
66
+ * when that is the short way round (Tokyo and Los Angeles).
67
+ *
68
+ * @param {[number, number][]} places [lat, lon] of each.
69
+ * @returns {Box} The box.
70
+ */
71
+ function fitPlaces(places) {
72
+ const lats = places.map((p) => p[0]);
73
+ const lons = places.map((p) => wrapLon(p[1])).sort((a, b) => a - b);
74
+ // The widest gap between neighbouring meridians (round the back too) is the part left out.
75
+ let gap = lons[0] + 360 - lons[lons.length - 1];
76
+ let west = lons[0];
77
+ for (let i = 1; i < lons.length; i++) {
78
+ if (lons[i] - lons[i - 1] > gap) {
79
+ gap = lons[i] - lons[i - 1];
80
+ west = lons[i];
81
+ }
82
+ }
83
+ const span = 360 - gap;
84
+ if (span > 300) return regionBounds('world');
85
+ const south = Math.min(...lats);
86
+ const north = Math.max(...lats);
87
+ const padLon = Math.max(6, span * 0.12, (16 - span) / 2);
88
+ const padLat = Math.max(4, (north - south) * 0.12, (10 - (north - south)) / 2);
89
+ return {
90
+ south: Math.max(SOUTH, south - padLat),
91
+ north: Math.min(NORTH, north + padLat),
92
+ west: west - padLon,
93
+ east: west + span + padLon,
94
+ };
95
+ }
96
+
97
+ /**
98
+ * @typedef {object} MapView
99
+ * @property {number} width The box's width, CSS px.
100
+ * @property {number} height The box's height, CSS px.
101
+ * @property {number} scale CSS px a degree of latitude.
102
+ * @property {number} squash cos(standard parallel): a degree of longitude is `scale * squash` px.
103
+ * @property {number} lat The latitude at the box's middle.
104
+ * @property {number} lon The longitude at the box's middle.
105
+ * @property {number} period CSS px once round the world.
106
+ * @property {number} top Where the region's north edge falls, CSS px down.
107
+ */
108
+
109
+ /**
110
+ * Fits bounds into a box.
111
+ *
112
+ * @param {Box} box The region.
113
+ * @param {number} width The box's width, CSS px.
114
+ * @param {number} height The box's height, CSS px.
115
+ * @param {'contain' | 'cover'} [fit='contain'] Show all of the region (`contain`), or fill the box with it (`cover`).
116
+ * @returns {MapView} The view.
117
+ */
118
+ export function fitView(box, width, height, fit = 'contain') {
119
+ const spanLon = box.east - box.west;
120
+ const spanLat = box.north - box.south;
121
+ const squash = spanLon >= 300 ? 1 : Math.cos((((box.north + box.south) / 2) * Math.PI) / 180);
122
+ const across = width / (spanLon * squash);
123
+ const down = height / spanLat;
124
+ const scale = fit === 'cover' ? Math.max(across, down) : Math.min(across, down);
125
+ const lat = (box.north + box.south) / 2;
126
+ return {
127
+ width,
128
+ height,
129
+ scale,
130
+ squash,
131
+ lat,
132
+ lon: wrapLon((box.west + box.east) / 2),
133
+ period: 360 * scale * squash,
134
+ top: height / 2 - (box.north - lat) * scale,
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Where a place falls, with the map unpanned: on the turn of the world
140
+ * centred on the view.
141
+ *
142
+ * @param {MapView} view The view.
143
+ * @param {number} lat Degrees north.
144
+ * @param {number} lon Degrees east.
145
+ * @returns {[number, number]} CSS px across and down.
146
+ */
147
+ export function project(view, lat, lon) {
148
+ return [view.width / 2 + wrapLon(lon - view.lon) * view.scale * view.squash, view.height / 2 - (lat - view.lat) * view.scale];
149
+ }
150
+
151
+ /**
152
+ * The place at a point, the inverse of `project` (longitude not wrapped).
153
+ *
154
+ * @param {MapView} view The view.
155
+ * @param {number} x CSS px across, unpanned.
156
+ * @param {number} y CSS px down.
157
+ * @returns {[number, number]} [lat, lon] in degrees.
158
+ */
159
+ export function unproject(view, x, y) {
160
+ return [view.lat - (y - view.height / 2) / view.scale, view.lon + (x - view.width / 2) / (view.scale * view.squash)];
161
+ }
162
+
163
+ /**
164
+ * Points along the great circle (the shortest way over the globe) between
165
+ * two places, longitudes running on unbroken from the first, so a route
166
+ * over the date line goes past 180° rather than jumping back.
167
+ *
168
+ * @param {[number, number]} from [lat, lon] in degrees.
169
+ * @param {[number, number]} to [lat, lon] in degrees.
170
+ * @param {number} steps How many pieces.
171
+ * @returns {[number, number][]} `steps + 1` points, [lat, lon].
172
+ */
173
+ export function greatCircle(from, to, steps) {
174
+ const rad = Math.PI / 180;
175
+ /**
176
+ * A place as a point on the unit sphere.
177
+ *
178
+ * @param {[number, number]} p [lat, lon] in degrees.
179
+ * @returns {[number, number, number]} x, y, z.
180
+ */
181
+ const toVector = ([lat, lon]) => [Math.cos(lat * rad) * Math.cos(lon * rad), Math.cos(lat * rad) * Math.sin(lon * rad), Math.sin(lat * rad)];
182
+ const a = toVector(from);
183
+ const b = toVector(to);
184
+ const angle = Math.acos(Math.min(1, Math.max(-1, a[0] * b[0] + a[1] * b[1] + a[2] * b[2])));
185
+ /** @type {[number, number][]} */
186
+ const points = [];
187
+ let last = from[1];
188
+ for (let i = 0; i <= steps; i++) {
189
+ const t = i / steps;
190
+ // Antipodes and the same place have no one great circle: run straight in degrees instead.
191
+ const near = Math.sin(angle) < 1e-6;
192
+ const wa = near ? 1 - t : Math.sin((1 - t) * angle) / Math.sin(angle);
193
+ const wb = near ? t : Math.sin(t * angle) / Math.sin(angle);
194
+ const [x, y, z] = [0, 1, 2].map((k) => wa * a[k] + wb * b[k]);
195
+ let lon = near ? from[1] + (to[1] - from[1]) * t : Math.atan2(y, x) / rad;
196
+ lon += Math.round((last - lon) / 360) * 360;
197
+ last = lon;
198
+ points.push([near ? from[0] + (to[0] - from[0]) * t : Math.atan2(z, Math.hypot(x, y)) / rad, lon]);
199
+ }
200
+ return points;
201
+ }
202
+
203
+ /**
204
+ * @typedef {object} LandStyle
205
+ * @property {string} color The dots' colour.
206
+ * @property {number} opacity Their opacity.
207
+ * @property {number} pitch Space between dots, CSS px.
208
+ * @property {number} dot A dot's radius (half its side, square), CSS px.
209
+ * @property {'round' | 'square'} shape The dots' shape.
210
+ * @property {number} graticule Degrees between graticule lines, 0 for none.
211
+ * @property {boolean} wrap Repeat the world round (a drifting map), rather than one turn of it.
212
+ */
213
+
214
+ /**
215
+ * Paints the land, a dot wherever the grid falls on it, and the graticule
216
+ * as finer dots along the lines, for one strip of the map. The grid is
217
+ * the same in every strip, so strips meet without a seam.
218
+ *
219
+ * @param {CanvasRenderingContext2D} ctx Scaled so units are CSS px, the strip starting at 0.
220
+ * @param {MapView} view The view.
221
+ * @param {LandStyle} style How it looks.
222
+ * @param {number} left The strip's left edge, CSS px across the unpanned map.
223
+ * @param {number} width The strip's width, CSS px.
224
+ */
225
+ export function paintLand(ctx, view, style, left, width) {
226
+ const { pitch, dot } = style;
227
+ const band = view.width / 2 - view.period / 2;
228
+ const gx = band + pitch / 2;
229
+ const gy = view.top + pitch / 2;
230
+ // Zoomed in so far that a cell spans several dots, blend the cells for round coasts.
231
+ const smooth = view.scale * view.squash * LAND.step > pitch * 1.5;
232
+ const ys = gridLine(gy, pitch, view.height, dot);
233
+ const xs = gridLine(gx - left, pitch, width, dot);
234
+
235
+ /**
236
+ * Whether a grid point (unpanned CSS px) is on this turn of the map.
237
+ *
238
+ * @param {number} x CSS px across.
239
+ * @returns {boolean} True when it shows.
240
+ */
241
+ const shows = (x) => style.wrap || (x >= band && x < band + view.period);
242
+
243
+ /**
244
+ * Adds a dot to the path.
245
+ *
246
+ * @param {number} x CSS px across the strip.
247
+ * @param {number} y CSS px down.
248
+ * @param {number} r Its radius.
249
+ */
250
+ const mark = (x, y, r) => {
251
+ if (style.shape === 'square') ctx.rect(x - r, y - r, r * 2, r * 2);
252
+ else {
253
+ ctx.moveTo(x + r, y);
254
+ ctx.arc(x, y, r, 0, Math.PI * 2);
255
+ }
256
+ };
257
+
258
+ ctx.fillStyle = style.color;
259
+ ctx.globalAlpha = style.opacity;
260
+ ctx.beginPath();
261
+ for (const y of ys) {
262
+ for (const sx of xs) {
263
+ if (!shows(sx + left)) continue;
264
+ const [lat, lon] = unproject(view, sx + left, y);
265
+ if (smooth ? landAt(lat, lon) > 0.5 : isLand(lat, lon)) mark(sx, y, dot);
266
+ }
267
+ }
268
+ ctx.fill();
269
+
270
+ if (style.graticule > 0) {
271
+ const g = style.graticule;
272
+ const fine = Math.max(0.5, dot * 0.45);
273
+ ctx.globalAlpha = style.opacity * 0.6;
274
+ ctx.beginPath();
275
+ for (let lat = Math.ceil(SOUTH / g) * g; lat <= NORTH; lat += g) {
276
+ const y = project(view, lat, view.lon)[1];
277
+ if (y < -dot || y > view.height + dot) continue;
278
+ for (let sx = xs[0] ?? 0; sx < width + dot; sx += pitch / 2) if (shows(sx + left)) mark(sx, y, fine);
279
+ }
280
+ const [, west] = unproject(view, left, 0);
281
+ const [, east] = unproject(view, left + width, 0);
282
+ const top = Math.max(0, project(view, NORTH, 0)[1]);
283
+ const bottom = Math.min(view.height, project(view, SOUTH, 0)[1]);
284
+ for (let lon = Math.ceil(west / g) * g; lon <= east; lon += g) {
285
+ const x = view.width / 2 + (lon - view.lon) * view.scale * view.squash;
286
+ if (!shows(x)) continue;
287
+ for (let y = gy + Math.ceil((top - gy) / (pitch / 2)) * (pitch / 2); y <= bottom; y += pitch / 2) mark(x - left, y, fine);
288
+ }
289
+ ctx.fill();
290
+ }
291
+ ctx.globalAlpha = 1;
292
+ }
293
+
294
+ /**
295
+ * The grid's positions along one axis that fall in a span (dots reaching
296
+ * in from either side included).
297
+ *
298
+ * @param {number} origin Where a grid line falls, CSS px from the span's start.
299
+ * @param {number} pitch The spacing.
300
+ * @param {number} length The span.
301
+ * @param {number} reach How far a dot reaches from its centre.
302
+ * @returns {number[]} The positions, from the span's start.
303
+ */
304
+ function gridLine(origin, pitch, length, reach) {
305
+ const out = [];
306
+ for (let p = origin + Math.ceil((-reach - origin) / pitch) * pitch; p < length + reach; p += pitch) out.push(p);
307
+ return out;
308
+ }
@@ -0,0 +1,101 @@
1
+ /** A city a route can name. */
2
+ export type CityKey =
3
+ | 'amsterdam' | 'athens' | 'auckland' | 'bangalore' | 'bangkok' | 'barcelona' | 'berlin' | 'bogota'
4
+ | 'boston' | 'brussels' | 'buenos-aires' | 'cairo' | 'cape-town' | 'chicago' | 'copenhagen' | 'delhi'
5
+ | 'denver' | 'dubai' | 'dublin' | 'edinburgh' | 'helsinki' | 'hong-kong' | 'istanbul'
6
+ | 'jakarta' | 'johannesburg' | 'kuala-lumpur' | 'lagos' | 'lima' | 'lisbon' | 'london' | 'los-angeles'
7
+ | 'madrid' | 'manchester' | 'manila' | 'melbourne' | 'mexico-city' | 'miami' | 'milan' | 'montreal'
8
+ | 'mumbai' | 'munich' | 'nairobi' | 'new-york' | 'osaka' | 'oslo' | 'paris' | 'prague' | 'reykjavik'
9
+ | 'riyadh' | 'rome' | 'san-francisco' | 'santiago' | 'sao-paulo' | 'seattle' | 'seoul' | 'shanghai'
10
+ | 'singapore' | 'stockholm' | 'sydney' | 'taipei' | 'tokyo' | 'toronto' | 'vancouver' | 'vienna' | 'warsaw'
11
+ | 'zurich';
12
+
13
+ /** Cities a route can name, as [degrees north, degrees east]. */
14
+ export const CITIES: Record<CityKey, [number, number]>;
15
+
16
+ /** A city's key, [degrees north, degrees east], or a named point. */
17
+ export type Place = CityKey | [number, number] | { name: string; lat: number; lon: number };
18
+
19
+ /** A route with settings of its own. */
20
+ export interface Route {
21
+ /** Where it starts. Default the home city. */
22
+ from?: Place;
23
+ /** Where it ends. */
24
+ to: Place;
25
+ /** Its colour (and its destination's, if nothing coloured that first). */
26
+ color?: string;
27
+ /** What hovering it shows. Default "From → To". */
28
+ label?: string;
29
+ /** How fast its comets run, times the usual. Default 1. */
30
+ speed?: number;
31
+ /** Its comets' width, CSS px. Default the map's `width`. */
32
+ width?: number;
33
+ /** Dash its faint arc. Default the map's `dashed`. */
34
+ dashed?: boolean;
35
+ }
36
+
37
+ /** A route as given: `[from, to]`, a route object, or a place alone (from the home city). */
38
+ export type RouteSpec = [Place, Place] | Route | Place;
39
+
40
+ /** What `planRoutes` reads. */
41
+ export interface PlanOptions {
42
+ routes?: RouteSpec[];
43
+ home?: Place;
44
+ color?: string;
45
+ colors?: string[];
46
+ gradient?: boolean;
47
+ width?: number;
48
+ dashed?: boolean;
49
+ }
50
+
51
+ /** A city to draw. */
52
+ export interface PlannedCity {
53
+ /** Its key, its name, or its coordinates. */
54
+ id: string;
55
+ /** What its label says. */
56
+ name: string;
57
+ lat: number;
58
+ lon: number;
59
+ home: boolean;
60
+ color: string;
61
+ /** How many routes start or end there. */
62
+ routes: number;
63
+ }
64
+
65
+ /** A route to draw. */
66
+ export interface PlannedRoute {
67
+ /** Its cities, as indices into `cities`. */
68
+ from: number;
69
+ to: number;
70
+ /** Its colour from start to end, RAMP + 1 steps. */
71
+ ramp: string[];
72
+ /** The same, nearer white, for the comets' heads. */
73
+ cores: string[];
74
+ label: string;
75
+ speed: number;
76
+ width: number;
77
+ dashed: boolean;
78
+ /** Where in its lap it starts, 0–1. */
79
+ offset: number;
80
+ }
81
+
82
+ /** The routes' colour when none is given: `#38bdf8`. */
83
+ export const DEFAULT_COLOR: string;
84
+
85
+ /** Steps in a route's colour ramp. */
86
+ export const RAMP: number;
87
+
88
+ /** A city's key as a name: `new-york` is New York, `sao-paulo` São Paulo. */
89
+ export function cityName(key: string): string;
90
+
91
+ /** Where a place is and what it is called; null for an unknown city or bad coordinates. */
92
+ export function resolvePlace(place: Place | undefined): { id: string; name: string; lat: number; lon: number } | null;
93
+
94
+ /** A route as given, as a route object; null when it is not one. */
95
+ export function normalizeRoute(spec: RouteSpec): Route | null;
96
+
97
+ /** RAMP + 1 colours from `from` to `to`, blended in Oklab and pulled `toward` white (0–1); solid `to` unless both are hex. */
98
+ export function colorRamp(from: string, to: string, toward?: number): string[];
99
+
100
+ /** The cities (each once, home first) and the routes between known places, with their colours. */
101
+ export function planRoutes(options: PlanOptions): { cities: PlannedCity[]; routes: PlannedRoute[] };