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
@@ -40,6 +40,9 @@ const PATHS = {
40
40
  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',
41
41
  box: 'M12 3l8 4.5v9L12 21l-8-4.5v-9zM4 7.5l8 4.5 8-4.5M12 12v9',
42
42
  file: 'M6 3h8l4 4v14H6zM14 3v4h4M9 12h6M9 16h6',
43
+ invoice: 'M6 3h12v18l-2-1.5-2 1.5-2-1.5-2 1.5-2-1.5-2 1.5zM9 8h6M9 12h6M9 16h3',
44
+ template: 'M4 4h16v5H4zM4 13h7v7H4zM15 13h5M15 17h5',
45
+ stack: 'M12 3l9 4.5-9 4.5-9-4.5zM3 12l9 4.5 9-4.5M3 16.5l9 4.5 9-4.5',
43
46
  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',
44
47
  settings: 'M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4',
45
48
  filter: 'M4 5h16l-6 8v6l-4-2v-4L4 5z',
@@ -50,6 +53,7 @@ const PATHS = {
50
53
  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',
51
54
  lock: 'M5 11h14v10H5zM8 11V7a4 4 0 0 1 8 0v4',
52
55
  calendar: 'M4 6h16v15H4zM4 10h16M8 3v4M16 3v4',
56
+ clock: 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18zM12 7v5l3 2',
53
57
  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',
54
58
  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',
55
59
  type: 'M5 7V4h14v3M12 4v16M9 20h6',
@@ -2,14 +2,16 @@ import './natives.ts';
2
2
  import './net.ts';
3
3
  import './page.ts';
4
4
  import './compress.ts';
5
+ import './share.ts';
5
6
  import './locale.ts';
6
7
  import { type Loader } from './modules.ts';
7
8
  import { type Cell, type ObjectCell, type Runtime } from '../core/index.ts';
8
9
  import { type Scheduler } from './scheduler.ts';
9
10
  export { output } from './natives.ts';
10
11
  export { fileHandle } from './net.ts';
12
+ export { setShareEnv, type ShareEnv, type ChannelLike, type LocksLike, type Envelope } from './share.ts';
11
13
  export { page } from './page.ts';
12
- export { mapAt, formatLocal, activeLanguage, shown, translate, uiText, editLocal, readLocal, readDate, weekStart, fileSize, LOCAL_KINDS } from './locale.ts';
14
+ export { mapAt, formatLocal, activeLanguage, shown, translate, uiText, editLocal, readLocal, readDate, readRange, readTime, weekStart, fileSize, LOCAL_KINDS, amountOf, countStep } from './locale.ts';
13
15
  export type { Loader } from './modules.ts';
14
16
  export * from './scheduler.ts';
15
17
  export interface Host {
@@ -29,6 +31,8 @@ export declare function startHost(opts?: HostOptions): Host;
29
31
  export declare const UI_SOURCE: string;
30
32
  /** URL of the languages module (i18n, tr, translated). */
31
33
  export declare const I18N_SOURCE: string;
34
+ /** URL of the words of screen tests (click, type, see...), which `trebol test` loads. */
35
+ export declare const TEST_SOURCE: string;
32
36
  /** Loads languages and the UI dialect (view, layout, stylize, theme...) into the user context. */
33
37
  export declare function startUi(host: Host): Promise<Cell>;
34
38
  /**
@@ -4,14 +4,16 @@ import "./natives.js";
4
4
  import "./net.js";
5
5
  import "./page.js";
6
6
  import "./compress.js";
7
+ import "./share.js";
7
8
  import "./locale.js";
8
9
  import { setLoader, defaultLoader } from "./modules.js";
9
- import { K, makeRuntime, load, bindSeries, doSource, scriptStart, errorMessage, form, mold, LIBRARY_FILES, } from "../core/index.js";
10
+ import { makeRuntime, load, bindSeries, runSync, scriptStart, errorMessage, form, LIBRARY_FILES, } from "../core/index.js";
10
11
  import { makeScheduler, spawn, taskResult } from "./scheduler.js";
11
12
  export { output } from "./natives.js";
12
13
  export { fileHandle } from "./net.js";
14
+ export { setShareEnv } from "./share.js";
13
15
  export { page } from "./page.js";
14
- export { mapAt, formatLocal, activeLanguage, shown, translate, uiText, editLocal, readLocal, readDate, weekStart, fileSize, LOCAL_KINDS } from "./locale.js";
16
+ export { mapAt, formatLocal, activeLanguage, shown, translate, uiText, editLocal, readLocal, readDate, readRange, readTime, weekStart, fileSize, LOCAL_KINDS, amountOf, countStep } from "./locale.js";
15
17
  export * from "./scheduler.js";
16
18
  /** Host mezzanines: the Trebol side of the host natives. */
17
19
  const HOST_MEZZANINES = String.raw `
@@ -24,8 +26,106 @@ fetch: func [
24
26
  url [url! string!]
25
27
  /with "method, headers, body, form, multipart, timeout, full"
26
28
  options [block! object!]
29
+ /local answer
27
30
  ][
28
- http-request url either with [either block? options [make object! options] [options]] [none]
31
+ if all [with block? options] [options: make object! options]
32
+ answer: http-request url either with [options] [none]
33
+ ; what was kept of the same path is old now
34
+ if all [with find [post put patch delete] attempt [to word! select options 'method]] [ui-cache-touched url]
35
+ answer
36
+ ]
37
+
38
+ ; --- answers kept: cached and refresh ---------------------------------------------
39
+ ;
40
+ ; Each url read with cached has an entry; a reaction that reads cached %/x has
41
+ ; the entry's version among its sources, so it runs again when an answer comes.
42
+ ; ui-cache-news counts every answer, for reactions whose url is not written out.
43
+
44
+ ui-cache-entries: copy []
45
+ ui-cache-news: make object! [version: 0]
46
+
47
+ ui-cache-entry: func ["The entry of what cached keeps for a url, made the first time." url /local key e] [
48
+ key: form url
49
+ unless e: select/case ui-cache-entries key [
50
+ e: make object! [url: none answer: none version: 0 stale: true asking: false again: false task: none]
51
+ e/url: url
52
+ append ui-cache-entries reduce [key e]
53
+ ]
54
+ e
55
+ ]
56
+
57
+ ; The path of a url, without the server, the query or the fragment.
58
+ ui-cache-path: func ["The path of a url, without the server, the query or the fragment." url /local s i] [
59
+ s: form url
60
+ if i: find s "#" [s: copy/part s i]
61
+ if i: find s "?" [s: copy/part s i]
62
+ if i: find s "://" [s: any [find skip i 3 "/" copy "/"]]
63
+ s
64
+ ]
65
+
66
+ ; Asks again behind; one request at a time per url, and one more if asked meanwhile.
67
+ ui-cache-ask: func ["Asks again behind for the answer of an entry of cached." e] [
68
+ e/stale: false
69
+ either e/asking [e/again: true] [
70
+ e/asking: true
71
+ e/task: spawn compose [ui-cache-answer (e)]
72
+ ]
73
+ ]
74
+
75
+ ui-cache-answer: func ["Asks for the answer of an entry of cached, and keeps it." e /local r] [
76
+ forever [
77
+ e/again: false
78
+ r: try [fetch e/url]
79
+ either error? :r [
80
+ ; the last answer stays; the next read asks again
81
+ e/stale: true
82
+ print ["cached:" form e/url "--" r/message]
83
+ ] [
84
+ e/answer: :r
85
+ e/version: e/version + 1
86
+ ui-cache-news/version: ui-cache-news/version + 1
87
+ ]
88
+ unless e/again [break]
89
+ ]
90
+ e/asking: false
91
+ ]
92
+
93
+ ; Every url kept is asked again: the page came back into view.
94
+ ui-caches-again: func ["Asks again for every answer cached keeps." /local key e] [
95
+ foreach [key e] ui-cache-entries [ui-cache-ask e]
96
+ ]
97
+
98
+ ; Every url kept is old: it is asked again the next time it is read (a screen is entered).
99
+ ui-caches-old: func ["Marks every answer cached keeps as old: the next read asks again." /local key e] [
100
+ foreach [key e] ui-cache-entries [e/stale: true]
101
+ ]
102
+
103
+ ; A post, put, patch or delete to url: what was kept of its path, or of a path
104
+ ; above or under it (/api/clients for /api/clients/7), is asked again.
105
+ ui-cache-touched: func ["Asks again for what cached keeps of the path of url, or above or under it." url /local key e a b] [
106
+ a: ui-cache-path url
107
+ foreach [key e] ui-cache-entries [
108
+ b: ui-cache-path e/url
109
+ if any [a = b find/match a join b "/" find/match b join a "/"] [ui-cache-ask e]
110
+ ]
111
+ ]
112
+
113
+ cached: func [
114
+ "The last answer to a GET of url, at once (none the first time), and asks again behind: a reaction (is, react) that reads it runs again when the answer comes."
115
+ url [url! string!]
116
+ /local e
117
+ ][
118
+ e: ui-cache-entry url
119
+ if e/stale [ui-cache-ask e]
120
+ e/answer
121
+ ]
122
+
123
+ refresh: func [
124
+ "Asks again for an answer kept by cached, now; reactions that read it run again when it comes."
125
+ url [url! string!]
126
+ ][
127
+ ui-cache-ask ui-cache-entry url
128
+ exit
29
129
  ]
30
130
 
31
131
  show-progress: func [
@@ -162,7 +262,10 @@ export function startHost(opts = {}) {
162
262
  const onError = opts.onError ?? (e => console.error(report(e)));
163
263
  const rt = makeRuntime();
164
264
  setLoader(rt, opts.loader ?? defaultLoader());
165
- const r = doSource(rt, HOST_MEZZANINES, 'host');
265
+ // in lib, as the core's mezzanines: a word a program sets never takes the place of one of them
266
+ const code = load(HOST_MEZZANINES, { file: 'host' });
267
+ bindSeries(code.s, rt.lib, true);
268
+ const r = runSync(rt, code);
166
269
  // Host mezzanines failing to load is a bug in Trebol itself.
167
270
  if (r.k === 'error')
168
271
  throw new Error(`host mezzanines failed: ${errorMessage(r.e)}`);
@@ -173,8 +276,10 @@ export function startHost(opts = {}) {
173
276
  export const UI_SOURCE = new URL('../ui/ui.trb', import.meta.url).href;
174
277
  /** URL of the languages module (i18n, tr, translated). */
175
278
  export const I18N_SOURCE = new URL('../ui/i18n.trb', import.meta.url).href;
279
+ /** URL of the words of screen tests (click, type, see...), which `trebol test` loads. */
280
+ export const TEST_SOURCE = new URL('../ui/test.trb', import.meta.url).href;
176
281
  // Trebol's own code: its errors point at the program's call (see LIBRARY_FILES).
177
- LIBRARY_FILES.add('host').add(UI_SOURCE).add(I18N_SOURCE);
282
+ LIBRARY_FILES.add('host').add(UI_SOURCE).add(I18N_SOURCE).add(TEST_SOURCE);
178
283
  /** Loads languages and the UI dialect (view, layout, stylize, theme...) into the user context. */
179
284
  export function startUi(host) {
180
285
  return runSource(host, `import ${I18N_SOURCE} import ${UI_SOURCE}`);
@@ -0,0 +1,5 @@
1
+ import { type ObjectCell } from '../core/index.ts';
2
+ /** countPages is count-pages, as Trebol names words. */
3
+ export declare function trebolName(js: string): string;
4
+ /** The object for a loaded JavaScript module, or an error message. */
5
+ export declare function jsModule(ns: Record<string, unknown>): ObjectCell | string;
@@ -0,0 +1,130 @@
1
+ // JavaScript modules as Trebol modules.
2
+ //
3
+ // `import %pdf-tools.js` loads a JavaScript module and gives an object with a
4
+ // function for each function it exports, named in Trebol's way (countPages is
5
+ // count-pages), and the other exports as values:
6
+ //
7
+ // pdf: import %pdf-tools.js
8
+ // pages: pdf/count-pages %contract.pdf
9
+ //
10
+ // Arguments and results cross as JSON, so text, numbers, blocks, maps, logic
11
+ // and none keep their shape; a promise is awaited while other tasks run, and
12
+ // a JavaScript exception is a Trebol error. A function's spec comes from its
13
+ // parameters, or from a `spec` property written as Trebol source:
14
+ //
15
+ // export function countPages(file) { ... }
16
+ // countPages.spec = '["The pages of a PDF." file [file! url!]]';
17
+ //
18
+ // No Trebol value holds the JavaScript function: each is a native built on one
19
+ // hidden native, carrying the function's index in a table here as its data.
20
+ import { K, NONE, registerNative, load, parseSpec, parseJson, toJson, context, ctxAdd, intern, makeError, value, throwError, } from "../core/index.js";
21
+ const functions = [];
22
+ const call = registerNative({
23
+ name: 'js-function', hidden: true, spec: parseSpec(load('[]').s.data[0]),
24
+ specBlock: load('[]').s.data[0],
25
+ }, (_t, f, v) => {
26
+ if (f.phase === 1)
27
+ return value(v);
28
+ const fn = functions[f.def.data];
29
+ const name = f.def.name;
30
+ let result;
31
+ try {
32
+ result = fn(...f.args.map(a => JSON.parse(toJson(a))));
33
+ }
34
+ catch (e) {
35
+ return throwError('script', 'js-error', `${name}: ${e?.message ?? String(e)}`);
36
+ }
37
+ if (!(result instanceof Promise))
38
+ return toTrebol(result, name);
39
+ f.phase = 1;
40
+ return {
41
+ k: 'await',
42
+ p: result.then(r => {
43
+ const step = toTrebol(r, name);
44
+ if (step.k === 'value')
45
+ return step.v;
46
+ throw step.e.v;
47
+ }, (e) => {
48
+ throw makeError('script', 'js-error', `${name}: ${e?.message ?? String(e)}`);
49
+ }),
50
+ };
51
+ }).p;
52
+ function toTrebol(r, name) {
53
+ if (r === undefined)
54
+ return value(NONE);
55
+ let json;
56
+ try {
57
+ json = JSON.stringify(r);
58
+ }
59
+ catch {
60
+ json = undefined;
61
+ }
62
+ if (json === undefined)
63
+ return throwError('script', 'js-error', `${name} gave a value that is not JSON`);
64
+ const v = parseJson(json);
65
+ return typeof v === 'string' ? throwError('script', 'js-error', `${name}: ${v}`) : value(v);
66
+ }
67
+ /** countPages is count-pages, as Trebol names words. */
68
+ export function trebolName(js) {
69
+ return js.replace(/([a-z0-9])([A-Z])/g, '$1-$2').replace(/_/g, '-').toLowerCase();
70
+ }
71
+ /** The parameter names of a plain function or an arrow, or none when they cannot be read. */
72
+ function params(fn) {
73
+ const src = fn.toString();
74
+ const m = /^\s*(?:async\s+)?([\w$]+)\s*=>/.exec(src) ?? /^[^(=]*\(([^)]*)\)/.exec(src);
75
+ if (m === null)
76
+ return null;
77
+ const names = m[1].split(',').map(p => p.trim()).filter(p => p !== '');
78
+ return names.every(p => /^[A-Za-z_$][\w$]*$/.test(p)) ? names.map(trebolName) : null;
79
+ }
80
+ function specOf(fn, name) {
81
+ const own = fn.spec;
82
+ const src = typeof own === 'string' ? own
83
+ : `[${(params(fn) ?? Array.from({ length: fn.length }, (_, i) => `arg${i + 1}`)).join(' ')}]`;
84
+ let specBlock;
85
+ try {
86
+ specBlock = load(src).s.data[0];
87
+ }
88
+ catch (e) {
89
+ return `${name}: bad spec: ${e.message}`;
90
+ }
91
+ if (specBlock?.t !== K.Block)
92
+ return `${name}: its spec is not a block`;
93
+ const spec = parseSpec(specBlock);
94
+ return typeof spec === 'string' ? `${name}: ${spec}` : { spec, specBlock };
95
+ }
96
+ /** The object for a loaded JavaScript module, or an error message. */
97
+ export function jsModule(ns) {
98
+ const ctx = context();
99
+ ctx.self = true;
100
+ for (const [key, x] of Object.entries(ns)) {
101
+ if (key === 'default')
102
+ continue;
103
+ const name = trebolName(key);
104
+ let v;
105
+ if (typeof x === 'function') {
106
+ const spec = specOf(x, name);
107
+ if (typeof spec === 'string')
108
+ return spec;
109
+ functions.push(x);
110
+ v = { t: K.Native, p: { ...call, ...spec, name, data: functions.length - 1, hidden: true } };
111
+ }
112
+ else {
113
+ let json;
114
+ try {
115
+ json = JSON.stringify(x);
116
+ }
117
+ catch {
118
+ json = undefined;
119
+ }
120
+ if (json === undefined)
121
+ continue;
122
+ const parsed = parseJson(json);
123
+ if (typeof parsed === 'string')
124
+ continue;
125
+ v = parsed;
126
+ }
127
+ ctxAdd(ctx, intern(name), v);
128
+ }
129
+ return { t: K.Object, ctx };
130
+ }
@@ -1,4 +1,11 @@
1
1
  import { type Cell, type MapCell, type Runtime } from '../core/index.ts';
2
+ /** How much a number, a percent or an amount is, as a JavaScript number; null for anything else. */
3
+ export declare function amountOf(c: Cell): number | null;
4
+ /**
5
+ * What a number that counts shows at x on its way to `to` (a text with `count`): a value of the kind of `to`,
6
+ * with no more digits than it has, so the run reads as the number it ends on.
7
+ */
8
+ export declare function countStep(to: Cell, x: number): Cell;
2
9
  /** The kinds `localize` formats; anything else shows as `form` gives it. */
3
10
  export declare const LOCAL_KINDS: ReadonlySet<number>;
4
11
  /** A value in the format of a language tag (`es`, `en-GB`); null when it has no local format. */
@@ -17,6 +24,17 @@ export declare function readLocal(s: string, lang: string): string | null;
17
24
  * reads in every language, and a two-digit year is in this century.
18
25
  */
19
26
  export declare function readDate(s: string, lang: string): string | null;
27
+ /**
28
+ * Two dates typed for a range, as `2026-11-03 2026-11-10` with the start first, or null. They are
29
+ * written apart by a dash with spaces around it, as `3/11/2026 – 10/11/2026` or `3/11/2026 - 10/11/2026`,
30
+ * or by a space alone; a range typed end first is turned round.
31
+ */
32
+ export declare function readRange(s: string, lang: string): string | null;
33
+ /**
34
+ * A time typed in any language, as `09:30`, or null: `9:30`, `9.30`, `9h30`, `930`, `21`, and with am or pm,
35
+ * `9:30 pm` or `9pm`. Minutes go from 00 to 59 and hours from 0 to 23, or 1 to 12 with am or pm.
36
+ */
37
+ export declare function readTime(s: string): string | null;
20
38
  /** The first day of the week in a language, 1 for Monday to 7 for Sunday. */
21
39
  export declare function weekStart(lang: string): number;
22
40
  /** The active language: `i18n/language` of the user context, `en` if there is none. */
@@ -1,7 +1,39 @@
1
1
  // Values in the format of a language: dates, times, numbers, percents and
2
2
  // money, through Intl. It works wherever Intl does (browser or Node); the
3
3
  // core keeps its own language-neutral form/mold.
4
- import { K, native, value, string, form, text, formatDec, spell, ctxFind, intern, } from "../core/index.js";
4
+ import { K, native, value, string, form, text, formatDec, spell, ctxFind, intern, integer, decimal, percent, money, dec, decToNumber, I64, } from "../core/index.js";
5
+ /** How much a number, a percent or an amount is, as a JavaScript number; null for anything else. */
6
+ export function amountOf(c) {
7
+ switch (c.t) {
8
+ case K.Integer: return I64.toNumber(c.v);
9
+ case K.Decimal:
10
+ case K.Percent: return c.v;
11
+ case K.Money: return decToNumber(c.v);
12
+ default: return null;
13
+ }
14
+ }
15
+ /** The digits after the point a decimal number is written with. */
16
+ function fractionDigits(n) {
17
+ const m = /\.(\d+)|e-(\d+)/.exec(String(n));
18
+ return m === null ? 0 : m[1] !== undefined ? m[1].length : Number(m[2]);
19
+ }
20
+ /**
21
+ * What a number that counts shows at x on its way to `to` (a text with `count`): a value of the kind of `to`,
22
+ * with no more digits than it has, so the run reads as the number it ends on.
23
+ */
24
+ export function countStep(to, x) {
25
+ switch (to.t) {
26
+ case K.Integer: return integer(Math.round(x));
27
+ case K.Money: return money(dec(BigInt(Math.round(x * 10 ** to.v.e)), to.v.e), to.cur);
28
+ case K.Decimal:
29
+ case K.Percent: {
30
+ const k = 10 ** fractionDigits(to.v);
31
+ const v = Math.round(x * k) / k;
32
+ return to.t === K.Decimal ? decimal(v) : percent(v);
33
+ }
34
+ default: return to;
35
+ }
36
+ }
5
37
  /** The kinds `localize` formats; anything else shows as `form` gives it. */
6
38
  export const LOCAL_KINDS = new Set([K.Date, K.Time, K.Integer, K.Decimal, K.Percent, K.Money]);
7
39
  const NS_PER_MS = 1e6;
@@ -128,6 +160,44 @@ export function readDate(s, lang) {
128
160
  return null;
129
161
  return `${y}-${String(m).padStart(2, '0')}-${String(d).padStart(2, '0')}`;
130
162
  }
163
+ /**
164
+ * Two dates typed for a range, as `2026-11-03 2026-11-10` with the start first, or null. They are
165
+ * written apart by a dash with spaces around it, as `3/11/2026 – 10/11/2026` or `3/11/2026 - 10/11/2026`,
166
+ * or by a space alone; a range typed end first is turned round.
167
+ */
168
+ export function readRange(s, lang) {
169
+ let parts = s.trim().split(/\s*[\u2013\u2014]\s*|\s+-\s+/);
170
+ if (parts.length === 1)
171
+ parts = s.trim().split(/\s+/);
172
+ if (parts.length !== 2)
173
+ return null;
174
+ const [a, b] = parts.map(p => readDate(p, lang));
175
+ if (a == null || b == null)
176
+ return null;
177
+ return a <= b ? `${a} ${b}` : `${b} ${a}`;
178
+ }
179
+ /**
180
+ * A time typed in any language, as `09:30`, or null: `9:30`, `9.30`, `9h30`, `930`, `21`, and with am or pm,
181
+ * `9:30 pm` or `9pm`. Minutes go from 00 to 59 and hours from 0 to 23, or 1 to 12 with am or pm.
182
+ */
183
+ export function readTime(s) {
184
+ const t = /^(\d{1,2})(?:\s*[:.h]\s*(\d{2})|(\d{2}))?\s*h?\s*(?:([ap])\.?\s*m\.?)?$/i.exec(s.trim());
185
+ if (t === null)
186
+ return null;
187
+ let h = Number(t[1]);
188
+ const m = Number(t[2] ?? t[3] ?? 0);
189
+ const half = t[4]?.toLowerCase();
190
+ if (m > 59)
191
+ return null;
192
+ if (half !== undefined) {
193
+ if (h < 1 || h > 12)
194
+ return null;
195
+ h = (h % 12) + (half === 'p' ? 12 : 0);
196
+ }
197
+ else if (h > 23)
198
+ return null;
199
+ return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`;
200
+ }
131
201
  /** The first day of the week in a language, 1 for Monday to 7 for Sunday. */
132
202
  export function weekStart(lang) {
133
203
  try {
@@ -144,8 +214,8 @@ export function weekStart(lang) {
144
214
  }
145
215
  /** The active language: `i18n/language` of the user context, `en` if there is none. */
146
216
  export function activeLanguage(rt) {
147
- const i = ctxFind(rt.user, intern('i18n'));
148
- const obj = i < 0 ? null : rt.user.vals[i];
217
+ const i = ctxFind(rt.lib, intern('i18n'));
218
+ const obj = i < 0 ? null : rt.lib.vals[i];
149
219
  if (obj === null || obj.t !== K.Object)
150
220
  return 'en';
151
221
  const o = obj;
@@ -159,8 +229,8 @@ export function activeLanguage(rt) {
159
229
  }
160
230
  /** A field of the user's `i18n` object, or null. */
161
231
  function i18nField(rt, name) {
162
- const i = ctxFind(rt.user, intern('i18n'));
163
- const obj = i < 0 ? null : rt.user.vals[i];
232
+ const i = ctxFind(rt.lib, intern('i18n'));
233
+ const obj = i < 0 ? null : rt.lib.vals[i];
164
234
  if (obj === null || obj.t !== K.Object)
165
235
  return null;
166
236
  const j = ctxFind(obj.ctx, intern(name));
@@ -24,5 +24,11 @@ export type Block = {
24
24
  };
25
25
  export declare function parseMd(src: string): Block[];
26
26
  export declare function printMd(blocks: Block[]): string;
27
+ /** Markdown with plain text added at its end, in its last paragraph or a new one after a heading or list. */
28
+ export declare function appendText(src: string, text: string): string;
27
29
  /** Only web and mail links open; anything else (javascript:...) is shown as plain text. */
28
30
  export declare function safeHref(href: string): boolean;
31
+ /** What a link face may open: web, mail and phone addresses and addresses with no scheme (a path,
32
+ * a #screen); anything else (javascript:, data:...) is null. Spaces before it and tabs or line
33
+ * breaks inside it are dropped first, as the browser does, so "java\tscript:" is caught too. */
34
+ export declare function linkHref(href: string): string | null;
@@ -145,7 +145,25 @@ export function printMd(blocks) {
145
145
  }
146
146
  }).join('\n\n');
147
147
  }
148
+ /** Markdown with plain text added at its end, in its last paragraph or a new one after a heading or list. */
149
+ export function appendText(src, text) {
150
+ const blocks = parseMd(src);
151
+ const last = blocks[blocks.length - 1];
152
+ if (last?.k === 'p')
153
+ last.kids.push({ k: 'text', text });
154
+ else
155
+ blocks.push({ k: 'p', kids: [{ k: 'text', text }] });
156
+ return printMd(blocks);
157
+ }
148
158
  /** Only web and mail links open; anything else (javascript:...) is shown as plain text. */
149
159
  export function safeHref(href) {
150
160
  return /^(https?:|mailto:)/i.test(href.trim());
151
161
  }
162
+ /** What a link face may open: web, mail and phone addresses and addresses with no scheme (a path,
163
+ * a #screen); anything else (javascript:, data:...) is null. Spaces before it and tabs or line
164
+ * breaks inside it are dropped first, as the browser does, so "java\tscript:" is caught too. */
165
+ export function linkHref(href) {
166
+ const plain = href.replace(/[\t\n\r]/g, '').replace(/^[\x00-\x20]+/, '');
167
+ const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(plain);
168
+ return scheme === null || /^(https?|mailto|tel)$/i.test(scheme[1]) ? href : null;
169
+ }
@@ -4,7 +4,11 @@ export interface Loader {
4
4
  base: string;
5
5
  /** Reads a module's source by its resolved URL. */
6
6
  read: (href: string) => Promise<string>;
7
+ /** Loads a JavaScript module by its resolved URL; the platform's import when not given. */
8
+ importJs?: (href: string) => Promise<Record<string, unknown>>;
7
9
  }
8
10
  export declare function setLoader(rt: Runtime, loader: Loader): void;
9
11
  export declare function defaultLoader(): Loader;
10
12
  export declare function addBuiltIn(href: string, src: string): void;
13
+ /** The source built in under a URL, or undefined. */
14
+ export declare function builtInText(href: string): string | undefined;