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
@@ -3,7 +3,7 @@
3
3
  // Each one is a small state machine over `f.phase`: phase 0 is the first
4
4
  // call with the arguments; later phases receive the value of the block or
5
5
  // expression the native asked the evaluator for.
6
- import { K, kindName } from "../kinds.js";
6
+ import { K } from "../kinds.js";
7
7
  import * as I64 from "../int64.js";
8
8
  import { NONE, UNSET, TRUE, block, context } from "../values.js";
9
9
  import { bindSeries, copyDeep, setWord } from "../ctx.js";
@@ -323,7 +323,7 @@ native('until', '["Evaluates the block until it gives true." body [block!]]', (_
323
323
  f.trap = LOOP_TRAP;
324
324
  return doBlock(f.args[0]);
325
325
  });
326
- native('break', '["Leaves the loop it is in." /return value [any-value!]]', (_t, f) => ({ k: 'throw', e: { kind: T.Break, v: f.args[0].t === K.Logic ? f.args[1] : NONE, name: null } }));
326
+ native('break', '["Leaves the loop it is in." /return value [any-value!]]', (_t, f) => ({ k: 'throw', e: { kind: T.Break, v: f.args[0].t === K.Logic ? f.args[1] : UNSET, name: null } }));
327
327
  native('continue', '["Goes on with the next turn of the loop it is in." ]', () => ({ k: 'throw', e: { kind: T.Continue, v: UNSET, name: null } }));
328
328
  // --- functions -------------------------------------------------------------------
329
329
  native('return', '["Leaves the function it is in, giving a value." value [any-type!]]', (_t, f) => ({ k: 'throw', e: { kind: T.Return, v: f.args[0], name: null } }));
@@ -242,8 +242,13 @@ native('spec-of', '["A copy of a function\'s spec block." value [any-function!]]
242
242
  const spec = c.t === K.Function ? p.specBlock : p.specBlock;
243
243
  return value({ t: K.Block, s: copyDeep(spec.s, spec.i), i: 0 });
244
244
  });
