trebol 0.1.1 → 0.2.0

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