trebol 0.1.1 → 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 (300) hide show
  1. package/README.md +12 -1
  2. package/dist/cli.js +17097 -12238
  3. package/dist/fonts/OFL.txt +93 -0
  4. package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
  5. package/dist/fonts/inter-cyrillic.woff2 +0 -0
  6. package/dist/fonts/inter-greek-ext.woff2 +0 -0
  7. package/dist/fonts/inter-greek.woff2 +0 -0
  8. package/dist/fonts/inter-latin-ext.woff2 +0 -0
  9. package/dist/fonts/inter-latin.woff2 +0 -0
  10. package/dist/fonts/inter-vietnamese.woff2 +0 -0
  11. package/dist/lib/core/boot.js +12 -8
  12. package/dist/lib/core/eval.js +2 -2
  13. package/dist/lib/core/func.d.ts +4 -0
  14. package/dist/lib/core/machine/checks.d.ts +1 -0
  15. package/dist/lib/core/machine/checks.js +250 -0
  16. package/dist/lib/core/machine/events.d.ts +1 -0
  17. package/dist/lib/core/machine/events.js +365 -0
  18. package/dist/lib/core/machine/running.d.ts +1 -0
  19. package/dist/lib/core/machine/running.js +180 -0
  20. package/dist/lib/core/machine/shared.d.ts +1 -0
  21. package/dist/lib/core/machine/shared.js +123 -0
  22. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  23. package/dist/lib/core/machine/snapshot.js +244 -0
  24. package/dist/lib/core/machine/spec.d.ts +1 -0
  25. package/dist/lib/core/machine/spec.js +274 -0
  26. package/dist/lib/core/machine/words.d.ts +1 -0
  27. package/dist/lib/core/machine/words.js +98 -0
  28. package/dist/lib/core/machine.d.ts +1 -0
  29. package/dist/lib/core/machine.js +17 -0
  30. package/dist/lib/core/mezz.js +31 -0
  31. package/dist/lib/core/natives/control.js +2 -2
  32. package/dist/lib/core/natives/data.js +6 -1
  33. package/dist/lib/core/natives/series.js +59 -9
  34. package/dist/lib/core/natives/text.js +3 -1
  35. package/dist/lib/host/browser/calendar.d.ts +34 -0
  36. package/dist/lib/host/browser/calendar.js +268 -0
  37. package/dist/lib/host/browser/count.d.ts +15 -0
  38. package/dist/lib/host/browser/count.js +48 -0
  39. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  40. package/dist/lib/host/browser/dialogs.js +443 -0
  41. package/dist/lib/host/browser/drag.d.ts +70 -0
  42. package/dist/lib/host/browser/drag.js +268 -0
  43. package/dist/lib/host/browser/drawings.d.ts +30 -0
  44. package/dist/lib/host/browser/drawings.js +176 -0
  45. package/dist/lib/host/browser/events.d.ts +16 -0
  46. package/dist/lib/host/browser/events.js +125 -0
  47. package/dist/lib/host/browser/faces.d.ts +35 -0
  48. package/dist/lib/host/browser/faces.js +131 -0
  49. package/dist/lib/host/browser/fields.d.ts +16 -0
  50. package/dist/lib/host/browser/fields.js +322 -0
  51. package/dist/lib/host/browser/keys.d.ts +29 -0
  52. package/dist/lib/host/browser/keys.js +151 -0
  53. package/dist/lib/host/browser/lookup.d.ts +25 -0
  54. package/dist/lib/host/browser/lookup.js +275 -0
  55. package/dist/lib/host/browser/menus.d.ts +20 -0
  56. package/dist/lib/host/browser/menus.js +149 -0
  57. package/dist/lib/host/browser/mount.d.ts +92 -0
  58. package/dist/lib/host/browser/mount.js +448 -0
  59. package/dist/lib/host/browser/orbits.d.ts +90 -0
  60. package/dist/lib/host/browser/orbits.js +379 -0
  61. package/dist/lib/host/browser/page.d.ts +13 -0
  62. package/dist/lib/host/browser/page.js +35 -0
  63. package/dist/lib/host/browser/richtext.d.ts +19 -0
  64. package/dist/lib/host/browser/richtext.js +379 -0
  65. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  66. package/dist/lib/host/browser/row-faces.js +74 -0
  67. package/dist/lib/host/browser/screens.d.ts +37 -0
  68. package/dist/lib/host/browser/screens.js +140 -0
  69. package/dist/lib/host/browser/swipe.d.ts +31 -0
  70. package/dist/lib/host/browser/swipe.js +178 -0
  71. package/dist/lib/host/browser/sync.d.ts +24 -0
  72. package/dist/lib/host/browser/sync.js +450 -0
  73. package/dist/lib/host/browser/tables.d.ts +65 -0
  74. package/dist/lib/host/browser/tables.js +505 -0
  75. package/dist/lib/host/browser/times.d.ts +14 -0
  76. package/dist/lib/host/browser/times.js +114 -0
  77. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  78. package/dist/lib/host/browser/toolbars.js +129 -0
  79. package/dist/lib/host/browser/trees.d.ts +20 -0
  80. package/dist/lib/host/browser/trees.js +235 -0
  81. package/dist/lib/host/browser/uploads.d.ts +29 -0
  82. package/dist/lib/host/browser/uploads.js +370 -0
  83. package/dist/lib/host/browser/widget.d.ts +13 -0
  84. package/dist/lib/host/browser/widget.js +105 -0
  85. package/dist/lib/host/browser.d.ts +25 -0
  86. package/dist/lib/host/browser.js +129 -3964
  87. package/dist/lib/host/devlog.d.ts +11 -0
  88. package/dist/lib/host/devlog.js +13 -0
  89. package/dist/lib/host/devtools/console.d.ts +9 -0
  90. package/dist/lib/host/devtools/console.js +104 -0
  91. package/dist/lib/host/devtools/faces.d.ts +25 -0
  92. package/dist/lib/host/devtools/faces.js +169 -0
  93. package/dist/lib/host/devtools/log.d.ts +3 -0
  94. package/dist/lib/host/devtools/log.js +32 -0
  95. package/dist/lib/host/devtools/machines.d.ts +34 -0
  96. package/dist/lib/host/devtools/machines.js +212 -0
  97. package/dist/lib/host/devtools/read.d.ts +13 -0
  98. package/dist/lib/host/devtools/read.js +52 -0
  99. package/dist/lib/host/devtools/state.d.ts +90 -0
  100. package/dist/lib/host/devtools/state.js +123 -0
  101. package/dist/lib/host/devtools.d.ts +19 -0
  102. package/dist/lib/host/devtools.js +238 -0
  103. package/dist/lib/host/fonts/OFL.txt +93 -0
  104. package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  105. package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
  106. package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
  107. package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
  108. package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
  109. package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
  110. package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
  111. package/dist/lib/host/fonts.d.ts +11 -0
  112. package/dist/lib/host/fonts.js +30 -0
  113. package/dist/lib/host/icons.js +4 -0
  114. package/dist/lib/host/index.d.ts +5 -1
  115. package/dist/lib/host/index.js +110 -5
  116. package/dist/lib/host/js.d.ts +5 -0
  117. package/dist/lib/host/js.js +130 -0
  118. package/dist/lib/host/locale.d.ts +18 -0
  119. package/dist/lib/host/locale.js +75 -5
  120. package/dist/lib/host/markdown.d.ts +6 -0
  121. package/dist/lib/host/markdown.js +18 -0
  122. package/dist/lib/host/modules.d.ts +4 -0
  123. package/dist/lib/host/modules.js +157 -20
  124. package/dist/lib/host/motion.d.ts +32 -0
  125. package/dist/lib/host/motion.js +190 -0
  126. package/dist/lib/host/net.js +14 -3
  127. package/dist/lib/host/orbit.d.ts +121 -0
  128. package/dist/lib/host/orbit.js +374 -0
  129. package/dist/lib/host/palette.d.ts +17 -0
  130. package/dist/lib/host/palette.js +131 -0
  131. package/dist/lib/host/rows.d.ts +14 -0
  132. package/dist/lib/host/rows.js +29 -0
  133. package/dist/lib/host/scheduler.d.ts +8 -0
  134. package/dist/lib/host/scheduler.js +64 -36
  135. package/dist/lib/host/share.d.ts +31 -0
  136. package/dist/lib/host/share.js +134 -0
  137. package/dist/lib/host/theme/classic.d.ts +1 -0
  138. package/dist/lib/host/theme/classic.js +120 -0
  139. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  140. package/dist/lib/host/theme/cupertino.js +65 -0
  141. package/dist/lib/host/theme/data.d.ts +1 -0
  142. package/dist/lib/host/theme/data.js +109 -0
  143. package/dist/lib/host/theme/devtools.d.ts +1 -0
  144. package/dist/lib/host/theme/devtools.js +166 -0
  145. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  146. package/dist/lib/host/theme/dialogs.js +63 -0
  147. package/dist/lib/host/theme/fluent.d.ts +1 -0
  148. package/dist/lib/host/theme/fluent.js +64 -0
  149. package/dist/lib/host/theme/forms.d.ts +1 -0
  150. package/dist/lib/host/theme/forms.js +239 -0
  151. package/dist/lib/host/theme/fusion.d.ts +1 -0
  152. package/dist/lib/host/theme/fusion.js +66 -0
  153. package/dist/lib/host/theme/layout.d.ts +1 -0
  154. package/dist/lib/host/theme/layout.js +166 -0
  155. package/dist/lib/host/theme/media.d.ts +1 -0
  156. package/dist/lib/host/theme/media.js +106 -0
  157. package/dist/lib/host/theme/navigation.d.ts +1 -0
  158. package/dist/lib/host/theme/navigation.js +36 -0
  159. package/dist/lib/host/theme/panes.d.ts +1 -0
  160. package/dist/lib/host/theme/panes.js +99 -0
  161. package/dist/lib/host/theme/popups.d.ts +1 -0
  162. package/dist/lib/host/theme/popups.js +149 -0
  163. package/dist/lib/host/theme/responsive.d.ts +1 -0
  164. package/dist/lib/host/theme/responsive.js +103 -0
  165. package/dist/lib/host/theme/toasts.d.ts +1 -0
  166. package/dist/lib/host/theme/toasts.js +62 -0
  167. package/dist/lib/host/theme.js +19 -1179
  168. package/dist/lib/ui/dialect/events.trb +276 -0
  169. package/dist/lib/ui/dialect/faces.trb +135 -0
  170. package/dist/lib/ui/dialect/layout.trb +283 -0
  171. package/dist/lib/ui/dialect/palette.trb +87 -0
  172. package/dist/lib/ui/dialect/problems.trb +174 -0
  173. package/dist/lib/ui/dialect/reactions.trb +198 -0
  174. package/dist/lib/ui/dialect/rows.trb +208 -0
  175. package/dist/lib/ui/dialect/screens.trb +293 -0
  176. package/dist/lib/ui/dialect/steps.trb +203 -0
  177. package/dist/lib/ui/dialect/validation.trb +137 -0
  178. package/dist/lib/ui/dialect/view.trb +110 -0
  179. package/dist/lib/ui/dialect/walking.trb +98 -0
  180. package/dist/lib/ui/dialect/words.trb +70 -0
  181. package/dist/lib/ui/i18n.trb +23 -0
  182. package/dist/lib/ui/test.trb +12 -0
  183. package/dist/lib/ui/testing/actions.trb +421 -0
  184. package/dist/lib/ui/testing/faces.trb +148 -0
  185. package/dist/lib/ui/testing/server.trb +73 -0
  186. package/dist/lib/ui/ui.trb +25 -1234
  187. package/dist/trebol.js +4882 -1088
  188. package/editors/vscode/README.md +15 -0
  189. package/editors/vscode/language-configuration.json +28 -0
  190. package/editors/vscode/package.json +42 -0
  191. package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
  192. package/package.json +7 -3
  193. package/src/core/boot.ts +10 -7
  194. package/src/core/eval.ts +2 -2
  195. package/src/core/func.ts +4 -0
  196. package/src/core/machine/checks.ts +251 -0
  197. package/src/core/machine/events.ts +366 -0
  198. package/src/core/machine/running.ts +181 -0
  199. package/src/core/machine/shared.ts +124 -0
  200. package/src/core/machine/snapshot.ts +245 -0
  201. package/src/core/machine/spec.ts +275 -0
  202. package/src/core/machine/words.ts +99 -0
  203. package/src/core/machine.ts +20 -0
  204. package/src/core/mezz.ts +31 -0
  205. package/src/core/natives/control.ts +2 -2
  206. package/src/core/natives/data.ts +6 -1
  207. package/src/core/natives/parse.ts +1 -1
  208. package/src/core/natives/series.ts +55 -11
  209. package/src/core/natives/text.ts +2 -1
  210. package/src/host/browser/calendar.ts +264 -0
  211. package/src/host/browser/count.ts +48 -0
  212. package/src/host/browser/dialogs.ts +439 -0
  213. package/src/host/browser/drag.ts +278 -0
  214. package/src/host/browser/drawings.ts +178 -0
  215. package/src/host/browser/events.ts +117 -0
  216. package/src/host/browser/faces.ts +143 -0
  217. package/src/host/browser/fields.ts +315 -0
  218. package/src/host/browser/keys.ts +145 -0
  219. package/src/host/browser/lookup.ts +262 -0
  220. package/src/host/browser/menus.ts +146 -0
  221. package/src/host/browser/mount.ts +420 -0
  222. package/src/host/browser/orbits.ts +418 -0
  223. package/src/host/browser/page.ts +43 -0
  224. package/src/host/browser/richtext.ts +346 -0
  225. package/src/host/browser/row-faces.ts +75 -0
  226. package/src/host/browser/screens.ts +142 -0
  227. package/src/host/browser/swipe.ts +168 -0
  228. package/src/host/browser/sync.ts +354 -0
  229. package/src/host/browser/tables.ts +461 -0
  230. package/src/host/browser/times.ts +115 -0
  231. package/src/host/browser/toolbars.ts +126 -0
  232. package/src/host/browser/trees.ts +205 -0
  233. package/src/host/browser/uploads.ts +367 -0
  234. package/src/host/browser/widget.ts +103 -0
  235. package/src/host/browser.ts +128 -3747
  236. package/src/host/devlog.ts +16 -0
  237. package/src/host/devtools/console.ts +102 -0
  238. package/src/host/devtools/faces.ts +160 -0
  239. package/src/host/devtools/log.ts +34 -0
  240. package/src/host/devtools/machines.ts +208 -0
  241. package/src/host/devtools/read.ts +58 -0
  242. package/src/host/devtools/state.ts +148 -0
  243. package/src/host/devtools.ts +238 -0
  244. package/src/host/fonts/OFL.txt +93 -0
  245. package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  246. package/src/host/fonts/inter-cyrillic.woff2 +0 -0
  247. package/src/host/fonts/inter-greek-ext.woff2 +0 -0
  248. package/src/host/fonts/inter-greek.woff2 +0 -0
  249. package/src/host/fonts/inter-latin-ext.woff2 +0 -0
  250. package/src/host/fonts/inter-latin.woff2 +0 -0
  251. package/src/host/fonts/inter-vietnamese.woff2 +0 -0
  252. package/src/host/fonts.ts +40 -0
  253. package/src/host/icons.ts +4 -0
  254. package/src/host/index.ts +110 -5
  255. package/src/host/js.ts +127 -0
  256. package/src/host/locale.ts +71 -5
  257. package/src/host/markdown.ts +18 -0
  258. package/src/host/modules.ts +150 -22
  259. package/src/host/motion.ts +204 -0
  260. package/src/host/net.ts +13 -3
  261. package/src/host/orbit.ts +432 -0
  262. package/src/host/palette.ts +139 -0
  263. package/src/host/rows.ts +30 -0
  264. package/src/host/scheduler.ts +67 -36
  265. package/src/host/share.ts +168 -0
  266. package/src/host/theme/classic.ts +121 -0
  267. package/src/host/theme/cupertino.ts +66 -0
  268. package/src/host/theme/data.ts +110 -0
  269. package/src/host/theme/devtools.ts +167 -0
  270. package/src/host/theme/dialogs.ts +64 -0
  271. package/src/host/theme/fluent.ts +65 -0
  272. package/src/host/theme/forms.ts +240 -0
  273. package/src/host/theme/fusion.ts +67 -0
  274. package/src/host/theme/layout.ts +167 -0
  275. package/src/host/theme/media.ts +107 -0
  276. package/src/host/theme/navigation.ts +37 -0
  277. package/src/host/theme/panes.ts +100 -0
  278. package/src/host/theme/popups.ts +150 -0
  279. package/src/host/theme/responsive.ts +104 -0
  280. package/src/host/theme/toasts.ts +63 -0
  281. package/src/host/theme.ts +19 -1179
  282. package/src/ui/dialect/events.trb +276 -0
  283. package/src/ui/dialect/faces.trb +135 -0
  284. package/src/ui/dialect/layout.trb +283 -0
  285. package/src/ui/dialect/palette.trb +87 -0
  286. package/src/ui/dialect/problems.trb +174 -0
  287. package/src/ui/dialect/reactions.trb +198 -0
  288. package/src/ui/dialect/rows.trb +208 -0
  289. package/src/ui/dialect/screens.trb +293 -0
  290. package/src/ui/dialect/steps.trb +203 -0
  291. package/src/ui/dialect/validation.trb +137 -0
  292. package/src/ui/dialect/view.trb +110 -0
  293. package/src/ui/dialect/walking.trb +98 -0
  294. package/src/ui/dialect/words.trb +70 -0
  295. package/src/ui/i18n.trb +23 -0
  296. package/src/ui/test.trb +12 -0
  297. package/src/ui/testing/actions.trb +421 -0
  298. package/src/ui/testing/faces.trb +148 -0
  299. package/src/ui/testing/server.trb +73 -0
  300. package/src/ui/ui.trb +25 -1234
