@beff/aula-cli 0.12.0 → 0.13.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 (42) hide show
  1. package/README.md +6 -1
  2. package/dist/src/{aula-voice-tts-YOS4IQXV.js → aula-voice-tts-H2OQFQ5J.js} +1 -1
  3. package/dist/src/aula.js +2 -2
  4. package/dist/src/{chunk-TDAWUJ2L.js → chunk-4FWDTPLR.js} +1 -1
  5. package/dist/src/{chunk-RAGZAJKD.js → chunk-D5N3QDDF.js} +1 -1
  6. package/dist/src/{chunk-DN2LVJO3.js → chunk-F5RPEFZR.js} +1 -0
  7. package/dist/src/{chunk-2PAZTBSE.js → chunk-G44UMBPW.js} +2 -2
  8. package/dist/src/{chunk-PZXFW6ZD.js → chunk-S6IM5XXK.js} +3 -3
  9. package/dist/src/{chunk-AXQBWV7J.js → chunk-THZNJBUF.js} +129 -20
  10. package/dist/src/{chunk-DC7A435Z.js → chunk-UBVMGS2E.js} +1 -1
  11. package/dist/src/{chunk-HD6FTA3H.js → chunk-UQOXT6QN.js} +109 -87
  12. package/dist/src/{chunk-T6CAPT32.js → chunk-WV2UYZND.js} +3 -2
  13. package/dist/src/chunk-XIVHJMET.js +111 -0
  14. package/dist/src/cli.js +29 -93
  15. package/dist/src/{commands-BSDNHYB3.js → commands-PLST75CP.js} +11 -10
  16. package/dist/src/problems-EI4DOEZ4.js +17 -0
  17. package/dist/src/project-7EROVEUE.js +16 -0
  18. package/dist/src/run-NE5HOAXA.js +235 -0
  19. package/dist/src/{server-TJTMSDO2.js → server-KXIU66BB.js} +24 -21
  20. package/dist/src/{site-RGPJOWSU.js → site-HUWODSZ3.js} +16 -89
  21. package/dist/src/workspace-load-DOHFEZFR.js +16 -0
  22. package/dist/web/app/assets/62289de9/build-worker.js +2 -0
  23. package/dist/web/app/assets/{bf5dd884 → 62289de9}/index.js +2 -2
  24. package/dist/web/app/assets/protocol-kcdbhuRm.js +15 -0
  25. package/dist/web/app/index.html +2 -2
  26. package/dist/web/site/assets/82618540/build-worker.js +2 -0
  27. package/dist/web/site/assets/{07fb5cf0 → 82618540}/index.js +2 -2
  28. package/dist/web/site/assets/protocol-XMWr-E-D.js +15 -0
  29. package/dist/web/site/index.html +2 -2
  30. package/package.json +1 -1
  31. package/dist/src/chunk-4QGX7XXO.js +0 -104
  32. package/dist/src/problems-CGKCPETU.js +0 -18
  33. package/dist/src/project-EUFMRQXR.js +0 -16
  34. package/dist/src/run-ER27SVTA.js +0 -183
  35. package/dist/web/app/assets/bf5dd884/build-worker.js +0 -2
  36. package/dist/web/app/assets/protocol-Dc79M9p3.js +0 -15
  37. package/dist/web/site/assets/07fb5cf0/build-worker.js +0 -2
  38. package/dist/web/site/assets/protocol-F-4tHoAW.js +0 -15
  39. /package/dist/web/app/assets/{bf5dd884 → 62289de9}/aula-method.js +0 -0
  40. /package/dist/web/app/assets/{bf5dd884 → 62289de9}/aula.js +0 -0
  41. /package/dist/web/site/assets/{07fb5cf0 → 82618540}/aula-method.js +0 -0
  42. /package/dist/web/site/assets/{07fb5cf0 → 82618540}/aula.js +0 -0
@@ -2,22 +2,24 @@ import {
2
2
  PACKAGE
3
3
  } from "./chunk-A5QHTZKT.js";
