trebol 0.1.2 → 0.2.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 (256) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +10040 -7519
  3. package/dist/lib/core/boot.js +10 -7
  4. package/dist/lib/core/eval.js +2 -2
  5. package/dist/lib/core/machine/checks.d.ts +1 -0
  6. package/dist/lib/core/machine/checks.js +250 -0
  7. package/dist/lib/core/machine/events.d.ts +1 -0
  8. package/dist/lib/core/machine/events.js +365 -0
  9. package/dist/lib/core/machine/running.d.ts +1 -0
  10. package/dist/lib/core/machine/running.js +180 -0
  11. package/dist/lib/core/machine/shared.d.ts +1 -0
  12. package/dist/lib/core/machine/shared.js +123 -0
  13. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  14. package/dist/lib/core/machine/snapshot.js +244 -0
  15. package/dist/lib/core/machine/spec.d.ts +1 -0
  16. package/dist/lib/core/machine/spec.js +274 -0
  17. package/dist/lib/core/machine/words.d.ts +1 -0
  18. package/dist/lib/core/machine/words.js +98 -0
  19. package/dist/lib/core/machine.d.ts +1 -0
  20. package/dist/lib/core/machine.js +17 -0
  21. package/dist/lib/core/mezz.js +31 -0
  22. package/dist/lib/core/natives/control.js +1 -1
  23. package/dist/lib/core/natives/data.js +6 -1
  24. package/dist/lib/core/natives/series.js +49 -9
  25. package/dist/lib/core/natives/text.js +0 -1
  26. package/dist/lib/host/browser/calendar.d.ts +34 -0
  27. package/dist/lib/host/browser/calendar.js +268 -0
  28. package/dist/lib/host/browser/count.d.ts +15 -0
  29. package/dist/lib/host/browser/count.js +48 -0
  30. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  31. package/dist/lib/host/browser/dialogs.js +443 -0
  32. package/dist/lib/host/browser/drag.d.ts +70 -0
  33. package/dist/lib/host/browser/drag.js +268 -0
  34. package/dist/lib/host/browser/drawings.d.ts +30 -0
  35. package/dist/lib/host/browser/drawings.js +176 -0
  36. package/dist/lib/host/browser/events.d.ts +16 -0
  37. package/dist/lib/host/browser/events.js +125 -0
  38. package/dist/lib/host/browser/faces.d.ts +35 -0
  39. package/dist/lib/host/browser/faces.js +131 -0
  40. package/dist/lib/host/browser/fields.d.ts +16 -0
  41. package/dist/lib/host/browser/fields.js +322 -0
  42. package/dist/lib/host/browser/keys.d.ts +29 -0
  43. package/dist/lib/host/browser/keys.js +151 -0
  44. package/dist/lib/host/browser/lookup.d.ts +25 -0
  45. package/dist/lib/host/browser/lookup.js +275 -0
  46. package/dist/lib/host/browser/menus.d.ts +20 -0
  47. package/dist/lib/host/browser/menus.js +149 -0
  48. package/dist/lib/host/browser/mount.d.ts +92 -0
  49. package/dist/lib/host/browser/mount.js +448 -0
  50. package/dist/lib/host/browser/orbits.d.ts +90 -0
  51. package/dist/lib/host/browser/orbits.js +379 -0
  52. package/dist/lib/host/browser/page.d.ts +13 -0
  53. package/dist/lib/host/browser/page.js +35 -0
  54. package/dist/lib/host/browser/richtext.d.ts +19 -0
  55. package/dist/lib/host/browser/richtext.js +379 -0
  56. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  57. package/dist/lib/host/browser/row-faces.js +74 -0
  58. package/dist/lib/host/browser/screens.d.ts +37 -0
  59. package/dist/lib/host/browser/screens.js +140 -0
  60. package/dist/lib/host/browser/swipe.d.ts +31 -0
  61. package/dist/lib/host/browser/swipe.js +178 -0
  62. package/dist/lib/host/browser/sync.d.ts +24 -0
  63. package/dist/lib/host/browser/sync.js +450 -0
  64. package/dist/lib/host/browser/tables.d.ts +65 -0
  65. package/dist/lib/host/browser/tables.js +505 -0
  66. package/dist/lib/host/browser/times.d.ts +14 -0
  67. package/dist/lib/host/browser/times.js +114 -0
  68. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  69. package/dist/lib/host/browser/toolbars.js +129 -0
  70. package/dist/lib/host/browser/trees.d.ts +20 -0
  71. package/dist/lib/host/browser/trees.js +235 -0
  72. package/dist/lib/host/browser/uploads.d.ts +29 -0
  73. package/dist/lib/host/browser/uploads.js +370 -0
  74. package/dist/lib/host/browser/widget.d.ts +13 -0
  75. package/dist/lib/host/browser/widget.js +105 -0
  76. package/dist/lib/host/browser.d.ts +25 -0
  77. package/dist/lib/host/browser.js +84 -4812
  78. package/dist/lib/host/devtools/console.d.ts +9 -0
  79. package/dist/lib/host/devtools/console.js +104 -0
  80. package/dist/lib/host/devtools/faces.d.ts +25 -0
  81. package/dist/lib/host/devtools/faces.js +169 -0
  82. package/dist/lib/host/devtools/log.d.ts +3 -0
  83. package/dist/lib/host/devtools/log.js +32 -0
  84. package/dist/lib/host/devtools/machines.d.ts +34 -0
  85. package/dist/lib/host/devtools/machines.js +212 -0
  86. package/dist/lib/host/devtools/read.d.ts +13 -0
  87. package/dist/lib/host/devtools/read.js +52 -0
  88. package/dist/lib/host/devtools/state.d.ts +90 -0
  89. package/dist/lib/host/devtools/state.js +123 -0
  90. package/dist/lib/host/devtools.d.ts +15 -19
  91. package/dist/lib/host/devtools.js +39 -427
  92. package/dist/lib/host/fonts.js +4 -3
  93. package/dist/lib/host/icons.js +4 -0
  94. package/dist/lib/host/index.d.ts +3 -1
  95. package/dist/lib/host/index.js +107 -4
  96. package/dist/lib/host/locale.d.ts +18 -0
  97. package/dist/lib/host/locale.js +75 -5
  98. package/dist/lib/host/markdown.d.ts +4 -0
  99. package/dist/lib/host/markdown.js +8 -0
  100. package/dist/lib/host/modules.js +118 -19
  101. package/dist/lib/host/motion.d.ts +32 -0
  102. package/dist/lib/host/motion.js +190 -0
  103. package/dist/lib/host/net.js +5 -2
  104. package/dist/lib/host/palette.d.ts +17 -0
  105. package/dist/lib/host/palette.js +131 -0
  106. package/dist/lib/host/scheduler.d.ts +2 -0
  107. package/dist/lib/host/scheduler.js +4 -0
  108. package/dist/lib/host/share.d.ts +31 -0
  109. package/dist/lib/host/share.js +134 -0
  110. package/dist/lib/host/theme/classic.d.ts +1 -0
  111. package/dist/lib/host/theme/classic.js +120 -0
  112. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  113. package/dist/lib/host/theme/cupertino.js +65 -0
  114. package/dist/lib/host/theme/data.d.ts +1 -0
  115. package/dist/lib/host/theme/data.js +109 -0
  116. package/dist/lib/host/theme/devtools.d.ts +1 -0
  117. package/dist/lib/host/theme/devtools.js +166 -0
  118. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  119. package/dist/lib/host/theme/dialogs.js +63 -0
  120. package/dist/lib/host/theme/fluent.d.ts +1 -0
  121. package/dist/lib/host/theme/fluent.js +64 -0
  122. package/dist/lib/host/theme/forms.d.ts +1 -0
  123. package/dist/lib/host/theme/forms.js +239 -0
  124. package/dist/lib/host/theme/fusion.d.ts +1 -0
  125. package/dist/lib/host/theme/fusion.js +66 -0
  126. package/dist/lib/host/theme/layout.d.ts +1 -0
  127. package/dist/lib/host/theme/layout.js +166 -0
  128. package/dist/lib/host/theme/media.d.ts +1 -0
  129. package/dist/lib/host/theme/media.js +106 -0
  130. package/dist/lib/host/theme/navigation.d.ts +1 -0
  131. package/dist/lib/host/theme/navigation.js +36 -0
  132. package/dist/lib/host/theme/panes.d.ts +1 -0
  133. package/dist/lib/host/theme/panes.js +99 -0
  134. package/dist/lib/host/theme/popups.d.ts +1 -0
  135. package/dist/lib/host/theme/popups.js +149 -0
  136. package/dist/lib/host/theme/responsive.d.ts +1 -0
  137. package/dist/lib/host/theme/responsive.js +103 -0
  138. package/dist/lib/host/theme/toasts.d.ts +1 -0
  139. package/dist/lib/host/theme/toasts.js +62 -0
  140. package/dist/lib/host/theme.js +19 -1384
  141. package/dist/lib/ui/dialect/events.trb +276 -0
  142. package/dist/lib/ui/dialect/faces.trb +135 -0
  143. package/dist/lib/ui/dialect/layout.trb +283 -0
  144. package/dist/lib/ui/dialect/palette.trb +87 -0
  145. package/dist/lib/ui/dialect/problems.trb +174 -0
  146. package/dist/lib/ui/dialect/reactions.trb +198 -0
  147. package/dist/lib/ui/dialect/rows.trb +208 -0
  148. package/dist/lib/ui/dialect/screens.trb +293 -0
  149. package/dist/lib/ui/dialect/steps.trb +203 -0
  150. package/dist/lib/ui/dialect/validation.trb +137 -0
  151. package/dist/lib/ui/dialect/view.trb +110 -0
  152. package/dist/lib/ui/dialect/walking.trb +98 -0
  153. package/dist/lib/ui/dialect/words.trb +70 -0
  154. package/dist/lib/ui/i18n.trb +17 -0
  155. package/dist/lib/ui/test.trb +3 -556
  156. package/dist/lib/ui/testing/actions.trb +421 -0
  157. package/dist/lib/ui/testing/faces.trb +148 -0
  158. package/dist/lib/ui/testing/server.trb +73 -0
  159. package/dist/lib/ui/ui.trb +25 -1675
  160. package/dist/trebol.js +4463 -1891
  161. package/package.json +1 -1
  162. package/src/core/boot.ts +9 -6
  163. package/src/core/eval.ts +2 -2
  164. package/src/core/machine/checks.ts +251 -0
  165. package/src/core/machine/events.ts +366 -0
  166. package/src/core/machine/running.ts +181 -0
  167. package/src/core/machine/shared.ts +124 -0
  168. package/src/core/machine/snapshot.ts +245 -0
  169. package/src/core/machine/spec.ts +275 -0
  170. package/src/core/machine/words.ts +99 -0
  171. package/src/core/machine.ts +20 -0
  172. package/src/core/mezz.ts +31 -0
  173. package/src/core/natives/control.ts +1 -1
  174. package/src/core/natives/data.ts +6 -1
  175. package/src/core/natives/parse.ts +1 -1
  176. package/src/core/natives/series.ts +47 -11
  177. package/src/core/natives/text.ts +0 -1
  178. package/src/host/browser/calendar.ts +264 -0
  179. package/src/host/browser/count.ts +48 -0
  180. package/src/host/browser/dialogs.ts +439 -0
  181. package/src/host/browser/drag.ts +278 -0
  182. package/src/host/browser/drawings.ts +178 -0
  183. package/src/host/browser/events.ts +117 -0
  184. package/src/host/browser/faces.ts +143 -0
  185. package/src/host/browser/fields.ts +315 -0
  186. package/src/host/browser/keys.ts +145 -0
  187. package/src/host/browser/lookup.ts +262 -0
  188. package/src/host/browser/menus.ts +146 -0
  189. package/src/host/browser/mount.ts +420 -0
  190. package/src/host/browser/orbits.ts +418 -0
  191. package/src/host/browser/page.ts +43 -0
  192. package/src/host/browser/richtext.ts +346 -0
  193. package/src/host/browser/row-faces.ts +75 -0
  194. package/src/host/browser/screens.ts +142 -0
  195. package/src/host/browser/swipe.ts +168 -0
  196. package/src/host/browser/sync.ts +354 -0
  197. package/src/host/browser/tables.ts +461 -0
  198. package/src/host/browser/times.ts +115 -0
  199. package/src/host/browser/toolbars.ts +126 -0
  200. package/src/host/browser/trees.ts +205 -0
  201. package/src/host/browser/uploads.ts +367 -0
  202. package/src/host/browser/widget.ts +103 -0
  203. package/src/host/browser.ts +82 -4612
  204. package/src/host/devtools/console.ts +102 -0
  205. package/src/host/devtools/faces.ts +160 -0
  206. package/src/host/devtools/log.ts +34 -0
  207. package/src/host/devtools/machines.ts +208 -0
  208. package/src/host/devtools/read.ts +58 -0
  209. package/src/host/devtools/state.ts +148 -0
  210. package/src/host/devtools.ts +39 -442
  211. package/src/host/fonts.ts +4 -3
  212. package/src/host/icons.ts +4 -0
  213. package/src/host/index.ts +107 -4
  214. package/src/host/locale.ts +71 -5
  215. package/src/host/markdown.ts +9 -0
  216. package/src/host/modules.ts +117 -21
  217. package/src/host/motion.ts +204 -0
  218. package/src/host/net.ts +4 -2
  219. package/src/host/palette.ts +139 -0
  220. package/src/host/scheduler.ts +5 -0
  221. package/src/host/share.ts +168 -0
  222. package/src/host/theme/classic.ts +121 -0
  223. package/src/host/theme/cupertino.ts +66 -0
  224. package/src/host/theme/data.ts +110 -0
  225. package/src/host/theme/devtools.ts +167 -0
  226. package/src/host/theme/dialogs.ts +64 -0
  227. package/src/host/theme/fluent.ts +65 -0
  228. package/src/host/theme/forms.ts +240 -0
  229. package/src/host/theme/fusion.ts +67 -0
  230. package/src/host/theme/layout.ts +167 -0
  231. package/src/host/theme/media.ts +107 -0
  232. package/src/host/theme/navigation.ts +37 -0
  233. package/src/host/theme/panes.ts +100 -0
  234. package/src/host/theme/popups.ts +150 -0
  235. package/src/host/theme/responsive.ts +104 -0
  236. package/src/host/theme/toasts.ts +63 -0
  237. package/src/host/theme.ts +19 -1384
  238. package/src/ui/dialect/events.trb +276 -0
  239. package/src/ui/dialect/faces.trb +135 -0
  240. package/src/ui/dialect/layout.trb +283 -0
  241. package/src/ui/dialect/palette.trb +87 -0
  242. package/src/ui/dialect/problems.trb +174 -0
  243. package/src/ui/dialect/reactions.trb +198 -0
  244. package/src/ui/dialect/rows.trb +208 -0
  245. package/src/ui/dialect/screens.trb +293 -0
  246. package/src/ui/dialect/steps.trb +203 -0
  247. package/src/ui/dialect/validation.trb +137 -0
  248. package/src/ui/dialect/view.trb +110 -0
  249. package/src/ui/dialect/walking.trb +98 -0
  250. package/src/ui/dialect/words.trb +70 -0
  251. package/src/ui/i18n.trb +17 -0
  252. package/src/ui/test.trb +3 -556
  253. package/src/ui/testing/actions.trb +421 -0
  254. package/src/ui/testing/faces.trb +148 -0
  255. package/src/ui/testing/server.trb +73 -0
  256. package/src/ui/ui.trb +25 -1675