245
- native('body-of', '["A copy of a function\'s body block, or none for a native." value [any-function!]]', (_t, f) => {
245
+ native('body-of', '["A copy of a function\'s body block, or none for a native; for an object, its fields as field: value." value [any-function! any-object!]]', (_t, f) => {
246
246
  const c = underOp(f.args[0]);
247
+ if (c.t === K.Object || c.t === K.Error) {
248
+ const out = [];
249
+ c.ctx.keys.forEach((k, i) => out.push(wordOf(K.SetWord, k), c.ctx.vals[i]));
250
+ return value(blockOf(K.Block, out));
251
+ }
247
252
  return value(c.t === K.Function ? { t: K.Block, s: copyDeep(c.p.body), i: 0 } : NONE);
248
253
  });
249
254
  native('words-of', '["The words of an object or map, or the arguments, refinements and local words of a function." value [any-object! map! any-function!]]', (_t, f) => {
@@ -3,14 +3,16 @@
3
3
  // Blocks hold cells, strings code points and binaries bytes; the helpers in
4
4
  // series.ts hide the difference. Searching is case-insensitive unless /case,
5
5
  // as `=` is.
6
- import { K, isAnyBlock, kindBit } from "../kinds.js";
6
+ import { K, isAnyBlock, isAnyString, kindBit } from "../kinds.js";
7
+ import { bitHas } from "../bitset.js";
7
8
  import * as I64 from "../int64.js";
8
9
  import { ownMeta, NONE, TRUE, integer, char, logic, strictEqual, } from "../values.js";
9
10
  import { bindSeries, copyDeep } from "../ctx.js";
10
11
  import { isEqual, compare, foldCase } from "../compare.js";
11
12
  import { pick } from "../access.js";
12
- import { context, time, sameValue } from "../values.js";
13
+ import { context, time, sameValue, string, bitset } from "../values.js";
13
14
  import { dateDiff } from "./math.js";
15
+ import { sourceOf } from "../mold.js";
14
16
  import { splice, itemsFor, lengthOf, at, clampIndex, } from "../series.js";
15
17
  import { T } from "../eval.js";
16
18
  import { native, value, fail, truthy, doBlock } from "./define.js";
@@ -80,6 +82,11 @@ native('at', '["The series at a position, counted from where it is." series [ser
80
82
  native('index?', '["The position of the series, from 1." series [series!]]', (_t, f) => value(integer(f.args[0].i + 1)));
81
83
  native('head?', '["True if the series is at its head." series [series!]]', (_t, f) => value(logic(f.args[0].i === 0)));
82
84
  native('tail?', '["True if the series is at its tail." series [series!]]', (_t, f) => value(logic(lengthOf(f.args[0]) === 0)));
85
+ native('loaded-at', '["Where the value at the position of a block was loaded from, as file:line:col; none if it was made at run time." block [any-block!]]', (_t, f) => {
86
+ const b = f.args[0];
87
+ const at = sourceOf(b.s, b.i);
88
+ return value(at === null ? NONE : string(at));
89
+ });
83
90
  // --- editing ---------------------------------------------------------------------
84
91
  const PUT_SPEC = 'series [series!] value [any-value!] /part "Put in only part of the value" range [integer! series!] /only "A block goes in as one value" /dup "Put it in several times" count [integer!]';
85
92
  const putArgs = (f) => toPut(f.args[0], f.args[1], used(f.args[4]), used(f.args[2]) ? f.args[3] : null, used(f.args[5]) ? f.args[6] : null);
@@ -138,6 +145,10 @@ native('copy', '["A copy of the series, map, object or bitset." value [series! m
138
145
  const part = { data: b.s.data.slice(from, end) };
139
146
  if (b.s.nl)
140
147
  part.nl = b.s.nl.slice(from, end);
148
+ if (b.s.pos)
149
+ part.pos = b.s.pos.slice(from, end);
150
+ if (b.s.file !== undefined)
151
+ part.file = b.s.file;
141
152
  return value({ t: b.t, s: deep ? copyDeep(part) : part, i: 0 });
142
153
  }
143
154
  return value({ t: s.t, s: { data: s.s.data.slice(from, end) }, i: 0 });
@@ -246,7 +257,7 @@ function findIn(s, v, o) {
246
257
  }
247
258
  return { at: -1, len };
248
259
  }
249
- native('find', '["Finds a value in a series; gives the series where it is, or none." series [series! none! typeset!] value [any-type!] /part "Look only this far" length [integer! series!] /only "A block is one value" /case "Capitals matter" /skip "Look only at every so many" size [integer!] /last "Find the last one" /tail "Give the series just after it" /match "Only where the series is" /reverse "Look back from where the series is" /any "In a string, * is any run of characters and ? any one" /same "In a block, the very same value (same?), not an equal one"]', (_t, f) => {
260
+ native('find', '["Finds a value in a series; gives the series where it is, or none." series [series! none! typeset! bitset!] value [any-type!] /part "Look only this far" length [integer! series!] /only "A block is one value" /case "Capitals matter" /skip "Look only at every so many" size [integer!] /last "Find the last one" /tail "Give the series just after it" /match "Only where the series is" /reverse "Look back from where the series is" /any "In a string, * is any run of characters and ? any one" /same "In a block, the very same value (same?), not an equal one"]', (_t, f) => {
250
261
  const x = f.args[0];
251
262
  if (x.t === K.None)
252
263
  return value(NONE);
@@ -254,6 +265,10 @@ native('find', '["Finds a value in a series; gives the series where it is, or no
254
265
  const v = f.args[1];
255
266
  return value(logic(v.t === K.Datatype && (x.bits & kindBit(v.k)) !== 0n));
256
267
  }
268
+ // In a bitset, whether it holds the character, the code point or every one of a text or block
269
+ // (R3); a letter holds either case unless /case.
270
+ if (x.t === K.Bitset)
271
+ return value(logic(bitsetHolds(x, f.args[1], used(f.args[5]))));
257
272
  const s = x;
258
273
  const a = f.args;
259
274
  const o = {
@@ -465,6 +480,22 @@ native('map-each', "[\"A block of what the block gives for each value of a serie
465
480
  }
466
481
  return eachNext(f, st, data) ?? value({ t: K.Block, s: { data: st.out }, i: 0 });
467
482
  });
483
+ function bitsetHolds(b, v, cased) {
484
+ const upper = (n) => { const u = String.fromCodePoint(n).toUpperCase(); return u.length === 1 || u.codePointAt(0) > 0xffff ? u.codePointAt(0) : n; };
485
+ const one = (n) => bitHas(b, n) || (!cased && (bitHas(b, foldCase(n)) || bitHas(b, upper(n))));
486
+ switch (v.t) {
487
+ case K.Char: return one(v.v);
488
+ case K.Integer: {
489
+ const n = I64.toNumber(v.v);
490
+ return Number.isSafeInteger(n) && n >= 0 && bitHas(b, n);
491
+ }
492
+ case K.Block: return v.s.data.slice(v.i).every(x => bitsetHolds(b, x, cased));
493
+ default:
494
+ if (isAnyString(v.t))
495
+ return v.s.data.slice(v.i).every(one);
496
+ return false;
497
+ }
498
+ }
468
499
  // --- set operations ----------------------------------------------------------------
469
500
  function itemEq(t, cased) {
470
501
  if (isAnyBlock(t))
@@ -483,7 +514,26 @@ function distinct(list, eq) {
483
514
  function setResult(like, list) {
484
515
  return { t: like.t, s: { data: list }, i: 0 };
485
516
  }
486
- function setOp(f, two, pick) {
517
+ // Of two bitsets, the one holding what op says of being in each. A complemented bitset
518
+ // (neg) holds what its bits do not, so each side is flipped before op and the result after.
519
+ function bitsetOp(a, b, op) {
520
+ const neg = op(a.neg ? 1 : 0, b.neg ? 1 : 0) !== 0;
521
+ const n = Math.max(a.s.data.length, b.s.data.length);
522
+ const bytes = [];
523
+ for (let i = 0; i < n; i++) {
524
+ const x = (a.s.data[i] ?? 0) ^ (a.neg ? 0xff : 0);
525
+ const y = (b.s.data[i] ?? 0) ^ (b.neg ? 0xff : 0);
526
+ bytes.push((op(x, y) ^ (neg ? 0xff : 0)) & 0xff);
527
+ }
528
+ return bitset(bytes, neg);
529
+ }
530
+ function setOp(f, two, pick, bits) {
531
+ if (two && (f.args[0].t === K.Bitset || f.args[1].t === K.Bitset)) {
532
+ const [x, y] = f.args;
533
+ if (x.t !== K.Bitset || y.t !== K.Bitset || bits === undefined)
534
+ return fail('script', 'bad-set', 'a bitset goes only with another bitset');
535
+ return value(bitsetOp(x, y, bits));
536
+ }
487
537
  const a = f.args[0];
488
538
  const b = two ? f.args[1] : null;
489
539
  if (b !== null && isAnyBlock(a.t) !== isAnyBlock(b.t))
@@ -494,16 +544,16 @@ function setOp(f, two, pick) {
494
544
  return value(setResult(a, pick(xs, ys, eq)));
495
545
  }
496
546
  native('unique', '["The values of the series, each once." set [series!] /case]', (_t, f) => setOp(f, false, (a, _b, eq) => distinct(a, eq)));
497
- native('union', '["The values that are in either series, each once." a [series!] b [series!] /case]', (_t, f) => setOp(f, true, (a, b, eq) => distinct([...a, ...b], eq)));
498
- native('intersect', '["The values that are in both series." a [series!] b [series!] /case]', (_t, f) => setOp(f, true, (a, b, eq) => distinct(a.filter(x => b.some(y => eq(x, y))), eq)));
547
+ native('union', '["The values that are in either series, each once." a [series! bitset!] b [series! bitset!] /case]', (_t, f) => setOp(f, true, (a, b, eq) => distinct([...a, ...b], eq), (x, y) => x | y));
548
+ native('intersect', '["The values that are in both series." a [series! bitset!] b [series! bitset!] /case]', (_t, f) => setOp(f, true, (a, b, eq) => distinct(a.filter(x => b.some(y => eq(x, y))), eq), (x, y) => x & y));
499
549
  // Of two dates, the time between them (R3).
500
- native('difference', '["The values that are in one series but not the other; of two dates, the time between them." a [series! date!] b [series! date!] /case]', (_t, f) => {
550
+ native('difference', '["The values that are in one series but not the other; of two dates, the time between them." a [series! date! bitset!] b [series! date! bitset!] /case]', (_t, f) => {
501
551
  const [a, b] = f.args;
502
552
  if (a.t === K.Date || b.t === K.Date) {
503
553
  if (a.t !== K.Date || b.t !== K.Date)
504
554
  return fail('script', 'bad-set', 'difference takes two dates or two series');
505
555
  return value(time(dateDiff(a.v, b.v)));
506
556
  }
507
- return setOp(f, true, (xs, ys, eq) => distinct([...xs.filter(x => !ys.some(y => eq(x, y))), ...ys.filter(y => !xs.some(x => eq(x, y)))], eq));
557
+ return setOp(f, true, (xs, ys, eq) => distinct([...xs.filter(x => !ys.some(y => eq(x, y))), ...ys.filter(y => !xs.some(x => eq(x, y)))], eq), (x, y) => x ^ y);
508
558
  });
509
- native('exclude', '["The values of the first series that are not in the second." a [series!] b [series!] /case]', (_t, f) => setOp(f, true, (a, b, eq) => distinct(a.filter(x => !b.some(y => eq(x, y))), eq)));
559
+ native('exclude', '["The values of the first series that are not in the second." a [series! bitset!] b [series! bitset!] /case]', (_t, f) => setOp(f, true, (a, b, eq) => distinct(a.filter(x => !b.some(y => eq(x, y))), eq), (x, y) => x & ~y));
@@ -9,7 +9,6 @@ import { ownMeta, NONE, TRUE, FALSE, integer, decimal, percent, money, char, log
9
9
  import { getWord, setWord } from "../ctx.js";
10
10
  import { foldCase, toDec } from "../compare.js";
11
11
  import { load, LoadError } from "../lexer.js";
12
- import { form } from "../mold.js";
13
12
  import { typesOf } from "../func.js";
14
13
  import { textOf, utf8, at } from "../series.js";
15
14
  import { T } from "../eval.js";
@@ -156,6 +155,9 @@ function toKind(k, v) {
156
155
  return { t: k, s: { data: codePoints(spell(v.sym)) }, i: 0 };
157
156
  if (v.t === K.Char)
158
157
  return { t: k, s: { data: [v.v] }, i: 0 };
158
+ // the text itself, so to string! <a> is "a", as in R3; form gives "<a>"
159
+ if (isAnyString(v.t))
160
+ return { t: k, s: { data: v.s.data.slice(v.i) }, i: 0 };
159
161
  return { t: k, s: { data: codePoints(textOf(v)) }, i: 0 };
160
162
  }
161
163
  case K.Binary:
@@ -0,0 +1,34 @@
1
+ import { type Cell, type ObjectCell } from '../../core/index.ts';
2
+ export interface Calendar {
3
+ face: ObjectCell;
4
+ opener: HTMLButtonElement;
5
+ box: HTMLElement;
6
+ month: HTMLElement;
7
+ at: Date;
8
+ range: HTMLElement | null;
9
+ from: Date | null;
10
+ }
11
+ export declare let calendar: Calendar | null;
12
+ export declare const DAY_MS = 86400000;
13
+ /** A date! cell as a UTC date at midnight, or null. */
14
+ export declare function utcDate(v: Cell): Date | null;
15
+ export declare function isoDay(d: Date): string;
16
+ /** The two days of a date-range's value, or null. */
17
+ export declare function rangeOf(v: Cell): [Date, Date] | null;
18
+ /** A range of dates as it shows on screen: 3 Nov 2026 – 10 Nov 2026. */
19
+ export declare function rangeText(v: Cell): string;
20
+ /** The argument of a rule of a face, as min or max, or none. */
21
+ export declare function ruleArg(face: ObjectCell, rule: string): Cell;
22
+ /** The date argument of a min or max rule of a face, or null. */
23
+ export declare function dateRule(face: ObjectCell, rule: string): Date | null;
24
+ export declare function openCalendar(face: ObjectCell, opener: HTMLButtonElement): void;
25
+ export declare function closeCalendar(refocus?: boolean): void;
26
+ export declare function outsideCalendar(ev: PointerEvent): void;
27
+ /** Draws the month of the focused day; the head stays. */
28
+ export declare function renderCalendar(): void;
29
+ /** With the first day of a range picked, marks the days between it and the one pointed or focused. */
30
+ export declare function spanTo(d: Date): void;
31
+ export declare function addMonths(d: Date, n: number): Date;
32
+ export declare function focusDay(): void;
33
+ export declare function pickDay(d: Date): void;
34
+ export declare function calendarKey(ev: KeyboardEvent): void;
@@ -0,0 +1,268 @@
1
+ // --- calendar ------------------------------------------------------------------------
2
+ //
3
+ // The calendar of a date field: a grid of days, as in the WAI-ARIA date picker
4
+ // pattern. Arrows move by days and weeks, Page Up/Down by months, Home/End to
5
+ // the ends of the week, Enter or Space picks, Esc closes. Days are UTC dates.
6
+ import { K, NONE, string, spell } from "../../core/index.js";
7
+ import { activeLanguage, weekStart } from "../index.js";
8
+ import { get, own, display, word, icon } from "./faces.js";
9
+ import { host, newId, fire, el } from "./mount.js";
10
+ import { seenKeys } from "./events.js";
11
+ export let calendar = null;
12
+ export const DAY_MS = 86400000;
13
+ /** A date! cell as a UTC date at midnight, or null. */
14
+ export function utcDate(v) {
15
+ return v.t === K.Date ? new Date(Date.UTC(v.v.y, v.v.m - 1, v.v.d)) : null;
16
+ }
17
+ export function isoDay(d) {
18
+ return d.toISOString().slice(0, 10);
19
+ }
20
+ /** The two days of a date-range's value, or null. */
21
+ export function rangeOf(v) {
22
+ if (v.t !== K.Block)
23
+ return null;
24
+ const a = utcDate(v.s.data[v.i] ?? NONE), b = utcDate(v.s.data[v.i + 1] ?? NONE);
25
+ return a !== null && b !== null ? [a, b] : null;
26
+ }
27
+ /** A range of dates as it shows on screen: 3 Nov 2026 – 10 Nov 2026. */
28
+ export function rangeText(v) {
29
+ if (v.t !== K.Block)
30
+ return display(v);
31
+ return v.s.data.slice(v.i, v.i + 2).map(display).join(' – ');
32
+ }
33
+ /** The argument of a rule of a face, as min or max, or none. */
34
+ export function ruleArg(face, rule) {
35
+ const rules = get(face, 'rules');
36
+ if (rules.t !== K.Block)
37
+ return NONE;
38
+ for (const r of rules.s.data) {
39
+ if (r.t !== K.Block || r.s.data[0]?.t !== K.Word || spell(r.s.data[0].sym) !== rule)
40
+ continue;
41
+ return r.s.data[1] ?? NONE;
42
+ }
43
+ return NONE;
44
+ }
45
+ /** The date argument of a min or max rule of a face, or null. */
46
+ export function dateRule(face, rule) {
47
+ return utcDate(ruleArg(face, rule));
48
+ }
49
+ export function openCalendar(face, opener) {
50
+ closeCalendar(false);
51
+ const today = new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()));
52
+ const box = el('div', 'tb-calendar');
53
+ box.setAttribute('role', 'dialog');
54
+ box.setAttribute('aria-label', opener.getAttribute('aria-label') ?? own('choose-date'));
55
+ box.setAttribute('popover', 'manual');
56
+ const month = el('h2', 'tb-calendar-month');
57
+ month.id = `tb-${newId()}`;
58
+ month.setAttribute('aria-live', 'polite');
59
+ const step = (name, label, by) => {
60
+ const b = el('button', 'tb-calendar-step');
61
+ b.type = 'button';
62
+ b.setAttribute('aria-label', label);
63
+ const svg = icon(name);
64
+ if (svg !== null)
65
+ b.append(svg);
66
+ b.addEventListener('click', () => {
67
+ if (calendar === null)
68
+ return;
69
+ calendar.at = addMonths(calendar.at, by);
70
+ renderCalendar();
71
+ });
72
+ return b;
73
+ };
74
+ const head = el('div', 'tb-calendar-head');
75
+ head.append(step('chevron-left', own('previous-month'), -1), month, step('chevron-right', own('next-month'), 1));
76
+ box.append(head);
77
+ const isRange = word(face, 'style') === 'date-range';
78
+ const value = get(face, 'value');
79
+ let range = null;
80
+ if (isRange) {
81
+ range = el('p', 'tb-calendar-hint');
82
+ range.setAttribute('aria-live', 'polite');
83
+ range.textContent = own('pick-start');
84
+ box.append(range);
85
+ }
86
+ calendar = { face, opener, box, month, at: (isRange ? rangeOf(value)?.[0] : utcDate(value)) ?? today, range, from: null };
87
+ opener.setAttribute('aria-expanded', 'true');
88
+ box.addEventListener('keydown', calendarKey);
89
+ box.addEventListener('focusout', ev => {
90
+ if (calendar?.box === box && !box.contains(ev.relatedTarget) && ev.relatedTarget !== null)
91
+ closeCalendar(false);
92
+ });
93
+ document.addEventListener('pointerdown', outsideCalendar, true);
94
+ document.body.append(box);
95
+ box.showPopover?.();
96
+ renderCalendar();
97
+ const r = opener.closest('.tb-date').getBoundingClientRect();
98
+ const c = box.getBoundingClientRect();
99
+ box.style.left = `${Math.max(8, Math.min(r.right - c.width, innerWidth - c.width - 8))}px`;
100
+ box.style.top = `${r.bottom + 4 + c.height > innerHeight - 8 ? Math.max(8, r.top - 4 - c.height) : r.bottom + 4}px`;
101
+ focusDay();
102
+ }
103
+ export function closeCalendar(refocus = true) {
104
+ if (calendar === null)
105
+ return;
106
+ const { box, opener } = calendar;
107
+ calendar = null;
108
+ box.hidePopover?.();
109
+ box.remove();
110
+ opener.setAttribute('aria-expanded', 'false');
111
+ document.removeEventListener('pointerdown', outsideCalendar, true);
112
+ if (refocus)
113
+ opener.focus();
114
+ }
115
+ export function outsideCalendar(ev) {
116
+ if (calendar !== null && !calendar.box.contains(ev.target) && !calendar.opener.contains(ev.target))
117
+ closeCalendar(false);
118
+ }
119
+ /** Draws the month of the focused day; the head stays. */
120
+ export function renderCalendar() {
121
+ const cal = calendar;
122
+ const lang = activeLanguage(host.rt);
123
+ const at = cal.at;
124
+ const min = dateRule(cal.face, 'min');
125
+ const max = dateRule(cal.face, 'max');
126
+ const value = get(cal.face, 'value');
127
+ // a range shows the days it holds; once its first day is picked, only that one until the last
128
+ const [low, high] = cal.range === null ? [utcDate(value), utcDate(value)]
129
+ : cal.from !== null ? [cal.from, cal.from] : rangeOf(value) ?? [null, null];
130
+ const now = new Date();
131
+ const today = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate());
132
+ const fmt = (opts) => new Intl.DateTimeFormat(lang, { timeZone: 'UTC', ...opts });
133
+ cal.month.textContent = fmt({ month: 'long', year: 'numeric' }).format(at);
134
+ const grid = el('table', 'tb-calendar-grid');
135
+ grid.setAttribute('role', 'grid');
136
+ grid.setAttribute('aria-labelledby', cal.month.id);
137
+ const first = weekStart(lang) % 7;
138
+ const names = el('tr');
139
+ for (let i = 0; i < 7; i++) {
140
+ // 4-Jan-1970 was a Sunday
141
+ const day = new Date(Date.UTC(1970, 0, 4 + ((first + i) % 7)));
142
+ const th = el('th');
143
+ th.scope = 'col';
144
+ th.abbr = fmt({ weekday: 'long' }).format(day);
145
+ th.textContent = fmt({ weekday: 'narrow' }).format(day);
146
+ names.append(th);
147
+ }
148
+ const thead = el('thead');
149
+ thead.append(names);
150
+ const body = el('tbody');
151
+ const start = Date.UTC(at.getUTCFullYear(), at.getUTCMonth(), 1);
152
+ let ms = start - ((new Date(start).getUTCDay() - first + 7) % 7) * DAY_MS;
153
+ const label = fmt({ dateStyle: 'full' });
154
+ do {
155
+ const row = el('tr');
156
+ for (let i = 0; i < 7; i++, ms += DAY_MS) {
157
+ const d = new Date(ms);
158
+ const td = el('td', 'tb-calendar-day');
159
+ td.setAttribute('role', 'gridcell');
160
+ td.textContent = String(d.getUTCDate());
161
+ td.setAttribute('aria-label', label.format(d));
162
+ td.dataset.day = isoDay(d);
163
+ td.tabIndex = ms === at.getTime() ? 0 : -1;
164
+ if (d.getUTCMonth() !== at.getUTCMonth())
165
+ td.classList.add('tb-calendar-other');
166
+ if (ms === today)
167
+ td.setAttribute('aria-current', 'date');
168
+ const ends = low !== null && high !== null && (ms === low.getTime() || ms === high.getTime());
169
+ td.setAttribute('aria-selected', ends ? 'true' : 'false');
170
+ if (cal.range !== null && low !== null && high !== null && ms > low.getTime() && ms < high.getTime())
171
+ td.classList.add('tb-calendar-in');
172
+ if (cal.range !== null)
173
+ td.addEventListener('pointerenter', () => spanTo(d));
174
+ if ((min !== null && d < min) || (max !== null && d > max))
175
+ td.setAttribute('aria-disabled', 'true');
176
+ td.addEventListener('click', () => pickDay(d));
177
+ row.append(td);
178
+ }
179
+ body.append(row);
180
+ } while (new Date(ms).getUTCMonth() === at.getUTCMonth());
181
+ grid.append(thead, body);
182
+ cal.box.querySelector('table')?.remove();
183
+ if (cal.range !== null)
184
+ cal.box.insertBefore(grid, cal.range);
185
+ else
186
+ cal.box.append(grid);
187
+ }
188
+ /** With the first day of a range picked, marks the days between it and the one pointed or focused. */
189
+ export function spanTo(d) {
190
+ const from = calendar?.from;
191
+ if (from == null)
192
+ return;
193
+ const [a, b] = from <= d ? [isoDay(from), isoDay(d)] : [isoDay(d), isoDay(from)];
194
+ calendar.box.querySelectorAll('td[data-day]').forEach(td => {
195
+ const day = td.dataset.day;
196
+ td.classList.toggle('tb-calendar-in', day > a && day < b);
197
+ });
198
+ }
199
+ export function addMonths(d, n) {
200
+ const y = d.getUTCFullYear(), m = d.getUTCMonth() + n;
201
+ // the same day, or the last one of a shorter month
202
+ const last = new Date(Date.UTC(y, m + 1, 0)).getUTCDate();
203
+ return new Date(Date.UTC(y, m, Math.min(d.getUTCDate(), last)));
204
+ }
205
+ export function focusDay() {
206
+ calendar?.box.querySelector('td[tabindex="0"]')?.focus();
207
+ }
208
+ export function pickDay(d) {
209
+ const cal = calendar;
210
+ if (cal === null)
211
+ return;
212
+ if (cal.box.querySelector(`td[data-day="${isoDay(d)}"]`)?.getAttribute('aria-disabled') === 'true')
213
+ return;
214
+ const face = cal.face;
215
+ if (cal.range !== null && cal.from === null) {
216
+ cal.from = d;
217
+ cal.range.textContent = own('pick-end');
218
+ renderCalendar();
219
+ focusDay();
220
+ return;
221
+ }
222
+ const picked = cal.from === null ? isoDay(d) : cal.from <= d ? `${isoDay(cal.from)} ${isoDay(d)}` : `${isoDay(d)} ${isoDay(cal.from)}`;
223
+ closeCalendar();
224
+ void fire('ui-input', face, string(picked)).then(() => fire('ui-blur', face));
225
+ }
226
+ export function calendarKey(ev) {
227
+ const cal = calendar;
228
+ if (cal === null)
229
+ return;
230
+ seenKeys.add(ev);
231
+ if (ev.key === 'Escape') {
232
+ ev.preventDefault();
233
+ ev.stopPropagation();
234
+ closeCalendar();
235
+ return;
236
+ }
237
+ if (!(ev.target instanceof HTMLTableCellElement))
238
+ return;
239
+ const at = cal.at;
240
+ const first = weekStart(activeLanguage(host.rt)) % 7;
241
+ const back = (at.getUTCDay() - first + 7) % 7;
242
+ const days = { ArrowLeft: -1, ArrowRight: 1, ArrowUp: -7, ArrowDown: 7, Home: -back, End: 6 - back };
243
+ let to = null;
244
+ if (ev.key in days)
245
+ to = new Date(at.getTime() + days[ev.key] * DAY_MS);
246
+ else if (ev.key === 'PageUp' || ev.key === 'PageDown')
247
+ to = addMonths(at, (ev.key === 'PageUp' ? -1 : 1) * (ev.shiftKey ? 12 : 1));
248
+ else if (ev.key === 'Enter' || ev.key === ' ') {
249
+ ev.preventDefault();
250
+ pickDay(at);
251
+ return;
252
+ }
253
+ if (to === null)
254
+ return;
255
+ ev.preventDefault();
256
+ cal.at = to;
257
+ if (to.getUTCMonth() === at.getUTCMonth()) {
258
+ cal.box.querySelectorAll('td[tabindex="0"]').forEach(td => { td.tabIndex = -1; });
259
+ const td = cal.box.querySelector(`td[data-day="${isoDay(to)}"]`);
260
+ td.tabIndex = 0;
261
+ td.focus();
262
+ }
263
+ else {
264
+ renderCalendar();
265
+ focusDay();
266
+ }
267
+ spanTo(to);
268
+ }
@@ -0,0 +1,15 @@
1
+ import { type Cell } from '../../core/index.ts';
2
+ import { type Mounted } from './mount.ts';
3
+ /** A text with `count`: the number it last showed, and the run on its way to a new one. */
4
+ export declare const counts: WeakMap<Mounted, {
5
+ was: Cell;
6
+ now: number;
7
+ frame: number;
8
+ }>;
9
+ export declare const COUNT_MS = 600;
10
+ /**
11
+ * A text with `count` whose number changed runs from the old one to the new in the kind and digits of the new,
12
+ * easing out, formatted for the active language at each frame; true while it runs, so sync leaves the text alone.
13
+ * The first number it shows, a change of kind or currency, or a page that may not move, shows the new one at once.
14
+ */
15
+ export declare function countRun(m: Mounted, to: Cell): boolean;
@@ -0,0 +1,48 @@
1
+ // --- numbers that count ------------------------------------------------------------
2
+ import { K } from "../../core/index.js";
3
+ import { amountOf, countStep } from "../index.js";
4
+ import { mayMove } from "../motion.js";
5
+ import { display } from "./faces.js";
6
+ import {} from "./mount.js";
7
+ /** A text with `count`: the number it last showed, and the run on its way to a new one. */
8
+ export const counts = new WeakMap();
9
+ export const COUNT_MS = 600;
10
+ /**
11
+ * A text with `count` whose number changed runs from the old one to the new in the kind and digits of the new,
12
+ * easing out, formatted for the active language at each frame; true while it runs, so sync leaves the text alone.
13
+ * The first number it shows, a change of kind or currency, or a page that may not move, shows the new one at once.
14
+ */
15
+ export function countRun(m, to) {
16
+ const end = amountOf(to);
17
+ const c = counts.get(m);
18
+ if (end === null) {
19
+ if (c !== undefined)
20
+ cancelAnimationFrame(c.frame);
21
+ counts.delete(m);
22
+ return false;
23
+ }
24
+ if (c === undefined) {
25
+ counts.set(m, { was: to, now: end, frame: 0 });
26
+ return false;
27
+ }
28
+ const running = c.frame !== 0;
29
+ const same = c.was.t === to.t && (to.t !== K.Money || c.was.cur === to.cur);
30
+ if (same && amountOf(c.was) === end)
31
+ return running;
32
+ const from = running ? c.now : amountOf(c.was);
33
+ cancelAnimationFrame(c.frame);
34
+ c.was = to;
35
+ c.frame = 0;
36
+ c.now = end;
37
+ if (!same || from === end || !mayMove())
38
+ return false;
39
+ const start = performance.now();
40
+ const step = (t) => {
41
+ const p = Math.min(1, (t - start) / COUNT_MS);
42
+ c.now = from + (end - from) * (1 - (1 - p) ** 3);
43
+ m.el.textContent = display(p === 1 ? to : countStep(to, c.now));
44
+ c.frame = p === 1 ? 0 : requestAnimationFrame(step);
45
+ };
46
+ c.frame = requestAnimationFrame(step);
47
+ return true;
48
+ }
@@ -0,0 +1,39 @@
1
+ import { type ObjectCell } from '../../core/index.ts';
2
+ import { type Mounted } from './mount.ts';
3
+ export declare function buildDialog(face: ObjectCell, m: Mounted): HTMLElement;
4
+ export declare function syncDialog(m: Mounted): void;
5
+ export declare function buildTabs(face: ObjectCell, m: Mounted): HTMLElement;
6
+ export declare function syncTabs(m: Mounted): void;
7
+ export interface StepsState {
8
+ steps: {
9
+ face: ObjectCell;
10
+ li: HTMLLIElement;
11
+ button: HTMLButtonElement;
12
+ num: HTMLElement;
13
+ title: HTMLElement;
14
+ }[];
15
+ count: HTMLElement;
16
+ /** The history entries of this face: the depth of each and the step it shows. */
17
+ trail: {
18
+ depth: number;
19
+ step: number;
20
+ }[];
21
+ shown: number;
22
+ }
23
+ export declare const stepsState: WeakMap<Mounted, StepsState>;
24
+ export declare const mountedSteps: Set<Mounted>;
25
+ export declare function buildSteps(face: ObjectCell, m: Mounted): HTMLElement;
26
+ export declare function syncSteps(m: Mounted): void;
27
+ /** A new step on show: forward is a new history entry; back returns to the entry that showed it. */
28
+ export declare function stepHistory(st: StepsState, to: number, from: number): void;
29
+ /** Back or Forward landed on an entry a form in steps made: it shows that step again. */
30
+ export declare function stepsLanded(): void;
31
+ export declare function buildSplit(face: ObjectCell, m: Mounted): HTMLElement;
32
+ export declare function syncSplit(m: Mounted): void;
33
+ export declare let toasts: HTMLElement | null;
34
+ /** The notices with an Undo button on show, by the id ui.trb gave them. */
35
+ export declare const undoToasts: Map<number, HTMLElement>;
36
+ /** A box where Ctrl+Z undoes typing: a text input, a text area or rich text. */
37
+ export declare function inTextBox(target: EventTarget | null): boolean;
38
+ /** Runs a function of ui.trb for the page, not for one face: the view on show is its face. */
39
+ export declare function fireRoot(fn: string, id: number): void;