4
4
  import {
5
- createNodeBundler,
5
+ resolveRootProjects
6
+ } from "./chunk-XIVHJMET.js";
7
+ import {
6
8
  nodeTree
7
9
  } from "./chunk-THQ5Y74K.js";
8
- import "./chunk-4QGX7XXO.js";
10
+ import "./chunk-THZNJBUF.js";
9
11
  import {
10
12
  SERVER_WEIGHTS_PATH
11
- } from "./chunk-TDAWUJ2L.js";
13
+ } from "./chunk-4FWDTPLR.js";
12
14
  import {
13
15
  exists
14
- } from "./chunk-DC7A435Z.js";
15
- import "./chunk-2PAZTBSE.js";
16
+ } from "./chunk-UBVMGS2E.js";
17
+ import "./chunk-G44UMBPW.js";
16
18
  import {
17
- bundleWorkspace
18
- } from "./chunk-T6CAPT32.js";
19
- import "./chunk-RAGZAJKD.js";
20
- import "./chunk-DN2LVJO3.js";
19
+ Problems
20
+ } from "./chunk-WV2UYZND.js";
21
+ import "./chunk-D5N3QDDF.js";
22
+ import "./chunk-F5RPEFZR.js";
21
23
  import {
22
24
  AulaError,
23
25
  fault
@@ -27,7 +29,7 @@ import "./chunk-CZ7CSFO4.js";
27
29
  // src/web/server.ts
28
30
  import { once } from "node:events";
29
31
  import { createServer } from "node:http";
30
- import { basename, dirname, join } from "node:path";
32
+ import { dirname, join } from "node:path";
31
33
 
32
34
  // src/web/page.ts
33
35
  var APP = new URL("web/app/", PACKAGE);
@@ -162,34 +164,36 @@ function openHost(host) {
162
164
  }
163
165
  async function serve(capabilities, options) {
164
166
  const host = options.host ?? "127.0.0.1";
167
+ const includeDrafts = options.includeDrafts === true;
165
168
  let generation = 0;
166
169
  let cached = null;
167
170
  const watching = changes(capabilities, () => {
168
171
  generation += 1;
169
172
  cached = null;
170
173
  });
171
- const bundler = createNodeBundler();
172
174
  const tree = nodeTree(capabilities, options.root);
173
175
  const buildBundle = () => {
174
176
  if (cached !== null && cached.generation === generation) return cached.result;
175
177
  const at = generation;
176
178
  const result = (async () => {
177
179
  await watchWorkspaceFolders(capabilities, options.root, watching);
178
- const bundled = await bundleWorkspace(bundler, tree, basename(options.root));
179
- if (bundled._tag === "Left") {
180
- for (const diagnostic of bundled.left) {
180
+ try {
181
+ const resolved = await resolveRootProjects(capabilities, options.root, includeDrafts);
182
+ for (const input of resolved.inputs) {
183
+ const disk = tree.diskPath(input);
184
+ if (disk !== null) watching.served(disk);
185
+ }
186
+ return { _tag: "Right", right: resolved.bundle };
187
+ } catch (error) {
188
+ if (!(error instanceof Problems)) throw error;
189
+ for (const diagnostic of error.diagnostics) {
181
190
  const file = diagnostic.location?.file;
182
191
  if (file === void 0) continue;
183
192
  const disk = tree.diskPath(file);
184
193
  if (disk !== null && exists(capabilities, disk)) watching.served(disk);
185
194
  }
186
- return bundled;
187
- }
188
- for (const input of bundled.right.inputs) {
189
- const disk = tree.diskPath(input);
190
- if (disk !== null) watching.served(disk);
195
+ return { _tag: "Left", left: error.diagnostics };
191
196
  }
192
- return { _tag: "Right", right: bundled.right.bundle };
193
197
  })();
194
198
  const entry = { generation: at, result };
195
199
  cached = entry;
@@ -218,7 +222,6 @@ async function serve(capabilities, options) {
218
222
  capabilities.log.out(`aula web: open ${open} in a browser${bindNote} (Ctrl-C stops it)`);
219
223
  options.stop.addEventListener("abort", () => {
220
224
  watching.close();
221
- void bundler.stop();
222
225
  server.close();
223
226
  server.closeAllConnections();
224
227
  });
@@ -2,39 +2,26 @@ import {
2
2
  PACKAGE
3
3
  } from "./chunk-A5QHTZKT.js";
4
4
  import {
5
- createNodeBundler,
6
- nodeTree
7
- } from "./chunk-THQ5Y74K.js";
8
- import {
9
- listedProjects,
10
- loadBuiltProjects,
11
- workspaceHost
12
- } from "./chunk-AXQBWV7J.js";
13
- import "./chunk-4QGX7XXO.js";
5
+ resolveRootProjects
6
+ } from "./chunk-XIVHJMET.js";
7
+ import "./chunk-THQ5Y74K.js";
8
+ import "./chunk-THZNJBUF.js";
14
9
  import {
15
10
  AULA_VOICE_WEIGHTS
16
- } from "./chunk-TDAWUJ2L.js";
11
+ } from "./chunk-4FWDTPLR.js";
17
12
  import {
18
- Problems,
19
- bundleProjects,
20
- bundleWorkspace,
21
- projectModules,
22
13
  wrongArgument
23
- } from "./chunk-T6CAPT32.js";
24
- import "./chunk-RAGZAJKD.js";
25
- import {
26
- v8Frames
27
- } from "./chunk-DN2LVJO3.js";
14
+ } from "./chunk-WV2UYZND.js";
15
+ import "./chunk-D5N3QDDF.js";
16
+ import "./chunk-F5RPEFZR.js";
28
17
  import {
29
18
  fault
30
19
  } from "./chunk-VX7UVLQW.js";
31
20
  import "./chunk-CZ7CSFO4.js";
32
21
 
33
22
  // src/site.ts
34
- import { existsSync } from "node:fs";
35
- import os from "node:os";
36
23
  import path from "node:path";
37
- import { fileURLToPath, pathToFileURL } from "node:url";
24
+ import { fileURLToPath } from "node:url";
38
25
  var PAGE = new URL("web/site/", PACKAGE);
39
26
  var PAGE_FOLDER = fileURLToPath(PAGE);
40
27
  var WRITTEN = ["index.html", "assets", "bundle.json", "media", "tree", "tree.json"];
@@ -64,34 +51,6 @@ async function mediaFiles(capabilities, folder, projects) {
64
51
  const inProject = (file) => folders.some((own) => own === "." || file.startsWith(`${own}/`));
65
52
  return (await walk(capabilities, folder)).filter((file) => MEDIA_FILE.test(file) && inProject(file)).toSorted();
66
53
  }
67
- var METHOD_STUB = "export const paragraph = () => () => ({});\n";
68
- async function loadSiteProjects(capabilities, workspaceBundle) {
69
- const scratch = await capabilities.fs.mkdtemp(path.join(os.tmpdir(), "aula-site-videos-"));
70
- let count = 0;
71
- try {
72
- const method = path.join(scratch, "aula-method.mjs");
73
- await capabilities.fs.writeFile(method, METHOD_STUB);
74
- const bundledAula = path.join(path.dirname(fileURLToPath(import.meta.url)), "aula.js");
75
- const player = {
76
- "@beff/aula": existsSync(bundledAula) ? pathToFileURL(bundledAula).href : import.meta.resolve("@beff/aula"),
77
- "@beff/aula-method": pathToFileURL(method).href
78
- };
79
- const modules = {
80
- load: async ({ code }) => {
81
- count += 1;
82
- const file = path.join(scratch, `bundle-${String(count)}.mjs`);
83
- await capabilities.fs.writeFile(file, code);
84
- const url = pathToFileURL(file).href;
85
- return { url, exports: await import(url) };
86
- }
87
- };
88
- const loaded = await loadBuiltProjects(workspaceBundle, workspaceHost(v8Frames), modules, player);
89
- if (loaded._tag === "Left") throw new Problems(loaded.left);
90
- return loaded.right;
91
- } finally {
92
- await capabilities.fs.rm(scratch, { recursive: true, force: true });
93
- }
94
- }
95
54
  var videosOf = (projects) => projects.map(({ name: projectName, title, section }) => ({
96
55
  name: projectName,
97
56
  title,
@@ -108,51 +67,19 @@ var inside = (outer, inner) => {
108
67
  return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
109
68
  };
110
69
  async function site(capabilities, options) {
111
- const { folder, out, title, base } = options;
70
+ const { folder, out, title, base, includeDrafts = false } = options;
112
71
  if (!capabilities.fs.existsSync(folder) || !(await capabilities.fs.stat(folder)).isDirectory()) {
113
- throw wrongArgument(`${folder} is not a folder`, "give the playlist folder: the folder of the projects");
72
+ throw wrongArgument(`${folder} is not a folder`, "give a project or playlist folder");
114
73
  }
115
74
  if (inside(folder, out) || inside(out, folder)) {
116
75
  throw wrongArgument(
117
- "the output folder and the playlist folder hold each other",
118
- "give an output folder that is outside the playlist folder"
119
- );
120
- }
121
- const tree = nodeTree(capabilities, folder);
122
- const folderName = path.basename(folder);
123
- const listed = await projectModules(tree, folderName);
124
- if (listed._tag === "Left") throw new Problems(listed.left);
125
- if (listed.right.length === 0) {
126
- throw wrongArgument(
127
- `no project in ${folder}: run from a project or playlist folder, or pass it (for example: aula site examples site-out)`
76
+ "the output folder and the root folder hold each other",
77
+ "give an output folder that is outside the root folder"
128
78
  );
129
79
  }
130
- const bundler = createNodeBundler();
131
- let workspaceBundle;
132
- let videos;
133
- try {
134
- const bundled = await bundleWorkspace(bundler, tree, folderName);
135
- if (bundled._tag === "Left") throw new Problems(bundled.left);
136
- workspaceBundle = bundled.right.bundle;
137
- const loaded = await loadSiteProjects(capabilities, workspaceBundle);
138
- const published = listedProjects(loaded);
139
- if (published.length === 0) {
140
- throw wrongArgument(
141
- `no published project in ${folder}`,
142
- "give a folder with at least one project that is not draft: true, or open a draft by its folder path"
143
- );
144
- }
145
- if (published.length !== loaded.length) {
146
- const keep = new Set(published.map((project) => project.name));
147
- const filtered = workspaceBundle.projects.filter((project) => keep.has(project.name));
148
- const rebundled = await bundleProjects(bundler, tree, folderName, filtered);
149
- if (rebundled._tag === "Left") throw new Problems(rebundled.left);
150
- workspaceBundle = rebundled.right.bundle;
151
- }
152
- videos = videosOf(published);
153
- } finally {
154
- await bundler.stop();
155
- }
80
+ const { projects, bundle: workspaceBundle } = await resolveRootProjects(capabilities, folder, includeDrafts);
81
+ if (projects.length === 0) return true;
82
+ const videos = videosOf(projects);
156
83
  const media = await mediaFiles(capabilities, folder, workspaceBundle.projects);
157
84
  const bundleJson = JSON.stringify({ ...workspaceBundle, videos, media });
158
85
  const weights = await capabilities.weights();
@@ -0,0 +1,16 @@
1
+ import {
2
+ resolveOneProject,
3
+ resolveRootProjects
4
+ } from "./chunk-XIVHJMET.js";
5
+ import "./chunk-THQ5Y74K.js";
6
+ import "./chunk-THZNJBUF.js";
7
+ import "./chunk-4FWDTPLR.js";
8
+ import "./chunk-WV2UYZND.js";
9
+ import "./chunk-D5N3QDDF.js";
10
+ import "./chunk-F5RPEFZR.js";
11
+ import "./chunk-VX7UVLQW.js";
12
+ import "./chunk-CZ7CSFO4.js";
13
+ export {
14
+ resolveOneProject,
15
+ resolveRootProjects
16
+ };
@@ -0,0 +1,2 @@
1
+ import{r as e,t}from"../rolldown-runtime-BLXQ4ufn.js";import{_ as n,a as r,d as i,f as a,g as o,i as s,l as c,m as l,n as u,o as d,p as f,u as p}from"../protocol-kcdbhuRm.js";import{S as m,g as h,v as g,y as _}from"../src-DWqZcp-P.js";var v=44,y=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,b=new Uint8Array(64),x=new Uint8Array(128);for(let e=0;e<y.length;e++){let t=y.charCodeAt(e);b[e]=t,x[t]=e}function S(e){let t=0,n=0,r=0;do r=x[e.next()],t|=(r&31)<<n,n+=5;while(r&32);return t}function C(e){return e&1?-0x80000000|-(e>>>1):e>>>1}function w(e,t){return e.pos>=t?!1:e.peek()!==v}var ee=class{constructor(e){this.pos=0,this.buffer=e}next(){return this.buffer.charCodeAt(this.pos++)}peek(){return this.buffer.charCodeAt(this.pos)}indexOf(e){let{buffer:t,pos:n}=this,r=t.indexOf(e,n);return r===-1?t.length:r}};function te(e){let{length:t}=e,n=new ee(e),r=[],i=0,a=0,o=0,s=0,c=0;do{let e=n.indexOf(`;`),t=[],l=!0,u=0;for(i=0;n.pos<e;){let r;i+=C(S(n)),i<u&&(l=!1),u=i,w(n,e)?(a+=C(S(n)),o+=C(S(n)),s+=C(S(n)),w(n,e)?(c+=C(S(n)),r=[i,a,o,s,c]):r=[i,a,o,s]):r=[i],t.push(r),n.pos++}l||T(t),r.push(t),n.pos=e+1}while(n.pos<=t);return r}function T(e){e.sort(E)}function E(e,t){return e[0]-t[0]}var ne=e(t(((e,t,n)=>{var r;(function(n,i){typeof e==`object`&&t!==void 0?t.exports=i():typeof r==`function`&&r.amd?r(i):(n=typeof globalThis<`u`?globalThis:n||self,n.resolveURI=i())})(n,(function(){let e=/^[\w+.-]+:\/\//,t=/^([\w+.-]+:)\/\/([^@/#?]*@)?(\[[^\]]+\]|[^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/,n=/^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;function r(t){return e.test(t)}function i(e){return e.startsWith(`//`)}function a(e){return e.startsWith(`/`)}function o(e){return e.startsWith(`file:`)}function s(e){return/^[.?#]/.test(e)}function c(e){let n=t.exec(e);return u(n[1],n[2]||``,n[3],n[4]||``,n[5]||`/`,n[6]||``,n[7]||``)}function l(e){let t=n.exec(e),r=t[2];return u(`file:`,``,t[1]||``,``,a(r)?r:`/`+r,t[3]||``,t[4]||``)}function u(e,t,n,r,i,a,o){return{scheme:e,user:t,host:n,port:r,path:i,query:a,hash:o,type:7}}function d(e){if(i(e)){let t=c(`http:`+e);return t.scheme=``,t.type=6,t}if(a(e)){let t=c(`http://foo.com`+e);return t.scheme=``,t.host=``,t.type=5,t}if(o(e))return l(e);if(r(e))return c(e);let t=c(`http://foo.com/`+e);return t.scheme=``,t.host=``,t.type=e?e.startsWith(`?`)?3:e.startsWith(`#`)?2:4:1,t}function f(e){if(e.endsWith(`/..`))return e;let t=e.lastIndexOf(`/`);return e.slice(0,t+1)}function p(e,t){m(t,t.type),e.path=e.path===`/`?t.path:f(t.path)+e.path}function m(e,t){let n=t<=4,r=e.path.split(`/`),i=1,a=0,o=!1;for(let e=1;e<r.length;e++){let t=r[e];t?(o=!1,t!==`.`&&(t===`..`?a?(o=!0,a--,i--):n&&(r[i++]=t):(r[i++]=t,a++))):o=!0}let s=``;for(let e=1;e<i;e++)s+=`/`+r[e];(!s||o&&!s.endsWith(`/..`))&&(s+=`/`),e.path=s}function h(e,t){if(!e&&!t)return``;let n=d(e),r=n.type;if(t&&r!==7){let e=d(t),i=e.type;switch(r){case 1:n.hash=e.hash;case 2:n.query=e.query;case 3:case 4:p(n,e);case 5:n.user=e.user,n.host=e.host,n.port=e.port;case 6:n.scheme=e.scheme}i>r&&(r=i)}m(n,r);let i=n.query+n.hash;switch(r){case 2:case 3:return i;case 4:{let r=n.path.slice(1);return r?s(t||e)&&!s(r)?`./`+r+i:r+i:i||`.`}case 5:return n.path+i;default:return n.scheme+`//`+n.user+n.host+n.port+n.path+i}}return h}))}))(),1);function D(e){if(!e)return``;let t=e.lastIndexOf(`/`);return e.slice(0,t+1)}function re(e,t){let n=D(e),r=t?t+`/`:``;return e=>(0,ne.default)(r+(e||``),n)}var O=0,ie=1,ae=2,k=3,A=4;function j(e,t){let n=M(e,0);if(n===e.length)return e;t||(e=e.slice());for(let r=n;r<e.length;r=M(e,r+1))e[r]=P(e[r],t);return e}function M(e,t){for(let n=t;n<e.length;n++)if(!N(e[n]))return n;return e.length}function N(e){for(let t=1;t<e.length;t++)if(e[t][O]<e[t-1][O])return!1;return!0}function P(e,t){return t||(e=e.slice()),e.sort(F)}function F(e,t){return e[O]-t[O]}var I=!1;function L(e,t,n,r){for(;n<=r;){let i=n+(r-n>>1),a=e[i][O]-t;if(a===0)return I=!0,i;a<0?n=i+1:r=i-1}return I=!1,n-1}function R(e,t,n){for(let r=n+1;r<e.length&&e[r][O]===t;n=r++);return n}function z(e,t,n){for(let r=n-1;r>=0&&e[r][O]===t;n=r--);return n}function B(){return{lastKey:-1,lastNeedle:-1,lastIndex:-1}}function V(e,t,n,r){let{lastKey:i,lastNeedle:a,lastIndex:o}=n,s=0,c=e.length-1;if(r===i){if(t===a)return I=o!==-1&&e[o][O]===t,o;t>=a?s=o===-1?0:o:c=o}return n.lastKey=r,n.lastNeedle=t,n.lastIndex=L(e,t,s,c)}function H(e){return typeof e==`string`?JSON.parse(e):e}var U="`line` must be greater than 0 (lines start at line 1)",oe="`column` must be greater than or equal to 0 (columns start at column 0)",W=class{constructor(e,t){let n=typeof e==`string`;if(!n&&e._decodedMemo)return e;let r=H(e),{version:i,file:a,names:o,sourceRoot:s,sources:c,sourcesContent:l}=r;this.version=i,this.file=a,this.names=o||[],this.sourceRoot=s,this.sources=c,this.sourcesContent=l,this.ignoreList=r.ignoreList||r.x_google_ignoreList||void 0;let u=re(t,s);this.resolvedSources=c.map(u);let{mappings:d}=r;if(typeof d==`string`)this._encoded=d,this._decoded=void 0;else if(Array.isArray(d))this._encoded=void 0,this._decoded=j(d,n);else if(r.sections)throw Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);else throw Error(`invalid source map: ${JSON.stringify(r)}`);this._decodedMemo=B(),this._bySources=void 0,this._bySourceMemos=void 0}};function G(e){return e}function K(e){var t;return(t=G(e))._decoded||(t._decoded=te(G(e)._encoded))}function q(e,t){let{line:n,column:r,bias:i}=t;if(n--,n<0)throw Error(U);if(r<0)throw Error(oe);let a=K(e);if(n>=a.length)return J(null,null,null,null);let o=a[n],s=se(o,G(e)._decodedMemo,n,r,i||1);if(s===-1)return J(null,null,null,null);let c=o[s];if(c.length===1)return J(null,null,null,null);let{names:l,resolvedSources:u}=e;return J(u[c[ie]],c[ae]+1,c[k],c.length===5?l[c[A]]:null)}function J(e,t,n,r){return{source:e,line:t,column:n,name:r}}function se(e,t,n,r,i){let a=V(e,r,t,n);return I?a=(i===-1?R:z)(e,r,a):i===-1&&a++,a===-1||a===e.length?-1:a}var Y=new Map;function ce(e,t,n){Y.set(e,{map:new W(t),prefix:n})}function le(e,t,n){let r=Y.get(e);if(!r)return{file:e,line:t,column:n};let i=q(r.map,{line:t,column:n-1});return i.source===null||i.line===null||i.column===null?{file:e,line:t,column:n}:{file:i.source.startsWith(r.prefix)?i.source.slice(r.prefix.length):i.source,line:i.line,column:i.column+1}}var X=n(le);function ue(e){let t=0,n=new Map;e.then(e=>{e.addEventListener(`message`,t=>{let i=t.data;if(i.kind===`error`)throw e.close(),new r(`the narrator stopped: ${i.message}`,i.stack);let a=n.get(i.id);n.delete(i.id),a?.(i)}),e.start()});let i=async(r,i)=>{let a=await e;return new Promise(e=>{let o=t++;n.set(o,e),a.postMessage({id:o,kind:r,words:i})})};return{speak:async e=>{let t=await i(`speak`,e);if(t.kind!==`speech`)throw Error(`the narrator answered ${t.kind} to a speech`);return{samples:t.samples,sampleRate:t.sampleRate,words:t.words}},time:async e=>{let t=await i(`time`,e);if(t.kind!==`timing`)throw Error(`the narrator answered ${t.kind} to a clock`);return{samples:t.samples,sampleRate:t.sampleRate,words:t.words}}}}function de(e){let t=0,n=0,r=!1,l=new Map,d=n=>{let r=r=>{let i=t++,{promise:a,resolve:o}=Promise.withResolvers();return l.set(i,o),e.post({kind:`files`,id:i,tree:n,question:r},[]),a};return{bundle:async()=>{let e=await r({kind:`bundle`});if(e.kind!==`bundle`)throw Error(`the page answered ${e.kind} to a question of the bundle`);return e.result},name:async()=>{let e=await r({kind:`name`});if(e.kind!==`name`)throw Error(`the page answered ${e.kind} to a question of the name`);return e.name},read:async e=>{let t=await r({kind:`read`,path:e});if(t.kind!==`read`)throw Error(`the page answered ${t.kind} to a read of ${e}`);return t.text},bytes:async e=>{let t=await r({kind:`bytes`,path:e});if(t.kind!==`bytes`)throw Error(`the page answered ${t.kind} to a read of the bytes of ${e}`);return t.bytes},list:async e=>{let t=await r({kind:`list`,folder:e});if(t.kind!==`list`)throw Error(`the page answered ${t.kind} to a list of ${e}`);return t.names}}},m=async()=>{let t=d(n++),o=new Map,s=new Set,c=e=>{let t=o.get(e);return t===void 0&&s.add(e),t?{size:t.length,read:()=>t}:void 0},[l]=await Promise.all([t.bundle(),_().then(async()=>{await g(),e.post({kind:`stage`,stage:`engine`},[])})]),u,m=!1;if(l!==null){if(l._tag===`Left`)return e.post({kind:`stage`,stage:`project`},[]),l;m=l.right.includeDrafts===!0,u=await i(l.right,f(X,c),e.modules,e.player)}else{let n=await t.name();if(n===null)return e.post({kind:`stage`,stage:`project`},[]),{_tag:`Right`,right:[]};let r={name:()=>Promise.resolve(n),read:t.read,list:t.list},i=await e.bundler();u=await a(r,f(X,c),e.modules,i,e.player)}if(e.post({kind:`stage`,stage:`project`},[]),u._tag===`Left`)return u;u={_tag:`Right`,right:p(u.right,{includeDrafts:m})},r||(r=!0,e.post({kind:`narrator`},[]));let v=async e=>{for(;;){s.clear();let n=e(),r=[...s].filter(e=>!o.has(e));if(r.length===0)return n;await Promise.all(r.map(async e=>o.set(e,await t.bytes(e))))}};return{_tag:`Right`,right:u.right.map(e=>{let t=new Set;return{...e,readScript:async()=>(await h(),v(()=>e.script())),readChapter:async n=>{t.has(n)||(await h(),await v(()=>e.walk?.(n)),t.add(n))}}})}},v=Promise.withResolvers(),y=o(c.create({voice:ue(v.promise),workspace:{projects:m}})),b=[],x=(t,{chapters:n,...r})=>{let i=[],a=[],o=[];n.forEach((e,t)=>{let n=b[t];if(e===n)return;if(!e){i.push([t,void 0]);return}let r=n?.cues.map(e=>e.samples)??[];if(e.animation!==n?.animation){let{animation:n,cues:a,...o}=e,c=a.map(e=>{let t=e.samples?r.indexOf(e.samples):-1;return t===-1?null:t}),l=a.map(({at:e,length:t},n)=>({at:e,length:t,keep:c[n]??null}));i.push([t,{...o,lottie:s(n),cues:l}]),r=c.map(e=>e===null?void 0:r[e])}e.cues.forEach((e,n)=>{if(!e.samples||e.samples===r[n])return;let i=e.samples.slice();o.push(i.buffer),a.push({chapter:t,cue:n,samples:i})})}),b=n;let c={building:r.building,timeline:r.timeline,duration:r.duration,errors:u(r.errors)};e.post({kind:`state`,watch:t,state:c,count:n.length,drawings:i,sounds:a},o)};return t=>{switch(t.kind){case`list`:y.build.list().then(n=>{let r=n._tag===`Left`?{_tag:`Left`,left:u(n.left)}:n;e.post({kind:`listed`,id:t.id,videos:r},[])});return;case`watch`:b=[],y.build.watch(t.name,{changed:e=>{x(t.watch,e)}});return;case`seek`:y.build.seek(t.name,t.place);return;case`halt`:y.halt();return;case`refresh`:y.refresh(t.place);return;case`files`:{let e=l.get(t.id);l.delete(t.id),e?.(t.answer);return}case`narrator`:v.resolve(t.port);return}}}var Z=(e,t=[])=>{self.postMessage(e,{transfer:t})},Q=e=>{let t=d(e,X);Z({kind:`error`,message:t.message,stack:t.stack.map(e=>` ${e}`).join(`
2
+ `)})};self.addEventListener(`error`,e=>{e.preventDefault(),Q(e.error??Error(e.message))}),self.addEventListener(`unhandledrejection`,e=>{e.preventDefault(),Q(e.reason)});var fe={"@beff/aula":new URL(`./aula.js`,import.meta.url).href,"@beff/aula-method":new URL(`./aula-method.js`,import.meta.url).href},pe={load:async({code:e,map:t})=>{let n=URL.createObjectURL(new Blob([e],{type:`text/javascript`}));return ce(n,t,l),{url:n,exports:await import(n)}}},$=null;function me(){return $??=(async()=>{let t=performance.now(),[n,r]=await Promise.all([m(()=>import(`../browser-sNTR4ahh.js`).then(t=>e(t.default,1)),[]),m(()=>import(`../esbuild-D6hmBtXM.js`),[])]);return await n.initialize({wasmURL:r.default,worker:!1}),console.log(`aula: esbuild loaded in ${((performance.now()-t)/1e3).toFixed(1)} s`),n})(),$}var he=de({post:Z,bundler:me,modules:pe,player:fe});self.addEventListener(`message`,e=>{he(e.data)});