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.
- package/README.md +12 -1
- package/dist/cli.js +17097 -12238
- package/dist/fonts/OFL.txt +93 -0
- package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/fonts/inter-greek.woff2 +0 -0
- package/dist/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/fonts/inter-latin.woff2 +0 -0
- package/dist/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/lib/core/boot.js +12 -8
- package/dist/lib/core/eval.js +2 -2
- package/dist/lib/core/func.d.ts +4 -0
- package/dist/lib/core/machine/checks.d.ts +1 -0
- package/dist/lib/core/machine/checks.js +250 -0
- package/dist/lib/core/machine/events.d.ts +1 -0
- package/dist/lib/core/machine/events.js +365 -0
- package/dist/lib/core/machine/running.d.ts +1 -0
- package/dist/lib/core/machine/running.js +180 -0
- package/dist/lib/core/machine/shared.d.ts +1 -0
- package/dist/lib/core/machine/shared.js +123 -0
- package/dist/lib/core/machine/snapshot.d.ts +1 -0
- package/dist/lib/core/machine/snapshot.js +244 -0
- package/dist/lib/core/machine/spec.d.ts +1 -0
- package/dist/lib/core/machine/spec.js +274 -0
- package/dist/lib/core/machine/words.d.ts +1 -0
- package/dist/lib/core/machine/words.js +98 -0
- package/dist/lib/core/machine.d.ts +1 -0
- package/dist/lib/core/machine.js +17 -0
- package/dist/lib/core/mezz.js +31 -0
- package/dist/lib/core/natives/control.js +2 -2
- package/dist/lib/core/natives/data.js +6 -1
- package/dist/lib/core/natives/series.js +59 -9
- package/dist/lib/core/natives/text.js +3 -1
- package/dist/lib/host/browser/calendar.d.ts +34 -0
- package/dist/lib/host/browser/calendar.js +268 -0
- package/dist/lib/host/browser/count.d.ts +15 -0
- package/dist/lib/host/browser/count.js +48 -0
- package/dist/lib/host/browser/dialogs.d.ts +39 -0
- package/dist/lib/host/browser/dialogs.js +443 -0
- package/dist/lib/host/browser/drag.d.ts +70 -0
- package/dist/lib/host/browser/drag.js +268 -0
- package/dist/lib/host/browser/drawings.d.ts +30 -0
- package/dist/lib/host/browser/drawings.js +176 -0
- package/dist/lib/host/browser/events.d.ts +16 -0
- package/dist/lib/host/browser/events.js +125 -0
- package/dist/lib/host/browser/faces.d.ts +35 -0
- package/dist/lib/host/browser/faces.js +131 -0
- package/dist/lib/host/browser/fields.d.ts +16 -0
- package/dist/lib/host/browser/fields.js +322 -0
- package/dist/lib/host/browser/keys.d.ts +29 -0
- package/dist/lib/host/browser/keys.js +151 -0
- package/dist/lib/host/browser/lookup.d.ts +25 -0
- package/dist/lib/host/browser/lookup.js +275 -0
- package/dist/lib/host/browser/menus.d.ts +20 -0
- package/dist/lib/host/browser/menus.js +149 -0
- package/dist/lib/host/browser/mount.d.ts +92 -0
- package/dist/lib/host/browser/mount.js +448 -0
- package/dist/lib/host/browser/orbits.d.ts +90 -0
- package/dist/lib/host/browser/orbits.js +379 -0
- package/dist/lib/host/browser/page.d.ts +13 -0
- package/dist/lib/host/browser/page.js +35 -0
- package/dist/lib/host/browser/richtext.d.ts +19 -0
- package/dist/lib/host/browser/richtext.js +379 -0
- package/dist/lib/host/browser/row-faces.d.ts +5 -0
- package/dist/lib/host/browser/row-faces.js +74 -0
- package/dist/lib/host/browser/screens.d.ts +37 -0
- package/dist/lib/host/browser/screens.js +140 -0
- package/dist/lib/host/browser/swipe.d.ts +31 -0
- package/dist/lib/host/browser/swipe.js +178 -0
- package/dist/lib/host/browser/sync.d.ts +24 -0
- package/dist/lib/host/browser/sync.js +450 -0
- package/dist/lib/host/browser/tables.d.ts +65 -0
- package/dist/lib/host/browser/tables.js +505 -0
- package/dist/lib/host/browser/times.d.ts +14 -0
- package/dist/lib/host/browser/times.js +114 -0
- package/dist/lib/host/browser/toolbars.d.ts +17 -0
- package/dist/lib/host/browser/toolbars.js +129 -0
- package/dist/lib/host/browser/trees.d.ts +20 -0
- package/dist/lib/host/browser/trees.js +235 -0
- package/dist/lib/host/browser/uploads.d.ts +29 -0
- package/dist/lib/host/browser/uploads.js +370 -0
- package/dist/lib/host/browser/widget.d.ts +13 -0
- package/dist/lib/host/browser/widget.js +105 -0
- package/dist/lib/host/browser.d.ts +25 -0
- package/dist/lib/host/browser.js +129 -3964
- package/dist/lib/host/devlog.d.ts +11 -0
- package/dist/lib/host/devlog.js +13 -0
- package/dist/lib/host/devtools/console.d.ts +9 -0
- package/dist/lib/host/devtools/console.js +104 -0
- package/dist/lib/host/devtools/faces.d.ts +25 -0
- package/dist/lib/host/devtools/faces.js +169 -0
- package/dist/lib/host/devtools/log.d.ts +3 -0
- package/dist/lib/host/devtools/log.js +32 -0
- package/dist/lib/host/devtools/machines.d.ts +34 -0
- package/dist/lib/host/devtools/machines.js +212 -0
- package/dist/lib/host/devtools/read.d.ts +13 -0
- package/dist/lib/host/devtools/read.js +52 -0
- package/dist/lib/host/devtools/state.d.ts +90 -0
- package/dist/lib/host/devtools/state.js +123 -0
- package/dist/lib/host/devtools.d.ts +19 -0
- package/dist/lib/host/devtools.js +238 -0
- package/dist/lib/host/fonts/OFL.txt +93 -0
- package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
- package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
- package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/lib/host/fonts.d.ts +11 -0
- package/dist/lib/host/fonts.js +30 -0
- package/dist/lib/host/icons.js +4 -0
- package/dist/lib/host/index.d.ts +5 -1
- package/dist/lib/host/index.js +110 -5
- package/dist/lib/host/js.d.ts +5 -0
- package/dist/lib/host/js.js +130 -0
- package/dist/lib/host/locale.d.ts +18 -0
- package/dist/lib/host/locale.js +75 -5
- package/dist/lib/host/markdown.d.ts +6 -0
- package/dist/lib/host/markdown.js +18 -0
- package/dist/lib/host/modules.d.ts +4 -0
- package/dist/lib/host/modules.js +157 -20
- package/dist/lib/host/motion.d.ts +32 -0
- package/dist/lib/host/motion.js +190 -0
- package/dist/lib/host/net.js +14 -3
- package/dist/lib/host/orbit.d.ts +121 -0
- package/dist/lib/host/orbit.js +374 -0
- package/dist/lib/host/palette.d.ts +17 -0
- package/dist/lib/host/palette.js +131 -0
- package/dist/lib/host/rows.d.ts +14 -0
- package/dist/lib/host/rows.js +29 -0
- package/dist/lib/host/scheduler.d.ts +8 -0
- package/dist/lib/host/scheduler.js +64 -36
- package/dist/lib/host/share.d.ts +31 -0
- package/dist/lib/host/share.js +134 -0
- package/dist/lib/host/theme/classic.d.ts +1 -0
- package/dist/lib/host/theme/classic.js +120 -0
- package/dist/lib/host/theme/cupertino.d.ts +1 -0
- package/dist/lib/host/theme/cupertino.js +65 -0
- package/dist/lib/host/theme/data.d.ts +1 -0
- package/dist/lib/host/theme/data.js +109 -0
- package/dist/lib/host/theme/devtools.d.ts +1 -0
- package/dist/lib/host/theme/devtools.js +166 -0
- package/dist/lib/host/theme/dialogs.d.ts +1 -0
- package/dist/lib/host/theme/dialogs.js +63 -0
- package/dist/lib/host/theme/fluent.d.ts +1 -0
- package/dist/lib/host/theme/fluent.js +64 -0
- package/dist/lib/host/theme/forms.d.ts +1 -0
- package/dist/lib/host/theme/forms.js +239 -0
- package/dist/lib/host/theme/fusion.d.ts +1 -0
- package/dist/lib/host/theme/fusion.js +66 -0
- package/dist/lib/host/theme/layout.d.ts +1 -0
- package/dist/lib/host/theme/layout.js +166 -0
- package/dist/lib/host/theme/media.d.ts +1 -0
- package/dist/lib/host/theme/media.js +106 -0
- package/dist/lib/host/theme/navigation.d.ts +1 -0
- package/dist/lib/host/theme/navigation.js +36 -0
- package/dist/lib/host/theme/panes.d.ts +1 -0
- package/dist/lib/host/theme/panes.js +99 -0
- package/dist/lib/host/theme/popups.d.ts +1 -0
- package/dist/lib/host/theme/popups.js +149 -0
- package/dist/lib/host/theme/responsive.d.ts +1 -0
- package/dist/lib/host/theme/responsive.js +103 -0
- package/dist/lib/host/theme/toasts.d.ts +1 -0
- package/dist/lib/host/theme/toasts.js +62 -0
- package/dist/lib/host/theme.js +19 -1179
- package/dist/lib/ui/dialect/events.trb +276 -0
- package/dist/lib/ui/dialect/faces.trb +135 -0
- package/dist/lib/ui/dialect/layout.trb +283 -0
- package/dist/lib/ui/dialect/palette.trb +87 -0
- package/dist/lib/ui/dialect/problems.trb +174 -0
- package/dist/lib/ui/dialect/reactions.trb +198 -0
- package/dist/lib/ui/dialect/rows.trb +208 -0
- package/dist/lib/ui/dialect/screens.trb +293 -0
- package/dist/lib/ui/dialect/steps.trb +203 -0
- package/dist/lib/ui/dialect/validation.trb +137 -0
- package/dist/lib/ui/dialect/view.trb +110 -0
- package/dist/lib/ui/dialect/walking.trb +98 -0
- package/dist/lib/ui/dialect/words.trb +70 -0
- package/dist/lib/ui/i18n.trb +23 -0
- package/dist/lib/ui/test.trb +12 -0
- package/dist/lib/ui/testing/actions.trb +421 -0
- package/dist/lib/ui/testing/faces.trb +148 -0
- package/dist/lib/ui/testing/server.trb +73 -0
- package/dist/lib/ui/ui.trb +25 -1234
- package/dist/trebol.js +4882 -1088
- package/editors/vscode/README.md +15 -0
- package/editors/vscode/language-configuration.json +28 -0
- package/editors/vscode/package.json +42 -0
- package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
- package/package.json +7 -3
- package/src/core/boot.ts +10 -7
- package/src/core/eval.ts +2 -2
- package/src/core/func.ts +4 -0
- package/src/core/machine/checks.ts +251 -0
- package/src/core/machine/events.ts +366 -0
- package/src/core/machine/running.ts +181 -0
- package/src/core/machine/shared.ts +124 -0
- package/src/core/machine/snapshot.ts +245 -0
- package/src/core/machine/spec.ts +275 -0
- package/src/core/machine/words.ts +99 -0
- package/src/core/machine.ts +20 -0
- package/src/core/mezz.ts +31 -0
- package/src/core/natives/control.ts +2 -2
- package/src/core/natives/data.ts +6 -1
- package/src/core/natives/parse.ts +1 -1
- package/src/core/natives/series.ts +55 -11
- package/src/core/natives/text.ts +2 -1
- package/src/host/browser/calendar.ts +264 -0
- package/src/host/browser/count.ts +48 -0
- package/src/host/browser/dialogs.ts +439 -0
- package/src/host/browser/drag.ts +278 -0
- package/src/host/browser/drawings.ts +178 -0
- package/src/host/browser/events.ts +117 -0
- package/src/host/browser/faces.ts +143 -0
- package/src/host/browser/fields.ts +315 -0
- package/src/host/browser/keys.ts +145 -0
- package/src/host/browser/lookup.ts +262 -0
- package/src/host/browser/menus.ts +146 -0
- package/src/host/browser/mount.ts +420 -0
- package/src/host/browser/orbits.ts +418 -0
- package/src/host/browser/page.ts +43 -0
- package/src/host/browser/richtext.ts +346 -0
- package/src/host/browser/row-faces.ts +75 -0
- package/src/host/browser/screens.ts +142 -0
- package/src/host/browser/swipe.ts +168 -0
- package/src/host/browser/sync.ts +354 -0
- package/src/host/browser/tables.ts +461 -0
- package/src/host/browser/times.ts +115 -0
- package/src/host/browser/toolbars.ts +126 -0
- package/src/host/browser/trees.ts +205 -0
- package/src/host/browser/uploads.ts +367 -0
- package/src/host/browser/widget.ts +103 -0
- package/src/host/browser.ts +128 -3747
- package/src/host/devlog.ts +16 -0
- package/src/host/devtools/console.ts +102 -0
- package/src/host/devtools/faces.ts +160 -0
- package/src/host/devtools/log.ts +34 -0
- package/src/host/devtools/machines.ts +208 -0
- package/src/host/devtools/read.ts +58 -0
- package/src/host/devtools/state.ts +148 -0
- package/src/host/devtools.ts +238 -0
- package/src/host/fonts/OFL.txt +93 -0
- package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/src/host/fonts/inter-cyrillic.woff2 +0 -0
- package/src/host/fonts/inter-greek-ext.woff2 +0 -0
- package/src/host/fonts/inter-greek.woff2 +0 -0
- package/src/host/fonts/inter-latin-ext.woff2 +0 -0
- package/src/host/fonts/inter-latin.woff2 +0 -0
- package/src/host/fonts/inter-vietnamese.woff2 +0 -0
- package/src/host/fonts.ts +40 -0
- package/src/host/icons.ts +4 -0
- package/src/host/index.ts +110 -5
- package/src/host/js.ts +127 -0
- package/src/host/locale.ts +71 -5
- package/src/host/markdown.ts +18 -0
- package/src/host/modules.ts +150 -22
- package/src/host/motion.ts +204 -0
- package/src/host/net.ts +13 -3
- package/src/host/orbit.ts +432 -0
- package/src/host/palette.ts +139 -0
- package/src/host/rows.ts +30 -0
- package/src/host/scheduler.ts +67 -36
- package/src/host/share.ts +168 -0
- package/src/host/theme/classic.ts +121 -0
- package/src/host/theme/cupertino.ts +66 -0
- package/src/host/theme/data.ts +110 -0
- package/src/host/theme/devtools.ts +167 -0
- package/src/host/theme/dialogs.ts +64 -0
- package/src/host/theme/fluent.ts +65 -0
- package/src/host/theme/forms.ts +240 -0
- package/src/host/theme/fusion.ts +67 -0
- package/src/host/theme/layout.ts +167 -0
- package/src/host/theme/media.ts +107 -0
- package/src/host/theme/navigation.ts +37 -0
- package/src/host/theme/panes.ts +100 -0
- package/src/host/theme/popups.ts +150 -0
- package/src/host/theme/responsive.ts +104 -0
- package/src/host/theme/toasts.ts +63 -0
- package/src/host/theme.ts +19 -1179
- package/src/ui/dialect/events.trb +276 -0
- package/src/ui/dialect/faces.trb +135 -0
- package/src/ui/dialect/layout.trb +283 -0
- package/src/ui/dialect/palette.trb +87 -0
- package/src/ui/dialect/problems.trb +174 -0
- package/src/ui/dialect/reactions.trb +198 -0
- package/src/ui/dialect/rows.trb +208 -0
- package/src/ui/dialect/screens.trb +293 -0
- package/src/ui/dialect/steps.trb +203 -0
- package/src/ui/dialect/validation.trb +137 -0
- package/src/ui/dialect/view.trb +110 -0
- package/src/ui/dialect/walking.trb +98 -0
- package/src/ui/dialect/words.trb +70 -0
- package/src/ui/i18n.trb +23 -0
- package/src/ui/test.trb +12 -0
- package/src/ui/testing/actions.trb +421 -0
- package/src/ui/testing/faces.trb +148 -0
- package/src/ui/testing/server.trb +73 -0
- package/src/ui/ui.trb +25 -1234
package/dist/lib/host/modules.js
CHANGED
|
@@ -9,11 +9,29 @@
|
|
|
9
9
|
// Trebol [exports: [load-clients]]
|
|
10
10
|
// export save-client: func [...] [...]
|
|
11
11
|
//
|
|
12
|
+
// A `.js` file is a JavaScript module instead (js.ts).
|
|
13
|
+
//
|
|
14
|
+
// `import 'trebol-es` imports a package by its name: the first node_modules/trebol-es/
|
|
15
|
+
// found going up from the importing file (from the page or the working directory when
|
|
16
|
+
// no file imports it), as Node finds packages. Its package.json says which file is the
|
|
17
|
+
// module, `"trebol": "es.trb"`. The same loader reads it, so this works on a disk and
|
|
18
|
+
// over http alike; `trebol build` puts the package's files inside the page where the
|
|
19
|
+
// page finds them, under node_modules/.
|
|
20
|
+
//
|
|
12
21
|
// `do %file` runs a script in the user context each time; `read` gives a
|
|
13
22
|
// file's text and `load %file` its values.
|
|
14
23
|
//
|
|
15
24
|
// Local storage keeps values molded with mold/all, so they load back exact.
|
|
16
|
-
|
|
25
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
26
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
27
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
28
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return path;
|
|
32
|
+
};
|
|
33
|
+
import { K, NONE, UNSET, native, value, text, load, mold, string, context, collectSetWords, bindSeries, bindSelf, copyDeep, setWord, getWord, splice, currentFile, throwError, makeError, scriptStart, LoadError, T, canon, intern, spell, LIBRARY_FILES, blockOf, } from "../core/index.js";
|
|
34
|
+
import { jsModule } from "./js.js";
|
|
17
35
|
const loaders = new WeakMap();
|
|
18
36
|
const modules = new WeakMap();
|
|
19
37
|
export function setLoader(rt, loader) {
|
|
@@ -44,6 +62,7 @@ const EXPORTS = canon(intern('exports'));
|
|
|
44
62
|
const EXPORT = canon(intern('export'));
|
|
45
63
|
const TYPE = canon(intern('type'));
|
|
46
64
|
const MODULE = canon(intern('module'));
|
|
65
|
+
const PARTS = canon(intern('parts'));
|
|
47
66
|
/** The value after `name:` in a script header, or null. */
|
|
48
67
|
function headerField(header, name) {
|
|
49
68
|
if (header === null)
|
|
@@ -88,6 +107,10 @@ const builtIn = new Map();
|
|
|
88
107
|
export function addBuiltIn(href, src) {
|
|
89
108
|
builtIn.set(href, src);
|
|
90
109
|
}
|
|
110
|
+
/** The source built in under a URL, or undefined. */
|
|
111
|
+
export function builtInText(href) {
|
|
112
|
+
return builtIn.get(href);
|
|
113
|
+
}
|
|
91
114
|
function readText(loader, href, path) {
|
|
92
115
|
const src = builtIn.get(href);
|
|
93
116
|
if (src !== undefined)
|
|
@@ -137,14 +160,70 @@ native('do-file', '["Runs the script in a file, as do does; a module is imported
|
|
|
137
160
|
bindSeries(code.s, t.rt.user, true);
|
|
138
161
|
return { k: 'do', s: code.s, i: start };
|
|
139
162
|
});
|
|
140
|
-
|
|
163
|
+
/** Package names as npm takes them, without a scope (a scope does not fit in a word). */
|
|
164
|
+
const PACKAGE_NAME = /^[a-z0-9][a-z0-9._-]*$/;
|
|
165
|
+
/** The href of a package's module: the "trebol" file of the first node_modules/<name>/ going up from `from`. */
|
|
166
|
+
async function packageModule(loader, from, name) {
|
|
167
|
+
let dir = new URL('./', from);
|
|
168
|
+
for (;;) {
|
|
169
|
+
const at = new URL(`node_modules/${name}/`, dir).href;
|
|
170
|
+
const json = builtIn.get(`${at}package.json`) ?? await loader.read(`${at}package.json`).catch(() => null);
|
|
171
|
+
if (json !== null) {
|
|
172
|
+
let main;
|
|
173
|
+
try {
|
|
174
|
+
main = JSON.parse(json).trebol;
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
throw makeError('access', 'cannot-open', `the package.json of ${name} is not JSON`);
|
|
178
|
+
}
|
|
179
|
+
if (typeof main !== 'string')
|
|
180
|
+
throw makeError('access', 'cannot-open', `${name} is not a Trebol package: its package.json has no "trebol" file`);
|
|
181
|
+
return string(new URL(main, at).href);
|
|
182
|
+
}
|
|
183
|
+
if (dir.pathname === '/' || dir.protocol !== 'file:' && dir.protocol !== 'http:' && dir.protocol !== 'https:')
|
|
184
|
+
break;
|
|
185
|
+
dir = new URL('../', dir);
|
|
186
|
+
}
|
|
187
|
+
throw makeError('access', 'cannot-open', `cannot find the package ${name}: no node_modules/${name}/package.json`);
|
|
188
|
+
}
|
|
189
|
+
/** Binds the bodies of a module (its parts, then its own code) to one context and runs the first. */
|
|
190
|
+
function startModule(rt, f, st, bodies) {
|
|
191
|
+
for (const b of bodies)
|
|
192
|
+
st.exports.push(...takeExports(b));
|
|
193
|
+
const ctx = context();
|
|
194
|
+
ctx.self = true;
|
|
195
|
+
for (const b of bodies)
|
|
196
|
+
collectSetWords(b, 0, ctx);
|
|
197
|
+
// Trebol's own modules (the UI dialect) see lib, as R3's modules do, so a word a program sets,
|
|
198
|
+
// form: or can?, never takes the place of one they use; their exports go to lib too
|
|
199
|
+
for (const b of bodies) {
|
|
200
|
+
bindSeries(b, st.lib ? rt.lib : rt.user, true);
|
|
201
|
+
bindSeries(b, ctx);
|
|
202
|
+
bindSelf(b, ctx);
|
|
203
|
+
}
|
|
204
|
+
st.ctx = ctx;
|
|
205
|
+
st.bodies = bodies;
|
|
206
|
+
st.at = 0;
|
|
207
|
+
f.phase = 2;
|
|
208
|
+
f.trap = 1 << T.Error;
|
|
209
|
+
return { k: 'do', s: bodies[0], i: 0 };
|
|
210
|
+
}
|
|
211
|
+
native('import', '["Runs a module and gives its exports; a word is a package by its name, from node_modules." source [file! url! string! word!]]', (t, f, v) => {
|
|
141
212
|
const rt = t.rt;
|
|
142
213
|
const loader = loaders.get(rt);
|
|
143
214
|
const mods = modules.get(rt);
|
|
144
215
|
if (loader === undefined || mods === undefined)
|
|
145
216
|
return throwError('access', 'no-loader', 'this host cannot load modules');
|
|
146
|
-
|
|
147
|
-
|
|
217
|
+
// a package: where its module is comes first, then it is imported as a file is
|
|
218
|
+
if (f.phase === 0 && f.args[0].t === K.Word) {
|
|
219
|
+
const name = spell(f.args[0].sym);
|
|
220
|
+
if (!PACKAGE_NAME.test(name))
|
|
221
|
+
return throwError('script', 'bad-module', `${name} is not the name of a package`);
|
|
222
|
+
f.phase = 5;
|
|
223
|
+
return { k: 'await', p: packageModule(loader, resolve(loader.base, currentFile(t), './'), name) };
|
|
224
|
+
}
|
|
225
|
+
if (f.phase === 0 || f.phase === 5) {
|
|
226
|
+
const href = f.phase === 5 ? text(v) : hrefOf(t, loader, f.args[0]);
|
|
148
227
|
const known = mods.get(href);
|
|
149
228
|
if (known !== undefined) {
|
|
150
229
|
if (known.obj !== null)
|
|
@@ -160,6 +239,29 @@ native('import', '["Runs a module and gives its exports." source [file! url! str
|
|
|
160
239
|
const entry = { obj: null, done, settle };
|
|
161
240
|
mods.set(href, entry);
|
|
162
241
|
f.data = { href, entry, ctx: null, exports: [] };
|
|
242
|
+
if (/\.m?js$/i.test(new URL(href).pathname)) {
|
|
243
|
+
f.phase = 4;
|
|
244
|
+
const load = loader.importJs ?? ((h) => import(__rewriteRelativeImportExtension(/* @vite-ignore */ h)));
|
|
245
|
+
return {
|
|
246
|
+
k: 'await',
|
|
247
|
+
p: load(href).then(ns => {
|
|
248
|
+
const obj = jsModule(ns);
|
|
249
|
+
if (typeof obj === 'string')
|
|
250
|
+
throw makeError('script', 'bad-module', obj);
|
|
251
|
+
return obj;
|
|
252
|
+
}, (e) => {
|
|
253
|
+
throw makeError('access', 'cannot-open', `cannot open ${mold(f.args[0])}: ${e?.message ?? String(e)}`);
|
|
254
|
+
}).then(obj => {
|
|
255
|
+
entry.obj = obj;
|
|
256
|
+
entry.settle(true, obj);
|
|
257
|
+
return obj;
|
|
258
|
+
}, (err) => {
|
|
259
|
+
mods.delete(href);
|
|
260
|
+
entry.settle(false, err);
|
|
261
|
+
throw err;
|
|
262
|
+
}),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
163
265
|
f.phase = 1;
|
|
164
266
|
return {
|
|
165
267
|
k: 'await',
|
|
@@ -170,17 +272,16 @@ native('import', '["Runs a module and gives its exports." source [file! url! str
|
|
|
170
272
|
}),
|
|
171
273
|
};
|
|
172
274
|
}
|
|
173
|
-
if (f.phase === 3)
|
|
275
|
+
if (f.phase === 3 || f.phase === 4)
|
|
174
276
|
return value(v);
|
|
175
277
|
const st = f.data;
|
|
176
278
|
const failed = (e) => {
|
|
177
279
|
mods.delete(st.href);
|
|
178
280
|
st.entry.settle(false, e);
|
|
179
281
|
};
|
|
180
|
-
|
|
181
|
-
let code;
|
|
282
|
+
const loadIt = (src, file) => {
|
|
182
283
|
try {
|
|
183
|
-
|
|
284
|
+
return load(text(src), { file });
|
|
184
285
|
}
|
|
185
286
|
catch (e) {
|
|
186
287
|
// LoadError is the one exception on the normal path; it becomes a value here.
|
|
@@ -191,22 +292,56 @@ native('import', '["Runs a module and gives its exports." source [file! url! str
|
|
|
191
292
|
failed(step.e.v);
|
|
192
293
|
return step;
|
|
193
294
|
}
|
|
295
|
+
};
|
|
296
|
+
if (f.phase === 1) {
|
|
297
|
+
const code = loadIt(v, st.href);
|
|
298
|
+
if ('k' in code)
|
|
299
|
+
return code;
|
|
194
300
|
const { header, start } = scriptStart(code);
|
|
195
301
|
const listed = headerField(header, EXPORTS);
|
|
196
302
|
if (listed !== null && listed.t === K.Block)
|
|
197
303
|
st.exports = listed.s.data.filter(w => w.t === K.Word);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
304
|
+
st.lib = LIBRARY_FILES.has(st.href);
|
|
305
|
+
// parts: [%a.trb %b.trb] are files of the same module, read before it runs
|
|
306
|
+
const parts = headerField(header, PARTS);
|
|
307
|
+
if (parts !== null) {
|
|
308
|
+
const files = parts.t === K.Block ? parts.s.data.slice(parts.i) : [];
|
|
309
|
+
if (files.length === 0 || files.some(x => x.t !== K.File)) {
|
|
310
|
+
const step = throwError('script', 'bad-module', 'parts: takes a block of files');
|
|
311
|
+
if (step.k === 'throw')
|
|
312
|
+
failed(step.e.v);
|
|
313
|
+
return step;
|
|
314
|
+
}
|
|
315
|
+
st.code = code;
|
|
316
|
+
st.start = start;
|
|
317
|
+
st.parts = files.map(x => new URL(text(x), st.href).href);
|
|
318
|
+
// the parts of Trebol's own modules are Trebol's own code too
|
|
319
|
+
if (st.lib)
|
|
320
|
+
for (const h of st.parts)
|
|
321
|
+
LIBRARY_FILES.add(h);
|
|
322
|
+
f.phase = 6;
|
|
323
|
+
const loader = loaders.get(rt);
|
|
324
|
+
return { k: 'await', p: Promise.all(st.parts.map((h, i) => readText(loader, h, files[i]))).then(texts => blockOf(K.Block, texts)) };
|
|
325
|
+
}
|
|
326
|
+
return startModule(rt, f, st, [copyDeep(code.s, start)]);
|
|
327
|
+
}
|
|
328
|
+
if (f.phase === 6) {
|
|
329
|
+
const bodies = [];
|
|
330
|
+
const texts = v.s.data;
|
|
331
|
+
for (let i = 0; i < texts.length; i++) {
|
|
332
|
+
const part = loadIt(texts[i], st.parts[i]);
|
|
333
|
+
if ('k' in part)
|
|
334
|
+
return part;
|
|
335
|
+
bodies.push(copyDeep(part.s, scriptStart(part).start));
|
|
336
|
+
}
|
|
337
|
+
bodies.push(copyDeep(st.code.s, st.start));
|
|
338
|
+
st.code = undefined;
|
|
339
|
+
return startModule(rt, f, st, bodies);
|
|
340
|
+
}
|
|
341
|
+
// a part ran: the next one, or the module's own body
|
|
342
|
+
if (f.phase === 2 && f.thrown === null && st.at + 1 < st.bodies.length) {
|
|
343
|
+
st.at++;
|
|
344
|
+
return { k: 'do', s: st.bodies[st.at], i: 0 };
|
|
210
345
|
}
|
|
211
346
|
// phase 2: the module body ran
|
|
212
347
|
if (f.thrown !== null) {
|
|
@@ -224,6 +359,8 @@ native('import', '["Runs a module and gives its exports." source [file! url! str
|
|
|
224
359
|
failed(step.e.v);
|
|
225
360
|
return step;
|
|
226
361
|
}
|
|
362
|
+
if (st.lib)
|
|
363
|
+
setWord({ t: K.Word, sym: w.sym, bind: rt.lib }, st.ctx.vals[i]);
|
|
227
364
|
setWord({ t: K.Word, sym: w.sym, bind: rt.user }, st.ctx.vals[i]);
|
|
228
365
|
}
|
|
229
366
|
st.entry.obj = obj;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The theme changed: read its time again. */
|
|
2
|
+
export declare function themeMoved(): void;
|
|
3
|
+
/** Whether the page may move now: the browser can, the user has not asked for less, the page is on show. */
|
|
4
|
+
export declare function mayMove(): boolean;
|
|
5
|
+
export declare function travelled(way: 'on' | 'back'): void;
|
|
6
|
+
/**
|
|
7
|
+
* Puts the screen coming in place of the one on show: the browser takes a picture of
|
|
8
|
+
* the page, swap changes it, and the old screen slides out as the new one slides in,
|
|
9
|
+
* the way the user went. Faces given the same `morph` in both become one another.
|
|
10
|
+
* swap is called once, now or at the browser's next frame; it may decide not to.
|
|
11
|
+
*/
|
|
12
|
+
export declare function changeScreen(box: HTMLElement, coming: HTMLElement, swap: () => void): void;
|
|
13
|
+
/** A name as the browser takes it: letters, digits, - and _, anything else spelled by its code. */
|
|
14
|
+
export declare function morphIdent(name: string): string;
|
|
15
|
+
/** Where each row stood before the rows changed. */
|
|
16
|
+
export declare function rowPlaces(rows: Iterable<HTMLElement>): Map<HTMLElement, DOMRect>;
|
|
17
|
+
/**
|
|
18
|
+
* After the rows changed: those that stayed glide from where they were to where
|
|
19
|
+
* they are, the new ones fade in.
|
|
20
|
+
*/
|
|
21
|
+
export declare function moveRows(rows: Iterable<HTMLElement>, was: Map<HTMLElement, DOMRect>): void;
|
|
22
|
+
/**
|
|
23
|
+
* A row that went fades where it stood, out of the flow so the others close the gap:
|
|
24
|
+
* its cells keep their widths, as it no longer lies in its table.
|
|
25
|
+
*/
|
|
26
|
+
export declare function leaveRow(r: HTMLElement, at: DOMRect): void;
|
|
27
|
+
/** Whether a face is folding away now. */
|
|
28
|
+
export declare function isFolding(e: HTMLElement): boolean;
|
|
29
|
+
/** A face shown again unfolds: from no height, if it lies among others one above another, and from clear. */
|
|
30
|
+
export declare function unfold(e: HTMLElement): void;
|
|
31
|
+
/** A face hidden folds away, and then done hides it. */
|
|
32
|
+
export declare function fold(e: HTMLElement, done: () => void): void;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// How the page moves when it changes: a screen that gives way to another, rows
|
|
2
|
+
// that come, go or change places, a face shown or hidden. Nothing here is asked
|
|
3
|
+
// for by the app; the theme's --tb-move and --tb-ease say how long and how, and a
|
|
4
|
+
// user who asks the system for less motion gets none.
|
|
5
|
+
/** The theme's time for a change of place, in ms, read from the page once. */
|
|
6
|
+
let moveMs = -1;
|
|
7
|
+
function duration() {
|
|
8
|
+
if (moveMs < 0) {
|
|
9
|
+
const v = getComputedStyle(document.documentElement).getPropertyValue('--tb-move').trim();
|
|
10
|
+
moveMs = v.endsWith('ms') ? parseFloat(v) : v.endsWith('s') ? parseFloat(v) * 1000 : 220;
|
|
11
|
+
if (!Number.isFinite(moveMs))
|
|
12
|
+
moveMs = 220;
|
|
13
|
+
}
|
|
14
|
+
return moveMs;
|
|
15
|
+
}
|
|
16
|
+
/** The theme changed: read its time again. */
|
|
17
|
+
export function themeMoved() {
|
|
18
|
+
moveMs = -1;
|
|
19
|
+
}
|
|
20
|
+
const EASE = 'cubic-bezier(0.2, 0, 0, 1)';
|
|
21
|
+
/** Whether the page may move now: the browser can, the user has not asked for less, the page is on show. */
|
|
22
|
+
export function mayMove() {
|
|
23
|
+
if (typeof matchMedia !== 'function' || typeof Element.prototype.animate !== 'function')
|
|
24
|
+
return false;
|
|
25
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches)
|
|
26
|
+
return false;
|
|
27
|
+
return document.visibilityState !== 'hidden' && duration() > 0;
|
|
28
|
+
}
|
|
29
|
+
// --- screens ---------------------------------------------------------------------
|
|
30
|
+
/** Which way the user went to the screen coming: on, or back to one seen before. */
|
|
31
|
+
let travel = 'on';
|
|
32
|
+
export function travelled(way) {
|
|
33
|
+
travel = way;
|
|
34
|
+
}
|
|
35
|
+
let swapping = false;
|
|
36
|
+
/**
|
|
37
|
+
* Puts the screen coming in place of the one on show: the browser takes a picture of
|
|
38
|
+
* the page, swap changes it, and the old screen slides out as the new one slides in,
|
|
39
|
+
* the way the user went. Faces given the same `morph` in both become one another.
|
|
40
|
+
* swap is called once, now or at the browser's next frame; it may decide not to.
|
|
41
|
+
*/
|
|
42
|
+
export function changeScreen(box, coming, swap) {
|
|
43
|
+
const doc = document;
|
|
44
|
+
// the first screen, or a page that cannot or may not move
|
|
45
|
+
const way = travel;
|
|
46
|
+
travel = 'on';
|
|
47
|
+
if (swapping)
|
|
48
|
+
return;
|
|
49
|
+
if (box.childElementCount === 0 || typeof doc.startViewTransition !== 'function' || !mayMove())
|
|
50
|
+
return swap();
|
|
51
|
+
swapping = true;
|
|
52
|
+
const root = document.documentElement;
|
|
53
|
+
root.dataset['tbTravel'] = way;
|
|
54
|
+
box.style.setProperty('view-transition-name', 'tb-screen');
|
|
55
|
+
// only the names in both screens: a face with no partner goes with its screen
|
|
56
|
+
const both = morphsIn(coming);
|
|
57
|
+
const was = nameMorphs(both);
|
|
58
|
+
const t = doc.startViewTransition(() => {
|
|
59
|
+
swapping = false;
|
|
60
|
+
clearMorphs();
|
|
61
|
+
swap();
|
|
62
|
+
nameMorphs(was);
|
|
63
|
+
});
|
|
64
|
+
void t.finished.catch(() => { }).then(() => {
|
|
65
|
+
box.style.removeProperty('view-transition-name');
|
|
66
|
+
delete root.dataset['tbTravel'];
|
|
67
|
+
clearMorphs();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** The faces given a morph name for the change of screen going on. */
|
|
71
|
+
let named = [];
|
|
72
|
+
/**
|
|
73
|
+
* Gives the browser the morph name of each face on show that has one among those
|
|
74
|
+
* given, so a face of the old screen and one of the new with the same name become
|
|
75
|
+
* one another; when two on show share a name, the first keeps it. Gives the names given.
|
|
76
|
+
*/
|
|
77
|
+
function nameMorphs(among) {
|
|
78
|
+
const seen = new Set();
|
|
79
|
+
for (const e of Array.from(document.querySelectorAll('[data-tb-morph]'))) {
|
|
80
|
+
const name = morphIdent(e.dataset['tbMorph']);
|
|
81
|
+
if (!among.has(name) || seen.has(name) || e.getClientRects().length === 0)
|
|
82
|
+
continue;
|
|
83
|
+
seen.add(name);
|
|
84
|
+
e.style.setProperty('view-transition-name', name);
|
|
85
|
+
named.push(e);
|
|
86
|
+
}
|
|
87
|
+
return seen;
|
|
88
|
+
}
|
|
89
|
+
/** The morph names of a screen not yet on the page. */
|
|
90
|
+
function morphsIn(screen) {
|
|
91
|
+
return new Set(Array.from(screen.querySelectorAll('[data-tb-morph]'), e => morphIdent(e.dataset['tbMorph'])));
|
|
92
|
+
}
|
|
93
|
+
function clearMorphs() {
|
|
94
|
+
for (const e of named)
|
|
95
|
+
e.style.removeProperty('view-transition-name');
|
|
96
|
+
named = [];
|
|
97
|
+
}
|
|
98
|
+
/** A name as the browser takes it: letters, digits, - and _, anything else spelled by its code. */
|
|
99
|
+
export function morphIdent(name) {
|
|
100
|
+
let out = 'tb-m-';
|
|
101
|
+
for (const ch of name)
|
|
102
|
+
out += /[A-Za-z0-9_-]/.test(ch) ? ch : `_${ch.codePointAt(0).toString(16)}_`;
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
// --- rows --------------------------------------------------------------------------
|
|
106
|
+
/** Where each row stood before the rows changed. */
|
|
107
|
+
export function rowPlaces(rows) {
|
|
108
|
+
const at = new Map();
|
|
109
|
+
for (const r of rows)
|
|
110
|
+
at.set(r, r.getBoundingClientRect());
|
|
111
|
+
return at;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* After the rows changed: those that stayed glide from where they were to where
|
|
115
|
+
* they are, the new ones fade in.
|
|
116
|
+
*/
|
|
117
|
+
export function moveRows(rows, was) {
|
|
118
|
+
const ms = duration();
|
|
119
|
+
for (const r of rows) {
|
|
120
|
+
const from = was.get(r);
|
|
121
|
+
if (from === undefined) {
|
|
122
|
+
r.animate([{ opacity: 0 }, { opacity: 1 }], { duration: ms, easing: EASE });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const to = r.getBoundingClientRect();
|
|
126
|
+
const dx = from.left - to.left;
|
|
127
|
+
const dy = from.top - to.top;
|
|
128
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5)
|
|
129
|
+
continue;
|
|
130
|
+
r.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }], { duration: ms, easing: EASE });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A row that went fades where it stood, out of the flow so the others close the gap:
|
|
135
|
+
* its cells keep their widths, as it no longer lies in its table.
|
|
136
|
+
*/
|
|
137
|
+
export function leaveRow(r, at) {
|
|
138
|
+
const widths = Array.from(r.children, c => c.getBoundingClientRect().width);
|
|
139
|
+
Array.from(r.children).forEach((c, i) => {
|
|
140
|
+
c.style.width = `${widths[i]}px`;
|
|
141
|
+
c.style.boxSizing = 'border-box';
|
|
142
|
+
});
|
|
143
|
+
r.classList.add('tb-leaving');
|
|
144
|
+
r.setAttribute('aria-hidden', 'true');
|
|
145
|
+
r.removeAttribute('tabindex');
|
|
146
|
+
Object.assign(r.style, { position: 'fixed', top: `${at.top}px`, left: `${at.left}px`, width: `${at.width}px`, height: `${at.height}px`, margin: '0' });
|
|
147
|
+
const a = r.animate([{ opacity: 1 }, { opacity: 0 }], { duration: duration() * 0.7, easing: EASE });
|
|
148
|
+
a.onfinish = () => r.remove();
|
|
149
|
+
a.oncancel = () => r.remove();
|
|
150
|
+
}
|
|
151
|
+
// --- shown and hidden --------------------------------------------------------------
|
|
152
|
+
/** The faces folding away now, so a face shown again stops folding. */
|
|
153
|
+
const folding = new WeakMap();
|
|
154
|
+
/** Whether a face is folding away now. */
|
|
155
|
+
export function isFolding(e) {
|
|
156
|
+
return folding.has(e);
|
|
157
|
+
}
|
|
158
|
+
/** A face shown again unfolds: from no height, if it lies among others one above another, and from clear. */
|
|
159
|
+
export function unfold(e) {
|
|
160
|
+
folding.get(e)?.cancel();
|
|
161
|
+
const h = e.getBoundingClientRect().height;
|
|
162
|
+
const stacked = stackedIn(e);
|
|
163
|
+
const frames = stacked && h > 0
|
|
164
|
+
? [{ height: '0px', opacity: 0, overflow: 'hidden' }, { height: `${h}px`, opacity: 1, overflow: 'hidden' }]
|
|
165
|
+
: [{ opacity: 0 }, { opacity: 1 }];
|
|
166
|
+
e.animate(frames, { duration: duration(), easing: EASE });
|
|
167
|
+
}
|
|
168
|
+
/** A face hidden folds away, and then done hides it. */
|
|
169
|
+
export function fold(e, done) {
|
|
170
|
+
const h = e.getBoundingClientRect().height;
|
|
171
|
+
const stacked = stackedIn(e);
|
|
172
|
+
const frames = stacked && h > 0
|
|
173
|
+
? [{ height: `${h}px`, opacity: 1, overflow: 'hidden' }, { height: '0px', opacity: 0, overflow: 'hidden', marginTop: '0px', marginBottom: '0px', paddingTop: '0px', paddingBottom: '0px' }]
|
|
174
|
+
: [{ opacity: 1 }, { opacity: 0 }];
|
|
175
|
+
const a = e.animate(frames, { duration: duration() * 0.8, easing: EASE });
|
|
176
|
+
folding.set(e, a);
|
|
177
|
+
a.onfinish = () => {
|
|
178
|
+
folding.delete(e);
|
|
179
|
+
done();
|
|
180
|
+
};
|
|
181
|
+
a.oncancel = () => folding.delete(e);
|
|
182
|
+
}
|
|
183
|
+
/** Whether a face lies among others one above another, so its height can open. */
|
|
184
|
+
function stackedIn(e) {
|
|
185
|
+
const p = e.parentElement;
|
|
186
|
+
if (p === null)
|
|
187
|
+
return false;
|
|
188
|
+
const s = getComputedStyle(p);
|
|
189
|
+
return !s.display.includes('flex') || s.flexDirection.startsWith('column');
|
|
190
|
+
}
|
package/dist/lib/host/net.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { K, NONE, I64, native, value, string, stringOf, text, binary, makeError, throwError, form, spell, ctxFind, intern, parseJson, toJson, queryText, } from "../core/index.js";
|
|
8
8
|
import { schedulerOf, spawn, spawnHandler, makeHandle, handleOf } from "./scheduler.js";
|
|
9
9
|
import { cancellers } from "./natives.js";
|
|
10
|
+
import { devLog } from "./devlog.js";
|
|
10
11
|
// --- files -----------------------------------------------------------------------
|
|
11
12
|
//
|
|
12
13
|
// A file the user chose (an upload field) is a handle of kind 'file' over a
|
|
@@ -155,7 +156,8 @@ function decodeBody(type, bytes) {
|
|
|
155
156
|
const r = parseJson(new TextDecoder().decode(bytes));
|
|
156
157
|
return typeof r === 'string' ? string(new TextDecoder().decode(bytes)) : r;
|
|
157
158
|
}
|
|
158
|
-
|
|
159
|
+
// xml only as the subtype or its +xml suffix: the type of an Excel file (…openxmlformats…) is binary
|
|
160
|
+
if (/^text\/|^[^;]*\/(?:xml|[^;]*\+xml)\s*(?:;|$)|javascript|x-www-form-urlencoded/i.test(type) || type === '') {
|
|
159
161
|
return string(new TextDecoder().decode(bytes));
|
|
160
162
|
}
|
|
161
163
|
return { t: K.Binary, s: { data: [...bytes] }, i: 0 };
|
|
@@ -248,8 +250,8 @@ function progressOf(t, target) {
|
|
|
248
250
|
return;
|
|
249
251
|
}
|
|
250
252
|
// a host mezzanine: in user, where the host's Trebol code is loaded
|
|
251
|
-
const i = ctxFind(t.rt.
|
|
252
|
-
const fn = i < 0 ? undefined : t.rt.
|
|
253
|
+
const i = ctxFind(t.rt.lib, intern('show-progress'));
|
|
254
|
+
const fn = i < 0 ? undefined : t.rt.lib.vals[i];
|
|
253
255
|
if (fn !== undefined)
|
|
254
256
|
spawn(sch, { data: [fn, target, done, total] }, 0);
|
|
255
257
|
};
|
|
@@ -342,11 +344,18 @@ native('http-request', '["Sends an HTTP request; used by fetch." url [url! strin
|
|
|
342
344
|
const watch = field(opts, 'progress');
|
|
343
345
|
const shown = watch === null ? null : progressOf(t, watch);
|
|
344
346
|
const p = (async () => {
|
|
347
|
+
const started = Date.now();
|
|
348
|
+
let status = null;
|
|
349
|
+
let problem = null;
|
|
345
350
|
try {
|
|
346
351
|
const init = { method: verb, headers, body, credentials, signal: ctl.signal };
|
|
352
|
+
// a page being hidden may close: a small request still goes (an Undo notice ending sends its delete)
|
|
353
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'hidden' && (body === undefined || (typeof body === 'string' && body.length < 60000)))
|
|
354
|
+
init.keepalive = true;
|
|
347
355
|
const res = shown !== null && typeof XMLHttpRequest !== 'undefined'
|
|
348
356
|
? await sendXhr(url, init, shown.tell)
|
|
349
357
|
: await sendFetch(url, init, shown === null ? null : shown.tell);
|
|
358
|
+
status = res.status;
|
|
350
359
|
const type = res.headers.find(([k]) => k === 'content-type')?.[1] ?? '';
|
|
351
360
|
const data = decodeBody(type, res.bytes);
|
|
352
361
|
if (full) {
|
|
@@ -369,6 +378,7 @@ native('http-request', '["Sends an HTTP request; used by fetch." url [url! strin
|
|
|
369
378
|
catch (e) {
|
|
370
379
|
if (e.t === K.Error)
|
|
371
380
|
throw e;
|
|
381
|
+
problem = timedOut ? 'timed out' : ctl.signal.aborted ? 'cancelled' : e.message;
|
|
372
382
|
if (timedOut)
|
|
373
383
|
throw makeError('access', 'timeout', `request to ${url} timed out`);
|
|
374
384
|
if (ctl.signal.aborted)
|
|
@@ -379,6 +389,7 @@ native('http-request', '["Sends an HTTP request; used by fetch." url [url! strin
|
|
|
379
389
|
if (timer !== null)
|
|
380
390
|
clearTimeout(timer);
|
|
381
391
|
shown?.end();
|
|
392
|
+
devLog.request(verb, url, status, Date.now() - started, problem);
|
|
382
393
|
}
|
|
383
394
|
})();
|
|
384
395
|
return { k: 'await', p };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type Cell } from '../core/index.ts';
|
|
2
|
+
import { type El } from './draw.ts';
|
|
3
|
+
export type EdgeLook = 'solid' | 'dashed' | 'faint';
|
|
4
|
+
export interface OrbitNode {
|
|
5
|
+
key: string;
|
|
6
|
+
/** The id as the app gave it: what face/value is when the person picks it. */
|
|
7
|
+
id: Cell;
|
|
8
|
+
/** A string, or a text per language. */
|
|
9
|
+
title: Cell;
|
|
10
|
+
color: string;
|
|
11
|
+
/** How many it holds: small moons around it and a number under its title. */
|
|
12
|
+
count: number | null;
|
|
13
|
+
/** It stands for many: a second ring. */
|
|
14
|
+
many: boolean;
|
|
15
|
+
/** A shortcut or link: a dashed border. */
|
|
16
|
+
dashed: boolean;
|
|
17
|
+
/** A ring of steps around it, the one at `at` the current one (1-based); 0 for none. */
|
|
18
|
+
steps: number;
|
|
19
|
+
at: number;
|
|
20
|
+
}
|
|
21
|
+
export interface OrbitEdge {
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
label: Cell | null;
|
|
25
|
+
look: EdgeLook;
|
|
26
|
+
}
|
|
27
|
+
export interface OrbitSpec {
|
|
28
|
+
focus: string | null;
|
|
29
|
+
nodes: Map<string, OrbitNode>;
|
|
30
|
+
edges: OrbitEdge[];
|
|
31
|
+
/** The nodes the person came from, most recent last. */
|
|
32
|
+
trail: string[];
|
|
33
|
+
}
|
|
34
|
+
/** What tells nodes apart: an id is a word, an integer, a string or an issue. */
|
|
35
|
+
export declare function idKey(c: Cell): string | null;
|
|
36
|
+
/** The orbit a block describes, and what was wrong with it; what is wrong is left out. */
|
|
37
|
+
export declare function readOrbit(data: Cell): {
|
|
38
|
+
spec: OrbitSpec;
|
|
39
|
+
error: string | null;
|
|
40
|
+
};
|
|
41
|
+
export type Role = 'focus' | 'near' | 'more' | 'trail';
|
|
42
|
+
/** Where a bubble is, in the orbit's own space with the focus at 0,0: its centre, radius and opacity. */
|
|
43
|
+
export interface Place {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
r: number;
|
|
47
|
+
o: number;
|
|
48
|
+
}
|
|
49
|
+
export interface Placed extends Place {
|
|
50
|
+
key: string;
|
|
51
|
+
role: Role;
|
|
52
|
+
}
|
|
53
|
+
export declare const FOCUS_R = 92;
|
|
54
|
+
/** Neighbours on show at once; past that, a "+N more" bubble pages through them. */
|
|
55
|
+
export declare const PAGE = 30;
|
|
56
|
+
/** Past this many neighbours, edge labels show only on hover. */
|
|
57
|
+
export declare const MANY = 18;
|
|
58
|
+
/** The key of the "+N more" bubble: no id gives it. */
|
|
59
|
+
export declare const MORE = "\0more";
|
|
60
|
+
export interface Box {
|
|
61
|
+
x0: number;
|
|
62
|
+
y0: number;
|
|
63
|
+
x1: number;
|
|
64
|
+
y1: number;
|
|
65
|
+
}
|
|
66
|
+
export interface OrbitLayout {
|
|
67
|
+
placed: Placed[];
|
|
68
|
+
/** The box everything drawn fits in, titles too: the camera fits it. */
|
|
69
|
+
box: Box;
|
|
70
|
+
/** The neighbours not on this page; 0 when they all fit. */
|
|
71
|
+
left: number;
|
|
72
|
+
pages: number;
|
|
73
|
+
}
|
|
74
|
+
/** The neighbours of the focus: every node given that is neither it nor in the trail, in the order given. */
|
|
75
|
+
export declare function neighbours(spec: OrbitSpec): string[];
|
|
76
|
+
/** Places the focus, its neighbours on rings (the given page of them) and the last few of the trail. */
|
|
77
|
+
export declare function layoutOrbit(spec: OrbitSpec, page?: number): OrbitLayout;
|
|
78
|
+
/** The edges to draw between bubbles on show: those given between the focus and its neighbours, and the trail's dotted line. */
|
|
79
|
+
export declare function shownEdges(spec: OrbitSpec, placed: Placed[]): Array<OrbitEdge & {
|
|
80
|
+
curve: number;
|
|
81
|
+
trail: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
/** The label of the edge between the focus and a neighbour, either way round; null if none. */
|
|
84
|
+
export declare function edgeLabel(spec: OrbitSpec, key: string): Cell | null;
|
|
85
|
+
/** A title in lines of at most `max` characters, three lines at most. */
|
|
86
|
+
export declare function wrapTitle(title: string, max: number): string[];
|
|
87
|
+
/** An arc of a circle of radius r from angle a0 to a1, as path data. */
|
|
88
|
+
export declare function arcPath(r: number, a0: number, a1: number): string;
|
|
89
|
+
export interface BubbleLook {
|
|
90
|
+
role: Role;
|
|
91
|
+
r: number;
|
|
92
|
+
/** The camera's zoom once it fits: titles are sized for the screen at it, as the rest of the page's text. */
|
|
93
|
+
scale: number;
|
|
94
|
+
/** A title outside the bubble goes above it rather than under it: for bubbles above the focus, away from their edge. */
|
|
95
|
+
above: boolean;
|
|
96
|
+
title: string;
|
|
97
|
+
color: string;
|
|
98
|
+
/** The ids of the gradients for this color: body and halo. */
|
|
99
|
+
body: string;
|
|
100
|
+
halo: string;
|
|
101
|
+
node: OrbitNode | null;
|
|
102
|
+
}
|
|
103
|
+
/** What a bubble draws, in unit space: halo, body, its rings, moons, title and count. */
|
|
104
|
+
export declare function bubble(b: BubbleLook): El[];
|
|
105
|
+
/** The two gradients of a color: a body lighter in the middle and a soft halo. */
|
|
106
|
+
export declare function gradients(color: string, body: string, halo: string): El[];
|
|
107
|
+
/** Where an edge's line goes, from bubble a to bubble b, cut at their borders; and the middle and angle for its label. */
|
|
108
|
+
export declare function edgePath(a: Place, b: Place, curve: number): {
|
|
109
|
+
d: string;
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
angle: number;
|
|
113
|
+
};
|
|
114
|
+
/** The ease of a move: slow at both ends. */
|
|
115
|
+
export declare const ease: (k: number) => number;
|
|
116
|
+
/** Where the camera goes to show the whole box in a view of w by h: centred on it, zoomed to fit, within limits. */
|
|
117
|
+
export declare function fitCamera(w: number, h: number, box: Box): {
|
|
118
|
+
x: number;
|
|
119
|
+
y: number;
|
|
120
|
+
s: number;
|
|
121
|
+
};
|