@@ -0,0 +1,148 @@
1
+ // --- what the dev tools share ------------------------------------------------------
2
+ //
3
+ // What the dev tools need from the host, the panel's elements and state, and small helpers to make and keep them.
4
+
5
+ import type { ObjectCell } from '../../core/index.ts';
6
+ import type { Host } from '../index.ts';
7
+
8
+ /** What the dev tools need from the browser host. */
9
+ export interface DevSide {
10
+ host: Host;
11
+ /** The folder trebol dev serves, to link a face to its file; null if unknown. */
12
+ root: string | null;
13
+ /** The face whose own node this is, if any. */
14
+ faceOf(e: Element): ObjectCell | null;
15
+ /** The face of a node or of the nearest node around it that is one. */
16
+ faceAt(e: Element): { face: ObjectCell; el: HTMLElement } | null;
17
+ /** The node of a face on the page, if it is on the page. */
18
+ nodeOf(face: ObjectCell): HTMLElement | null;
19
+ }
20
+
21
+ export type Tab = 'faces' | 'machines' | 'console' | 'log';
22
+
23
+ /** The panel's state, kept across the reloads of live reload. */
24
+ export interface State { open: boolean; tab: Tab; height: number }
25
+
26
+ export const STATE_KEY = 'trebol-dev';
27
+ export const HISTORY_KEY = 'trebol-dev-history';
28
+ export const MAX_HISTORY = 100;
29
+ export const MAX_LOG = 500;
30
+ export const MAX_MOLD = 2000;
31
+
32
+ export let side: DevSide;
33
+ export function setSide(v: DevSide): void {
34
+ side = v;
35
+ }
36
+ export let state: State = { open: false, tab: 'faces', height: 320 };
37
+ export function setState(v: State): void {
38
+ state = v;
39
+ }
40
+ export let panel: HTMLElement;
41
+ export function setPanel(v: HTMLElement): void {
42
+ panel = v;
43
+ }
44
+ export let opener: HTMLButtonElement;
45
+ export function setOpener(v: HTMLButtonElement): void {
46
+ opener = v;
47
+ }
48
+ export let outline: HTMLElement;
49
+ export function setOutline(v: HTMLElement): void {
50
+ outline = v;
51
+ }
52
+ export let pickButton: HTMLButtonElement;
53
+ export function setPickButton(v: HTMLButtonElement): void {
54
+ pickButton = v;
55
+ }
56
+ export let tree: HTMLElement;
57
+ export function setTree(v: HTMLElement): void {
58
+ tree = v;
59
+ }
60
+ export let detail: HTMLElement;
61
+ export function setDetail(v: HTMLElement): void {
62
+ detail = v;
63
+ }
64
+ export let consoleOut: HTMLElement;
65
+ export function setConsoleOut(v: HTMLElement): void {
66
+ consoleOut = v;
67
+ }
68
+ export let consoleIn: HTMLTextAreaElement;
69
+ export function setConsoleIn(v: HTMLTextAreaElement): void {
70
+ consoleIn = v;
71
+ }
72
+ export let consoleFace: HTMLElement;
73
+ export function setConsoleFace(v: HTMLElement): void {
74
+ consoleFace = v;
75
+ }
76
+ export let logList: HTMLElement;
77
+ export function setLogList(v: HTMLElement): void {
78
+ logList = v;
79
+ }
80
+ export const tabs = new Map<Tab, { button: HTMLButtonElement; pane: HTMLElement }>();
81
+
82
+ /** The face chosen in Faces, `face` in Console. */
83
+ export let picked: ObjectCell | null = null;
84
+ export function setPicked(v: ObjectCell | null): void {
85
+ picked = v;
86
+ }
87
+ /** The face under the pointer or the tree row the pointer is on. */
88
+ export let pointed: ObjectCell | null = null;
89
+ export function setPointed(v: ObjectCell | null): void {
90
+ pointed = v;
91
+ }
92
+ export let picking = false;
93
+ export function storePicking(v: typeof picking): void {
94
+ picking = v;
95
+ }
96
+ export let history: string[] = [];
97
+ export function setHistory(v: string[]): void {
98
+ history = v;
99
+ }
100
+ export let back = 0;
101
+ export function setBack(v: typeof back): void {
102
+ back = v;
103
+ }
104
+ export let lastLog: { key: string; li: HTMLElement; text: HTMLElement; count: number } | null = null;
105
+ export function setLastLog(v: { key: string; li: HTMLElement; text: HTMLElement; count: number } | null): void {
106
+ lastLog = v;
107
+ }
108
+ export let treeFrame = 0;
109
+ export function setTreeFrame(v: typeof treeFrame): void {
110
+ treeFrame = v;
111
+ }
112
+ /** The code typed so far runs one piece after another. */
113
+ export let running: Promise<void> = Promise.resolve();
114
+ export function setRunning(v: Promise<void>): void {
115
+ running = v;
116
+ }
117
+
118
+ export function el<T extends keyof HTMLElementTagNameMap>(tag: T, cls?: string, content?: string): HTMLElementTagNameMap[T] {
119
+ const e = document.createElement(tag);
120
+ if (cls) e.className = cls;
121
+ if (content !== undefined) e.textContent = content;
122
+ return e;
123
+ }
124
+
125
+ export function button(cls: string, content: string, act: () => void): HTMLButtonElement {
126
+ const b = el('button', cls, content);
127
+ b.type = 'button';
128
+ b.addEventListener('click', act);
129
+ return b;
130
+ }
131
+
132
+ export function read<T>(store: () => Storage, key: string, fallback: T): T {
133
+ try {
134
+ const v = store().getItem(key);
135
+ return v === null ? fallback : { ...fallback, ...(JSON.parse(v) as T) };
136
+ } catch {
137
+ return fallback;
138
+ }
139
+ }
140
+
141
+ export function write(store: () => Storage, key: string, v: unknown): void {
142
+ try {
143
+ store().setItem(key, JSON.stringify(v));
144
+ } catch {
145
+ // a private window or blocked storage: the panel forgets, nothing else
146
+ }
147
+ }
148
+
@@ -0,0 +1,238 @@
1
+ // The dev tools of trebol dev: a panel docked at the bottom of the page, opened
2
+ // with Ctrl+` or the small button in the corner. Only a page that trebol dev
3
+ // serves has them (it adds <meta name="trebol-dev">); a built page never does.
4
+ //
5
+ // Faces the faces on the page as a tree, and what one of them holds:
6
+ // pick one on the page or in the tree; where it was written links
7
+ // to the editor (vscode://).
8
+ // Console >> and == as in the trebol console, against the running app;
9
+ // `face` is the face picked; print shows here too.
10
+ // Machines the machines the program holds in its words: their states as a
11
+ // tree, the ones they are in marked, and of the one chosen its
12
+ // data, the ways out of its states and the events it takes now.
13
+ // Log events, requests, toasts, errors and warnings, and each change
14
+ // of state of a machine, newest last.
15
+
16
+ //
17
+ // This file is the panel; the tabs and what they share are in devtools/.
18
+
19
+ import { K, mold } from '../core/index.ts';
20
+ import { output } from './index.ts';
21
+ import { devLog } from './devlog.ts';
22
+ import { type DevSide, type Tab, STATE_KEY, HISTORY_KEY, side, setSide, state, setState, panel, setPanel, opener, setOpener, outline, setOutline, pickButton, setPickButton, consoleIn, consoleFace, logList, tabs, picked, picking, setHistory, treeFrame, setTreeFrame, el, button, read, write } from './devtools/state.ts';
23
+ import { wordText, short, faceRef } from './devtools/read.ts';
24
+ import { faceKey, buildFaces, drawTree, drawDetail, point, placeOutline, setPicking, pickMove, pickDown, pickClick } from './devtools/faces.ts';
25
+ import { buildMachines, noteMachines, drawMachines } from './devtools/machines.ts';
26
+ import { buildConsole, say } from './devtools/console.ts';
27
+ import { buildLog, log } from './devtools/log.ts';
28
+ export { faceRef } from './devtools/read.ts';
29
+ export type { DevSide } from './devtools/state.ts';
30
+
31
+ // --- the panel -----------------------------------------------------------------------
32
+
33
+ /** Starts the dev tools on a page served by trebol dev; not in a frame (the documentation's examples). */
34
+ export function startDevtools(s: DevSide): void {
35
+ if (window !== window.top) return;
36
+ setSide(s);
37
+ setState(read(() => sessionStorage, STATE_KEY, state));
38
+ setHistory(read<{ lines: string[] }>(() => localStorage, HISTORY_KEY, { lines: [] }).lines);
39
+
40
+ setPanel(el('section', 'tb-dev-tools'));
41
+ panel.popover = 'manual';
42
+ panel.setAttribute('aria-label', 'Trebol dev tools');
43
+ const grip = el('div', 'tb-dev-grip');
44
+ grip.addEventListener('pointerdown', resizeFrom);
45
+ const head = el('header');
46
+ const list = el('div', 'tb-dev-tabs');
47
+ list.setAttribute('role', 'tablist');
48
+ head.append(list);
49
+ const body = el('div', 'tb-dev-body');
50
+ for (const [tab, label] of [['faces', 'Faces'], ['machines', 'Machines'], ['console', 'Console'], ['log', 'Log']] as const) {
51
+ const b = button('tb-dev-tab', label, () => openTab(tab));
52
+ b.setAttribute('role', 'tab');
53
+ b.id = `tb-dev-tab-${tab}`;
54
+ const pane = el('div', `tb-dev-pane tb-dev-${tab}`);
55
+ pane.setAttribute('role', 'tabpanel');
56
+ pane.setAttribute('aria-labelledby', b.id);
57
+ list.append(b);
58
+ body.append(pane);
59
+ tabs.set(tab, { button: b, pane });
60
+ }
61
+ setPickButton(button('tb-dev-button', 'Pick', () => setPicking(!picking)));
62
+ pickButton.title = 'Click a face on the page to see it here';
63
+ pickButton.setAttribute('aria-pressed', 'false');
64
+ const close = button('tb-dev-button', 'Close', () => setOpen(false));
65
+ close.title = 'Close (Ctrl+`)';
66
+ head.append(el('span', 'tb-dev-space'), pickButton, close);
67
+ panel.append(grip, head, body);
68
+ // keys typed here are not for a face around the panel, and Escape does not close a dialog it is in
69
+ panel.addEventListener('keydown', ev => {
70
+ ev.stopPropagation();
71
+ if (ev.key === 'Escape') ev.preventDefault();
72
+ });
73
+ buildFaces(tabs.get('faces')!.pane);
74
+ buildMachines(tabs.get('machines')!.pane);
75
+ buildConsole(tabs.get('console')!.pane);
76
+ buildLog(tabs.get('log')!.pane);
77
+
78
+ setOpener(button('tb-dev-opener', 'Trebol', () => setOpen(true)));
79
+ opener.popover = 'manual';
80
+ opener.title = 'Dev tools (Ctrl+`)';
81
+ setOutline(el('div', 'tb-dev-outline'));
82
+ outline.popover = 'manual';
83
+ outline.setAttribute('aria-hidden', 'true');
84
+ document.body.append(panel, opener, outline);
85
+
86
+ addEventListener('keydown', ev => {
87
+ if (ev.ctrlKey && !ev.altKey && !ev.metaKey && ev.code === 'Backquote') {
88
+ ev.preventDefault();
89
+ ev.stopImmediatePropagation();
90
+ setOpen(!state.open);
91
+ } else if (picking && ev.key === 'Escape') {
92
+ ev.preventDefault();
93
+ ev.stopImmediatePropagation();
94
+ setPicking(false);
95
+ }
96
+ }, true);
97
+ addEventListener('pointermove', pickMove, true);
98
+ addEventListener('pointerdown', pickDown, true);
99
+ addEventListener('click', pickClick, true);
100
+ addEventListener('scroll', () => placeOutline(), { capture: true, passive: true });
101
+ addEventListener('resize', () => {
102
+ setHeight(state.height);
103
+ placeOutline();
104
+ });
105
+
106
+ hook();
107
+ openTab(state.tab);
108
+ setOpen(state.open);
109
+ }
110
+
111
+ /** Keys typed in the panel are not the app's: its shortcuts and on-key leave them. */
112
+ export function inDevtools(target: EventTarget | null): boolean {
113
+ return target instanceof Element && target.closest('.tb-dev-tools') !== null;
114
+ }
115
+
116
+ /**
117
+ * Puts the panel, its opener and the outline inside the dialog on show, or back in the body: while a
118
+ * modal dialog is open everything outside it is inert, the panel too.
119
+ */
120
+ export function home(): void {
121
+ const modals = document.querySelectorAll('dialog:modal');
122
+ const into = modals.length > 0 ? modals[modals.length - 1]! : document.body;
123
+ if (panel.parentElement === into) return;
124
+ for (const e of [panel, opener, outline]) {
125
+ const shown = e.matches(':popover-open');
126
+ into.append(e);
127
+ if (shown) e.showPopover();
128
+ }
129
+ }
130
+
131
+ export function setOpen(open: boolean): void {
132
+ state.open = open;
133
+ write(() => sessionStorage, STATE_KEY, state);
134
+ home();
135
+ if (open) {
136
+ opener.hidePopover();
137
+ panel.showPopover();
138
+ setHeight(state.height);
139
+ refresh();
140
+ if (state.tab === 'console') consoleIn.focus();
141
+ } else {
142
+ setPicking(false);
143
+ point(null);
144
+ const focused = panel.contains(document.activeElement);
145
+ panel.hidePopover();
146
+ opener.showPopover();
147
+ if (focused) opener.focus();
148
+ document.body.style.paddingBottom = '';
149
+ }
150
+ }
151
+
152
+ export function setHeight(h: number): void {
153
+ state.height = Math.round(Math.max(140, Math.min(h, innerHeight - 60)));
154
+ panel.style.height = `${state.height}px`;
155
+ // the end of the page stays reachable above the panel
156
+ if (state.open) document.body.style.paddingBottom = `${state.height}px`;
157
+ }
158
+
159
+ export function resizeFrom(ev: PointerEvent): void {
160
+ ev.preventDefault();
161
+ const grip = ev.currentTarget as HTMLElement;
162
+ grip.setPointerCapture(ev.pointerId);
163
+ const move = (e: PointerEvent): void => setHeight(innerHeight - e.clientY);
164
+ const up = (): void => {
165
+ grip.removeEventListener('pointermove', move);
166
+ grip.removeEventListener('pointerup', up);
167
+ write(() => sessionStorage, STATE_KEY, state);
168
+ };
169
+ grip.addEventListener('pointermove', move);
170
+ grip.addEventListener('pointerup', up);
171
+ }
172
+
173
+ export function openTab(tab: Tab): void {
174
+ state.tab = tab;
175
+ write(() => sessionStorage, STATE_KEY, state);
176
+ for (const [t, { button: b, pane }] of tabs) {
177
+ b.setAttribute('aria-selected', String(t === tab));
178
+ b.tabIndex = t === tab ? 0 : -1;
179
+ pane.hidden = t !== tab;
180
+ }
181
+ refresh();
182
+ placeOutline();
183
+ if (tab === 'console' && state.open) consoleIn.focus();
184
+ if (tab === 'log') logList.scrollTop = logList.scrollHeight;
185
+ }
186
+
187
+ /** What the host tells: events, requests, notes and repaints. */
188
+ export function hook(): void {
189
+ devLog.event = (fn, face, args) => {
190
+ if (fn === 'ui-blur') return;
191
+ let what = fn.replace(/^ui-/, '');
192
+ let rest = args;
193
+ if (fn === 'ui-event' && args[0] !== undefined) {
194
+ what = wordText(args[0]) ?? what;
195
+ rest = [];
196
+ }
197
+ const shown = rest.length > 0 && rest[0]!.t !== K.Object ? ' ' + short(mold(rest[0]!), 60) : '';
198
+ log('event', `${what} · ${faceRef(face, side.host.rt)}${shown}`, `${fn} ${faceKey(face)}`);
199
+ };
200
+ devLog.request = (verb, url, status, ms, problem) => {
201
+ let where = url;
202
+ try {
203
+ const u = new URL(url, location.href);
204
+ if (u.origin === location.origin) where = u.pathname + u.search;
205
+ } catch {
206
+ // not a URL: shown as given
207
+ }
208
+ const outcome = status !== null ? String(status) : `failed (${problem ?? 'network'})`;
209
+ log(status !== null && status < 400 ? 'request' : 'failed', `${verb} ${where} ${outcome} · ${ms} ms`);
210
+ };
211
+ devLog.note = (kind, text) => log(kind, text);
212
+ devLog.repainted = () => {
213
+ home();
214
+ noteMachines();
215
+ if (!state.open) return;
216
+ placeOutline();
217
+ if ((state.tab === 'faces' || state.tab === 'machines') && treeFrame === 0) setTreeFrame(requestAnimationFrame(() => {
218
+ setTreeFrame(0);
219
+ refresh();
220
+ }));
221
+ };
222
+ const line = output.line;
223
+ output.line = text => {
224
+ line(text);
225
+ say('out', text);
226
+ };
227
+ }
228
+
229
+ export function refresh(): void {
230
+ if (!state.open) return;
231
+ if (state.tab === 'faces') {
232
+ drawTree();
233
+ drawDetail();
234
+ }
235
+ if (state.tab === 'machines') void drawMachines();
236
+ consoleFace.textContent = picked !== null ? `face: ${faceRef(picked, side.host.rt)}` : 'face: none (pick one in Faces)';
237
+ }
238
+
@@ -0,0 +1,93 @@
1
+ Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter) Inter-Italic[opsz,wght].ttf: Copyright 2016 The Inter Project Authors (https://github.com/rsms/inter)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
Binary file
@@ -0,0 +1,40 @@
1
+ // Inter, the font of the default theme, as variable woff2 files in fonts/:
2
+ // one per script, so a browser downloads only those its text needs (the
3
+ // unicode-range of each face). They come from @fontsource-variable/inter
4
+ // 5.3.0, under the SIL Open Font License (fonts/OFL.txt).
5
+ //
6
+ // trebol.js declares them, with addresses next to itself, in a constructed
7
+ // style sheet (a strict Content-Security-Policy drops a <style> made by
8
+ // script); a page made by `trebol build` carries the files inside and declares
9
+ // them in its own <style data-tb-fonts>, which the host then leaves alone.
10
+
11
+ export interface FontFile {
12
+ /** File name in fonts/. */
13
+ file: string;
14
+ /** The characters the file has, as CSS unicode-range. */
15
+ range: string;
16
+ }
17
+
18
+ // The order of @fontsource: where ranges overlap, the last face declared wins.
19
+ export const INTER: readonly FontFile[] = [
20
+ { file: 'inter-cyrillic-ext.woff2', range: 'U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F' },
21
+ { file: 'inter-cyrillic.woff2', range: 'U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116' },
22
+ { file: 'inter-greek-ext.woff2', range: 'U+1F00-1FFF' },
23
+ { file: 'inter-greek.woff2', range: 'U+0370-0377,U+037A-037F,U+0384-038A,U+038C,U+038E-03A1,U+03A3-03FF' },
24
+ { file: 'inter-vietnamese.woff2', range: 'U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB' },
25
+ { file: 'inter-latin-ext.woff2', range: 'U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF' },
26
+ { file: 'inter-latin.woff2', range: 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD' },
27
+ ];
28
+
29
+ /** The @font-face rules of Inter, each file at the address `src` gives it. */
30
+ export function interCss(src: (file: string) => string, faces: readonly FontFile[] = INTER): string {
31
+ return faces.map(f => `@font-face { font-family: Inter; font-style: normal; font-weight: 100 900; font-display: swap; src: url(${src(f.file)}) format("woff2"); unicode-range: ${f.range}; }`).join('\n');
32
+ }
33
+
34
+ /** Whether a code point is in a unicode-range. */
35
+ export function inRange(range: string, cp: number): boolean {
36
+ return range.split(',').some(r => {
37
+ const [lo, hi] = r.slice(2).split('-').map(h => parseInt(h, 16));
38
+ return cp >= lo! && cp <= (hi ?? lo!);
39
+ });
40
+ }
package/src/host/icons.ts CHANGED
@@ -41,6 +41,9 @@ const PATHS: Record<string, string> = {
41
41
  truck: 'M2 6h12v11H2zM14 10h4l4 4v3h-8zM6.5 15a2 2 0 1 0 0 4a2 2 0 1 0 0-4zM17.5 15a2 2 0 1 0 0 4a2 2 0 1 0 0-4z',
42
42
  box: 'M12 3l8 4.5v9L12 21l-8-4.5v-9zM4 7.5l8 4.5 8-4.5M12 12v9',
43
43
  file: 'M6 3h8l4 4v14H6zM14 3v4h4M9 12h6M9 16h6',
44
+ invoice: 'M6 3h12v18l-2-1.5-2 1.5-2-1.5-2 1.5-2-1.5-2 1.5zM9 8h6M9 12h6M9 16h3',
45
+ template: 'M4 4h16v5H4zM4 13h7v7H4zM15 13h5M15 17h5',
46
+ stack: 'M12 3l9 4.5-9 4.5-9-4.5zM3 12l9 4.5 9-4.5M3 16.5l9 4.5 9-4.5',
44
47
  image: 'M4 5h16v14H4zM4 16l5-5 4 4 2-2 5 5M15 8.5a1.5 1.5 0 1 0 0 3a1.5 1.5 0 1 0 0-3z',
45
48
  settings: 'M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4',
46
49
  filter: 'M4 5h16l-6 8v6l-4-2v-4L4 5z',
@@ -51,6 +54,7 @@ const PATHS: Record<string, string> = {
51
54
  eye: 'M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12zM12 9a3 3 0 1 0 0 6a3 3 0 1 0 0-6z',
52
55
  lock: 'M5 11h14v10H5zM8 11V7a4 4 0 0 1 8 0v4',
53
56
  calendar: 'M4 6h16v15H4zM4 10h16M8 3v4M16 3v4',
57
+ clock: 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18zM12 7v5l3 2',
54
58
  star: 'M12 3l2.8 5.8 6.2.9-4.5 4.4 1 6.3L12 17.5l-5.5 2.9 1-6.3L3 9.7l6.2-.9L12 3z',
55
59
  heart: 'M12 20s-8-5-8-11a4.5 4.5 0 0 1 8-2.8A4.5 4.5 0 0 1 20 9c0 6-8 11-8 11z',
56
60
  type: 'M5 7V4h14v3M12 4v16M9 20h6',