jq79 0.5.9 → 0.5.11

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/dist/dev.js CHANGED
@@ -2,11 +2,15 @@
2
2
  import { createServer } from "http";
3
3
  import { readFile, realpath, stat } from "fs/promises";
4
4
  import { watch } from "fs";
5
- import { basename, extname, join, relative, resolve, sep } from "path";
5
+ import { basename, dirname, extname, isAbsolute, join, matchesGlob, relative, resolve, sep } from "path";
6
6
  var CONTENT_TYPES = {
7
7
  ".html": "text/html; charset=utf-8",
8
8
  ".js": "text/javascript; charset=utf-8",
9
9
  ".mjs": "text/javascript; charset=utf-8",
10
+ // the streaming WebAssembly APIs reject every other type, including the
11
+ // default below - a module served as octet-stream still runs, but it is
12
+ // buffered whole instead of compiling as it downloads
13
+ ".wasm": "application/wasm",
10
14
  ".json": "application/json; charset=utf-8",
11
15
  ".css": "text/css; charset=utf-8",
12
16
  ".svg": "image/svg+xml",
@@ -52,6 +56,10 @@ var injectClient = (html) => {
52
56
  var devServer = async (options = {}) => {
53
57
  const root = await realpath(resolve(options.rootDir ?? "."));
54
58
  const host = options.host ?? "localhost";
59
+ const headers = Object.entries(options.headers ?? {}).filter(
60
+ ([name]) => !["content-type", "content-length"].includes(name.toLowerCase())
61
+ );
62
+ const hooks = options.beforeResponse ?? [];
55
63
  const clients = /* @__PURE__ */ new Set();
56
64
  const send = (event, data) => {
57
65
  const frame = `event: ${event}
@@ -60,22 +68,28 @@ data: ${JSON.stringify(data)}
60
68
  `;
61
69
  clients.forEach((client) => client.write(frame));
62
70
  };
71
+ const head = (res, status, own = {}) => {
72
+ res.removeHeader("content-length");
73
+ const write = { ...own };
74
+ if (res.hasHeader("content-type")) delete write["content-type"];
75
+ return res.writeHead(status, write);
76
+ };
63
77
  const serveStatic = async (req, res, pathname) => {
64
78
  let file;
65
79
  try {
66
80
  file = resolve(join(root, decodeURIComponent(pathname)));
67
81
  } catch {
68
- res.writeHead(400).end("bad request");
82
+ head(res, 400).end("bad request");
69
83
  return;
70
84
  }
71
85
  if (file !== root && !file.startsWith(root + sep)) {
72
- res.writeHead(403).end("forbidden");
86
+ head(res, 403).end("forbidden");
73
87
  return;
74
88
  }
75
89
  try {
76
90
  if ((await stat(file)).isDirectory()) {
77
91
  if (!pathname.endsWith("/")) {
78
- res.writeHead(301, { location: pathname + "/" }).end();
92
+ head(res, 301, { location: pathname + "/" }).end();
79
93
  return;
80
94
  }
81
95
  file = join(file, "index.html");
@@ -84,62 +98,135 @@ data: ${JSON.stringify(data)}
84
98
  const type = CONTENT_TYPES[extname(file).toLowerCase()] ?? "application/octet-stream";
85
99
  const html = type.startsWith("text/html") && isDocument(req);
86
100
  const payload = html ? Buffer.from(injectClient(body.toString("utf8"))) : body;
87
- res.writeHead(200, {
88
- "content-type": type,
89
- "content-length": payload.byteLength,
90
- "cache-control": "no-store"
91
- // the file on disk is always the truth here
92
- });
101
+ head(res, 200, { "content-type": type, "content-length": payload.byteLength });
93
102
  res.end(payload);
94
103
  } catch {
95
- res.writeHead(404, { "content-type": "text/plain; charset=utf-8" }).end("not found");
104
+ head(res, 404, { "content-type": "text/plain; charset=utf-8" }).end("not found");
96
105
  }
97
106
  };
98
- const server = createServer((req, res) => {
107
+ const handle = async (req, res) => {
108
+ res.setHeader("cache-control", "no-store");
109
+ for (const [name, value] of headers) res.setHeader(name, value);
110
+ for (const hook of hooks) await hook(req, res);
111
+ if (res.headersSent || res.writableEnded) return;
99
112
  const pathname = (req.url ?? "/").split(/[?#]/)[0];
100
113
  if (pathname === CLIENT_URL) {
101
- res.writeHead(200, { "content-type": "text/javascript; charset=utf-8", "cache-control": "no-store" });
114
+ head(res, 200, { "content-type": "text/javascript; charset=utf-8" });
102
115
  res.end(CLIENT);
103
116
  return;
104
117
  }
105
118
  if (pathname === EVENTS_URL) {
106
- res.writeHead(200, {
107
- "content-type": "text/event-stream",
108
- "cache-control": "no-store",
109
- connection: "keep-alive"
110
- });
119
+ head(res, 200, { "content-type": "text/event-stream", connection: "keep-alive" });
111
120
  res.write(": jq79\n\n");
112
121
  clients.add(res);
113
122
  req.on("close", () => clients.delete(res));
114
123
  return;
115
124
  }
116
- void serveStatic(req, res, pathname);
125
+ await serveStatic(req, res, pathname);
126
+ };
127
+ const server = createServer((req, res) => {
128
+ void handle(req, res).catch((error) => {
129
+ console.error(`jq79 dev: failed to respond to ${req.url}
130
+ `, error);
131
+ if (!res.headersSent) {
132
+ res.removeHeader("content-length");
133
+ res.writeHead(500, { "content-type": "text/plain; charset=utf-8" });
134
+ }
135
+ if (!res.writableEnded) res.end("internal error");
136
+ });
117
137
  });
118
138
  const ignored = (rel) => rel.split(sep).some((part) => part.startsWith(".") || part === "node_modules");
119
139
  const pending = /* @__PURE__ */ new Map();
120
- const changed = async (rel) => {
121
- const file = join(root, rel);
140
+ const cwd = process.cwd();
141
+ const entries = (options.watch ?? []).map((entry) => ({
142
+ patterns: [entry.pattern].flat(),
143
+ fn: entry.fn,
144
+ batch: /* @__PURE__ */ new Set(),
145
+ running: false
146
+ }));
147
+ const claims = (entry, file) => entry.patterns.some(
148
+ (pattern) => matchesGlob(isAbsolute(pattern) ? posix(file) : posix(relative(cwd, file)), pattern)
149
+ );
150
+ const collect = (entry, file) => {
151
+ entry.batch.add(file);
152
+ clearTimeout(entry.timer);
153
+ entry.timer = setTimeout(() => void fire(entry), 30);
154
+ };
155
+ const fire = async (entry) => {
156
+ if (entry.running || !entry.batch.size) return;
157
+ const files = [...entry.batch];
158
+ entry.batch.clear();
159
+ entry.running = true;
160
+ try {
161
+ await entry.fn?.(files);
162
+ } catch (error) {
163
+ console.error(`jq79 dev: watch handler for ${entry.patterns.join(", ")} failed
164
+ `, error);
165
+ } finally {
166
+ entry.running = false;
167
+ if (entry.batch.size) void fire(entry);
168
+ }
169
+ };
170
+ const changed = async (file, dir) => {
171
+ const rel = relative(root, file);
172
+ const served = !!rel && !rel.startsWith("..");
122
173
  let src = null;
123
174
  try {
124
175
  if ((await stat(file)).isDirectory()) return;
125
- if (rel.endsWith(".html")) src = await readFile(file, "utf8");
176
+ if (served && file.endsWith(".html")) src = await readFile(file, "utf8");
126
177
  } catch {
127
- if (rel === basename(root)) return;
178
+ if (file === join(dir, basename(dir))) return;
128
179
  }
129
- const url = "/" + posix(rel);
130
- if (src === null) send("reload", { url });
131
- else send("update", { url, src });
180
+ const claimed = entries.filter((entry) => claims(entry, file));
181
+ claimed.forEach((entry) => entry.fn && collect(entry, file));
182
+ if (served) {
183
+ const url = "/" + posix(rel);
184
+ if (src === null) send("reload", { url });
185
+ else send("update", { url, src });
186
+ return;
187
+ }
188
+ if (claimed.some((entry) => !entry.fn)) send("reload", { url: posix(rel) });
132
189
  };
133
- const watcher = watch(root, { recursive: true }, (_event, filename) => {
134
- if (!filename) return;
135
- const rel = relative(root, resolve(root, filename.toString()));
136
- if (!rel || rel.startsWith("..") || ignored(rel)) return;
137
- clearTimeout(pending.get(rel));
138
- pending.set(rel, setTimeout(() => {
139
- pending.delete(rel);
140
- void changed(rel);
190
+ const queue = (file, dir) => {
191
+ clearTimeout(pending.get(file));
192
+ pending.set(file, setTimeout(() => {
193
+ pending.delete(file);
194
+ void changed(file, dir);
141
195
  }, 30));
142
- });
196
+ };
197
+ const watchers = [];
198
+ const watchTree = (dir, only) => {
199
+ watchers.push(watch(dir, { recursive: !only }, (_event, filename) => {
200
+ if (!filename) return;
201
+ const file = resolve(dir, filename.toString());
202
+ const rel = relative(dir, file);
203
+ if (!rel || rel.startsWith("..")) return;
204
+ if (only ? rel !== only : ignored(rel)) return;
205
+ queue(file, dir);
206
+ }));
207
+ };
208
+ const literalHead = (pattern) => {
209
+ const parts = pattern.split("/");
210
+ const magic = parts.findIndex((part) => /[*?[\]{}!]/.test(part));
211
+ return resolve(magic === -1 ? pattern : parts.slice(0, magic).join("/") || ".");
212
+ };
213
+ const extra = /* @__PURE__ */ new Map();
214
+ for (const entry of entries) {
215
+ for (const [i, pattern] of entry.patterns.entries()) {
216
+ const head2 = literalHead(pattern);
217
+ const info = await stat(head2).catch(() => null);
218
+ if (!info) throw new Error(`jq79 dev: nothing to watch at ${head2}`);
219
+ if (info.isDirectory() && head2 === resolve(pattern)) {
220
+ entry.patterns[i] = pattern.replace(/\/+$/, "") + "/**";
221
+ }
222
+ const real = await realpath(head2);
223
+ if (real === root || real.startsWith(root + sep)) continue;
224
+ const watched = info.isDirectory() ? { dir: real } : { dir: dirname(real), only: basename(real) };
225
+ extra.set(`${watched.dir}\0${watched.only ?? ""}`, watched);
226
+ }
227
+ }
228
+ watchTree(root);
229
+ extra.forEach(({ dir, only }) => watchTree(dir, only));
143
230
  const heartbeat = setInterval(() => clients.forEach((client) => client.write(": ping\n\n")), 3e4);
144
231
  heartbeat.unref();
145
232
  await new Promise((done, fail) => {
@@ -152,8 +239,9 @@ data: ${JSON.stringify(data)}
152
239
  port,
153
240
  close: () => new Promise((done) => {
154
241
  clearInterval(heartbeat);
155
- watcher.close();
242
+ watchers.forEach((watcher) => watcher.close());
156
243
  pending.forEach(clearTimeout);
244
+ entries.forEach((entry) => clearTimeout(entry.timer));
157
245
  clients.forEach((client) => client.end());
158
246
  clients.clear();
159
247
  server.close(() => done());
package/dist/dev.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../dev/dev.ts"],"sourcesContent":["import { createServer, type Server, type IncomingMessage, type ServerResponse } from \"node:http\"\nimport { readFile, realpath, stat } from \"node:fs/promises\"\nimport { watch, type FSWatcher } from \"node:fs\"\nimport { basename, extname, join, relative, resolve, sep } from \"node:path\"\n\n// A dev server for the no-bundle path: serve a directory of .html components\n// over HTTP, watch it, and hot-reload the components that changed.\n//\n// npx jq79 dev // the CLI\n// import { devServer } from \"jq79/dev\" // or from a script\n// await devServer({ rootDir: \".\" })\n//\n// It is a static file server and nothing else - no transforms, no bundling, no\n// module graph. Which is the point: the files it serves are the files you would\n// deploy, so what you develop against and what a static host serves are the same\n// bytes. The one thing it adds is the hot-reload channel, and it adds it to\n// *documents* only (a component fetched by the runtime is served verbatim).\n//\n// The reload is fine-grained. On a change the server pushes the new source down\n// an SSE channel and the runtime swaps it into every live instance of that file,\n// keeping its data - see hotUpdate in jq79.ts. Anything the runtime can't place\n// (a page, a stylesheet, a component nothing has mounted yet) falls back to a\n// full page reload.\n\nexport interface DevServerOptions {\n // the directory to serve, and to watch (default: the current directory)\n rootDir?: string\n // default: 4179, or the first free port after it\n port?: number\n // default: localhost\n host?: string\n}\n\nexport interface DevServer {\n url: string\n port: number\n close: () => Promise<void>\n}\n\nconst CONTENT_TYPES: Record<string, string> = {\n \".html\": \"text/html; charset=utf-8\",\n \".js\": \"text/javascript; charset=utf-8\",\n \".mjs\": \"text/javascript; charset=utf-8\",\n \".json\": \"application/json; charset=utf-8\",\n \".css\": \"text/css; charset=utf-8\",\n \".svg\": \"image/svg+xml\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".webp\": \"image/webp\",\n \".avif\": \"image/avif\",\n \".ico\": \"image/x-icon\",\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".map\": \"application/json; charset=utf-8\",\n}\n\nconst CLIENT_URL = \"/__jq79/client.js\"\nconst EVENTS_URL = \"/__jq79/events\"\n\n// Served as a *classic* script, and injected into the <head>: classic scripts\n// run at parse time and module scripts are deferred, so the flag is set before\n// the page's `import ... from \"jq79\"` evaluates - which is what the runtime\n// waits for before it starts tracking instances. The client can't import the\n// runtime itself: the page's copy may come from a CDN or an import map, and a\n// second copy would have a second, empty registry.\nconst CLIENT = `(() => {\n window.__JQ79_HMR_ENABLED__ = true\n\n const events = new EventSource(${JSON.stringify(EVENTS_URL)})\n\n events.addEventListener(\"update\", event => {\n const { url, src } = JSON.parse(event.data)\n const runtime = window.__JQ79_HMR__\n // no runtime (the page doesn't use jq79), or no live instance from this\n // file (it isn't mounted, or it *is* the page) - nothing to swap into\n const patched = runtime ? runtime.update(url, src) : 0\n if (patched) console.log(\"[jq79] hot-updated \" + url + \" (\" + patched + (patched === 1 ? \" instance)\" : \" instances)\"))\n else location.reload()\n })\n\n events.addEventListener(\"reload\", () => location.reload())\n})()`\n\nconst posix = (path: string) => path.split(sep).join(\"/\")\n\nconst isDocument = (req: IncomingMessage) => req.headers[\"sec-fetch-dest\"] === \"document\"\n\n// the client goes in the <head> so it is the first thing the page runs. A file\n// with neither <head> nor <body> is still a document a browser will render, so\n// fall back to the top of it rather than skipping the injection\nconst injectClient = (html: string): string => {\n const tag = `<script src=\"${CLIENT_URL}\"></script>`\n // (\\s[^>]*)? rather than [^>]*, or <header> would pass for <head>\n const open = /<head(\\s[^>]*)?>/i.exec(html) ?? /<body(\\s[^>]*)?>/i.exec(html)\n if (!open) return tag + html\n const at = open.index + open[0].length\n return html.slice(0, at) + tag + html.slice(at)\n}\n\nexport const devServer = async (options: DevServerOptions = {}): Promise<DevServer> => {\n // the *real* path: the watcher reports what changed relative to the directory\n // it actually opened, so a root reached through a symlink (/tmp and /var are\n // symlinks on macOS) would hand back paths that don't line up with it\n const root = await realpath(resolve(options.rootDir ?? \".\"))\n const host = options.host ?? \"localhost\"\n\n const clients = new Set<ServerResponse>()\n\n const send = (event: string, data: unknown) => {\n const frame = `event: ${event}\\ndata: ${JSON.stringify(data)}\\n\\n`\n clients.forEach(client => client.write(frame))\n }\n\n // --- serving ---------------------------------------------------------------\n\n const serveStatic = async (req: IncomingMessage, res: ServerResponse, pathname: string) => {\n // a URL path is not a file path: decode it, then keep the result inside the\n // root (\"..\" in a request must not walk out of the served directory)\n let file: string\n try {\n file = resolve(join(root, decodeURIComponent(pathname)))\n } catch {\n res.writeHead(400).end(\"bad request\")\n return\n }\n if (file !== root && !file.startsWith(root + sep)) {\n res.writeHead(403).end(\"forbidden\")\n return\n }\n\n try {\n if ((await stat(file)).isDirectory()) {\n // a directory is served through its trailing-slash URL, like every\n // static host: /docs rendered as-is would resolve its relative links\n // against the parent (\"img.png\" -> /img.png instead of /docs/img.png)\n if (!pathname.endsWith(\"/\")) {\n res.writeHead(301, { location: pathname + \"/\" }).end()\n return\n }\n file = join(file, \"index.html\")\n }\n const body = await readFile(file)\n const type = CONTENT_TYPES[extname(file).toLowerCase()] ?? \"application/octet-stream\"\n\n // only a navigation gets the hot-reload client. A component is fetched by\n // the runtime (sec-fetch-dest: empty), and it must arrive as written -\n // injecting a <script> into it would make the runtime parse and run it\n const html = type.startsWith(\"text/html\") && isDocument(req)\n const payload = html ? Buffer.from(injectClient(body.toString(\"utf8\"))) : body\n\n res.writeHead(200, {\n \"content-type\": type,\n \"content-length\": payload.byteLength,\n \"cache-control\": \"no-store\", // the file on disk is always the truth here\n })\n res.end(payload)\n } catch {\n res.writeHead(404, { \"content-type\": \"text/plain; charset=utf-8\" }).end(\"not found\")\n }\n }\n\n const server: Server = createServer((req, res) => {\n const pathname = (req.url ?? \"/\").split(/[?#]/)[0]\n\n if (pathname === CLIENT_URL) {\n res.writeHead(200, { \"content-type\": \"text/javascript; charset=utf-8\", \"cache-control\": \"no-store\" })\n res.end(CLIENT)\n return\n }\n\n if (pathname === EVENTS_URL) {\n res.writeHead(200, {\n \"content-type\": \"text/event-stream\",\n \"cache-control\": \"no-store\",\n connection: \"keep-alive\",\n })\n res.write(\": jq79\\n\\n\") // opens the stream, so the browser fires onopen\n clients.add(res)\n req.on(\"close\", () => clients.delete(res))\n return\n }\n\n void serveStatic(req, res, pathname)\n })\n\n // --- watching --------------------------------------------------------------\n\n const ignored = (rel: string) =>\n rel.split(sep).some(part => part.startsWith(\".\") || part === \"node_modules\")\n\n // one save can arrive as several events (a rename plus a change, an editor's\n // atomic write); collapsing per file keeps that down to one push\n const pending = new Map<string, NodeJS.Timeout>()\n\n const changed = async (rel: string) => {\n const file = join(root, rel)\n\n let src: string | null = null\n try {\n // a directory changes whenever anything inside it does, and the event for\n // the file itself is already on its way - acting on both would reload the\n // page every time a component is saved\n if ((await stat(file)).isDirectory()) return\n if (rel.endsWith(\".html\")) src = await readFile(file, \"utf8\")\n } catch {\n // gone: deleted, or renamed away - and there is nothing to swap in, so the\n // page has to reload. Unless it was never there: macOS reports a change to\n // the watched directory *itself* under its own basename, which resolves to\n // a path inside it that does not exist\n if (rel === basename(root)) return\n }\n\n // the url is the one the component was served from, because that is what the\n // runtime resolves its instances' filenames against\n const url = \"/\" + posix(rel)\n if (src === null) send(\"reload\", { url })\n else send(\"update\", { url, src })\n }\n\n const watcher: FSWatcher = watch(root, { recursive: true }, (_event, filename) => {\n if (!filename) return\n const rel = relative(root, resolve(root, filename.toString()))\n if (!rel || rel.startsWith(\"..\") || ignored(rel)) return\n\n clearTimeout(pending.get(rel))\n pending.set(rel, setTimeout(() => {\n pending.delete(rel)\n void changed(rel)\n }, 30))\n })\n\n // proxies and load balancers cut an idle stream; a comment every 30s is the\n // conventional way to keep it open. unref'd, so it never holds the process up\n const heartbeat = setInterval(() => clients.forEach(client => client.write(\": ping\\n\\n\")), 30_000)\n heartbeat.unref()\n\n // --- go --------------------------------------------------------------------\n\n await new Promise<void>((done, fail) => {\n server.once(\"error\", fail)\n server.listen(options.port ?? 4179, host, done)\n })\n const { port } = server.address() as { port: number }\n\n return {\n url: `http://${host}:${port}`,\n port,\n close: () =>\n new Promise(done => {\n clearInterval(heartbeat)\n watcher.close()\n pending.forEach(clearTimeout)\n clients.forEach(client => client.end())\n clients.clear()\n server.close(() => done())\n }),\n }\n}\n\nexport default devServer\n"],"mappings":";AAAA,SAAS,oBAA4E;AACrF,SAAS,UAAU,UAAU,YAAY;AACzC,SAAS,aAA6B;AACtC,SAAS,UAAU,SAAS,MAAM,UAAU,SAAS,WAAW;AAoChE,IAAM,gBAAwC;AAAA,EAC5C,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EAC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QAAM,IAAI,QAAc,CAAC,MAAM,SAAS;AACtC,WAAO,KAAK,SAAS,IAAI;AACzB,WAAO,OAAO,QAAQ,QAAQ,MAAM,MAAM,IAAI;AAAA,EAChD,CAAC;AACD,QAAM,EAAE,KAAK,IAAI,OAAO,QAAQ;AAEhC,SAAO;AAAA,IACL,KAAK,UAAU,IAAI,IAAI,IAAI;AAAA,IAC3B;AAAA,IACA,OAAO,MACL,IAAI,QAAQ,UAAQ;AAClB,oBAAc,SAAS;AACvB,cAAQ,MAAM;AACd,cAAQ,QAAQ,YAAY;AAC5B,cAAQ,QAAQ,YAAU,OAAO,IAAI,CAAC;AACtC,cAAQ,MAAM;AACd,aAAO,MAAM,MAAM,KAAK,CAAC;AAAA,IAC3B,CAAC;AAAA,EACL;AACF;AAEA,IAAO,cAAQ;","names":[]}
1
+ {"version":3,"sources":["../dev/dev.ts"],"sourcesContent":["import { createServer, type Server, type IncomingMessage, type ServerResponse } from \"node:http\"\nimport { readFile, realpath, stat } from \"node:fs/promises\"\nimport { watch, type FSWatcher } from \"node:fs\"\nimport { basename, dirname, extname, isAbsolute, join, matchesGlob, relative, resolve, sep } from \"node:path\"\n\n// A dev server for the no-bundle path: serve a directory of .html components\n// over HTTP, watch it, and hot-reload the components that changed.\n//\n// npx jq79 dev // the CLI\n// import { devServer } from \"jq79/dev\" // or from a script\n// await devServer({ rootDir: \".\" })\n//\n// It is a static file server and nothing else - no transforms, no bundling, no\n// module graph. Which is the point: the files it serves are the files you would\n// deploy, so what you develop against and what a static host serves are the same\n// bytes. The one thing it adds is the hot-reload channel, and it adds it to\n// *documents* only (a component fetched by the runtime is served verbatim).\n//\n// The reload is fine-grained. On a change the server pushes the new source down\n// an SSE channel and the runtime swaps it into every live instance of that file,\n// keeping its data - see hotUpdate in jq79.ts. Anything the runtime can't place\n// (a page, a stylesheet, a component nothing has mounted yet) falls back to a\n// full page reload.\n\nexport interface DevServerOptions {\n // the directory to serve, and to watch (default: the current directory)\n rootDir?: string\n // default: 4179, or the first free port after it\n port?: number\n // default: localhost\n host?: string\n // response headers to send on everything - a static host is configured, and\n // these are that configuration (default: none)\n headers?: Record<string, string>\n // the same thing per request: a hook gets the request and its response before\n // anything has been written to it (default: none)\n beforeResponse?: ResponseHook[]\n // what to watch on top of rootDir, and what to do about it (default: none)\n watch?: WatchEntry[]\n}\n\n// runs on every response the server makes - a page, a component, the client,\n// the event stream, a 404 - with nothing written yet, so `res.setHeader` still\n// applies. A hook that answers the request itself (`res.end`) is left alone\nexport type ResponseHook = (req: IncomingMessage, res: ServerResponse) => void | Promise<void>\n\n// the handler gets every file of the burst that woke it, absolute, so a save\n// that touches three of them is one build rather than three\nexport type WatchHandler = (files: string[]) => void | Promise<void>\n\nexport interface WatchEntry {\n // glob(s) resolved against the cwd, like rootDir: \"styles/**/*.scss\". A bare\n // directory means everything under it\n pattern: string | string[]\n // what a match runs. Without one, a match outside the served root reloads the\n // page - which is the only other thing a file served from nowhere can do\n fn?: WatchHandler\n}\n\nexport interface DevServer {\n url: string\n port: number\n close: () => Promise<void>\n}\n\nconst CONTENT_TYPES: Record<string, string> = {\n \".html\": \"text/html; charset=utf-8\",\n \".js\": \"text/javascript; charset=utf-8\",\n \".mjs\": \"text/javascript; charset=utf-8\",\n // the streaming WebAssembly APIs reject every other type, including the\n // default below - a module served as octet-stream still runs, but it is\n // buffered whole instead of compiling as it downloads\n \".wasm\": \"application/wasm\",\n \".json\": \"application/json; charset=utf-8\",\n \".css\": \"text/css; charset=utf-8\",\n \".svg\": \"image/svg+xml\",\n \".png\": \"image/png\",\n \".jpg\": \"image/jpeg\",\n \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\",\n \".webp\": \"image/webp\",\n \".avif\": \"image/avif\",\n \".ico\": \"image/x-icon\",\n \".woff\": \"font/woff\",\n \".woff2\": \"font/woff2\",\n \".map\": \"application/json; charset=utf-8\",\n}\n\nconst CLIENT_URL = \"/__jq79/client.js\"\nconst EVENTS_URL = \"/__jq79/events\"\n\n// Served as a *classic* script, and injected into the <head>: classic scripts\n// run at parse time and module scripts are deferred, so the flag is set before\n// the page's `import ... from \"jq79\"` evaluates - which is what the runtime\n// waits for before it starts tracking instances. The client can't import the\n// runtime itself: the page's copy may come from a CDN or an import map, and a\n// second copy would have a second, empty registry.\nconst CLIENT = `(() => {\n window.__JQ79_HMR_ENABLED__ = true\n\n const events = new EventSource(${JSON.stringify(EVENTS_URL)})\n\n events.addEventListener(\"update\", event => {\n const { url, src } = JSON.parse(event.data)\n const runtime = window.__JQ79_HMR__\n // no runtime (the page doesn't use jq79), or no live instance from this\n // file (it isn't mounted, or it *is* the page) - nothing to swap into\n const patched = runtime ? runtime.update(url, src) : 0\n if (patched) console.log(\"[jq79] hot-updated \" + url + \" (\" + patched + (patched === 1 ? \" instance)\" : \" instances)\"))\n else location.reload()\n })\n\n events.addEventListener(\"reload\", () => location.reload())\n})()`\n\nconst posix = (path: string) => path.split(sep).join(\"/\")\n\nconst isDocument = (req: IncomingMessage) => req.headers[\"sec-fetch-dest\"] === \"document\"\n\n// the client goes in the <head> so it is the first thing the page runs. A file\n// with neither <head> nor <body> is still a document a browser will render, so\n// fall back to the top of it rather than skipping the injection\nconst injectClient = (html: string): string => {\n const tag = `<script src=\"${CLIENT_URL}\"></script>`\n // (\\s[^>]*)? rather than [^>]*, or <header> would pass for <head>\n const open = /<head(\\s[^>]*)?>/i.exec(html) ?? /<body(\\s[^>]*)?>/i.exec(html)\n if (!open) return tag + html\n const at = open.index + open[0].length\n return html.slice(0, at) + tag + html.slice(at)\n}\n\nexport const devServer = async (options: DevServerOptions = {}): Promise<DevServer> => {\n // the *real* path: the watcher reports what changed relative to the directory\n // it actually opened, so a root reached through a symlink (/tmp and /var are\n // symlinks on macOS) would hand back paths that don't line up with it\n const root = await realpath(resolve(options.rootDir ?? \".\"))\n const host = options.host ?? \"localhost\"\n\n // a configured header goes on every response, which is the one thing\n // content-type and content-length cannot do - each describes the bytes of a\n // single response. Dropped here rather than at write time, so that either of\n // them still standing by then can only have come from a hook, which saw the\n // request and is entitled to say\n const headers = Object.entries(options.headers ?? {}).filter(\n ([name]) => ![\"content-type\", \"content-length\"].includes(name.toLowerCase()),\n )\n const hooks = options.beforeResponse ?? []\n\n const clients = new Set<ServerResponse>()\n\n const send = (event: string, data: unknown) => {\n const frame = `event: ${event}\\ndata: ${JSON.stringify(data)}\\n\\n`\n clients.forEach(client => client.write(frame))\n }\n\n // --- serving ---------------------------------------------------------------\n\n // what the response says about its own bytes, written last so the layers\n // below can't contradict it. A hook is the one exception: it saw the request,\n // so it is entitled to an opinion about what these bytes *are* - never about\n // how many there are, since a wrong content-length truncates the body or\n // hangs the socket\n const head = (res: ServerResponse, status: number, own: Record<string, string | number> = {}) => {\n res.removeHeader(\"content-length\")\n const write = { ...own }\n if (res.hasHeader(\"content-type\")) delete write[\"content-type\"]\n return res.writeHead(status, write)\n }\n\n const serveStatic = async (req: IncomingMessage, res: ServerResponse, pathname: string) => {\n // a URL path is not a file path: decode it, then keep the result inside the\n // root (\"..\" in a request must not walk out of the served directory)\n let file: string\n try {\n file = resolve(join(root, decodeURIComponent(pathname)))\n } catch {\n head(res, 400).end(\"bad request\")\n return\n }\n if (file !== root && !file.startsWith(root + sep)) {\n head(res, 403).end(\"forbidden\")\n return\n }\n\n try {\n if ((await stat(file)).isDirectory()) {\n // a directory is served through its trailing-slash URL, like every\n // static host: /docs rendered as-is would resolve its relative links\n // against the parent (\"img.png\" -> /img.png instead of /docs/img.png)\n if (!pathname.endsWith(\"/\")) {\n head(res, 301, { location: pathname + \"/\" }).end()\n return\n }\n file = join(file, \"index.html\")\n }\n const body = await readFile(file)\n const type = CONTENT_TYPES[extname(file).toLowerCase()] ?? \"application/octet-stream\"\n\n // only a navigation gets the hot-reload client. A component is fetched by\n // the runtime (sec-fetch-dest: empty), and it must arrive as written -\n // injecting a <script> into it would make the runtime parse and run it\n const html = type.startsWith(\"text/html\") && isDocument(req)\n const payload = html ? Buffer.from(injectClient(body.toString(\"utf8\"))) : body\n\n head(res, 200, { \"content-type\": type, \"content-length\": payload.byteLength })\n res.end(payload)\n } catch {\n head(res, 404, { \"content-type\": \"text/plain; charset=utf-8\" }).end(\"not found\")\n }\n }\n\n // three layers, general to specific, each one free to replace the last: the\n // server's own defaults, the configured headers over them, and a hook - which\n // saw the request - over those. They go on with setHeader rather than into an\n // object, because setHeader is case-insensitive where an object is not: a\n // \"Cache-Control\" replaces the cache-control below it instead of arriving\n // beside it, and the same goes for whatever a hook names\n const handle = async (req: IncomingMessage, res: ServerResponse) => {\n res.setHeader(\"cache-control\", \"no-store\") // the file on disk is always the truth here\n for (const [name, value] of headers) res.setHeader(name, value)\n for (const hook of hooks) await hook(req, res)\n\n // a hook can answer the request itself, and one that did needs nothing else\n if (res.headersSent || res.writableEnded) return\n\n const pathname = (req.url ?? \"/\").split(/[?#]/)[0]\n\n if (pathname === CLIENT_URL) {\n head(res, 200, { \"content-type\": \"text/javascript; charset=utf-8\" })\n res.end(CLIENT)\n return\n }\n\n if (pathname === EVENTS_URL) {\n head(res, 200, { \"content-type\": \"text/event-stream\", connection: \"keep-alive\" })\n res.write(\": jq79\\n\\n\") // opens the stream, so the browser fires onopen\n clients.add(res)\n req.on(\"close\", () => clients.delete(res))\n return\n }\n\n await serveStatic(req, res, pathname)\n }\n\n const server: Server = createServer((req, res) => {\n // a hook is someone's code, and the watch handlers already settled what that\n // means around here: report it and stay up. This one owes the browser a\n // reply as well, because a socket nobody answers hangs the page\n void handle(req, res).catch(error => {\n console.error(`jq79 dev: failed to respond to ${req.url}\\n`, error)\n if (!res.headersSent) {\n // whatever the hook had said about the bytes, it is not what is being\n // sent now - and a content-length it set before throwing would hang this\n res.removeHeader(\"content-length\")\n res.writeHead(500, { \"content-type\": \"text/plain; charset=utf-8\" })\n }\n if (!res.writableEnded) res.end(\"internal error\")\n })\n })\n\n // --- watching --------------------------------------------------------------\n\n const ignored = (rel: string) =>\n rel.split(sep).some(part => part.startsWith(\".\") || part === \"node_modules\")\n\n // one save can arrive as several events (a rename plus a change, an editor's\n // atomic write); collapsing per file keeps that down to one push\n const pending = new Map<string, NodeJS.Timeout>()\n\n // a pattern is written against the cwd (`resolve` reads it the same way), and\n // captured here so a later chdir can't move what the globs mean\n const cwd = process.cwd()\n\n type Entry = {\n patterns: string[]\n fn?: WatchHandler\n batch: Set<string>\n timer?: NodeJS.Timeout\n running: boolean\n }\n\n const entries: Entry[] = (options.watch ?? []).map(entry => ({\n patterns: [entry.pattern].flat(),\n fn: entry.fn,\n batch: new Set(),\n running: false,\n }))\n\n const claims = (entry: Entry, file: string) =>\n entry.patterns.some(pattern =>\n matchesGlob(isAbsolute(pattern) ? posix(file) : posix(relative(cwd, file)), pattern),\n )\n\n // a burst is one call: the handler is a build step, and building once per file\n // of a save that touched four is three builds nobody asked for\n const collect = (entry: Entry, file: string) => {\n entry.batch.add(file)\n clearTimeout(entry.timer)\n entry.timer = setTimeout(() => void fire(entry), 30)\n }\n\n const fire = async (entry: Entry) => {\n if (entry.running || !entry.batch.size) return\n const files = [...entry.batch]\n entry.batch.clear()\n entry.running = true\n try {\n await entry.fn?.(files)\n } catch (error) {\n // a handler is someone's build script, and a build that fails is a normal\n // morning. Reporting it and staying up beats taking the server with it\n console.error(`jq79 dev: watch handler for ${entry.patterns.join(\", \")} failed\\n`, error)\n } finally {\n entry.running = false\n if (entry.batch.size) void fire(entry) // saved again while it ran\n }\n }\n\n // `dir` is the directory whose watcher reported this - only needed for the\n // macOS quirk below, and only when the file turns out not to exist\n const changed = async (file: string, dir: string) => {\n // where the browser knows the file from, which only exists for a file under\n // the served root: a watched path outside it is served from nowhere, so\n // there is no url for the runtime to match an instance against\n const rel = relative(root, file)\n const served = !!rel && !rel.startsWith(\"..\")\n\n let src: string | null = null\n try {\n // a directory changes whenever anything inside it does, and the event for\n // the file itself is already on its way - acting on both would reload the\n // page every time a component is saved\n if ((await stat(file)).isDirectory()) return\n if (served && file.endsWith(\".html\")) src = await readFile(file, \"utf8\")\n } catch {\n // gone: deleted, or renamed away - and there is nothing to swap in, so the\n // page has to reload. Unless it was never there: macOS reports a change to\n // a watched directory *itself* under its own basename, which resolves to a\n // path inside it that does not exist\n if (file === join(dir, basename(dir))) return\n }\n\n // every entry that names this file gets it, wherever the file lives. What\n // the root does with its own files is not up for negotiation: no pattern can\n // switch hot reload off, so a handler can never cost you the thing you came\n // for by matching more than its author meant it to\n const claimed = entries.filter(entry => claims(entry, file))\n claimed.forEach(entry => entry.fn && collect(entry, file))\n\n if (served) {\n // the url is the one the component was served from, because that is what\n // the runtime resolves its instances' filenames against\n const url = \"/\" + posix(rel)\n if (src === null) send(\"reload\", { url })\n else send(\"update\", { url, src })\n return\n }\n\n // outside the root a handler *is* the answer: it ran, and whatever it writes\n // into the served directory comes back round as a change of its own, with a\n // url. An entry with no handler is asking for the page, and gets a path\n // relative to the root - the client only logs it, and an absolute one would\n // publish the machine's layout to the page\n if (claimed.some(entry => !entry.fn)) send(\"reload\", { url: posix(rel) })\n }\n\n const queue = (file: string, dir: string) => {\n clearTimeout(pending.get(file))\n pending.set(file, setTimeout(() => {\n pending.delete(file)\n void changed(file, dir)\n }, 30))\n }\n\n const watchers: FSWatcher[] = []\n\n // a directory is watched whole. A single file is watched through the directory\n // it sits in (`only` filtering the rest back out), because a watcher on a file\n // holds its inode, and an editor's atomic save renames a new one over it - the\n // watcher survives as a handle on a file nothing will ever write to again\n const watchTree = (dir: string, only?: string) => {\n watchers.push(watch(dir, { recursive: !only }, (_event, filename) => {\n if (!filename) return\n const file = resolve(dir, filename.toString())\n const rel = relative(dir, file)\n if (!rel || rel.startsWith(\"..\")) return\n if (only ? rel !== only : ignored(rel)) return\n queue(file, dir)\n }))\n }\n\n // a glob is a filter and a watcher needs a directory to open, so the watch\n // starts at the literal head of the pattern - everything before the first\n // magic character. \"styles/**/*.scss\" opens styles/, \"**/*.scss\" opens the cwd\n const literalHead = (pattern: string) => {\n const parts = pattern.split(\"/\")\n const magic = parts.findIndex(part => /[*?[\\]{}!]/.test(part))\n return resolve(magic === -1 ? pattern : parts.slice(0, magic).join(\"/\") || \".\")\n }\n\n // the patterns are resolved like rootDir, against the cwd, and all checked\n // before anything is watched: a path that isn't there is a typo, and a watcher\n // that silently isn't running is worse than a server that won't start\n const extra = new Map<string, { dir: string; only?: string }>()\n for (const entry of entries) {\n for (const [i, pattern] of entry.patterns.entries()) {\n const head = literalHead(pattern)\n const info = await stat(head).catch(() => null)\n if (!info) throw new Error(`jq79 dev: nothing to watch at ${head}`)\n\n // a bare directory means everything under it, which is what it looks like\n // it means - as a pattern it would watch the directory and match nothing\n // in it, and the mistake is invisible until a save doesn't fire\n if (info.isDirectory() && head === resolve(pattern)) {\n entry.patterns[i] = pattern.replace(/\\/+$/, \"\") + \"/**\"\n }\n\n // real paths on both sides, so a symlink pointing out of the root reads as\n // what it is - outside, and not covered by the recursive watch below\n const real = await realpath(head)\n if (real === root || real.startsWith(root + sep)) continue // already watched\n const watched = info.isDirectory() ? { dir: real } : { dir: dirname(real), only: basename(real) }\n extra.set(`${watched.dir}\\0${watched.only ?? \"\"}`, watched) // two patterns can share a head\n }\n }\n\n watchTree(root)\n extra.forEach(({ dir, only }) => watchTree(dir, only))\n\n // proxies and load balancers cut an idle stream; a comment every 30s is the\n // conventional way to keep it open. unref'd, so it never holds the process up\n const heartbeat = setInterval(() => clients.forEach(client => client.write(\": ping\\n\\n\")), 30_000)\n heartbeat.unref()\n\n // --- go --------------------------------------------------------------------\n\n await new Promise<void>((done, fail) => {\n server.once(\"error\", fail)\n server.listen(options.port ?? 4179, host, done)\n })\n const { port } = server.address() as { port: number }\n\n return {\n url: `http://${host}:${port}`,\n port,\n close: () =>\n new Promise(done => {\n clearInterval(heartbeat)\n watchers.forEach(watcher => watcher.close())\n pending.forEach(clearTimeout)\n entries.forEach(entry => clearTimeout(entry.timer))\n clients.forEach(client => client.end())\n clients.clear()\n server.close(() => done())\n }),\n }\n}\n\nexport default devServer\n"],"mappings":";AAAA,SAAS,oBAA4E;AACrF,SAAS,UAAU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EAAE,KAAK,KAAK,MAAM,UAAU,KAAK,IAAI,CAAC;AAIrD,QAAM,YAAY,YAAY,MAAM,QAAQ,QAAQ,YAAU,OAAO,MAAM,YAAY,CAAC,GAAG,GAAM;AACjG,YAAU,MAAM;AAIhB,QAAM,IAAI,QAAc,CAAC,MAAM,SAAS;AACtC,WAAO,KAAK,SAAS,IAAI;AACzB,WAAO,OAAO,QAAQ,QAAQ,MAAM,MAAM,IAAI;AAAA,EAChD,CAAC;AACD,QAAM,EAAE,KAAK,IAAI,OAAO,QAAQ;AAEhC,SAAO;AAAA,IACL,KAAK,UAAU,IAAI,IAAI,IAAI;AAAA,IAC3B;AAAA,IACA,OAAO,MACL,IAAI,QAAQ,UAAQ;AAClB,oBAAc,SAAS;AACvB,eAAS,QAAQ,aAAW,QAAQ,MAAM,CAAC;AAC3C,cAAQ,QAAQ,YAAY;AAC5B,cAAQ,QAAQ,WAAS,aAAa,MAAM,KAAK,CAAC;AAClD,cAAQ,QAAQ,YAAU,OAAO,IAAI,CAAC;AACtC,cAAQ,MAAM;AACd,aAAO,MAAM,MAAM,KAAK,CAAC;AAAA,IAC3B,CAAC;AAAA,EACL;AACF;AAEA,IAAO,cAAQ;","names":["head"]}
package/dist/jq79.cjs CHANGED
@@ -4,7 +4,7 @@ var ie=Object.defineProperty;var qt=Object.getOwnPropertyDescriptor;var It=Objec
4
4
  `){let o=de(e,s+1);if(!(o<e.length&&(tn.test(e.slice(o,o+2))||[",","="].includes(nn(e,s)))))return s;s=o;continue}}s++}return e.length},sn=e=>{let t=[],n=0,s=0,r=0,o=a=>{t.push({raw:e.slice(s,a),codeEnd:Math.max(0,r-s)}),s=a+1,r=s},i=0;for(;i<e.length;){let a=e[i];if(a==="'"||a==='"'||a==="`"){i=I(e,i),r=i;continue}if(a==="/"&&e[i+1]==="/"){i=D(e,i);continue}if(a==="/"&&e[i+1]==="*"){i=k(e,i);continue}if(a==="/"&&W(e,i)){i=U(e,i),r=i;continue}if("([{".includes(a))n++;else if(")]}".includes(a))n--;else if(a===","&&n<=0){o(i),i++;continue}/\s/.test(a)||(r=i+1),i++}return o(e.length),t},Te=e=>{let t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return he.test(t)?[t]:[];let n=[];for(let s of _e(t.slice(1,rt(t)))){s.startsWith("...")&&(s=s.slice(3).trim());let r=Ce(s);if(r!==-1&&(s=s.slice(0,r).trim()),t.startsWith("{")){let o=xe(s,":");if(o!==-1){n.push(...Te(s.slice(o+1)));continue}}n.push(...Te(s))}return n},rn=e=>{let t=[],n=sn(e).map(({raw:o,codeEnd:i})=>{let a=o.match(/^\s*/)[0];if(i<=a.length)return{text:o,empty:!0};let l=o.slice(a.length,i),p=o.slice(i),u=Ce(l),g=(u===-1?l:l.slice(0,u)).trim(),R=l[0]==="{"||l[0]==="[";R?t.push(...Te(g)):he.test(g)&&t.push(g);let j=ge(l).code;return{text:`${a}${R?`(${j})`:j}${p}`,empty:!1}}),s=[];for(;n.length&&n[n.length-1].empty;)s.unshift(n.pop().text);let r=n.map(o=>o.text).join(",")+s.join("");return r.trimStart().startsWith("(")&&(r=`;${r}`),{vars:t,code:r}},ge=e=>{let t=[],n="",s=0,r=0,o=!0;for(;s<e.length;){let i=e[s],a=e[s+1];if(i==="'"||i==='"'||i==="`"){let l=I(e,s);n+=e.slice(s,l),s=l,o=!1;continue}if(i==="/"&&(a==="/"||a==="*")){let l=a==="/"?D(e,s):k(e,s);n+=e.slice(s,l),s=l;continue}if(i==="/"&&W(e,s)){let l=U(e,s);n+=e.slice(s,l),s=l,o=!1;continue}if(i==="i"&&(s===0||!/[\w$.]/.test(e[s-1]))&&(fe.lastIndex=s,fe.test(e))){n+="$__import",s+=6,o=!1;continue}if(r===0&&o){Ye.lastIndex=s;let l=Ye.exec(e);if(l){let u=s+l[0].length,g=nt(e,u),{vars:R,code:j}=rn(e.slice(u,g));t.push(...R),n+=j,s=g,o=!1;continue}et.lastIndex=s;let p=et.exec(e);if(p){tt.lastIndex=s;let u=tt.exec(e);u&&t.push(u[1]);let g=s+p[0].length,R=nt(e,g);n+=`$__effect(() => { ${ge(e.slice(g,R)).code} });`,s=R;continue}}"([{".includes(i)?r++:")]}".includes(i)&&(r=Math.max(0,r-1)),i===`
5
5
  `||i===";"||i==="}"?o=!0:/\s/.test(i)||(o=!1),n+=i,s++}return{vars:t,code:n}},pe=/export\s+default(?![\w$])/y,st=/import\s*(?:([\w$\s,{}*]+?)\s*from\s*)?(["'])([^"'\n]+)\2/y,on=e=>{let t=[],n=0,s=0;for(let r=0;r<=e.length;r++){let o=e[r];if(o==="{")n++;else if(o==="}")n--;else if(r===e.length||o===","&&n===0){let i=e.slice(s,r).trim();i&&t.push(i),s=r+1}}return t},an=(e,t,n)=>{let s=`await $__import(${JSON.stringify(t)})`;if(e===void 0)return s;let r=on(e),o=[],i=s;if(r.length>1){let a=`$__mod${n}`;o.push(`${a} = ${s}`),i=a}for(let a of r)a.startsWith("{")?o.push(`${a.replace(/\s+as\s+/g,": ")} = ${i}`):a.startsWith("*")?o.push(`${a.replace(/^\*\s*as\s+/,"")} = ${i}`):o.push(`${a} = $__default(${i})`);return`const ${o.join(", ")}`},he=/^[A-Za-z_$][\w$]*$/,rt=e=>{let t=0,n=0;for(;n<e.length;){let s=e[n];if(s==="'"||s==='"'||s==="`"){n=I(e,n);continue}if(s==="/"&&e[n+1]==="/"){n=D(e,n);continue}if(s==="/"&&e[n+1]==="*"){n=k(e,n);continue}if(s==="/"&&W(e,n)){n=U(e,n);continue}if("([{".includes(s))t++;else if(")]}".includes(s)&&--t===0)return n;n++}return e.length},xe=(e,t)=>{let n=0,s=0;for(;s<e.length;){let r=e[s];if(r==="'"||r==='"'||r==="`"){s=I(e,s);continue}if(r==="/"&&e[s+1]==="/"){s=D(e,s);continue}if(r==="/"&&e[s+1]==="*"){s=k(e,s);continue}if(r==="/"&&r!==t&&W(e,s)){s=U(e,s);continue}if("([{".includes(r))n++;else if(")]}".includes(r))n--;else if(n===0&&r===t)return s;s++}return-1},_e=e=>{let t=[],n=0,s=0,r=0;for(;r<=e.length;){let o=e[r];if(o==="'"||o==='"'||o==="`"){r=I(e,r);continue}if(o==="/"&&e[r+1]==="/"){r=D(e,r);continue}if(o==="/"&&e[r+1]==="*"){r=k(e,r);continue}if(o==="/"&&W(e,r)){r=U(e,r);continue}if(o!==void 0&&"([{".includes(o))n++;else if(o!==void 0&&")]}".includes(o))n--;else if(r===e.length||o===","&&n===0){let i=e.slice(s,r).trim();i&&t.push(i),s=r+1}r++}return t},Ce=e=>{let t=0;for(;t<e.length;){let n=xe(e.slice(t),"=");if(n===-1)return-1;let s=t+n;if(e[s+1]!=="="&&e[s+1]!==">"&&e[s-1]!=="="&&e[s-1]!=="!")return s;t=s+1}return-1},me=e=>{let t=(e??"").trim();if(!t.startsWith("{"))return null;let n=rt(t);if(n>=t.length)return null;let s=[];for(let r of _e(t.slice(1,n))){if(r.startsWith("..."))continue;let o=Ce(r),i=o===-1?r:r.slice(0,o),a=o===-1?void 0:r.slice(o+1).trim(),l=xe(i,":"),p=(l===-1?i:i.slice(0,l)).trim();if(!he.test(p))continue;let u={name:p};a!==void 0&&(u.default=a);let g=l===-1?"":i.slice(l+1).trim();he.test(g)&&(u.as=g),s.push(u)}return s},ln=e=>{let t=0,n=0,s=!0;for(;t<e.length;){let r=e[t];if(r==="'"||r==='"'||r==="`"){t=I(e,t),s=!1;continue}if(r==="/"&&e[t+1]==="/"){t=D(e,t);continue}if(r==="/"&&e[t+1]==="*"){t=k(e,t);continue}if(r==="/"&&W(e,t)){t=U(e,t),s=!1;continue}if(r==="e"&&n===0&&s&&(t===0||!/[\w$.]/.test(e[t-1]))){pe.lastIndex=t;let o=pe.exec(e);if(o)return t+o[0].length}"([{".includes(r)?n++:")]}".includes(r)&&(n=Math.max(0,n-1)),r===`
6
6
  `||r===";"||r==="}"?s=!0:/\s/.test(r)||(s=!1),t++}return-1},cn=/^async(?![\w$])/,un=/^function(?![\w$])\s*\*?\s*[A-Za-z_$][\w$]*|^function(?![\w$])\s*\*?/,dn=e=>{let t=ln(e);if(t===-1)return null;let n=de(e,t),s=e.slice(n);cn.test(s)&&(n=de(e,n+5));let r=un.exec(e.slice(n));if(r&&(n=de(e,n+r[0].length)),e[n]!=="(")return null;let o=0,i=n;for(;i<e.length;){let a=e[i];if(a==="'"||a==='"'||a==="`"){i=I(e,i);continue}if(a==="/"&&e[i+1]==="/"){i=D(e,i);continue}if(a==="/"&&e[i+1]==="*"){i=k(e,i);continue}if(a==="/"&&W(e,i)){i=U(e,i);continue}if("([{".includes(a))o++;else if(")]}".includes(a)&&--o===0)break;i++}return _e(e.slice(n+1,i))[0]??""},ye=e=>{let t=dn(e);if(t===null)return null;let n=me(t),s=n?.find(r=>r.name.startsWith("$"))?.name;if(s)throw new Error(`jq79: the factory signature is (props, ctx), so \`${s}\` can't be destructured from the first parameter. Write \`export default (props, { ${s} }) => \u2026\`, or \`_\` in place of props if the component takes none.`);return n},ot=e=>{let t="",n=0,s=0,r=!0,o=!1,i=0;for(;n<e.length;){let a=e[n],l=e[n+1],p=n===0||!/[\w$.]/.test(e[n-1]);if(a==="'"||a==='"'||a==="`"){let u=I(e,n);t+=e.slice(n,u),n=u,r=!1;continue}if(a==="/"&&(l==="/"||l==="*")){let u=l==="/"?D(e,n):k(e,n);t+=e.slice(n,u),n=u;continue}if(a==="/"&&W(e,n)){let u=U(e,n);t+=e.slice(n,u),n=u,r=!1;continue}if(a==="i"&&p){if(fe.lastIndex=n,fe.test(e)){t+="$__import",n+=6,r=!1;continue}if(s===0&&r){st.lastIndex=n;let u=st.exec(e);if(u){t+=an(u[1],u[3],i++),n+=u[0].length,r=!1;continue}}}if(a==="e"&&p&&s===0&&r){pe.lastIndex=n;let u=pe.exec(e);if(u){o=!0,t+="$__exports.default =",n+=u[0].length,r=!1;continue}}"([{".includes(a)?s++:")]}".includes(a)&&(s=Math.max(0,s-1)),a===`
7
- `||a===";"||a==="}"?r=!0:/\s/.test(a)||(r=!1),t+=a,n++}return o?t:null};var fn="0.5.9",Et=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),St=e=>{let t=Et(e),n=t[ve];return delete t[ve],{tag:e.tagName.toLowerCase(),attrs:t,...n===void 0?{}:{component:n},children:Array.from((e instanceof HTMLTemplateElement?e.content:e).childNodes).flatMap(s=>{if(s.nodeType===Node.TEXT_NODE){let r=s.textContent??"";return r?[r]:[]}return s.nodeType===Node.ELEMENT_NODE?[St(s)]:[]})}},it=new Map,wt=(e,t)=>{let n=`${t.join(",")}|${e}`,s=it.get(n);if(s===void 0){try{s=new Function("$scope",...t,`with ($scope) { return (${e}
7
+ `||a===";"||a==="}"?r=!0:/\s/.test(a)||(r=!1),t+=a,n++}return o?t:null};var fn="0.5.11",Et=e=>Object.fromEntries(Array.from(e.attributes).map(t=>[t.name,t.value])),St=e=>{let t=Et(e),n=t[ve];return delete t[ve],{tag:e.tagName.toLowerCase(),attrs:t,...n===void 0?{}:{component:n},children:Array.from((e instanceof HTMLTemplateElement?e.content:e).childNodes).flatMap(s=>{if(s.nodeType===Node.TEXT_NODE){let r=s.textContent??"";return r?[r]:[]}return s.nodeType===Node.ELEMENT_NODE?[St(s)]:[]})}},it=new Map,wt=(e,t)=>{let n=`${t.join(",")}|${e}`,s=it.get(n);if(s===void 0){try{s=new Function("$scope",...t,`with ($scope) { return (${e}
8
8
  ); }`)}catch{s=null}it.set(n,s)}return s},pn=/^(?:([\w$]+) is not defined|Can't find variable: ([\w$]+))/,hn=100,z=new Map,De=new Set,be=0,je=!1,Ne=new Set,gn=()=>{je=!1,!(be>0)&&(z.forEach(({name:e,expr:t,scope:n},s)=>{e in n||(De.add(s),console.warn(`jq79: ${e} is not defined - evaluating "${t}". Template expressions resolve against the component store: a top-level let/var/const in a :setup script, a declared prop, or a global. Note a "function name() {}" declaration is not on the store - write "const name = () => {}".`))}),z.clear())},Rt=()=>{je||be>0||!z.size||(je=!0,queueMicrotask(gn))},$t=e=>{be++;let t=()=>{be--,Rt()};e.then(t,t)},mn=(e,t)=>{if(Ne.has(e))return;Ne.add(e);let n=t?.message||String(t);console.error(`jq79: ${n} - evaluating "${e}". The expression rendered as nothing. If the value arrives later, guard it - "a?.b", or :if on the element.`)},Tt=(e,t,n)=>{if(!(n instanceof ReferenceError))return mn(e,n);let s=pn.exec(n.message),r=s?.[1]??s?.[2];if(!r)return;let o=`${r}|${e}`;De.has(o)||z.has(o)||z.size>=hn||(z.set(o,{name:r,expr:e,scope:t}),Rt())},xt=(e,t,n)=>{let s=wt(e,n?Object.keys(n):[]);if(s)return s(t,...n?Object.values(n):[])},C=(e,t,n)=>{try{return xt(e,t,n)}catch(s){Tt(e,t,s);return}},_t=(e,t,n)=>{try{return xt(e,t,n)}catch(s){if(!(s instanceof ReferenceError))throw s;Tt(e,t,s);return}},yn=(e,t)=>e.replace(/{{\s*([\s\S]+?)\s*}}/g,(n,s)=>C(s,t)??""),bn=new Set([":attrs",":class",":value",":checked",":selected",":if",":elseif",":else",":each",":key",":with",":text",":html",":html.allowed",":props"]),ke=e=>bn.has(e)||e.startsWith(":class.")||e.startsWith(":props.")||e===":slot"||e.startsWith(":slot."),En=/^\s*\(?\s*(\w+)\s*(?:,\s*(\w+))?\s*\)?\s+in\s+([\s\S]+)$/,Sn=(e,t,n,s)=>{let[r,...o]=t.slice(1).split("."),i=new Set(o);e.addEventListener(r,a=>{if(i.has("self")&&a.target!==e)return;i.has("prevent")&&a.preventDefault(),i.has("stop")&&a.stopPropagation();let l=_t(n,s,{$event:a});typeof l=="function"&&l.call(e,a)},{once:i.has("once"),capture:i.has("capture")})},wn=(e,t,n,s)=>{let[r,...o]=t.slice(1).split("."),i=new Set(o),a=l=>{i.has("prevent")&&l.preventDefault(),i.has("stop")&&l.stopPropagation(),i.has("once")&&e.off(r,a),ee(()=>{let p=_t(n,s,{$event:l});typeof p=="function"&&p(l)})};e.on(r,a)},F=e=>e.replace(/-(\w)/g,(t,n)=>n.toUpperCase()),Oe=e=>e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`),qe=e=>e instanceof DocumentFragment?{first:e.firstChild,last:e.lastChild}:{first:e,last:e},Ee=({first:e,last:t})=>{for(let n=e;n;){let s=n===t?null:n.nextSibling;n.parentNode?.removeChild(n),n=s}},Rn=({first:e,last:t},n)=>{let s=n.nextSibling;for(let r=e;r;){let o=r===t?null:r.nextSibling;n.parentNode.insertBefore(r,s),r=o}},at=(e,t)=>{let n=t.replace(/-/g,"").toLowerCase();for(let s=e;s&&s!==Object.prototype;s=Object.getPrototypeOf(s))for(let r of Object.keys(s))if(/^[A-Z]/.test(r)&&r.replace(/-/g,"").toLowerCase()===n)return r;return null},$n=e=>{let t=new Set;for(let n=e;n&&n!==Object.prototype;n=Object.getPrototypeOf(n))for(let s of Object.keys(n))/^[A-Z]/.test(s)&&t.add(s);return[...t].sort()},Tn=(e,t)=>{let n=$n(t);return new Error(`jq79: <${e}> is not defined - no component of that name is in scope, and nothing renders here. Import it in a :setup script, declare it as a prop, or add a <template name="${e}"> to this file. In scope: ${n.length?n.join(", "):"(none)"}.`)},lt=200,Ae=0,Ct=Symbol("jq79.slots"),xn=e=>e==="slot"||e.startsWith("slot."),At=e=>e?F(e):"default",Ie=e=>Object.keys(e.attrs).find(t=>t===":slot"||t.startsWith(":slot.")),_n=e=>e==="default"?":slot":`:slot.${e}`,Cn=e=>typeof e!="string"||e.trim()!=="",An=e=>{let t={},n=[];e.children.forEach(r=>{let o=typeof r=="object"&&r.tag==="template"?Ie(r):void 0;if(typeof r=="string"||o===void 0){n.push(r);return}let i=At(o.slice(6));if(i in t){console.warn(`jq79: two <template ${_n(i)}> in <${e.tag}>; the second was ignored`);return}t[i]={nodes:r.children,binder:r.attrs[o]||void 0}});let s=n.some(Cn);return s&&"default"in t?console.warn(`jq79: <${e.tag}> has both a <template :slot> and content outside it - the <template> is the default slot's content, and the rest was ignored`):s&&(t.default={nodes:n,binder:e.attrs[":slot"]||void 0}),t},jn=(e,t,n)=>{me(t)?.forEach(({name:s,as:r,default:o})=>{let i=r??s;Object.defineProperty(e,i,{enumerable:!0,configurable:!0,get:()=>{let a=n[s]?.();return a===void 0&&o!==void 0?C(o,e):a},set:()=>console.warn(`jq79: "${i}" is a slot prop - it comes from the component, so assigning to it does nothing`)})})},Nn=e=>{let t=Ie(e);return console.warn(`jq79: <template ${t}> fills a slot only as a direct child of a component tag; here it rendered nothing`),document.createComment(`misplaced ${t}`)},On=(e,t)=>{let n=Object.entries(An(e));if(!n.length)return null;let s={};return n.forEach(([r,o])=>{s[r]=vn(o,t)}),s},vn=(e,t)=>(n,s,r,o)=>{let i=Object.create(t);jn(i,e.binder,n);let a=i[ue]??[];Object.defineProperty(i,ue,{value:[...a,s]});let l=H(i);return r.onDispose(()=>l.dispose()),Z(e.nodes,i,l,o)},Pn=(e,t,n,s)=>{let r=At(e.tag.slice(5)),o=document.createDocumentFragment(),i=document.createComment(e.tag),a=document.createComment(`/${e.tag}`);o.append(i,a);let l=t[Ct]?.[r];if(!l)return o.insertBefore(Z(e.children,t,n,s),a),o;let p={};return Object.entries(e.attrs).forEach(([u,g])=>{if(!(u===Re||ke(u)||u.startsWith("@")))if(u.startsWith(":")){let R=g||u.slice(1);p[F(u.slice(1))]=()=>C(R,t)}else p[F(u)]=()=>g}),o.insertBefore(l(p,t,n,s),a),o},ct=(e,t,n,s,r)=>{let o=document.createComment(e),i=document.createComment(`/${e}`),a=document.createDocumentFragment();a.append(o,i);let l=On(t,n),p={},u={},g=[],R=[],j=!1;Object.entries(t.attrs).forEach(([d,f])=>{if(d!==Re){if(d===":props"||d.startsWith(":props.")){j=!0,R.push({expr:f});return}if(!ke(d))if(d.startsWith("@"))g.push([d,f]);else if(d===":model"||d.startsWith(":model.")){let c=d===":model"?"default":F(d.slice(7));u[c]=f||(d===":model"?"model":c)}else if(d.startsWith(":")){let c=F(d.slice(1));p[c]=f||c,R.push({name:c,expr:f||c})}else{let c=F(d),m=JSON.stringify(f);p[c]=m,R.push({name:c,expr:m})}}});let N=d=>d==="default"?":model":`:model.${d}`,O=d=>d==="default"?"model":d,y=d=>`${d}
9
9
  = $value`,w=new Set;Object.entries(u).forEach(([d,f])=>{let c=O(d);p[c]!==void 0&&console.warn(`jq79: <${t.tag}> binds prop "${c}" through both :${c} and ${N(d)} - ${N(d)} wins`),p[c]=f,wt(y(f),["$value"])===null&&(w.add(d),console.warn(`jq79: ${N(d)}="${f}" is not assignable - updates from <${t.tag}> will be dropped`))});let x=()=>{let d={};return R.forEach(({name:f,expr:c})=>{if(f!==void 0)d[f]=C(c,n);else{let m=C(c,n);m!==null&&typeof m=="object"&&Object.assign(d,m)}}),Object.entries(u).forEach(([f,c])=>{d[O(f)]=C(c,n)}),d},h=null,b=null,T=null,S=new Set,A=d=>{if(d==null){if(!n[Pt]?.has(e)||S.has("unfilled"))return;S.add("unfilled"),console.error(`jq79: <${t.tag}> is declared as a prop and the parent passed nothing - nothing renders here. Pass it (:${e}="\u2026"), or drop it from the signature to use the one declared in this file.`);return}S.has("type")||(S.add("type"),console.error(`jq79: <${t.tag}> is ${typeof d}, not a component - nothing renders here`))};return s.effect(()=>{let d=C(e,n),f=d instanceof q?d:null;if(f||A(d),f===b||(T?.dispose(),T=null,h?.destroy(),h=null,b=f,!f))return;let c=new q({template:f.template,scripts:f.scripts,styles:f.styles,modules:f.modules,filename:f.filename,siblings:f.siblings,name:f.name});if(l&&(c.slots=l),Object.keys(u).length){let v=new Set;c.modelWriteback=(M,B)=>{let P=M==null?"default":F(String(M)),K=u[P];return K===void 0?(v.has(P)||(v.add(P),console.warn(`jq79: <${t.tag}> has no ${N(P)} - bound: ${Object.keys(u).map(N).join(", ")}`)),!1):w.has(P)?!1:(ee(()=>C(y(K),n,{$value:B})),!0)}}g.forEach(([v,M])=>wn(c,v,M,n));let m=ds(c.scripts);fs(t,e,Object.keys(p),m);let E=gt(ee(x),m),$=document.createDocumentFragment();if(Ae>=lt){console.error(`jq79: <${t.tag}> is ${lt} levels deep inside itself; giving up here. A component that renders itself stops when its data stops - is there a cycle in it?`);return}Ae++;try{(r?c.renderShadow(E):c.render(E)).mount($)}finally{Ae--}i.parentNode.insertBefore($,i);let L=H(n);if(j){let v=[];L.effect(()=>{let M=gt(x(),m),B=Object.keys(M);v.forEach(P=>{P in M||(c.data[P]=void 0)}),B.forEach(P=>{c.data[P]=M[P]}),v=B})}else Object.entries(p).forEach(([v,M])=>{m!==null&&!m.has(v)||L.effect(()=>{c.data[v]=C(M,n)})});T=L,h=c}),s.onDispose(()=>{T?.dispose(),h?.destroy()}),a},Ln=(e,t)=>{let n=()=>{let s=C(e,t);return s!==null&&typeof s=="object"?s:null};return new Proxy(t,{has(s,r){let o=n();return o!==null&&Reflect.has(o,r)||Reflect.has(s,r)},get(s,r){let o=n();return o!==null&&Reflect.has(o,r)?o[r]:Reflect.get(s,r)},set(s,r,o){let i=n();return i!==null&&Reflect.has(i,r)?(i[r]=o,!0):Reflect.set(s,r,o)}})},se=e=>typeof e=="string"?e.split(/\s+/).filter(Boolean):Array.isArray(e)?e.flatMap(se):e!==null&&typeof e=="object"?Object.entries(e).flatMap(([t,n])=>n?se(t):[]):[],Mn=e=>typeof e=="function"?(t,n,s)=>{try{return!!e(t,n,s)}catch{return!1}}:typeof e=="string"||Array.isArray(e)?Ge(e):()=>!1,Dn=new Set(["allowfullscreen","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","inert","ismap","itemscope","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),ut=(e,t,n)=>{let s=Dn.has(t);(s?!n:n==null)?e.removeAttribute(t):e.setAttribute(t,s?"":String(n))},We=(e,t,n,s)=>{let r=e.attrs[":with"],o=r!==void 0?Ln(r,t):t;if(xn(e.tag))return Pn(e,o,n,s);if(e.tag==="template"&&Ie(e)!==void 0)return Nn(e);let i=at(o,e.tag);if(i)return ct(i,e,o,n,s);let a=document.createElement(e.tag);if(e.component&&a instanceof HTMLUnknownElement&&o[Le]?.count===0)throw Tn(e.component,o);let l=a instanceof HTMLUnknownElement||e.tag.includes("-");if(l){let y=!1;n.effect(()=>{if(y)return;let w=at(o,e.tag);if(!w)return;y=!0;let x=ct(w,e,o,n,s),h=qe(x);n.onDispose(()=>Ee(h)),a.replaceWith(x)})}Object.entries(e.attrs).forEach(([y,w])=>{if(y.startsWith("@"))Sn(a,y,w,o);else if(y===":model"||y.startsWith(":model."))l||console.warn(`jq79: ${y} on <${e.tag}> does nothing - :model binds component tags only (for now)`);else if(!ke(y))if(y.startsWith(":"))if(l)a.setAttribute(y,w);else{let x=y.slice(1),h=w||F(x);n.effect(()=>ut(a,x,C(h,o)))}else a.setAttribute(y,w)});let p=e.attrs[":attrs"];if(p!==void 0){let y=[];n.effect(()=>{y.forEach(x=>a.removeAttribute(x));let w=C(p,o);y=w&&typeof w=="object"?Object.keys(w):[],y.forEach(x=>ut(a,x,w[x]))})}let u=e.attrs[":class"],g=Object.entries(e.attrs).filter(([y])=>y.startsWith(":class.")).map(([y,w])=>[y.slice(7),w]);if(u!==void 0||g.length){let y=new Set(se(e.attrs.class??"")),w=[];n.effect(()=>{let x=u!==void 0?se(C(u,o)):[];g.forEach(([h,b])=>{C(b,o)&&x.push(...se(h))}),w.forEach(h=>{!x.includes(h)&&!y.has(h)&&a.classList.remove(h)}),a.classList.add(...x),w=x})}let R=e.attrs[":text"],j=e.attrs[":html"],N=e.attrs[":html.allowed"];N!==void 0&&j===void 0&&console.warn("jq79: :html.allowed without :html on the same element does nothing"),R!==void 0?n.effect(()=>{a.textContent=String(C(R,o)??"")}):j!==void 0?n.effect(()=>{let y=N!==void 0?{allowUrl:Mn(C(N,o))}:void 0;a.innerHTML=Ke(String(C(j,o)??""),y)}):a instanceof HTMLTemplateElement?a.content.appendChild(Z(e.children,o,n,s)):a.appendChild(Z(e.children,o,n,s));let O=e.attrs[":value"];return O!==void 0&&n.effect(()=>{let y=String(C(O,o)??"");a.value!==y&&(a.value=y)}),[":checked",":selected"].forEach(y=>{let w=e.attrs[y];if(w===void 0)return;let x=y.slice(1);n.effect(()=>{a[x]=!!C(w,o)})}),a},kn=(e,t,n,s)=>{let r=document.createComment("if"),o=document.createDocumentFragment();o.appendChild(r);let i=null,a=null,l=null;return n.effect(()=>{let p=e.find(g=>g.expr===void 0||C(g.expr,t))??null;if(p===a||(l?.dispose(),i&&Ee(i),i=null,a=p,!p))return;l=H(t);let u=We(p.node,t,l,s);i=qe(u),r.parentNode.insertBefore(u,r.nextSibling)}),o},ne=(e,t,n)=>{Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})},qn=e=>{if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},In=(e,t,n,s)=>{let r=e.attrs[":each"].match(En);if(!r)return document.createComment(`invalid :each expression "${e.attrs[":each"]}"`);let[,o,i,a]=r,l=e.attrs[":key"],{[":each"]:p,[":key"]:u,...g}=e.attrs,R={...e,attrs:g},j=document.createComment("each"),N=document.createDocumentFragment();N.appendChild(j),(":if"in e.attrs||":elseif"in e.attrs||":else"in e.attrs)&&console.warn("jq79: :if/:elseif/:else on a :each element is ignored; filter the list expression instead");let O=[],y=!1;return n.effect(()=>{let w=C(a,t),x=Array.isArray(w)?w.map((d,f)=>[f,d]):qn(w)?Object.entries(w):[],h=new Map;O.forEach(d=>{let f=h.get(d.key);f?f.push(d):h.set(d.key,[d])});let b=new Set,T=[],S=x.map(([d,f],c)=>{let m=Object.create(t);ne(m,o,f),i&&ne(m,i,d),ne(m,"$index",c);let E=l!==void 0?C(l,m):d;b.has(E)&&!y&&(y=!0,console.warn(`jq79: duplicate :key in :each "${e.attrs[":each"]}"; duplicates pair up by position`)),b.add(E);let $=h.get(E)?.shift();if($&&Object.is($.item,f))return $.scope.$index!==c&&T.push($),ne($.scope,"$index",c),i&&ne($.scope,i,d),$;$&&($.fx.dispose(),Ee($.range));let L=H(t),v=qe(We(R,m,L,s));return{key:E,item:f,scope:m,fx:L,range:v}});h.forEach(d=>d.forEach(f=>{f.fx.dispose(),Ee(f.range)}));let A=j;S.forEach(d=>{A.nextSibling!==d.range.first&&Rn(d.range,A),A=d.range.last}),T.forEach(d=>ee(()=>d.fx.refresh())),O=S}),N},Z=(e,t,n,s=!1)=>{let r=document.createDocumentFragment(),o=0;for(;o<e.length;){let i=e[o];if(typeof i=="string"){let a=document.createTextNode(i);i.includes("{{")&&n.effect(()=>{a.textContent=yn(i,t)}),r.appendChild(a),o++;continue}if(":each"in i.attrs){r.appendChild(In(i,t,n,s)),o++;continue}if(":if"in i.attrs){let a=[{expr:i.attrs[":if"],node:i}];o++;let l=u=>{let g=o;for(;g<e.length&&typeof e[g]=="string"&&!e[g].trim();)g++;let R=e[g];if(typeof R=="object"&&u in R.attrs)return o=g+1,R};for(let u=l(":elseif");u;u=l(":elseif"))a.push({expr:u.attrs[":elseif"],node:u});let p=l(":else");p&&a.push({node:p}),r.appendChild(kn(a,t,n,s));continue}r.appendChild(We(i,t,n,s)),o++}return r},Wn=(e,t,n=!1)=>Z(e.template,t,H(t),n),Un=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Fn=/<([A-Za-z][\w.-]*)((?:"[^"]*"|'[^']*'|[^>"'])*?)\/>/g,Ue=/(<script[\s\S]*?<\/script\s*>|<style[\s\S]*?<\/style\s*>)/gi,Bn=e=>e.split(Ue).map((t,n)=>n%2===1?t:t.replace(Fn,(s,r,o)=>Un.has(r.toLowerCase())?s:`<${r}${o}></${r}>`)).join(""),jt=/<([A-Za-z][\w.-]*)((?:"[^"]*"|'[^']*'|[^>"'])*)>/g,Hn=/"[^"]*"|'[^']*'|(^|\s)\.\.\.([A-Za-z_$][\w$.]*)/g,zn=e=>e.split(Ue).map((t,n)=>n%2===1?t:t.replace(jt,(s,r,o)=>{let i=0,a=o.replace(Hn,(l,p,u)=>u===void 0?l:`${p}:props.${i++}="${u}"`);return`<${r}${a}>`})).join(""),Gn=/"[^"]*"|'[^']*'|(^|\s)(:[\w.$-]+)/g,Zn=/<\/slot\.([\w.$-]+)(\s*)>/gi,Kn=/^slot\./i,Vn=e=>Kn.test(e)?`slot.${Oe(e.slice(5))}`:e,ve=":jq79-component",Jn=/^[A-Z]/,Xn=/\/\s*$/,Qn=(e,t)=>{if(!Jn.test(e))return t;let n=` ${ve}="${e}"`,s=Xn.exec(t);return s?`${t.slice(0,s.index)}${n}${s[0]}`:`${t}${n}`},Yn=e=>e.split(Ue).map((t,n)=>n%2===1?t:t.replace(jt,(s,r,o)=>{let i=o.replace(Gn,(a,l,p)=>p===void 0?a:`${l}${Oe(p)}`);return`<${Vn(r)}${Qn(r,i)}>`}).replace(Zn,(s,r,o)=>`</slot.${Oe(r)}${o}>`)).join(""),Re="data-jq79",es=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return(t>>>0).toString(36)},Nt=(e,t)=>{e.forEach(n=>{typeof n!="string"&&(n.attrs[Re]=t,Nt(n.children,t))})},ts=(e,t)=>e.split(",").map(n=>{let s=n.trim(),r=s.indexOf("::"),o=r===-1?s:s.slice(0,r),i=r===-1?"":s.slice(r);return`${o}[${Re}="${t}"]${i}`}).join(", "),Ot=(e,t)=>{Array.from(e).forEach(n=>{n instanceof CSSStyleRule?n.selectorText=ts(n.selectorText,t):n instanceof CSSGroupingRule&&Ot(n.cssRules,t)})},ns=(e,t)=>{/:deep\(|::v-deep|>>>/.test(e)&&console.warn("jq79: :deep()/::v-deep/>>> are not supported in <style scoped>; the rule will be dropped by the browser");let n=new CSSStyleSheet;return n.replaceSync(e),Ot(n.cssRules,t),Array.from(n.cssRules).map(s=>s.cssText).join(`
10
10
  `)},ss=/^[A-Z][A-Za-z0-9]*$/,Pe=e=>{let t=Bn(zn(Yn(e))),s=new DOMParser().parseFromString(`<template>${t}</template>`,"text/html").querySelector("template"),r=[],o=[];Array.from(s.content.children).forEach(l=>{l.tagName==="TEMPLATE"?o.push(l):r.push(l)});let i=dt(r,e),a={};return o.forEach(l=>{let p=l.getAttribute("name");if(p===null){console.warn("jq79: a top-level <template> without a name declares nothing and was ignored");return}if(!ss.test(p)){console.warn(`jq79: <template name="${p}"> was ignored - a component name has to be PascalCase, or no tag could ever reference it (only capitalized names resolve as components)`);return}if(p in a){console.warn(`jq79: two <template name="${p}"> in one file; the second was ignored`);return}a[p]=new q({...dt(Array.from(l.content.children),l.innerHTML),siblings:a,name:p})}),Object.keys(a).length&&(i.siblings=a),i},dt=(e,t)=>{let n=[],s=[],r=[];e.forEach(i=>{let a={attrs:Et(i),content:i.textContent??""};i.tagName==="SCRIPT"?n.push(a):i.tagName==="STYLE"?s.push(a):r.push(St(i))}),s.forEach(i=>{"lang"in i.attrs&&console.warn(`jq79: <style lang="${i.attrs.lang}"> needs the jq79/vite plugin to compile it. This component didn't go through the bundler, so its styles were left uncompiled and the browser will ignore them.`)});let o=i=>"scoped"in i.attrs&&!("lang"in i.attrs);if(s.some(o)){let i=es(t);Nt(r,i),s.forEach(a=>{o(a)&&(a.scoped=ns(a.content,i))})}return{template:r,scripts:n,styles:s}},Fe=e=>/\.html?([?#]|$)/.test(e)?Me(e):import(e),rs=/^(?:\.\.?\/|\/|[a-z][a-z0-9+.-]*:)/i,os=(e,t)=>{if(!rs.test(e))return e;try{return new URL(e,new URL(t??"",document.baseURI)).href}catch{return e}},vt=(e,t)=>e?`