@@ -0,0 +1,379 @@
1
+ // --- orbits -------------------------------------------------------------------------------
2
+ import { NONE, TRUE, FALSE } from "../../core/index.js";
3
+ import { translate } from "../index.js";
4
+ import { readOrbit, layoutOrbit, shownEdges, edgeLabel, bubble, gradients, edgePath, ease, fitCamera, MANY } from "../orbit.js";
5
+ import { get, str, own, flag } from "./faces.js";
6
+ import { host, fire, el } from "./mount.js";
7
+ import { SVG_NS, svgNode } from "./drawings.js";
8
+ export let orbitCount = 0;
9
+ /** An orbit: an SVG the size of the face, a world the camera moves, edges under the bubbles. */
10
+ export function buildOrbit(m) {
11
+ const node = el('div', 'tb-orbit');
12
+ const svg = document.createElementNS(SVG_NS, 'svg');
13
+ svg.setAttribute('role', 'group');
14
+ svg.setAttribute('tabindex', '-1');
15
+ const defs = document.createElementNS(SVG_NS, 'defs');
16
+ const world = document.createElementNS(SVG_NS, 'g');
17
+ const lines = document.createElementNS(SVG_NS, 'g');
18
+ const bubbles = document.createElementNS(SVG_NS, 'g');
19
+ world.append(lines, bubbles);
20
+ svg.append(defs, world);
21
+ node.append(svg);
22
+ const st = {
23
+ svg, defs, world, lines, bubbles, vis: new Map(), edges: [], spec: readOrbit(NONE).spec, signature: '', page: 0, pageOf: null,
24
+ box: { x0: -100, y0: -100, x1: 100, y1: 100 }, placed: [], left: 0, cam: { x: 0, y: 0, s: 1 }, camFrom: null, camTo: null, anim: 0, picked: null, byKey: false, dragged: false,
25
+ gradients: new Map(), width: 0, height: 0,
26
+ };
27
+ m.kids = st;
28
+ orbitCamera(m, st);
29
+ orbitKeys(m, st);
30
+ if (typeof ResizeObserver !== 'undefined') {
31
+ new ResizeObserver(() => {
32
+ if (svg.clientWidth === st.width && svg.clientHeight === st.height)
33
+ return;
34
+ st.width = svg.clientWidth;
35
+ st.height = svg.clientHeight;
36
+ // a move under way ends where the new size fits; titles take the new zoom
37
+ const fit = fitCamera(st.width, st.height, st.box);
38
+ if (st.camTo !== null)
39
+ st.camTo = fit;
40
+ else
41
+ st.cam = fit;
42
+ orbitDressAll(m, st, fit.s);
43
+ orbitApplyCam(st);
44
+ orbitDrawEdges(st);
45
+ }).observe(svg);
46
+ }
47
+ return node;
48
+ }
49
+ /** Drag to pan, Ctrl and the wheel (or a pinch) to zoom about the pointer, double click to fit again. */
50
+ export function orbitCamera(m, st) {
51
+ const { svg } = st;
52
+ let drag = null;
53
+ svg.addEventListener('pointerdown', ev => {
54
+ if (ev.button !== 0)
55
+ return;
56
+ drag = { x: ev.clientX, y: ev.clientY, cx: st.cam.x, cy: st.cam.y, id: ev.pointerId };
57
+ st.dragged = false;
58
+ });
59
+ svg.addEventListener('pointermove', ev => {
60
+ if (drag === null || ev.pointerId !== drag.id)
61
+ return;
62
+ const dx = ev.clientX - drag.x;
63
+ const dy = ev.clientY - drag.y;
64
+ if (!st.dragged && Math.hypot(dx, dy) > 4) {
65
+ st.dragged = true;
66
+ svg.setPointerCapture(ev.pointerId);
67
+ svg.classList.add('tb-orbit-panning');
68
+ }
69
+ if (st.dragged) {
70
+ st.cam = { ...st.cam, x: drag.cx + dx, y: drag.cy + dy };
71
+ orbitApplyCam(st);
72
+ }
73
+ });
74
+ const end = () => {
75
+ drag = null;
76
+ svg.classList.remove('tb-orbit-panning');
77
+ // the click that ends a drag picks nothing
78
+ setTimeout(() => { st.dragged = false; }, 0);
79
+ };
80
+ svg.addEventListener('pointerup', end);
81
+ svg.addEventListener('pointercancel', end);
82
+ svg.addEventListener('wheel', ev => {
83
+ // the page scrolls past an orbit; with Ctrl (or a pinch), or when it fills the window, the wheel zooms
84
+ if (!ev.ctrlKey && !ev.metaKey && !flag(m.face, 'fit'))
85
+ return;
86
+ ev.preventDefault();
87
+ const box = svg.getBoundingClientRect();
88
+ const ox = box.width / 2 + st.cam.x;
89
+ const oy = box.height / 2 + st.cam.y;
90
+ const s = Math.max(0.15, Math.min(4, st.cam.s * Math.exp(-ev.deltaY * (ev.ctrlKey ? 0.01 : 0.0015))));
91
+ const px = ev.clientX - box.left;
92
+ const py = ev.clientY - box.top;
93
+ const wx = (px - ox) / st.cam.s;
94
+ const wy = (py - oy) / st.cam.s;
95
+ st.cam = { x: px - box.width / 2 - wx * s, y: py - box.height / 2 - wy * s, s };
96
+ orbitApplyCam(st);
97
+ }, { passive: false });
98
+ svg.addEventListener('dblclick', ev => {
99
+ if (ev.target.closest('.tb-orbit-node') !== null)
100
+ return;
101
+ st.camFrom = { ...st.cam };
102
+ st.camTo = fitCamera(st.width, st.height, st.box);
103
+ orbitAnimate(st, 500);
104
+ });
105
+ }
106
+ /** Tab goes through the neighbours, Enter or Space picks one, Escape or Backspace steps back. */
107
+ export function orbitKeys(m, st) {
108
+ st.svg.addEventListener('keydown', ev => {
109
+ const g = ev.target.closest('.tb-orbit-node');
110
+ if ((ev.key === 'Enter' || ev.key === ' ') && g !== null) {
111
+ ev.preventDefault();
112
+ orbitPick(m, st, g.dataset['key'], true);
113
+ }
114
+ else if ((ev.key === 'Escape' || ev.key === 'Backspace') && st.spec.trail.length > 0) {
115
+ const back = [...st.spec.trail].reverse().find(k => st.spec.nodes.has(k));
116
+ if (back === undefined)
117
+ return;
118
+ ev.preventDefault();
119
+ ev.stopPropagation();
120
+ orbitPick(m, st, back, true);
121
+ }
122
+ });
123
+ }
124
+ /** The person picked a bubble: a neighbour enters, the trail steps back, "+N more" turns the page. */
125
+ export function orbitPick(m, st, key, byKey) {
126
+ if (flag(m.face, 'disabled'))
127
+ return;
128
+ const v = st.vis.get(key);
129
+ if (v === undefined || v.dying)
130
+ return;
131
+ if (v.role === 'more') {
132
+ st.page++;
133
+ st.picked = st.spec.focus;
134
+ orbitRender(m, st);
135
+ return;
136
+ }
137
+ const node = st.spec.nodes.get(key);
138
+ if (node === undefined || v.role === 'focus')
139
+ return;
140
+ st.picked = key;
141
+ st.byKey = byKey;
142
+ void fire('ui-orbit', m.face, node.id, v.role === 'trail' ? TRUE : FALSE);
143
+ }
144
+ export function syncOrbit(m) {
145
+ const st = m.kids;
146
+ const { spec, error } = readOrbit(get(m.face, 'data'));
147
+ if (error !== null)
148
+ console.warn(`Trebol: ${error}`);
149
+ const t = str(m.face, 'text');
150
+ const focus = spec.focus === null ? undefined : spec.nodes.get(spec.focus);
151
+ const focusTitle = focus === undefined ? '' : translate(focus.title, host.rt);
152
+ st.svg.setAttribute('aria-label', t === null ? focusTitle : focusTitle === '' ? t : `${t}: ${focusTitle}`);
153
+ // a repaint of the same thing in the same language keeps what is on screen, moving or not
154
+ const signature = orbitSignature(spec);
155
+ if (signature === st.signature)
156
+ return;
157
+ st.signature = signature;
158
+ st.spec = spec;
159
+ if (spec.focus !== st.pageOf) {
160
+ st.page = 0;
161
+ st.pageOf = spec.focus;
162
+ }
163
+ orbitRender(m, st);
164
+ }
165
+ export function orbitSignature(spec) {
166
+ const tx = (c) => (c === null ? '' : translate(c, host.rt));
167
+ const nodes = [...spec.nodes.values()].map(n => [n.key, tx(n.title), n.color, n.count, n.many, n.dashed, n.steps, n.at].join('\u0002'));
168
+ const edges = spec.edges.map(e => [e.from, e.to, tx(e.label), e.look].join('\u0002'));
169
+ return [spec.focus ?? '', nodes.join('\u0001'), edges.join('\u0001'), spec.trail.join('\u0001')].join('\u0000');
170
+ }
171
+ /** The ids of the gradients of a color, made the first time it is used. */
172
+ export function orbitGradients(st, color) {
173
+ let ids = st.gradients.get(color);
174
+ if (ids === undefined) {
175
+ const n = `tb-orbit${orbitCount++}`;
176
+ ids = [`${n}-body`, `${n}-halo`];
177
+ st.gradients.set(color, ids);
178
+ st.defs.append(...gradients(color, ids[0], ids[1]).map(svgNode));
179
+ }
180
+ return ids;
181
+ }
182
+ /** Moves from what is on screen to what the spec says: bubbles that stay move, new ones grow from the one picked, the rest fade. */
183
+ export function orbitRender(m, st) {
184
+ const { spec } = st;
185
+ const lay = layoutOrbit(spec, st.page);
186
+ st.box = lay.box;
187
+ const want = new Map(lay.placed.map(p => [p.key, p]));
188
+ for (const [k, v] of [...st.vis]) {
189
+ if (v.dying)
190
+ continue;
191
+ const p = want.get(k);
192
+ if (p === undefined || p.role !== v.role || p.role === 'more') {
193
+ // gone, or something else now: it fades where it is, and a new one takes its key
194
+ v.dying = true;
195
+ v.from = { ...v.cur };
196
+ v.to = { ...v.cur, r: v.cur.r * (p === undefined ? 0.4 : 1), o: 0 };
197
+ v.g.setAttribute('tabindex', '-1');
198
+ v.g.setAttribute('aria-hidden', 'true');
199
+ st.vis.delete(k);
200
+ st.vis.set(`${k}\u0000old${orbitCount++}`, v);
201
+ if (p !== undefined)
202
+ st.vis.set(k, orbitBubble(m, st, p, { ...v.cur }));
203
+ }
204
+ else {
205
+ v.from = { ...v.cur };
206
+ v.to = p;
207
+ }
208
+ }
209
+ const was = st.picked === null ? undefined : [...st.vis.values()].find(v => v.key === st.picked);
210
+ const spawn = was !== undefined ? was.cur : { x: 0, y: 0 };
211
+ for (const p of lay.placed) {
212
+ if (st.vis.has(p.key))
213
+ continue;
214
+ st.vis.set(p.key, orbitBubble(m, st, p, { x: spawn.x, y: spawn.y, r: p.r * 0.2, o: 0 }));
215
+ }
216
+ st.width = st.svg.clientWidth;
217
+ st.height = st.svg.clientHeight;
218
+ st.camFrom = { ...st.cam };
219
+ st.camTo = fitCamera(st.width || 600, st.height || 480, lay.box);
220
+ st.placed = lay.placed;
221
+ st.left = lay.left;
222
+ orbitDressAll(m, st, st.camTo.s);
223
+ st.bubbles.append(...lay.placed.map(p => st.vis.get(p.key).g));
224
+ st.picked = null;
225
+ orbitAnimate(st, matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 900);
226
+ if (st.byKey) {
227
+ st.byKey = false;
228
+ st.svg.focus();
229
+ }
230
+ }
231
+ /** Every bubble on show drawn anew (its title, hints and size may have changed), and the edges, for the camera's zoom. */
232
+ export function orbitDressAll(m, st, scale) {
233
+ for (const p of st.placed) {
234
+ const v = st.vis.get(p.key);
235
+ if (v !== undefined)
236
+ orbitDress(m, st, v, p, st.left, scale);
237
+ }
238
+ orbitEdges(st, st.placed, scale);
239
+ }
240
+ export function orbitBubble(m, st, p, start) {
241
+ const g = document.createElementNS(SVG_NS, 'g');
242
+ const inner = document.createElementNS(SVG_NS, 'g');
243
+ g.append(inner);
244
+ g.dataset['key'] = p.key;
245
+ g.addEventListener('click', ev => {
246
+ if (st.dragged)
247
+ return;
248
+ ev.stopPropagation();
249
+ orbitPick(m, st, p.key, false);
250
+ });
251
+ // with many neighbours, the labels of a bubble's edges show while the pointer is on it
252
+ g.addEventListener('pointerenter', () => orbitHover(st, p.key, true));
253
+ g.addEventListener('pointerleave', () => orbitHover(st, p.key, false));
254
+ g.addEventListener('focus', () => orbitHover(st, p.key, true));
255
+ g.addEventListener('blur', () => orbitHover(st, p.key, false));
256
+ st.bubbles.append(g);
257
+ return { key: p.key, g, inner, role: p.role, cur: start, from: { ...start }, to: p, dying: false };
258
+ }
259
+ /** What a bubble shows and how it reads: a link to a neighbour, back to the trail, or the next page. */
260
+ export function orbitDress(m, st, v, p, left, scale) {
261
+ const node = st.spec.nodes.get(p.key) ?? null;
262
+ const title = p.role === 'more' ? (left > 0 ? own('orbit-more', String(left)) : own('orbit-first')) : node === null ? '' : translate(node.title, host.rt);
263
+ const color = p.role === 'more' ? 'var(--tb-muted)' : node?.color ?? 'var(--tb-primary)';
264
+ const [body, halo] = orbitGradients(st, color);
265
+ const label = p.role === 'near' ? orbitEdgeText(st.spec, p.key) : '';
266
+ const said = p.role === 'trail' ? own('orbit-back-to', title) : label === '' ? title : `${title}, ${label}`;
267
+ v.g.setAttribute('class', `tb-orbit-node tb-orbit-${p.role}`);
268
+ const tip = document.createElementNS(SVG_NS, 'title');
269
+ tip.textContent = said;
270
+ v.g.replaceChildren(tip, v.inner);
271
+ v.inner.replaceChildren(...bubble({ role: p.role, r: p.r, scale, above: p.role !== 'trail' && p.y < -1, title, color, body, halo, node }).map(svgNode));
272
+ if (p.role === 'focus') {
273
+ // Chrome stops Tab on an SVG group with a click handler unless told not to
274
+ v.g.setAttribute('tabindex', '-1');
275
+ v.g.removeAttribute('role');
276
+ v.g.removeAttribute('aria-label');
277
+ v.g.setAttribute('aria-hidden', 'true');
278
+ }
279
+ else {
280
+ v.g.setAttribute('tabindex', '0');
281
+ v.g.setAttribute('role', p.role === 'more' ? 'button' : 'link');
282
+ v.g.setAttribute('aria-label', said);
283
+ v.g.removeAttribute('aria-hidden');
284
+ }
285
+ if (flag(m.face, 'disabled'))
286
+ v.g.setAttribute('tabindex', '-1');
287
+ }
288
+ export function orbitEdgeText(spec, key) {
289
+ const c = edgeLabel(spec, key);
290
+ return c === null ? '' : translate(c, host.rt);
291
+ }
292
+ export function orbitEdges(st, placed, scale) {
293
+ const many = placed.filter(p => p.role === 'near').length > MANY;
294
+ st.edges = shownEdges(st.spec, placed).map(e => {
295
+ const path = document.createElementNS(SVG_NS, 'path');
296
+ path.setAttribute('class', `tb-orbit-edge tb-orbit-edge-${e.trail ? 'trail' : e.look}`);
297
+ let text = null;
298
+ if (e.label !== null) {
299
+ text = document.createElementNS(SVG_NS, 'text');
300
+ text.setAttribute('class', many ? 'tb-orbit-label tb-orbit-later' : 'tb-orbit-label');
301
+ // the size of the page's small text once the camera fits
302
+ text.style.fontSize = `${11 / scale}px`;
303
+ text.style.strokeWidth = `${3 / scale}px`;
304
+ text.textContent = translate(e.label, host.rt);
305
+ }
306
+ return { a: e.from, b: e.to, path, text, curve: e.curve };
307
+ });
308
+ st.lines.replaceChildren(...st.edges.flatMap(e => (e.text === null ? [e.path] : [e.path, e.text])));
309
+ st.lines.setAttribute('aria-hidden', 'true');
310
+ }
311
+ export function orbitHover(st, key, on) {
312
+ for (const e of st.edges)
313
+ if (e.text !== null && (e.a === key || e.b === key))
314
+ e.text.classList.toggle('tb-orbit-shown', on);
315
+ }
316
+ export function orbitApplyCam(st) {
317
+ const w = st.svg.clientWidth || st.width;
318
+ const h = st.svg.clientHeight || st.height;
319
+ st.world.setAttribute('transform', `translate(${w / 2 + st.cam.x},${h / 2 + st.cam.y}) scale(${st.cam.s})`);
320
+ }
321
+ /** Tweens every bubble and the camera from where they are to where they go; 0 ms puts them there at once. */
322
+ export function orbitAnimate(st, ms) {
323
+ cancelAnimationFrame(st.anim);
324
+ const t0 = performance.now();
325
+ const step = (now) => {
326
+ const k = ms === 0 ? 1 : ease(Math.min(1, (now - t0) / ms));
327
+ for (const v of st.vis.values()) {
328
+ if (v.from !== v.to || v.dying) {
329
+ const f = v.from;
330
+ const t = v.to;
331
+ v.cur = { x: f.x + (t.x - f.x) * k, y: f.y + (t.y - f.y) * k, r: f.r + (t.r - f.r) * k, o: f.o + (t.o - f.o) * k };
332
+ }
333
+ v.g.setAttribute('transform', `translate(${v.cur.x},${v.cur.y})`);
334
+ v.inner.setAttribute('transform', `scale(${Math.max(v.cur.r, 0.001)})`);
335
+ v.g.style.opacity = String(v.cur.o);
336
+ v.g.style.pointerEvents = v.cur.o < 0.05 ? 'none' : '';
337
+ }
338
+ if (st.camFrom !== null && st.camTo !== null) {
339
+ const a = st.camFrom;
340
+ const b = st.camTo;
341
+ st.cam = { x: a.x + (b.x - a.x) * k, y: a.y + (b.y - a.y) * k, s: a.s + (b.s - a.s) * k };
342
+ }
343
+ orbitApplyCam(st);
344
+ orbitDrawEdges(st);
345
+ if (k < 1)
346
+ st.anim = requestAnimationFrame(step);
347
+ else {
348
+ st.camFrom = st.camTo = null;
349
+ for (const [k2, v] of st.vis) {
350
+ if (v.dying) {
351
+ v.g.remove();
352
+ st.vis.delete(k2);
353
+ }
354
+ }
355
+ }
356
+ };
357
+ if (ms === 0)
358
+ step(t0);
359
+ else
360
+ st.anim = requestAnimationFrame(step);
361
+ }
362
+ export function orbitDrawEdges(st) {
363
+ for (const e of st.edges) {
364
+ const a = st.vis.get(e.a);
365
+ const b = st.vis.get(e.b);
366
+ if (a === undefined || b === undefined) {
367
+ e.path.setAttribute('d', '');
368
+ continue;
369
+ }
370
+ const at = edgePath(a.cur, b.cur, e.curve);
371
+ e.path.setAttribute('d', at.d);
372
+ const o = String(Math.min(a.cur.o, b.cur.o));
373
+ e.path.style.opacity = o;
374
+ if (e.text !== null) {
375
+ e.text.setAttribute('transform', `translate(${at.x},${at.y}) rotate(${at.angle}) translate(0,-5)`);
376
+ e.text.style.opacity = o;
377
+ }
378
+ }
379
+ }
@@ -0,0 +1,13 @@
1
+ import type { ObjectCell } from '../../core/index.ts';
2
+ import { type ThemeParams } from '../theme.ts';
3
+ export declare let root: HTMLElement | null;
4
+ export declare function setRoot(v: HTMLElement | null): void;
5
+ /** The view on show, whose palette Ctrl+K opens. */
6
+ export declare let rootFace: ObjectCell | null;
7
+ export declare function setRootFace(v: ObjectCell | null): void;
8
+ /** The face whose text is the page title: the view's title, or the screen shown. */
9
+ export declare let titleFace: ObjectCell | null;
10
+ export declare function setTitleFace(v: ObjectCell | null): void;
11
+ export declare const sheets: Map<string, CSSStyleSheet>;
12
+ export declare function setSheet(id: string, css: string): void;
13
+ export declare function setTheme(p: ThemeParams): void;
@@ -0,0 +1,35 @@
1
+ // --- page -----------------------------------------------------------------------
2
+ //
3
+ // What the page shows as a whole: its root element, the view and title on show, and the style sheets of the theme.
4
+ import { themeCss } from "../theme.js";
5
+ import { themeMoved } from "../motion.js";
6
+ export let root = null;
7
+ export function setRoot(v) {
8
+ root = v;
9
+ }
10
+ /** The view on show, whose palette Ctrl+K opens. */
11
+ export let rootFace = null;
12
+ export function setRootFace(v) {
13
+ rootFace = v;
14
+ }
15
+ /** The face whose text is the page title: the view's title, or the screen shown. */
16
+ export let titleFace = null;
17
+ export function setTitleFace(v) {
18
+ titleFace = v;
19
+ }
20
+ // The host's own CSS goes in constructed style sheets, not <style> elements: a page whose
21
+ // Content-Security-Policy says style-src 'self' drops a <style> made by script, but adopts these.
22
+ export const sheets = new Map();
23
+ export function setSheet(id, css) {
24
+ let sheet = sheets.get(id);
25
+ if (sheet === undefined) {
26
+ sheet = new CSSStyleSheet();
27
+ sheets.set(id, sheet);
28
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
29
+ }
30
+ sheet.replaceSync(css);
31
+ }
32
+ export function setTheme(p) {
33
+ setSheet('theme', themeCss(p));
34
+ themeMoved();
35
+ }
@@ -0,0 +1,19 @@
1
+ import { type ObjectCell } from '../../core/index.ts';
2
+ import { type Block, type Inline } from '../markdown.ts';
3
+ import { type Mounted } from './mount.ts';
4
+ export declare const RICH_TOOLS: readonly [string, string][];
5
+ export declare function inlineNodes(items: Inline[]): Node[];
6
+ export declare function blockNodes(blocks: Block[]): Node[];
7
+ export declare function readInline(nodes: Iterable<Node>): Inline[];
8
+ export declare const RICH_BLOCK: RegExp;
9
+ export declare function readBlocks(box: HTMLElement): Block[];
10
+ export declare function buildRich(face: ObjectCell, m: Mounted): HTMLElement;
11
+ export declare function syncRich(m: Mounted, err: string | null): void;
12
+ /** Inputs that have had the focus, so a cursor of their own. */
13
+ export declare const hadCaret: WeakSet<Element>;
14
+ /** The last selection inside each rich text box. */
15
+ export declare const richCaret: WeakMap<HTMLElement, Range>;
16
+ /** While insert-text writes in a rich text box, its own input event is not the user's. */
17
+ export declare let inserting: boolean;
18
+ export declare let keepingCarets: boolean;
19
+ export declare function keepCarets(): void;