trebol 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +10040 -7519
  3. package/dist/lib/core/boot.js +10 -7
  4. package/dist/lib/core/eval.js +2 -2
  5. package/dist/lib/core/machine/checks.d.ts +1 -0
  6. package/dist/lib/core/machine/checks.js +250 -0
  7. package/dist/lib/core/machine/events.d.ts +1 -0
  8. package/dist/lib/core/machine/events.js +365 -0
  9. package/dist/lib/core/machine/running.d.ts +1 -0
  10. package/dist/lib/core/machine/running.js +180 -0
  11. package/dist/lib/core/machine/shared.d.ts +1 -0
  12. package/dist/lib/core/machine/shared.js +123 -0
  13. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  14. package/dist/lib/core/machine/snapshot.js +244 -0
  15. package/dist/lib/core/machine/spec.d.ts +1 -0
  16. package/dist/lib/core/machine/spec.js +274 -0
  17. package/dist/lib/core/machine/words.d.ts +1 -0
  18. package/dist/lib/core/machine/words.js +98 -0
  19. package/dist/lib/core/machine.d.ts +1 -0
  20. package/dist/lib/core/machine.js +17 -0
  21. package/dist/lib/core/mezz.js +31 -0
  22. package/dist/lib/core/natives/control.js +1 -1
  23. package/dist/lib/core/natives/data.js +6 -1
  24. package/dist/lib/core/natives/series.js +49 -9
  25. package/dist/lib/core/natives/text.js +0 -1
  26. package/dist/lib/host/browser/calendar.d.ts +34 -0
  27. package/dist/lib/host/browser/calendar.js +268 -0
  28. package/dist/lib/host/browser/count.d.ts +15 -0
  29. package/dist/lib/host/browser/count.js +48 -0
  30. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  31. package/dist/lib/host/browser/dialogs.js +443 -0
  32. package/dist/lib/host/browser/drag.d.ts +70 -0
  33. package/dist/lib/host/browser/drag.js +268 -0
  34. package/dist/lib/host/browser/drawings.d.ts +30 -0
  35. package/dist/lib/host/browser/drawings.js +176 -0
  36. package/dist/lib/host/browser/events.d.ts +16 -0
  37. package/dist/lib/host/browser/events.js +125 -0
  38. package/dist/lib/host/browser/faces.d.ts +35 -0
  39. package/dist/lib/host/browser/faces.js +131 -0
  40. package/dist/lib/host/browser/fields.d.ts +16 -0
  41. package/dist/lib/host/browser/fields.js +322 -0
  42. package/dist/lib/host/browser/keys.d.ts +29 -0
  43. package/dist/lib/host/browser/keys.js +151 -0
  44. package/dist/lib/host/browser/lookup.d.ts +25 -0
  45. package/dist/lib/host/browser/lookup.js +275 -0
  46. package/dist/lib/host/browser/menus.d.ts +20 -0
  47. package/dist/lib/host/browser/menus.js +149 -0
  48. package/dist/lib/host/browser/mount.d.ts +92 -0
  49. package/dist/lib/host/browser/mount.js +448 -0
  50. package/dist/lib/host/browser/orbits.d.ts +90 -0
  51. package/dist/lib/host/browser/orbits.js +379 -0
  52. package/dist/lib/host/browser/page.d.ts +13 -0
  53. package/dist/lib/host/browser/page.js +35 -0
  54. package/dist/lib/host/browser/richtext.d.ts +19 -0
  55. package/dist/lib/host/browser/richtext.js +379 -0
  56. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  57. package/dist/lib/host/browser/row-faces.js +74 -0
  58. package/dist/lib/host/browser/screens.d.ts +37 -0
  59. package/dist/lib/host/browser/screens.js +140 -0
  60. package/dist/lib/host/browser/swipe.d.ts +31 -0
  61. package/dist/lib/host/browser/swipe.js +178 -0
  62. package/dist/lib/host/browser/sync.d.ts +24 -0
  63. package/dist/lib/host/browser/sync.js +450 -0
  64. package/dist/lib/host/browser/tables.d.ts +65 -0
  65. package/dist/lib/host/browser/tables.js +505 -0
  66. package/dist/lib/host/browser/times.d.ts +14 -0
  67. package/dist/lib/host/browser/times.js +114 -0
  68. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  69. package/dist/lib/host/browser/toolbars.js +129 -0
  70. package/dist/lib/host/browser/trees.d.ts +20 -0
  71. package/dist/lib/host/browser/trees.js +235 -0
  72. package/dist/lib/host/browser/uploads.d.ts +29 -0
  73. package/dist/lib/host/browser/uploads.js +370 -0
  74. package/dist/lib/host/browser/widget.d.ts +13 -0
  75. package/dist/lib/host/browser/widget.js +105 -0
  76. package/dist/lib/host/browser.d.ts +25 -0
  77. package/dist/lib/host/browser.js +84 -4812
  78. package/dist/lib/host/devtools/console.d.ts +9 -0
  79. package/dist/lib/host/devtools/console.js +104 -0
  80. package/dist/lib/host/devtools/faces.d.ts +25 -0
  81. package/dist/lib/host/devtools/faces.js +169 -0
  82. package/dist/lib/host/devtools/log.d.ts +3 -0
  83. package/dist/lib/host/devtools/log.js +32 -0
  84. package/dist/lib/host/devtools/machines.d.ts +34 -0
  85. package/dist/lib/host/devtools/machines.js +212 -0
  86. package/dist/lib/host/devtools/read.d.ts +13 -0
  87. package/dist/lib/host/devtools/read.js +52 -0
  88. package/dist/lib/host/devtools/state.d.ts +90 -0
  89. package/dist/lib/host/devtools/state.js +123 -0
  90. package/dist/lib/host/devtools.d.ts +15 -19
  91. package/dist/lib/host/devtools.js +39 -427
  92. package/dist/lib/host/fonts.js +4 -3
  93. package/dist/lib/host/icons.js +4 -0
  94. package/dist/lib/host/index.d.ts +3 -1
  95. package/dist/lib/host/index.js +107 -4
  96. package/dist/lib/host/locale.d.ts +18 -0
  97. package/dist/lib/host/locale.js +75 -5
  98. package/dist/lib/host/markdown.d.ts +4 -0
  99. package/dist/lib/host/markdown.js +8 -0
  100. package/dist/lib/host/modules.js +118 -19
  101. package/dist/lib/host/motion.d.ts +32 -0
  102. package/dist/lib/host/motion.js +190 -0
  103. package/dist/lib/host/net.js +5 -2
  104. package/dist/lib/host/palette.d.ts +17 -0
  105. package/dist/lib/host/palette.js +131 -0
  106. package/dist/lib/host/scheduler.d.ts +2 -0
  107. package/dist/lib/host/scheduler.js +4 -0
  108. package/dist/lib/host/share.d.ts +31 -0
  109. package/dist/lib/host/share.js +134 -0
  110. package/dist/lib/host/theme/classic.d.ts +1 -0
  111. package/dist/lib/host/theme/classic.js +120 -0
  112. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  113. package/dist/lib/host/theme/cupertino.js +65 -0
  114. package/dist/lib/host/theme/data.d.ts +1 -0
  115. package/dist/lib/host/theme/data.js +109 -0
  116. package/dist/lib/host/theme/devtools.d.ts +1 -0
  117. package/dist/lib/host/theme/devtools.js +166 -0
  118. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  119. package/dist/lib/host/theme/dialogs.js +63 -0
  120. package/dist/lib/host/theme/fluent.d.ts +1 -0
  121. package/dist/lib/host/theme/fluent.js +64 -0
  122. package/dist/lib/host/theme/forms.d.ts +1 -0
  123. package/dist/lib/host/theme/forms.js +239 -0
  124. package/dist/lib/host/theme/fusion.d.ts +1 -0
  125. package/dist/lib/host/theme/fusion.js +66 -0
  126. package/dist/lib/host/theme/layout.d.ts +1 -0
  127. package/dist/lib/host/theme/layout.js +166 -0
  128. package/dist/lib/host/theme/media.d.ts +1 -0
  129. package/dist/lib/host/theme/media.js +106 -0
  130. package/dist/lib/host/theme/navigation.d.ts +1 -0
  131. package/dist/lib/host/theme/navigation.js +36 -0
  132. package/dist/lib/host/theme/panes.d.ts +1 -0
  133. package/dist/lib/host/theme/panes.js +99 -0
  134. package/dist/lib/host/theme/popups.d.ts +1 -0
  135. package/dist/lib/host/theme/popups.js +149 -0
  136. package/dist/lib/host/theme/responsive.d.ts +1 -0
  137. package/dist/lib/host/theme/responsive.js +103 -0
  138. package/dist/lib/host/theme/toasts.d.ts +1 -0
  139. package/dist/lib/host/theme/toasts.js +62 -0
  140. package/dist/lib/host/theme.js +19 -1384
  141. package/dist/lib/ui/dialect/events.trb +276 -0
  142. package/dist/lib/ui/dialect/faces.trb +135 -0
  143. package/dist/lib/ui/dialect/layout.trb +283 -0
  144. package/dist/lib/ui/dialect/palette.trb +87 -0
  145. package/dist/lib/ui/dialect/problems.trb +174 -0
  146. package/dist/lib/ui/dialect/reactions.trb +198 -0
  147. package/dist/lib/ui/dialect/rows.trb +208 -0
  148. package/dist/lib/ui/dialect/screens.trb +293 -0
  149. package/dist/lib/ui/dialect/steps.trb +203 -0
  150. package/dist/lib/ui/dialect/validation.trb +137 -0
  151. package/dist/lib/ui/dialect/view.trb +110 -0
  152. package/dist/lib/ui/dialect/walking.trb +98 -0
  153. package/dist/lib/ui/dialect/words.trb +70 -0
  154. package/dist/lib/ui/i18n.trb +17 -0
  155. package/dist/lib/ui/test.trb +3 -556
  156. package/dist/lib/ui/testing/actions.trb +421 -0
  157. package/dist/lib/ui/testing/faces.trb +148 -0
  158. package/dist/lib/ui/testing/server.trb +73 -0
  159. package/dist/lib/ui/ui.trb +25 -1675
  160. package/dist/trebol.js +4463 -1891
  161. package/package.json +1 -1
  162. package/src/core/boot.ts +9 -6
  163. package/src/core/eval.ts +2 -2
  164. package/src/core/machine/checks.ts +251 -0
  165. package/src/core/machine/events.ts +366 -0
  166. package/src/core/machine/running.ts +181 -0
  167. package/src/core/machine/shared.ts +124 -0
  168. package/src/core/machine/snapshot.ts +245 -0
  169. package/src/core/machine/spec.ts +275 -0
  170. package/src/core/machine/words.ts +99 -0
  171. package/src/core/machine.ts +20 -0
  172. package/src/core/mezz.ts +31 -0
  173. package/src/core/natives/control.ts +1 -1
  174. package/src/core/natives/data.ts +6 -1
  175. package/src/core/natives/parse.ts +1 -1
  176. package/src/core/natives/series.ts +47 -11
  177. package/src/core/natives/text.ts +0 -1
  178. package/src/host/browser/calendar.ts +264 -0
  179. package/src/host/browser/count.ts +48 -0
  180. package/src/host/browser/dialogs.ts +439 -0
  181. package/src/host/browser/drag.ts +278 -0
  182. package/src/host/browser/drawings.ts +178 -0
  183. package/src/host/browser/events.ts +117 -0
  184. package/src/host/browser/faces.ts +143 -0
  185. package/src/host/browser/fields.ts +315 -0
  186. package/src/host/browser/keys.ts +145 -0
  187. package/src/host/browser/lookup.ts +262 -0
  188. package/src/host/browser/menus.ts +146 -0
  189. package/src/host/browser/mount.ts +420 -0
  190. package/src/host/browser/orbits.ts +418 -0
  191. package/src/host/browser/page.ts +43 -0
  192. package/src/host/browser/richtext.ts +346 -0
  193. package/src/host/browser/row-faces.ts +75 -0
  194. package/src/host/browser/screens.ts +142 -0
  195. package/src/host/browser/swipe.ts +168 -0
  196. package/src/host/browser/sync.ts +354 -0
  197. package/src/host/browser/tables.ts +461 -0
  198. package/src/host/browser/times.ts +115 -0
  199. package/src/host/browser/toolbars.ts +126 -0
  200. package/src/host/browser/trees.ts +205 -0
  201. package/src/host/browser/uploads.ts +367 -0
  202. package/src/host/browser/widget.ts +103 -0
  203. package/src/host/browser.ts +82 -4612
  204. package/src/host/devtools/console.ts +102 -0
  205. package/src/host/devtools/faces.ts +160 -0
  206. package/src/host/devtools/log.ts +34 -0
  207. package/src/host/devtools/machines.ts +208 -0
  208. package/src/host/devtools/read.ts +58 -0
  209. package/src/host/devtools/state.ts +148 -0
  210. package/src/host/devtools.ts +39 -442
  211. package/src/host/fonts.ts +4 -3
  212. package/src/host/icons.ts +4 -0
  213. package/src/host/index.ts +107 -4
  214. package/src/host/locale.ts +71 -5
  215. package/src/host/markdown.ts +9 -0
  216. package/src/host/modules.ts +117 -21
  217. package/src/host/motion.ts +204 -0
  218. package/src/host/net.ts +4 -2
  219. package/src/host/palette.ts +139 -0
  220. package/src/host/scheduler.ts +5 -0
  221. package/src/host/share.ts +168 -0
  222. package/src/host/theme/classic.ts +121 -0
  223. package/src/host/theme/cupertino.ts +66 -0
  224. package/src/host/theme/data.ts +110 -0
  225. package/src/host/theme/devtools.ts +167 -0
  226. package/src/host/theme/dialogs.ts +64 -0
  227. package/src/host/theme/fluent.ts +65 -0
  228. package/src/host/theme/forms.ts +240 -0
  229. package/src/host/theme/fusion.ts +67 -0
  230. package/src/host/theme/layout.ts +167 -0
  231. package/src/host/theme/media.ts +107 -0
  232. package/src/host/theme/navigation.ts +37 -0
  233. package/src/host/theme/panes.ts +100 -0
  234. package/src/host/theme/popups.ts +150 -0
  235. package/src/host/theme/responsive.ts +104 -0
  236. package/src/host/theme/toasts.ts +63 -0
  237. package/src/host/theme.ts +19 -1384
  238. package/src/ui/dialect/events.trb +276 -0
  239. package/src/ui/dialect/faces.trb +135 -0
  240. package/src/ui/dialect/layout.trb +283 -0
  241. package/src/ui/dialect/palette.trb +87 -0
  242. package/src/ui/dialect/problems.trb +174 -0
  243. package/src/ui/dialect/reactions.trb +198 -0
  244. package/src/ui/dialect/rows.trb +208 -0
  245. package/src/ui/dialect/screens.trb +293 -0
  246. package/src/ui/dialect/steps.trb +203 -0
  247. package/src/ui/dialect/validation.trb +137 -0
  248. package/src/ui/dialect/view.trb +110 -0
  249. package/src/ui/dialect/walking.trb +98 -0
  250. package/src/ui/dialect/words.trb +70 -0
  251. package/src/ui/i18n.trb +17 -0
  252. package/src/ui/test.trb +3 -556
  253. package/src/ui/testing/actions.trb +421 -0
  254. package/src/ui/testing/faces.trb +148 -0
  255. package/src/ui/testing/server.trb +73 -0
  256. package/src/ui/ui.trb +25 -1675
@@ -0,0 +1,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;