@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,333 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/world-plan
3
+ *
4
+ * <WorldRoutes>'s settings turned into what it draws: the cities, each
5
+ * once, with a name and a colour, and the routes between them, each with
6
+ * the colours along it, its label, speed, width and dash.
7
+ *
8
+ * Colours: every city takes the next colour of the palette in the order
9
+ * the cities first appear (a home city takes the first, and keeps it to
10
+ * itself), and a route is the colour of the city it runs to; with `gradient`, it blends from its
11
+ * origin's colour to its destination's, in Oklab. A route's own `color`
12
+ * is its colour, and its destination's if nothing coloured that first.
13
+ */
14
+
15
+ import { mixOklab, parseColor, toHex } from './color.js';
16
+ import { pickColors } from './palettes.js';
17
+
18
+ /** Cities a route can name, as [degrees north, degrees east]. */
19
+ export const CITIES = {
20
+ amsterdam: [52.37, 4.9],
21
+ athens: [37.98, 23.73],
22
+ auckland: [-36.85, 174.76],
23
+ bangalore: [12.97, 77.59],
24
+ bangkok: [13.76, 100.5],
25
+ barcelona: [41.39, 2.17],
26
+ berlin: [52.52, 13.4],
27
+ bogota: [4.71, -74.07],
28
+ boston: [42.36, -71.06],
29
+ brussels: [50.85, 4.35],
30
+ 'buenos-aires': [-34.6, -58.38],
31
+ cairo: [30.04, 31.24],
32
+ 'cape-town': [-33.92, 18.42],
33
+ chicago: [41.88, -87.63],
34
+ copenhagen: [55.68, 12.57],
35
+ delhi: [28.61, 77.21],
36
+ denver: [39.74, -104.99],
37
+ dubai: [25.2, 55.27],
38
+ dublin: [53.35, -6.26],
39
+ edinburgh: [55.95, -3.19],
40
+ helsinki: [60.17, 24.94],
41
+ 'hong-kong': [22.32, 114.17],
42
+ istanbul: [41.01, 28.98],
43
+ jakarta: [-6.2, 106.85],
44
+ johannesburg: [-26.2, 28.05],
45
+ 'kuala-lumpur': [3.14, 101.69],
46
+ lagos: [6.52, 3.38],
47
+ lima: [-12.05, -77.04],
48
+ lisbon: [38.72, -9.14],
49
+ london: [51.51, -0.13],
50
+ 'los-angeles': [34.05, -118.24],
51
+ madrid: [40.42, -3.7],
52
+ manchester: [53.48, -2.24],
53
+ manila: [14.6, 120.98],
54
+ melbourne: [-37.81, 144.96],
55
+ 'mexico-city': [19.43, -99.13],
56
+ miami: [25.76, -80.19],
57
+ milan: [45.46, 9.19],
58
+ montreal: [45.5, -73.57],
59
+ mumbai: [19.08, 72.88],
60
+ munich: [48.14, 11.58],
61
+ nairobi: [-1.29, 36.82],
62
+ 'new-york': [40.71, -74.01],
63
+ osaka: [34.69, 135.5],
64
+ oslo: [59.91, 10.75],
65
+ paris: [48.86, 2.35],
66
+ prague: [50.08, 14.44],
67
+ reykjavik: [64.15, -21.94],
68
+ riyadh: [24.71, 46.68],
69
+ rome: [41.9, 12.5],
70
+ 'san-francisco': [37.77, -122.42],
71
+ santiago: [-33.45, -70.67],
72
+ 'sao-paulo': [-23.55, -46.63],
73
+ seattle: [47.61, -122.33],
74
+ seoul: [37.57, 126.98],
75
+ shanghai: [31.23, 121.47],
76
+ singapore: [1.35, 103.82],
77
+ stockholm: [59.33, 18.07],
78
+ sydney: [-33.87, 151.21],
79
+ taipei: [25.03, 121.57],
80
+ tokyo: [35.68, 139.69],
81
+ toronto: [43.65, -79.38],
82
+ vancouver: [49.28, -123.12],
83
+ vienna: [48.21, 16.37],
84
+ warsaw: [52.23, 21.01],
85
+ zurich: [47.38, 8.54],
86
+ };
87
+
88
+ /** Names that are not just the key in title case. */
89
+ const NAMES = /** @type {Record<string, string>} */ ({ bogota: 'Bogotá', reykjavik: 'Reykjavík', 'sao-paulo': 'São Paulo', zurich: 'Zürich' });
90
+
91
+ /** @typedef {keyof typeof CITIES | [number, number] | { name: string, lat: number, lon: number }} Place */
92
+
93
+ /**
94
+ * @typedef {object} Route
95
+ * @property {Place} [from] Where it starts. Default the home city.
96
+ * @property {Place} to Where it ends.
97
+ * @property {string} [color] Its colour.
98
+ * @property {string} [label] What hovering it shows. Default "From → To".
99
+ * @property {number} [speed] How fast its comets run, times the usual.
100
+ * @property {number} [width] Its comets' width, CSS px.
101
+ * @property {boolean} [dashed] Dash its faint arc.
102
+ */
103
+
104
+ /** @typedef {[Place, Place] | Route | Place} RouteSpec */
105
+
106
+ /**
107
+ * @typedef {object} PlanOptions
108
+ * @property {RouteSpec[]} [routes] The routes.
109
+ * @property {Place} [home] The city every route without a `from` starts at.
110
+ * @property {string} [color] One colour for everything.
111
+ * @property {string[]} [colors] A palette, used in place of `color`.
112
+ * @property {boolean} [gradient] Blend each route from its origin's colour to its destination's.
113
+ * @property {number} [width] The comets' width, CSS px.
114
+ * @property {boolean} [dashed] Dash the faint arcs.
115
+ */
116
+
117
+ /**
118
+ * @typedef {object} PlannedCity
119
+ * @property {string} id Its key, its name, or its coordinates.
120
+ * @property {string} name What its label says.
121
+ * @property {number} lat Degrees north.
122
+ * @property {number} lon Degrees east.
123
+ * @property {boolean} home Whether it is the home city.
124
+ * @property {string} color Its colour.
125
+ * @property {number} routes How many routes start or end there.
126
+ */
127
+
128
+ /**
129
+ * @typedef {object} PlannedRoute
130
+ * @property {number} from The city it starts at (an index into `cities`).
131
+ * @property {number} to The city it ends at.
132
+ * @property {string[]} ramp Its colour from start to end, RAMP + 1 steps (all the same without a gradient).
133
+ * @property {string[]} cores The same, nearer white, for the comets' heads.
134
+ * @property {string} label What hovering it shows.
135
+ * @property {number} speed How fast its comets run, times the usual.
136
+ * @property {number} width Its comets' width, CSS px.
137
+ * @property {boolean} dashed Whether its faint arc is dashed.
138
+ * @property {number} offset Where in its lap it starts, 0–1, so the comets do not all leave at once.
139
+ */
140
+
141
+ /** The routes' colour when none is given. */
142
+ export const DEFAULT_COLOR = '#38bdf8';
143
+
144
+ /** Steps in a route's colour ramp. */
145
+ export const RAMP = 16;
146
+
147
+ /**
148
+ * Ten routes round the world: the map with no routes given.
149
+ *
150
+ * @type {RouteSpec[]}
151
+ */
152
+ const ROUTES = [
153
+ ['new-york', 'london'],
154
+ ['london', 'berlin'],
155
+ ['berlin', 'shanghai'],
156
+ ['shanghai', 'tokyo'],
157
+ ['tokyo', 'sydney'],
158
+ ['new-york', 'sao-paulo'],
159
+ ['london', 'mumbai'],
160
+ ['shanghai', 'singapore'],
161
+ ['paris', 'sao-paulo'],
162
+ ['toronto', 'london'],
163
+ ];
164
+
165
+ /** Where routes from a home city run when none are given. */
166
+ const SPOKES = /** @type {const} */ (['new-york', 'sao-paulo', 'lagos', 'dubai', 'mumbai', 'singapore', 'tokyo', 'sydney', 'los-angeles', 'cape-town']);
167
+
168
+ /**
169
+ * A city's key as a name: `new-york` is New York.
170
+ *
171
+ * @param {string} key The key.
172
+ * @returns {string} The name.
173
+ */
174
+ export function cityName(key) {
175
+ return NAMES[key] ?? key.replace(/(^|-)(\w)/g, (_, dash, c) => (dash ? ' ' : '') + c.toUpperCase());
176
+ }
177
+
178
+ /**
179
+ * Is it a place, rather than a route?
180
+ *
181
+ * @param {unknown} value A route as given.
182
+ * @returns {value is Place} True for a key, [lat, lon], or { name, lat, lon }.
183
+ */
184
+ const isPlace = (value) =>
185
+ typeof value === 'string' ||
186
+ (Array.isArray(value) && typeof value[0] === 'number' && typeof value[1] === 'number') ||
187
+ (!!value && typeof value === 'object' && !Array.isArray(value) && 'lat' in value && 'lon' in value);
188
+
189
+ /**
190
+ * Where a place is, and what it is called.
191
+ *
192
+ * @param {Place | undefined} place A city's key, [lat, lon], or { name, lat, lon }.
193
+ * @returns {{ id: string, name: string, lat: number, lon: number } | null} The place, or null for an unknown city or bad coordinates.
194
+ */
195
+ export function resolvePlace(place) {
196
+ if (typeof place === 'string') {
197
+ const at = /** @type {Record<string, number[]>} */ (CITIES)[place];
198
+ return at ? { id: place, name: cityName(place), lat: at[0], lon: at[1] } : null;
199
+ }
200
+ if (Array.isArray(place)) {
201
+ const [lat, lon] = place;
202
+ if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
203
+ const name = `${Math.abs(lat).toFixed(1)}°${lat < 0 ? 'S' : 'N'} ${Math.abs(lon).toFixed(1)}°${lon < 0 ? 'W' : 'E'}`;
204
+ return { id: `${lat},${lon}`, name, lat, lon };
205
+ }
206
+ if (place && Number.isFinite(place.lat) && Number.isFinite(place.lon)) {
207
+ return { id: `@${place.name}`, name: String(place.name ?? ''), lat: place.lat, lon: place.lon };
208
+ }
209
+ return null;
210
+ }
211
+
212
+ /**
213
+ * A route as given, in one shape.
214
+ *
215
+ * @param {RouteSpec} spec `[from, to]`, a place (from home), or a route object.
216
+ * @returns {Route | null} The route, or null when it is not one.
217
+ */
218
+ export function normalizeRoute(spec) {
219
+ if (isPlace(spec)) return { to: spec };
220
+ if (Array.isArray(spec)) return spec.length >= 2 ? { from: spec[0], to: spec[1] } : null;
221
+ return spec && typeof spec === 'object' && 'to' in spec ? spec : null;
222
+ }
223
+
224
+ /**
225
+ * A colour as CSS, and as channels when it is hex (so it can be blended).
226
+ *
227
+ * @param {string} css Any CSS colour.
228
+ * @returns {{ css: string, rgb: import('./color.js').Rgb | null }} The colour.
229
+ */
230
+ function readPaint(css) {
231
+ try {
232
+ return { css, rgb: parseColor(css) };
233
+ } catch {
234
+ return { css, rgb: null };
235
+ }
236
+ }
237
+
238
+ /**
239
+ * The colours along a route, blended in Oklab.
240
+ *
241
+ * @param {string} from Its colour at the start.
242
+ * @param {string} to Its colour at the end.
243
+ * @param {number} toward How far each step is pulled toward white, 0–1 (heads are hotter than tails).
244
+ * @returns {string[]} RAMP + 1 colours. Without hex at both ends, there is no blend: every step is `to`.
245
+ */
246
+ export function colorRamp(from, to, toward = 0) {
247
+ const a = readPaint(from);
248
+ const b = readPaint(to);
249
+ if (!a.rgb || !b.rgb) {
250
+ const solid = b.rgb && toward ? toHex(mixOklab(b.rgb, [1, 1, 1], toward)) : to;
251
+ return Array.from({ length: RAMP + 1 }, () => solid);
252
+ }
253
+ const [start, end] = [a.rgb, b.rgb];
254
+ return Array.from({ length: RAMP + 1 }, (_, i) => {
255
+ const c = mixOklab(start, end, i / RAMP);
256
+ return toHex(toward ? mixOklab(c, [1, 1, 1], toward) : c);
257
+ });
258
+ }
259
+
260
+ /**
261
+ * The cities and routes to draw.
262
+ *
263
+ * @param {PlanOptions} options The settings.
264
+ * @returns {{ cities: PlannedCity[], routes: PlannedRoute[] }} Each city once, in the order they appear (home first), and each route that has two known places.
265
+ */
266
+ export function planRoutes(options) {
267
+ const palette = pickColors(options, [options.color ?? DEFAULT_COLOR]);
268
+ const home = resolvePlace(options.home);
269
+ /** @type {PlannedCity[]} */
270
+ const cities = [];
271
+ /** @type {Map<string, number>} */
272
+ const index = new Map();
273
+ /** Cities whose colour a route has set, so the first route to set it wins. */
274
+ const set = new Set();
275
+
276
+ /**
277
+ * A place's index among the cities, adding it the first time.
278
+ *
279
+ * @param {{ id: string, name: string, lat: number, lon: number }} place The place.
280
+ * @returns {number} Its index.
281
+ */
282
+ const add = (place) => {
283
+ const known = index.get(place.id);
284
+ if (known !== undefined) return known;
285
+ const i = cities.length;
286
+ // The home city keeps the first colour to itself; the rest go round the others.
287
+ const shared = !home || palette.length < 2 ? i % palette.length : i && 1 + ((i - 1) % (palette.length - 1));
288
+ cities.push({ ...place, home: place.id === home?.id, color: palette[shared], routes: 0 });
289
+ index.set(place.id, i);
290
+ return i;
291
+ };
292
+
293
+ if (home) add(home);
294
+ const given = options.routes ?? (home ? SPOKES.filter((key) => key !== home.id) : ROUTES);
295
+ /** @type {{ from: number, to: number, route: Route, i: number }[]} */
296
+ const pending = [];
297
+ given.forEach((spec, i) => {
298
+ const route = normalizeRoute(spec);
299
+ const to = resolvePlace(route?.to);
300
+ if (!route || !to) return;
301
+ const from = route.from === undefined ? home : resolvePlace(route.from);
302
+ if (route.from !== undefined && !from) return;
303
+ const a = from ? add(from) : -1;
304
+ const b = add(to);
305
+ if (a < 0 || a === b) return;
306
+ pending.push({ from: a, to: b, route, i });
307
+ if (route.color && !set.has(b)) {
308
+ cities[b].color = route.color;
309
+ set.add(b);
310
+ }
311
+ });
312
+
313
+ const routes = pending.map(({ from, to, route, i }) => {
314
+ cities[from].routes++;
315
+ cities[to].routes++;
316
+ const end = route.color ?? cities[to].color;
317
+ const startColor = options.gradient ? cities[from].color : end;
318
+ const speed = Number(route.speed);
319
+ const width = Number(route.width ?? options.width);
320
+ return {
321
+ from,
322
+ to,
323
+ ramp: colorRamp(startColor, end),
324
+ cores: colorRamp(startColor, end, 0.55),
325
+ label: route.label ?? `${cities[from].name} → ${cities[to].name}`,
326
+ speed: speed > 0 ? speed : 1,
327
+ width: width > 0 ? width : 2.2,
328
+ dashed: route.dashed ?? options.dashed ?? false,
329
+ offset: (i * 0.37) % 1,
330
+ };
331
+ });
332
+ return { cities, routes };
333
+ }
@@ -0,0 +1,75 @@
1
+ import type { PaletteName } from './palettes.js';
2
+ import type { Place, RouteSpec } from './world-plan.js';
3
+ import type { Bounds, RegionName } from './world-map.js';
4
+
5
+ export { CITIES } from './world-plan.js';
6
+ export type { CityKey, Place, Route, RouteSpec } from './world-plan.js';
7
+ export type { Bounds, RegionName } from './world-map.js';
8
+
9
+ export interface WorldRoutesConfig {
10
+ /** The routes: `[from, to]`, a place alone (from `home`), or `{ from, to, color, label, speed, width, dashed }`. A place is a key of CITIES, [degrees north, degrees east], or `{ name, lat, lon }`. Default ten routes round the world, or, with a `home`, routes from it to ten cities round the world. */
11
+ routes?: RouteSpec[];
12
+ /** A hub: routes with no `from` start here, and it is marked out with a ring and a halo. Default none. */
13
+ home?: Place;
14
+ /** The routes' colour. Default `#38bdf8`. */
15
+ color?: string;
16
+ /** A palette in place of `color`: each city takes the next colour in the order they appear (a home city takes the first and keeps it), and each route the colour of the city it runs to. Default none. */
17
+ colors?: string[];
18
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
19
+ palette?: PaletteName | (string & {});
20
+ /** Blend each route from its origin's colour to its destination's, in Oklab (with `colors`). Default false. */
21
+ gradient?: boolean;
22
+ /** The land dots' colour, and the names'. Default `#ffffff`. */
23
+ land?: string;
24
+ /** The land dots' opacity. Default 0.18. */
25
+ landOpacity?: number;
26
+ /** Space between land dots, CSS px. Default 7. */
27
+ pitch?: number;
28
+ /** A land dot's radius, CSS px. Default 1.4. */
29
+ dot?: number;
30
+ /** The land dots' shape: `round` or `square`. Default `round`. */
31
+ dotShape?: 'round' | 'square';
32
+ /** Faint lines of latitude and longitude, in dots: true for every 30°, or the degrees between them. Default false. */
33
+ graticule?: boolean | number;
34
+ /** What the map shows: `world`, `europe`, `north-america`, `south-america`, `africa`, `middle-east`, `asia`, `oceania`, `routes` (fitted round the cities and the arcs between them), or [[south, west], [north, east]]. Default `world`. */
35
+ region?: RegionName | 'routes' | Bounds;
36
+ /** `contain` shows all of the region; `cover` fills the box with it. Default `contain`. */
37
+ fit?: 'contain' | 'cover';
38
+ /** Pan the map east this many degrees a second (negative for west), round and round the world. Default 0. */
39
+ drift?: number;
40
+ /** Seconds a comet takes along a route. Default 3.2. */
41
+ lap?: number;
42
+ /** How high the arcs bow, a share of their length. Default 0.3, or 0.08 with a great-circle `curve`. */
43
+ lift?: number;
44
+ /** `bow`: arcs bow up between the cities. `great-circle`: they follow the shortest way over the globe, over the date line where that is shorter. Default `bow`. */
45
+ curve?: 'bow' | 'great-circle';
46
+ /** The faint arcs' opacity. Default 0.14. */
47
+ arcOpacity?: number;
48
+ /** Dash the faint arcs, the dashes running from origin to destination. Default false. */
49
+ dashed?: boolean;
50
+ /** The comets' width, CSS px; the faint arcs are a line half as wide. Default 2.2. */
51
+ width?: number;
52
+ /** A comet's length, a share of its route. Default 0.28. */
53
+ tail?: number;
54
+ /** The glow round a comet's head, CSS px; 0 for none. Default 10. */
55
+ glow?: number;
56
+ /** Comets on each route at once. Default 1. */
57
+ comets?: number;
58
+ /** How wide the ring a landing comet opens grows, CSS px; 0 for none. Default 17. */
59
+ ping?: number;
60
+ /** Mark the cities with a dot. Default true. */
61
+ markers?: boolean;
62
+ /** A city dot's radius, CSS px. Default 2.2. */
63
+ markerSize?: number;
64
+ /** A soft halo breathing round every city (the home city always has one). Default false. */
65
+ halo?: boolean;
66
+ /** Name the cities, leaving out names that would overlap (hovering a city names it either way). Default false. */
67
+ labels?: boolean;
68
+ /** The names' CSS font. Default `500 11px system-ui, sans-serif`. */
69
+ font?: string;
70
+ /** Hovering a city or a route (not through a link or button) brightens it and names it. Default true. */
71
+ interactive?: boolean;
72
+ }
73
+
74
+ /** Starts a dotted world map with comets running between cities in `el`'s canvas. Returns a function that stops it. */
75
+ export function worldRoutes(el: HTMLElement, config: WorldRoutesConfig): () => void;