@vesk/vesk-cli 0.2.64 → 0.2.66

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 (2) hide show
  1. package/dist/cli.js +1801 -589
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -1177,10 +1177,10 @@ function run_block(block2) {
1177
1177
  const res = block2.fn(block2.s);
1178
1178
  if (typeof res === "function") {
1179
1179
  block2.t = res;
1180
- let current2 = block2;
1181
- while (current2 !== null && (current2.f & CONTAINS_TEARDOWN) === 0) {
1182
- current2.f ^= CONTAINS_TEARDOWN;
1183
- current2 = current2.p;
1180
+ let current3 = block2;
1181
+ while (current3 !== null && (current3.f & CONTAINS_TEARDOWN) === 0) {
1182
+ current3.f ^= CONTAINS_TEARDOWN;
1183
+ current3 = current3.p;
1184
1184
  }
1185
1185
  }
1186
1186
  block2.d = active_dependency;
@@ -1227,13 +1227,13 @@ function create_dependency(tracked2) {
1227
1227
  if (is_orphan(tracked2.b)) {
1228
1228
  (tracked2.r ??= /* @__PURE__ */ new Set()).add(reaction);
1229
1229
  }
1230
- const existing = reaction.d;
1231
- if (existing !== null) {
1232
- reaction.d = existing.n;
1233
- existing.c = tracked2.c;
1234
- existing.t = tracked2;
1235
- existing.n = null;
1236
- return existing;
1230
+ const existing2 = reaction.d;
1231
+ if (existing2 !== null) {
1232
+ reaction.d = existing2.n;
1233
+ existing2.c = tracked2.c;
1234
+ existing2.t = tracked2;
1235
+ existing2.n = null;
1236
+ return existing2;
1237
1237
  }
1238
1238
  return {
1239
1239
  c: tracked2.c,
@@ -1276,44 +1276,44 @@ function is_block_dirty(block2) {
1276
1276
  return is_tracking_dirty(block2.d);
1277
1277
  }
1278
1278
  function flush_updates(root_block) {
1279
- let current2 = root_block;
1279
+ let current3 = root_block;
1280
1280
  const pre_effects = [];
1281
1281
  const other_blocks = [];
1282
1282
  const effects = [];
1283
1283
  let scope_root = disable_scoped_flush ? root_block : null;
1284
- while (current2 !== null) {
1285
- const flags = current2.f;
1284
+ while (current3 !== null) {
1285
+ const flags = current3.f;
1286
1286
  const on_path = (flags & CONTAINS_UPDATE) !== 0;
1287
1287
  if (on_path) {
1288
- current2.f ^= CONTAINS_UPDATE;
1288
+ current3.f ^= CONTAINS_UPDATE;
1289
1289
  }
1290
1290
  if ((flags & UPDATE_SOURCE) !== 0) {
1291
- current2.f ^= UPDATE_SOURCE;
1291
+ current3.f ^= UPDATE_SOURCE;
1292
1292
  if (scope_root === null) {
1293
- scope_root = current2;
1293
+ scope_root = current3;
1294
1294
  }
1295
1295
  }
1296
1296
  if ((flags & PAUSED) === 0 && (on_path || scope_root !== null)) {
1297
1297
  if ((flags & PRE_EFFECT_BLOCK) !== 0) {
1298
- pre_effects.push(current2);
1298
+ pre_effects.push(current3);
1299
1299
  } else if ((flags & EFFECT_BLOCK) !== 0) {
1300
- effects.push(current2);
1300
+ effects.push(current3);
1301
1301
  } else {
1302
- other_blocks.push(current2);
1302
+ other_blocks.push(current3);
1303
1303
  }
1304
- const child = current2.first;
1304
+ const child = current3.first;
1305
1305
  if (child !== null) {
1306
- current2 = child;
1306
+ current3 = child;
1307
1307
  continue;
1308
1308
  }
1309
1309
  }
1310
- let parent = current2.p;
1311
- current2 = current2.next;
1312
- while (current2 === null && parent !== null) {
1310
+ let parent = current3.p;
1311
+ current3 = current3.next;
1312
+ while (current3 === null && parent !== null) {
1313
1313
  if (parent === scope_root) {
1314
1314
  scope_root = null;
1315
1315
  }
1316
- current2 = parent.next;
1316
+ current3 = parent.next;
1317
1317
  parent = parent.p;
1318
1318
  }
1319
1319
  }
@@ -1406,17 +1406,17 @@ function schedule_update(block2) {
1406
1406
  queue_microtask();
1407
1407
  }
1408
1408
  block2.f |= UPDATE_SOURCE;
1409
- let current2 = block2;
1410
- while (current2 !== null) {
1411
- const flags = current2.f;
1409
+ let current3 = block2;
1410
+ while (current3 !== null) {
1411
+ const flags = current3.f;
1412
1412
  if ((flags & CONTAINS_UPDATE) !== 0) return;
1413
- current2.f ^= CONTAINS_UPDATE;
1413
+ current3.f ^= CONTAINS_UPDATE;
1414
1414
  if ((flags & ROOT_BLOCK) !== 0) {
1415
1415
  break;
1416
1416
  }
1417
- current2 = current2.p;
1417
+ current3 = current3.p;
1418
1418
  }
1419
- queued_root_blocks.push(current2);
1419
+ queued_root_blocks.push(current3);
1420
1420
  }
1421
1421
  function register_dependency(tracked2) {
1422
1422
  if (!disable_scoped_flush && active_block !== null && active_block !== tracked2.b) {
@@ -1445,20 +1445,20 @@ function register_dependency(tracked2) {
1445
1445
  dependency = create_dependency(tracked2);
1446
1446
  active_dependency = dependency;
1447
1447
  } else {
1448
- let current2 = dependency;
1449
- while (current2 !== null) {
1450
- if (current2.t === tracked2) {
1451
- current2.c = tracked2.c;
1448
+ let current3 = dependency;
1449
+ while (current3 !== null) {
1450
+ if (current3.t === tracked2) {
1451
+ current3.c = tracked2.c;
1452
1452
  return;
1453
1453
  }
1454
- const next = current2.n;
1454
+ const next = current3.n;
1455
1455
  if (next === null) {
1456
1456
  break;
1457
1457
  }
1458
- current2 = next;
1458
+ current3 = next;
1459
1459
  }
1460
1460
  dependency = create_dependency(tracked2);
1461
- current2.n = dependency;
1461
+ current3.n = dependency;
1462
1462
  }
1463
1463
  }
1464
1464
  function unsubscribe_reaction(reaction) {
@@ -1837,10 +1837,10 @@ var init_context = __esm({
1837
1837
  * way to every reader.
1838
1838
  */
1839
1839
  get() {
1840
- let current2 = getActiveComponent();
1841
- while (current2) {
1842
- if (current2.c?.has(this)) return current2.c.get(this);
1843
- current2 = current2.p;
1840
+ let current3 = getActiveComponent();
1841
+ while (current3) {
1842
+ if (current3.c?.has(this)) return current3.c.get(this);
1843
+ current3 = current3.p;
1844
1844
  }
1845
1845
  return this._v;
1846
1846
  }
@@ -1858,11 +1858,11 @@ var init_context = __esm({
1858
1858
 
1859
1859
  // ../runtime/src/server-events.ts
1860
1860
  function getStore() {
1861
- const g4 = globalThis;
1862
- if (!g4.__vesk_server_ctx || typeof g4.__vesk_server_ctx !== "object") {
1863
- g4.__vesk_server_ctx = {};
1861
+ const g5 = globalThis;
1862
+ if (!g5.__vesk_server_ctx || typeof g5.__vesk_server_ctx !== "object") {
1863
+ g5.__vesk_server_ctx = {};
1864
1864
  }
1865
- return g4.__vesk_server_ctx;
1865
+ return g5.__vesk_server_ctx;
1866
1866
  }
1867
1867
  function server_locals() {
1868
1868
  return getStore();
@@ -2126,8 +2126,8 @@ function streamText(res, into, onChunk) {
2126
2126
  function settle(handle2, data2) {
2127
2127
  if (handle2.block !== null && is_destroyed(handle2.block)) return;
2128
2128
  if (handle2.into) setInto(handle2.into, data2);
2129
- const current2 = get(handle2.state);
2130
- if (!(current2.data === data2 && !current2.loading && current2.error === null)) {
2129
+ const current3 = get(handle2.state);
2130
+ if (!(current3.data === data2 && !current3.loading && current3.error === null)) {
2131
2131
  set(handle2.state, { loading: false, error: null, data: data2 });
2132
2132
  }
2133
2133
  handle2.settleNotify();
@@ -2136,22 +2136,22 @@ function settleError(handle2, error) {
2136
2136
  if (handle2.block !== null && is_destroyed(handle2.block)) return;
2137
2137
  if (isAbortError(error)) {
2138
2138
  if (handle2.controller !== null) return;
2139
- const current3 = get(handle2.state);
2140
- if (current3.loading) set(handle2.state, { loading: false, error: null, data: current3.data });
2139
+ const current4 = get(handle2.state);
2140
+ if (current4.loading) set(handle2.state, { loading: false, error: null, data: current4.data });
2141
2141
  handle2.settleNotify();
2142
2142
  return;
2143
2143
  }
2144
- const current2 = get(handle2.state);
2145
- set(handle2.state, { loading: false, error, data: current2.data });
2144
+ const current3 = get(handle2.state);
2145
+ set(handle2.state, { loading: false, error, data: current3.data });
2146
2146
  handle2.settleNotify();
2147
2147
  }
2148
2148
  function markRefetching(handle2) {
2149
- const current2 = get(handle2.state);
2150
- if (current2.loading) return;
2149
+ const current3 = get(handle2.state);
2150
+ if (current3.loading) return;
2151
2151
  set(handle2.state, {
2152
2152
  loading: true,
2153
2153
  error: null,
2154
- data: handle2.options.keepPreviousData ? current2.data : void 0
2154
+ data: handle2.options.keepPreviousData ? current3.data : void 0
2155
2155
  });
2156
2156
  }
2157
2157
  function attachSettle(handle2, promise) {
@@ -2217,10 +2217,10 @@ function startRequest(handle2, skipCache) {
2217
2217
  });
2218
2218
  return settled;
2219
2219
  }
2220
- const existing = getInflight().get(key);
2220
+ const existing2 = getInflight().get(key);
2221
2221
  const startToken = g().__vsk_ssr_token || void 0;
2222
- const prom2 = existing ?? runFetcher(handle2, options.timeout || 0);
2223
- if (!existing) {
2222
+ const prom2 = existing2 ?? runFetcher(handle2, options.timeout || 0);
2223
+ if (!existing2) {
2224
2224
  getInflight().set(key, prom2);
2225
2225
  prom2.then(
2226
2226
  (data2) => {
@@ -2252,10 +2252,10 @@ function startRequest(handle2, skipCache) {
2252
2252
  }
2253
2253
  }
2254
2254
  if (options.dedupe !== false) {
2255
- const existing = getInflight().get(key);
2256
- if (existing) {
2257
- attachSettle(handle2, existing);
2258
- return existing;
2255
+ const existing2 = getInflight().get(key);
2256
+ if (existing2) {
2257
+ attachSettle(handle2, existing2);
2258
+ return existing2;
2259
2259
  }
2260
2260
  }
2261
2261
  markRefetching(handle2);
@@ -2398,8 +2398,8 @@ function createResource(fn, key, into, options = {}) {
2398
2398
  on_destroy(() => {
2399
2399
  if (is_destroyed(handle2.block)) {
2400
2400
  handle2.controller?.abort();
2401
- const current2 = getRegistry().get(resourceKey);
2402
- if (current2) current2.delete(handle2);
2401
+ const current3 = getRegistry().get(resourceKey);
2402
+ if (current3) current3.delete(handle2);
2403
2403
  }
2404
2404
  });
2405
2405
  }
@@ -2860,9 +2860,9 @@ function createHydrateWalker(container, markerList) {
2860
2860
  }
2861
2861
  function bumpNavEpoch() {
2862
2862
  try {
2863
- const g4 = globalThis;
2864
- const next = (g4.__vesk_nav_epoch || 0) + 1;
2865
- g4.__vesk_nav_epoch = next;
2863
+ const g5 = globalThis;
2864
+ const next = (g5.__vesk_nav_epoch || 0) + 1;
2865
+ g5.__vesk_nav_epoch = next;
2866
2866
  return next;
2867
2867
  } catch {
2868
2868
  return 0;
@@ -4009,8 +4009,8 @@ function LoadingIndicator(props = {}, _registry, hydrate) {
4009
4009
  if (hydrate && typeof hydrate.nextElement === "function") {
4010
4010
  el = hydrate.nextElement("div");
4011
4011
  if (el && !el.parentNode && hydrate.root) {
4012
- const existing = hydrate.root.querySelector(`[${INDICATOR_ATTR}]`);
4013
- if (existing) el = existing;
4012
+ const existing2 = hydrate.root.querySelector(`[${INDICATOR_ATTR}]`);
4013
+ if (existing2) el = existing2;
4014
4014
  }
4015
4015
  } else {
4016
4016
  el = document.createElement("div");
@@ -4330,8 +4330,8 @@ function NavLink(props, registry, hydrate) {
4330
4330
  if (hydrate && hydrate.nextElement) {
4331
4331
  let a2 = hydrate.nextElement("a");
4332
4332
  if (a2 && !a2.parentNode && hydrate.root) {
4333
- const existing = hydrate.root.querySelector("a");
4334
- if (existing) a2 = existing;
4333
+ const existing2 = hydrate.root.querySelector("a");
4334
+ if (existing2) a2 = existing2;
4335
4335
  }
4336
4336
  const claimed = a2 ? a2.parentNode !== null : false;
4337
4337
  if (!a2) a2 = document.createElement("a");
@@ -4779,8 +4779,8 @@ async function fetchRouteData(path) {
4779
4779
  }
4780
4780
  function getRouteData(path, scope2) {
4781
4781
  const key = scope2 === void 0 ? path : path + "\0" + scope2;
4782
- const existing = _dataPromises.get(key);
4783
- if (existing) return existing;
4782
+ const existing2 = _dataPromises.get(key);
4783
+ if (existing2) return existing2;
4784
4784
  const p = fetchRouteData(path).finally(() => {
4785
4785
  _dataPromises.delete(key);
4786
4786
  });
@@ -5604,8 +5604,8 @@ function createRouter(routes, options = {}) {
5604
5604
  },
5605
5605
  _runGuards(to) {
5606
5606
  const from = get(_state.path) || window.location.pathname;
5607
- for (const g4 of this._beforeGuards ?? []) {
5608
- const d = g4(to, from);
5607
+ for (const g5 of this._beforeGuards ?? []) {
5608
+ const d = g5(to, from);
5609
5609
  if (d instanceof Promise) {
5610
5610
  return d.then((r) => {
5611
5611
  if (r === false || typeof r === "string") return r;
@@ -5931,8 +5931,8 @@ function createFileRouter(routeTree, options = {}) {
5931
5931
  },
5932
5932
  _runGuards(to) {
5933
5933
  const from = get(_state.path) || window.location.pathname;
5934
- for (const g4 of this._beforeGuards ?? []) {
5935
- const d = g4(to, from);
5934
+ for (const g5 of this._beforeGuards ?? []) {
5935
+ const d = g5(to, from);
5936
5936
  if (d instanceof Promise) {
5937
5937
  return d.then((r) => {
5938
5938
  if (r === false || typeof r === "string") return r;
@@ -6377,6 +6377,58 @@ var init_router = __esm({
6377
6377
  }
6378
6378
  });
6379
6379
 
6380
+ // ../runtime/src/security-overrides.ts
6381
+ function resolveAls() {
6382
+ try {
6383
+ const proc = g2.process;
6384
+ const mod = proc?.getBuiltinModule?.("async_hooks");
6385
+ const ctor = mod?.AsyncLocalStorage;
6386
+ return ctor ? new ctor() : null;
6387
+ } catch {
6388
+ return null;
6389
+ }
6390
+ }
6391
+ function current() {
6392
+ if (als) return als.getStore() ?? null;
6393
+ return fallbackStore;
6394
+ }
6395
+ function runWithSecurityOverrides(fn) {
6396
+ const bag = {};
6397
+ if (als) return als.run(bag, fn);
6398
+ const prev = fallbackStore;
6399
+ fallbackStore = bag;
6400
+ try {
6401
+ return fn();
6402
+ } finally {
6403
+ fallbackStore = prev;
6404
+ }
6405
+ }
6406
+ function setSecurityOverride(key, value) {
6407
+ const bag = current();
6408
+ if (bag) bag[key] = value;
6409
+ }
6410
+ function getSecurityOverrides() {
6411
+ const bag = current();
6412
+ if (!bag) return null;
6413
+ return Object.keys(bag).length > 0 ? bag : null;
6414
+ }
6415
+ var g2, als, fallbackStore, bridge, existing;
6416
+ var init_security_overrides = __esm({
6417
+ "../runtime/src/security-overrides.ts"() {
6418
+ "use strict";
6419
+ g2 = globalThis;
6420
+ als = resolveAls();
6421
+ fallbackStore = null;
6422
+ bridge = {
6423
+ run: runWithSecurityOverrides,
6424
+ get: getSecurityOverrides,
6425
+ set: setSecurityOverride
6426
+ };
6427
+ existing = g2.__vesk_security || {};
6428
+ g2.__vesk_security = { ...existing, ...bridge };
6429
+ }
6430
+ });
6431
+
6380
6432
  // ../../node_modules/acorn/dist/acorn.mjs
6381
6433
  var acorn_exports = {};
6382
6434
  __export(acorn_exports, {
@@ -10098,7 +10150,7 @@ var init_acorn = __esm({
10098
10150
  }
10099
10151
  return i + 2;
10100
10152
  };
10101
- RegExpValidationState.prototype.current = function current(forceU) {
10153
+ RegExpValidationState.prototype.current = function current2(forceU) {
10102
10154
  if (forceU === void 0) forceU = false;
10103
10155
  return this.at(this.pos, forceU);
10104
10156
  };
@@ -10123,8 +10175,8 @@ var init_acorn = __esm({
10123
10175
  var pos = this.pos;
10124
10176
  for (var i = 0, list = chs; i < list.length; i += 1) {
10125
10177
  var ch = list[i];
10126
- var current2 = this.at(pos, forceU);
10127
- if (current2 === -1 || current2 !== ch) {
10178
+ var current3 = this.at(pos, forceU);
10179
+ if (current3 === -1 || current3 !== ch) {
10128
10180
  return false;
10129
10181
  }
10130
10182
  pos = this.nextIndex(pos, forceU);
@@ -20367,8 +20419,8 @@ function collectModuleSpecifiers(ast) {
20367
20419
  return specs;
20368
20420
  }
20369
20421
  function collectModuleBundled(absPath, collector) {
20370
- const existing = collector.keysByAbs.get(absPath);
20371
- if (existing) return existing;
20422
+ const existing2 = collector.keysByAbs.get(absPath);
20423
+ if (existing2) return existing2;
20372
20424
  const key = `__veskMod${collector.keysByAbs.size}`;
20373
20425
  collector.keysByAbs.set(absPath, key);
20374
20426
  const dir = dirname2(absPath);
@@ -22417,16 +22469,16 @@ function generateIR(ast, source, filename) {
22417
22469
  if (called.has(fn)) usedFunctions.add(fn);
22418
22470
  }
22419
22471
  if (usedFunctions.size > 0) {
22420
- const existing = /* @__PURE__ */ new Set();
22472
+ const existing2 = /* @__PURE__ */ new Set();
22421
22473
  for (const imp of imports) {
22422
22474
  if (importModuleTarget(imp) !== "@vesk/runtime") continue;
22423
- for (const n of extractImportNames(imp)) existing.add(n);
22475
+ for (const n of extractImportNames(imp)) existing2.add(n);
22424
22476
  }
22425
22477
  const boundLocally = /* @__PURE__ */ new Set();
22426
22478
  for (const imp of imports) {
22427
22479
  for (const pair of importBindingPairs(imp)) boundLocally.add(pair.local);
22428
22480
  }
22429
- const missing = [...usedFunctions].filter((f) => !existing.has(f) && !boundLocally.has(f));
22481
+ const missing = [...usedFunctions].filter((f) => !existing2.has(f) && !boundLocally.has(f));
22430
22482
  if (missing.length > 0) {
22431
22483
  imports.push(`import { ${missing.join(", ")} } from '@vesk/runtime';`);
22432
22484
  }
@@ -22494,6 +22546,7 @@ __export(server_utils_exports, {
22494
22546
  escapeHtml: () => escapeHtml,
22495
22547
  evalTopLevelCode: () => evalTopLevelCode,
22496
22548
  exprJS: () => exprJS,
22549
+ extractRuntimeBindingPairs: () => extractRuntimeBindingPairs,
22497
22550
  extractRuntimeNames: () => extractRuntimeNames,
22498
22551
  extractTopLevelNames: () => extractTopLevelNames,
22499
22552
  getClientIp: () => getClientIp,
@@ -22835,16 +22888,16 @@ function sha256Bytes(msg) {
22835
22888
  const s1 = rr(w[j - 2], 17) ^ rr(w[j - 2], 19) ^ w[j - 2] >>> 10;
22836
22889
  w[j] = w[j - 16] + s0 + w[j - 7] + s1 >>> 0;
22837
22890
  }
22838
- let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g4 = h6, h = h7;
22891
+ let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g5 = h6, h = h7;
22839
22892
  for (let j = 0; j < 64; j++) {
22840
22893
  const S1 = rr(e, 6) ^ rr(e, 11) ^ rr(e, 25);
22841
- const ch = e & f ^ ~e & g4;
22894
+ const ch = e & f ^ ~e & g5;
22842
22895
  const t1 = h + S1 + ch + SHA_K[j] + w[j] >>> 0;
22843
22896
  const S0 = rr(a, 2) ^ rr(a, 13) ^ rr(a, 22);
22844
22897
  const maj = a & b ^ a & c ^ b & c;
22845
22898
  const t2 = S0 + maj >>> 0;
22846
- h = g4;
22847
- g4 = f;
22899
+ h = g5;
22900
+ g5 = f;
22848
22901
  f = e;
22849
22902
  e = d + t1 >>> 0;
22850
22903
  d = c;
@@ -22858,7 +22911,7 @@ function sha256Bytes(msg) {
22858
22911
  h3 = h3 + d >>> 0;
22859
22912
  h4 = h4 + e >>> 0;
22860
22913
  h5 = h5 + f >>> 0;
22861
- h6 = h6 + g4 >>> 0;
22914
+ h6 = h6 + g5 >>> 0;
22862
22915
  h7 = h7 + h >>> 0;
22863
22916
  }
22864
22917
  const out = new Uint8Array(32);
@@ -23281,33 +23334,39 @@ function tryParseTopLevel(code) {
23281
23334
  return null;
23282
23335
  }
23283
23336
  }
23284
- function extractRuntimeNames(importStrs) {
23285
- const names = [];
23337
+ function extractRuntimeBindingPairs(importStrs) {
23338
+ const pairs = [];
23339
+ const isRuntimeTarget = (src2) => src2 === "@vesk/runtime" || src2 === "@vesk/reactivity" || src2.startsWith("@vesk/runtime/");
23286
23340
  for (const imp of importStrs) {
23287
23341
  const ast = tryParseImport(imp);
23288
23342
  if (ast) {
23289
23343
  for (const stmt of ast.body) {
23290
23344
  if (stmt.type !== "ImportDeclaration") continue;
23345
+ if (stmt.importKind === "type") continue;
23291
23346
  const src2 = stmt.source?.value;
23292
- if (typeof src2 !== "string" || src2 !== "@vesk/runtime" && src2 !== "@vesk/reactivity") continue;
23347
+ if (typeof src2 !== "string" || !isRuntimeTarget(src2)) continue;
23293
23348
  for (const spec of stmt.specifiers || []) {
23294
23349
  if (spec.importKind === "type") continue;
23295
23350
  if (spec.type === "ImportSpecifier") {
23296
- const name = spec.local?.name || spec.imported?.name;
23297
- if (name) names.push(name);
23351
+ const local = spec.local?.name;
23352
+ const imported = spec.imported?.name;
23353
+ if (local) pairs.push({ imported: imported || local, local });
23298
23354
  } else if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportNamespaceSpecifier") {
23299
- if (spec.local?.name) names.push(spec.local.name);
23355
+ if (spec.local?.name) pairs.push({ imported: "*", local: spec.local.name });
23300
23356
  }
23301
23357
  }
23302
23358
  }
23303
23359
  continue;
23304
23360
  }
23305
23361
  const target = importModuleTarget(imp);
23306
- if (target === "@vesk/runtime" || target === "@vesk/reactivity") {
23307
- for (const name of extractImportNames(imp)) names.push(name);
23362
+ if (target && isRuntimeTarget(target)) {
23363
+ for (const name of extractImportNames(imp)) pairs.push({ imported: name, local: name });
23308
23364
  }
23309
23365
  }
23310
- return names;
23366
+ return pairs;
23367
+ }
23368
+ function extractRuntimeNames(importStrs) {
23369
+ return extractRuntimeBindingPairs(importStrs).map((p) => p.local);
23311
23370
  }
23312
23371
  function tryParseImport(code) {
23313
23372
  try {
@@ -23348,7 +23407,7 @@ function setRuntimeModule(mod) {
23348
23407
  __cachedRuntimeModule = mod;
23349
23408
  }
23350
23409
  function loadRuntimeImports(importStrs) {
23351
- const names = extractRuntimeNames(importStrs);
23410
+ const pairs = extractRuntimeBindingPairs(importStrs);
23352
23411
  const mod = __cachedRuntimeModule || index_server_exports;
23353
23412
  if (mod) {
23354
23413
  const result = {};
@@ -23357,8 +23416,12 @@ function loadRuntimeImports(importStrs) {
23357
23416
  for (const name of ["get", "set", "track"]) {
23358
23417
  if (name in mod) result[name] = mod[name];
23359
23418
  }
23360
- for (const name of names) {
23361
- if (name in mod) result[name] = mod[name];
23419
+ for (const { imported, local } of pairs) {
23420
+ if (imported === "*") {
23421
+ result[local] = mod;
23422
+ } else if (imported in mod) {
23423
+ result[local] = mod[imported];
23424
+ }
23362
23425
  }
23363
23426
  return result;
23364
23427
  }
@@ -23871,7 +23934,7 @@ function headers() {
23871
23934
  }
23872
23935
  function applyRequestSecurity(request, response) {
23873
23936
  if (!request || !response) return;
23874
- const overrides = request.getSecurityOverrides?.() || {};
23937
+ const overrides = getSecurityOverrides() || request.getSecurityOverrides?.() || {};
23875
23938
  if (overrides.contentSecurityPolicy !== void 0) {
23876
23939
  response.setCsp(overrides.contentSecurityPolicy);
23877
23940
  }
@@ -23951,6 +24014,7 @@ var ServerRequest, ServerResponse, DEFAULT_MAX_BODY_BYTES2, PayloadTooLargeError
23951
24014
  var init_request = __esm({
23952
24015
  "../runtime/src/request.ts"() {
23953
24016
  "use strict";
24017
+ init_security_overrides();
23954
24018
  ServerRequest = class extends Request {
23955
24019
  _cookies;
23956
24020
  _params;
@@ -24192,19 +24256,25 @@ var init_request = __esm({
24192
24256
  }
24193
24257
  setCsp(policy) {
24194
24258
  this._security.contentSecurityPolicy = policy;
24259
+ setSecurityOverride("contentSecurityPolicy", policy);
24195
24260
  }
24196
24261
  setRateLimit(options) {
24197
24262
  this._security.rateLimit = options;
24263
+ setSecurityOverride("rateLimit", options);
24198
24264
  }
24199
24265
  setCsrf(enable) {
24200
24266
  this._security.csrf = enable;
24267
+ setSecurityOverride("csrf", enable);
24201
24268
  }
24202
24269
  setSecurityHeader(name, value) {
24203
24270
  if (!this._security.customHeaders) this._security.customHeaders = {};
24204
24271
  this._security.customHeaders[name] = value;
24272
+ const existing2 = this._security.customHeaders;
24273
+ setSecurityOverride("customHeaders", { ...existing2 });
24205
24274
  }
24206
24275
  setTrustProxy(enable) {
24207
24276
  this._security.trustProxy = enable;
24277
+ setSecurityOverride("trustProxy", enable);
24208
24278
  }
24209
24279
  getSecurityOverrides() {
24210
24280
  return this._security;
@@ -24302,14 +24372,14 @@ var init_request = __esm({
24302
24372
  _flushSecurityHeaders() {
24303
24373
  for (const [name, value] of Object.entries(this._secHeaders)) {
24304
24374
  if (value === null) continue;
24305
- const existing = this.headers?.get(name);
24306
- if (!existing) this.headers?.set(name, value);
24375
+ const existing2 = this.headers?.get(name);
24376
+ if (!existing2) this.headers?.set(name, value);
24307
24377
  }
24308
24378
  this._secHeaders = {};
24309
24379
  if (this._cookieHeaders.length > 0) {
24310
- const existing = this.headers?.get("Set-Cookie");
24311
- if (existing) {
24312
- this.headers?.set("Set-Cookie", existing + ", " + this._cookieHeaders.join(", "));
24380
+ const existing2 = this.headers?.get("Set-Cookie");
24381
+ if (existing2) {
24382
+ this.headers?.set("Set-Cookie", existing2 + ", " + this._cookieHeaders.join(", "));
24313
24383
  } else {
24314
24384
  this.headers?.set("Set-Cookie", this._cookieHeaders.join(", "));
24315
24385
  }
@@ -24769,8 +24839,8 @@ function Experiment(props) {
24769
24839
  }
24770
24840
  if (track3 && assignedVariant && typeof window !== "undefined") {
24771
24841
  const w = window;
24772
- const existing = w.__vsk_experiments || (w.__vsk_experiments = []);
24773
- existing.push({ experiment: name, variant: assignedVariant.name || "default" });
24842
+ const existing2 = w.__vsk_experiments || (w.__vsk_experiments = []);
24843
+ existing2.push({ experiment: name, variant: assignedVariant.name || "default" });
24774
24844
  }
24775
24845
  return assignedVariant ? assignedVariant.children || assignedVariant.content || null : defaultContent;
24776
24846
  }
@@ -24844,8 +24914,8 @@ function Field(props, registry, hydrate) {
24844
24914
  if (hydrate && hydrate.nextElement) {
24845
24915
  let wrapper2 = hydrate.nextElement("div");
24846
24916
  if (wrapper2 && !wrapper2.parentNode && hydrate.root) {
24847
- const existing = hydrate.root.querySelector(`[data-vsk-field="${name}"]`);
24848
- if (existing) wrapper2 = existing;
24917
+ const existing2 = hydrate.root.querySelector(`[data-vsk-field="${name}"]`);
24918
+ if (existing2) wrapper2 = existing2;
24849
24919
  }
24850
24920
  const inner = wrapper2 ? wrapper2.querySelector(`[data-vsk-field="${name}"]`) : null;
24851
24921
  const fieldEl = inner || wrapper2;
@@ -24987,8 +25057,8 @@ function Form(props, registry, hydrate) {
24987
25057
  const skipK = typeof hydrate.takeSkipK === "function" ? hydrate.takeSkipK() : 0;
24988
25058
  let form2 = hydrate.nextElement("form", skipK);
24989
25059
  if (form2 && !form2.parentNode && hydrate.root) {
24990
- const existing = hydrate.root.querySelector("form");
24991
- if (existing) form2 = existing;
25060
+ const existing2 = hydrate.root.querySelector("form");
25061
+ if (existing2) form2 = existing2;
24992
25062
  }
24993
25063
  if (form2) {
24994
25064
  form2.noValidate = true;
@@ -26846,8 +26916,8 @@ function Md(props, _registry, hydrate) {
26846
26916
  if (hydrate && typeof hydrate.nextElement === "function") {
26847
26917
  let el = hydrate.nextElement("div");
26848
26918
  if (el && !el.parentNode && hydrate.root) {
26849
- const existing = hydrate.root.querySelector("div");
26850
- if (existing) el = existing;
26919
+ const existing2 = hydrate.root.querySelector("div");
26920
+ if (existing2) el = existing2;
26851
26921
  }
26852
26922
  const claimed = !!el.parentNode;
26853
26923
  if (pathMode && claimed) {
@@ -27417,18 +27487,18 @@ function rerenderNode(node, deps, call) {
27417
27487
  if (typeof document === "undefined") return node;
27418
27488
  if (deps.length === 0) return node;
27419
27489
  let owned = null;
27420
- let current2 = null;
27490
+ let current3 = null;
27421
27491
  if (Array.isArray(node)) {
27422
27492
  const roots = node.filter((n) => n && typeof n.nodeType === "number");
27423
27493
  owned = roots.length ? roots : null;
27424
- current2 = owned ? owned[0] : null;
27494
+ current3 = owned ? owned[0] : null;
27425
27495
  } else if (node && typeof node.nodeType === "number") {
27426
- current2 = node;
27496
+ current3 = node;
27427
27497
  }
27428
- if (!current2) return node;
27498
+ if (!current3) return node;
27429
27499
  const liveRange = () => {
27430
27500
  if (owned) return owned;
27431
- return current2 && current2.parentNode ? [current2] : null;
27501
+ return current3 && current3.parentNode ? [current3] : null;
27432
27502
  };
27433
27503
  let seen = deps.map(readDep);
27434
27504
  effect(() => {
@@ -27444,7 +27514,7 @@ function rerenderNode(node, deps, call) {
27444
27514
  for (const freshNode of fresh) parent.insertBefore(freshNode, old[0]);
27445
27515
  for (const oldNode of old) if (oldNode.parentNode) oldNode.parentNode.removeChild(oldNode);
27446
27516
  owned = next.nodeType === 11 ? fresh : null;
27447
- current2 = fresh[0] ?? current2;
27517
+ current3 = fresh[0] ?? current3;
27448
27518
  });
27449
27519
  return node;
27450
27520
  }
@@ -27460,9 +27530,9 @@ var init_primitive = __esm({
27460
27530
 
27461
27531
  // ../runtime/src/action.ts
27462
27532
  function getActionRegistry() {
27463
- const g4 = globalThis;
27464
- if (!g4[registryKey]) g4[registryKey] = {};
27465
- return g4[registryKey];
27533
+ const g5 = globalThis;
27534
+ if (!g5[registryKey]) g5[registryKey] = {};
27535
+ return g5[registryKey];
27466
27536
  }
27467
27537
  function hashString(str3) {
27468
27538
  let h1 = 2166136261;
@@ -27500,8 +27570,8 @@ function getAction(id) {
27500
27570
  return getActionRegistry()[id] || null;
27501
27571
  }
27502
27572
  function clearActions() {
27503
- const g4 = globalThis;
27504
- g4[registryKey] = {};
27573
+ const g5 = globalThis;
27574
+ g5[registryKey] = {};
27505
27575
  }
27506
27576
  function isFormAction(action) {
27507
27577
  return typeof action === "object" && action !== null && (action.__veskAction === true || typeof action.id === "string" && typeof action.url === "string");
@@ -27714,8 +27784,8 @@ function setIn(value, path, next) {
27714
27784
  const [key, ...rest] = path;
27715
27785
  const container = Array.isArray(value) ? value : isObject(value) ? value : null;
27716
27786
  if (container === null) return value;
27717
- const current2 = Array.isArray(container) ? container[typeof key === "number" ? key : Number(key)] : container[String(key)];
27718
- if (rest.length > 0 && current2 === void 0) return value;
27787
+ const current3 = Array.isArray(container) ? container[typeof key === "number" ? key : Number(key)] : container[String(key)];
27788
+ if (rest.length > 0 && current3 === void 0) return value;
27719
27789
  if (Array.isArray(value)) {
27720
27790
  const index = typeof key === "number" ? key : Number(key);
27721
27791
  if (!Number.isInteger(index) || index < 0) return value;
@@ -27736,18 +27806,18 @@ function updateIn(value, path, fn) {
27736
27806
  return setIn(value, [key], next);
27737
27807
  }
27738
27808
  function getIn(value, path) {
27739
- let current2 = value;
27809
+ let current3 = value;
27740
27810
  for (const key of path) {
27741
- if (Array.isArray(current2)) {
27811
+ if (Array.isArray(current3)) {
27742
27812
  const index = typeof key === "number" ? key : Number(key);
27743
27813
  if (!Number.isInteger(index)) return void 0;
27744
- current2 = current2[index];
27814
+ current3 = current3[index];
27745
27815
  continue;
27746
27816
  }
27747
- if (!isObject(current2)) return void 0;
27748
- current2 = current2[String(key)];
27817
+ if (!isObject(current3)) return void 0;
27818
+ current3 = current3[String(key)];
27749
27819
  }
27750
- return current2;
27820
+ return current3;
27751
27821
  }
27752
27822
  var init_nested_update = __esm({
27753
27823
  "../runtime/src/nested-update.ts"() {
@@ -27755,6 +27825,1019 @@ var init_nested_update = __esm({
27755
27825
  }
27756
27826
  });
27757
27827
 
27828
+ // ../runtime/src/store-persistence.ts
27829
+ function currentSsrToken() {
27830
+ const g5 = globalThis;
27831
+ return typeof g5.__vsk_ssr_token === "string" ? g5.__vsk_ssr_token : "";
27832
+ }
27833
+ function persistedStoreCookieName(storageKey) {
27834
+ return "vsk_store_" + encodeURIComponent(storageKey);
27835
+ }
27836
+ function bucketFor(token) {
27837
+ const set2 = pendingKeys.get(token);
27838
+ if (set2) return set2;
27839
+ const fresh = /* @__PURE__ */ new Set();
27840
+ pendingKeys.set(token, fresh);
27841
+ return fresh;
27842
+ }
27843
+ function readPersistedStorage(storageKey) {
27844
+ if (!storageKey) return null;
27845
+ if (typeof window === "undefined") {
27846
+ bucketFor(currentSsrToken()).add(storageKey);
27847
+ return serverReadHook ? serverReadHook(storageKey) ?? null : null;
27848
+ }
27849
+ const init = globalThis.__VESK_STORE_INIT__;
27850
+ if (init && init[storageKey] !== void 0) {
27851
+ const raw2 = init[storageKey];
27852
+ delete init[storageKey];
27853
+ try {
27854
+ localStorage.setItem(storageKey, raw2);
27855
+ } catch {
27856
+ }
27857
+ return raw2;
27858
+ }
27859
+ try {
27860
+ return localStorage.getItem(storageKey);
27861
+ } catch {
27862
+ return null;
27863
+ }
27864
+ }
27865
+ function writePersistedStorage(storageKey, raw2) {
27866
+ if (!storageKey) return;
27867
+ if (typeof window !== "undefined") {
27868
+ try {
27869
+ localStorage.setItem(storageKey, raw2);
27870
+ } catch {
27871
+ }
27872
+ }
27873
+ if (typeof document !== "undefined") {
27874
+ try {
27875
+ document.cookie = persistedStoreCookieName(storageKey) + "=" + encodeURIComponent(raw2) + "; path=/; max-age=31536000; SameSite=Lax";
27876
+ } catch {
27877
+ }
27878
+ }
27879
+ }
27880
+ function clearPersistedStorage(storageKey) {
27881
+ if (!storageKey) return;
27882
+ if (typeof window !== "undefined") {
27883
+ try {
27884
+ localStorage.removeItem(storageKey);
27885
+ } catch {
27886
+ }
27887
+ }
27888
+ if (typeof document !== "undefined") {
27889
+ try {
27890
+ document.cookie = persistedStoreCookieName(storageKey) + "=; path=/; max-age=0";
27891
+ } catch {
27892
+ }
27893
+ }
27894
+ }
27895
+ var serverReadHook, pendingKeys;
27896
+ var init_store_persistence = __esm({
27897
+ "../runtime/src/store-persistence.ts"() {
27898
+ "use strict";
27899
+ serverReadHook = null;
27900
+ pendingKeys = /* @__PURE__ */ new Map();
27901
+ }
27902
+ });
27903
+
27904
+ // ../runtime/src/store.ts
27905
+ function cloneState(value) {
27906
+ return Array.isArray(value) ? value.slice() : { ...value };
27907
+ }
27908
+ function createStore(initial, options = {}) {
27909
+ const { persist = false, storageKey, devtools = false } = options;
27910
+ let value = cloneState(initial);
27911
+ if (persist && storageKey) {
27912
+ const stored = readPersistedStorage(storageKey);
27913
+ if (stored) {
27914
+ try {
27915
+ value = JSON.parse(stored);
27916
+ } catch {
27917
+ }
27918
+ }
27919
+ }
27920
+ const stateCell = track(value);
27921
+ const subs = /* @__PURE__ */ new Set();
27922
+ const watchers = [];
27923
+ const middlewares = [];
27924
+ let prevValue = cloneState(value);
27925
+ let batchDepth = 0;
27926
+ let dirty = false;
27927
+ function notifyNow(action, payload) {
27928
+ const current3 = stateCell.get();
27929
+ if (current3 === prevValue) return;
27930
+ subs.forEach((fn) => fn(current3));
27931
+ watchers.forEach(({ selector, cb, equals }) => {
27932
+ const eq = equals ?? Object.is;
27933
+ const newVal = selector(current3);
27934
+ const oldVal = selector(prevValue);
27935
+ if (!eq(newVal, oldVal)) cb(newVal, oldVal);
27936
+ });
27937
+ middlewares.forEach((fn) => fn(current3, action, payload));
27938
+ if (devtools && typeof window !== "undefined") {
27939
+ const dt = window.__VESK_STORE_DEVTOOLS__;
27940
+ if (dt && typeof dt.send === "function") {
27941
+ dt.send({ type: action, payload, state: structuredClone(current3) });
27942
+ }
27943
+ }
27944
+ prevValue = cloneState(current3);
27945
+ }
27946
+ function notifyDirty(action, payload) {
27947
+ if (batchDepth > 0) {
27948
+ dirty = true;
27949
+ } else {
27950
+ notifyNow(action, payload);
27951
+ }
27952
+ }
27953
+ function persistToStorage() {
27954
+ if (persist && storageKey) {
27955
+ try {
27956
+ writePersistedStorage(storageKey, JSON.stringify(stateCell.get()));
27957
+ } catch (err) {
27958
+ console.log("error saving to localStorage: ", err);
27959
+ }
27960
+ }
27961
+ }
27962
+ function get2() {
27963
+ return stateCell.get();
27964
+ }
27965
+ function set2(next, action = "set") {
27966
+ stateCell.set(next);
27967
+ persistToStorage();
27968
+ notifyDirty(action, next);
27969
+ }
27970
+ function update(partialOrFn, action = "update") {
27971
+ const current3 = stateCell.get();
27972
+ const patch = typeof partialOrFn === "function" ? partialOrFn(current3) : partialOrFn;
27973
+ const next = Object.assign(cloneState(current3), patch);
27974
+ stateCell.set(next);
27975
+ persistToStorage();
27976
+ notifyDirty(action, patch);
27977
+ }
27978
+ function deleteKeys(keys, action = "delete") {
27979
+ const current3 = stateCell.get();
27980
+ const kArray = Array.isArray(keys) ? keys : [keys];
27981
+ const next = cloneState(current3);
27982
+ kArray.forEach((k) => {
27983
+ delete next[k];
27984
+ });
27985
+ stateCell.set(next);
27986
+ persistToStorage();
27987
+ notifyDirty(action, keys);
27988
+ }
27989
+ function reset2() {
27990
+ stateCell.set(cloneState(initial));
27991
+ notifyDirty("reset");
27992
+ }
27993
+ function rehydrate(newInitial) {
27994
+ Object.assign(initial, newInitial);
27995
+ stateCell.set(cloneState(initial));
27996
+ notifyDirty("rehydrate");
27997
+ }
27998
+ function clear() {
27999
+ stateCell.set(cloneState(initial));
28000
+ if (persist && storageKey) {
28001
+ clearPersistedStorage(storageKey);
28002
+ }
28003
+ notifyDirty("clear");
28004
+ }
28005
+ function batch(fn) {
28006
+ batchDepth++;
28007
+ try {
28008
+ return flush_sync(fn);
28009
+ } finally {
28010
+ batchDepth--;
28011
+ if (batchDepth === 0 && dirty) {
28012
+ notifyDirty("batch");
28013
+ dirty = false;
28014
+ }
28015
+ }
28016
+ }
28017
+ function subscribe(fn, selector, equals) {
28018
+ const eq = equals ?? Object.is;
28019
+ let hasPrev = false;
28020
+ let prev;
28021
+ const wrapper = selector ? (state) => {
28022
+ const selected = selector(state);
28023
+ if (!hasPrev || !eq(selected, prev)) {
28024
+ hasPrev = true;
28025
+ prev = selected;
28026
+ fn(selected);
28027
+ }
28028
+ } : fn;
28029
+ subs.add(wrapper);
28030
+ wrapper(stateCell.get());
28031
+ return () => subs.delete(wrapper);
28032
+ }
28033
+ function watch2(selector, callback, equals) {
28034
+ watchers.push({ selector, cb: callback, equals });
28035
+ return () => {
28036
+ const i = watchers.findIndex((w) => w.cb === callback);
28037
+ if (i >= 0) watchers.splice(i, 1);
28038
+ };
28039
+ }
28040
+ function use(middleware) {
28041
+ middlewares.push(middleware);
28042
+ return () => {
28043
+ const i = middlewares.indexOf(middleware);
28044
+ if (i >= 0) middlewares.splice(i, 1);
28045
+ };
28046
+ }
28047
+ function derive(selector, equals) {
28048
+ return {
28049
+ subscribe(cb) {
28050
+ return subscribe(
28051
+ (v) => cb(v),
28052
+ selector,
28053
+ equals
28054
+ );
28055
+ }
28056
+ };
28057
+ }
28058
+ function toJSON() {
28059
+ return structuredClone(stateCell.get());
28060
+ }
28061
+ return {
28062
+ get: get2,
28063
+ set: set2,
28064
+ update,
28065
+ delete: deleteKeys,
28066
+ clear,
28067
+ subscribe,
28068
+ watch: watch2,
28069
+ use,
28070
+ derive,
28071
+ batch,
28072
+ reset: reset2,
28073
+ rehydrate,
28074
+ toJSON
28075
+ };
28076
+ }
28077
+ var init_store = __esm({
28078
+ "../runtime/src/store.ts"() {
28079
+ "use strict";
28080
+ init_ripple_runtime();
28081
+ init_store_persistence();
28082
+ }
28083
+ });
28084
+
28085
+ // ../runtime/src/path-store.ts
28086
+ function isObject2(value) {
28087
+ return value !== null && typeof value === "object";
28088
+ }
28089
+ function isDigits(s) {
28090
+ if (s.length === 0) return false;
28091
+ for (let i = 0; i < s.length; i++) {
28092
+ const c = s.charCodeAt(i);
28093
+ if (c < 48 || c > 57) return false;
28094
+ }
28095
+ return true;
28096
+ }
28097
+ function parseStorePath(input) {
28098
+ const tokens = [];
28099
+ let i = 0;
28100
+ const n = input.length;
28101
+ const readBracketed = () => {
28102
+ i++;
28103
+ let start = i;
28104
+ while (i < n && input[i] >= "0" && input[i] <= "9") i++;
28105
+ if (start === i || input[i] !== "]") {
28106
+ throw new Error(`Path store: bad index in path "${input}"`);
28107
+ }
28108
+ tokens.push(Number(input.slice(start, i)));
28109
+ i++;
28110
+ };
28111
+ while (i < n) {
28112
+ const c = input[i];
28113
+ if (c === ".") {
28114
+ i++;
28115
+ continue;
28116
+ }
28117
+ if (c === "[") {
28118
+ readBracketed();
28119
+ continue;
28120
+ }
28121
+ let start = i;
28122
+ while (i < n && input[i] !== "." && input[i] !== "[") i++;
28123
+ tokens.push(input.slice(start, i));
28124
+ }
28125
+ return tokens;
28126
+ }
28127
+ function pathKey(tokens) {
28128
+ return tokens.join("\0");
28129
+ }
28130
+ function tokensOfKey(key) {
28131
+ if (key === "") return [];
28132
+ return key.split("\0").map((t) => isDigits(t) ? Number(t) : t);
28133
+ }
28134
+ function isPrefix(prefix, full) {
28135
+ if (prefix.length > full.length) return false;
28136
+ for (let i = 0; i < prefix.length; i++) {
28137
+ if (String(prefix[i]) !== String(full[i])) return false;
28138
+ }
28139
+ return true;
28140
+ }
28141
+ function isStrictPrefix(prefix, full) {
28142
+ return prefix.length > 0 && prefix.length < full.length && isPrefix(prefix, full);
28143
+ }
28144
+ function cloneValue(value, seen) {
28145
+ if (value === null || typeof value !== "object") return value;
28146
+ seen = seen ?? /* @__PURE__ */ new Map();
28147
+ const existing2 = seen.get(value);
28148
+ if (existing2 !== void 0) return existing2;
28149
+ if (value instanceof Date) {
28150
+ const d = new Date(value.getTime());
28151
+ seen.set(value, d);
28152
+ return d;
28153
+ }
28154
+ if (value instanceof RegExp) {
28155
+ const r = new RegExp(value.source, value.flags);
28156
+ seen.set(value, r);
28157
+ return r;
28158
+ }
28159
+ if (value instanceof Map) {
28160
+ const out = /* @__PURE__ */ new Map();
28161
+ seen.set(value, out);
28162
+ for (const [k, v] of value) out.set(cloneValue(k, seen), cloneValue(v, seen));
28163
+ return out;
28164
+ }
28165
+ if (value instanceof Set) {
28166
+ const out = /* @__PURE__ */ new Set();
28167
+ seen.set(value, out);
28168
+ for (const v of value) out.add(cloneValue(v, seen));
28169
+ return out;
28170
+ }
28171
+ if (Array.isArray(value)) {
28172
+ const out = [];
28173
+ seen.set(value, out);
28174
+ for (const item of value) out.push(cloneValue(item, seen));
28175
+ return out;
28176
+ }
28177
+ if (ArrayBuffer.isView(value)) {
28178
+ const out = value.slice();
28179
+ seen.set(value, out);
28180
+ return out;
28181
+ }
28182
+ const proto = Object.getPrototypeOf(value);
28183
+ if (proto === Object.prototype || proto === null) {
28184
+ const out = {};
28185
+ seen.set(value, out);
28186
+ for (const key of Object.keys(value)) {
28187
+ out[key] = cloneValue(value[key], seen);
28188
+ }
28189
+ return out;
28190
+ }
28191
+ seen.set(value, value);
28192
+ try {
28193
+ return structuredClone(value);
28194
+ } catch {
28195
+ return value;
28196
+ }
28197
+ }
28198
+ function plainClone(value, seen) {
28199
+ if (value === null || typeof value !== "object") return value;
28200
+ seen = seen ?? /* @__PURE__ */ new Set();
28201
+ if (seen.has(value)) throw new Error("Path store: toJSON() cannot serialize cyclic state");
28202
+ seen.add(value);
28203
+ if (value instanceof Date) return value.toISOString();
28204
+ if (value instanceof RegExp) return String(value);
28205
+ if (value instanceof Map) {
28206
+ const out2 = [];
28207
+ for (const [k, v] of value) out2.push([plainClone(k, seen), plainClone(v, seen)]);
28208
+ return out2;
28209
+ }
28210
+ if (value instanceof Set) {
28211
+ const out2 = [];
28212
+ for (const v of value) out2.push(plainClone(v, seen));
28213
+ return out2;
28214
+ }
28215
+ if (Array.isArray(value)) {
28216
+ const out2 = [];
28217
+ for (const item of value) out2.push(plainClone(item, seen));
28218
+ return out2;
28219
+ }
28220
+ const out = {};
28221
+ for (const key of Object.keys(value)) {
28222
+ out[key] = plainClone(value[key], seen);
28223
+ }
28224
+ return out;
28225
+ }
28226
+ function shallowDiff(before, after, base, out) {
28227
+ if (Object.is(before, after)) return;
28228
+ const beforeObj = isObject2(before);
28229
+ const afterObj = isObject2(after);
28230
+ if (!beforeObj || !afterObj || Array.isArray(before) !== Array.isArray(after)) {
28231
+ out.push({ path: pathKey(base), before, after });
28232
+ return;
28233
+ }
28234
+ const array = Array.isArray(before);
28235
+ const keys = /* @__PURE__ */ new Set([
28236
+ ...Object.keys(before),
28237
+ ...Object.keys(after)
28238
+ ]);
28239
+ for (const key of keys) {
28240
+ const segment = array && isDigits(key) ? Number(key) : key;
28241
+ shallowDiff(
28242
+ before[key],
28243
+ after[key],
28244
+ [...base, segment],
28245
+ out
28246
+ );
28247
+ }
28248
+ }
28249
+ function createPathStore(initial, options = {}) {
28250
+ const { persist = false, storageKey, historyLimit = 500 } = options;
28251
+ let state = cloneValue(initial);
28252
+ if (persist && storageKey) {
28253
+ const raw2 = readPersistedStorage(storageKey);
28254
+ if (raw2) {
28255
+ try {
28256
+ const parsed = JSON.parse(raw2);
28257
+ if (parsed !== null && typeof parsed === "object") {
28258
+ state = { ...state, ...cloneValue(parsed) };
28259
+ }
28260
+ } catch {
28261
+ }
28262
+ }
28263
+ }
28264
+ const rootCell = track(state);
28265
+ const cellRoot = {};
28266
+ function nodeFor(path, create) {
28267
+ let node = cellRoot;
28268
+ for (const seg of path) {
28269
+ const key = String(seg);
28270
+ let child = node.children?.get(key);
28271
+ if (!child) {
28272
+ if (!create) return null;
28273
+ child = {};
28274
+ if (!node.children) node.children = /* @__PURE__ */ new Map();
28275
+ node.children.set(key, child);
28276
+ }
28277
+ node = child;
28278
+ }
28279
+ return node;
28280
+ }
28281
+ function cellFor(path) {
28282
+ const node = nodeFor(path, true);
28283
+ if (!node.cell) {
28284
+ node.cell = track(getIn(state, path));
28285
+ setImprint(node, path);
28286
+ }
28287
+ return node.cell;
28288
+ }
28289
+ function collectCellNodes(node) {
28290
+ const out = [];
28291
+ if (!node) return out;
28292
+ const stack = [node];
28293
+ while (stack.length > 0) {
28294
+ const n = stack.pop();
28295
+ if (n.cell) out.push(n);
28296
+ if (n.children) for (const child of n.children.values()) stack.push(child);
28297
+ }
28298
+ return out;
28299
+ }
28300
+ function cellsRelatedTo(path) {
28301
+ const out = [];
28302
+ const tNode = nodeFor(path, false);
28303
+ out.push(...collectCellNodes(tNode));
28304
+ for (let i = path.length - 1; i > 0; i--) {
28305
+ const ancestor = nodeFor(path.slice(0, i), false);
28306
+ if (ancestor?.cell) out.push(ancestor);
28307
+ }
28308
+ return out;
28309
+ }
28310
+ function syncCell(node, path) {
28311
+ const cell = node.cell;
28312
+ const next = getIn(state, path);
28313
+ if (!Object.is(cell.get(), next)) cell.set(next);
28314
+ }
28315
+ function syncPathCells(touched) {
28316
+ if (touched === null) {
28317
+ for (const node of collectCellNodes(cellRoot)) {
28318
+ if (node.cell) syncCell(node, nodePathOf(node));
28319
+ }
28320
+ return;
28321
+ }
28322
+ for (const node of cellsRelatedTo(touched)) {
28323
+ if (!node.cell) continue;
28324
+ syncCell(node, nodePathOf(node));
28325
+ }
28326
+ }
28327
+ function nodePathOf(node) {
28328
+ return nodePathCache.get(node) ?? [];
28329
+ }
28330
+ const nodePathCache = /* @__PURE__ */ new Map();
28331
+ function setImprint(node, path) {
28332
+ nodePathCache.set(node, path.slice());
28333
+ }
28334
+ const derivedDefs = /* @__PURE__ */ new Map();
28335
+ const depRoot = { defs: null };
28336
+ function depNodeFor(tokens, create) {
28337
+ let node = depRoot;
28338
+ for (const seg of tokens) {
28339
+ const key = String(seg);
28340
+ let child = node.children?.get(key);
28341
+ if (!child) {
28342
+ if (!create) return null;
28343
+ child = { defs: null };
28344
+ if (!node.children) node.children = /* @__PURE__ */ new Map();
28345
+ node.children.set(key, child);
28346
+ }
28347
+ node = child;
28348
+ }
28349
+ return node;
28350
+ }
28351
+ function registerDep(def, tokens) {
28352
+ const node = depNodeFor(tokens, true);
28353
+ if (!node.defs) node.defs = /* @__PURE__ */ new Set();
28354
+ node.defs.add(def);
28355
+ }
28356
+ function unregisterDep(def, tokens) {
28357
+ const node = depNodeFor(tokens, false);
28358
+ if (node?.defs) {
28359
+ node.defs.delete(def);
28360
+ if (node.defs.size === 0) node.defs = null;
28361
+ }
28362
+ }
28363
+ function registerDef(def) {
28364
+ for (const dep of def.deps) registerDep(def, dep);
28365
+ }
28366
+ function unregisterDef(def) {
28367
+ for (const dep of def.deps) unregisterDep(def, dep);
28368
+ }
28369
+ function derivedsRelatedTo(path, out) {
28370
+ const n = depNodeFor(path, false);
28371
+ if (n) {
28372
+ const stack = [n];
28373
+ while (stack.length > 0) {
28374
+ const node = stack.pop();
28375
+ if (node.defs) for (const def of node.defs) out.add(def);
28376
+ if (node.children) for (const child of node.children.values()) stack.push(child);
28377
+ }
28378
+ }
28379
+ for (let i = path.length - 1; i > 0; i--) {
28380
+ const ancestor = depNodeFor(path.slice(0, i), false);
28381
+ if (ancestor?.defs) for (const def of ancestor.defs) out.add(def);
28382
+ }
28383
+ return Array.from(out);
28384
+ }
28385
+ const COLLAPSE_THRESHOLD = 8;
28386
+ const proxyTargets = /* @__PURE__ */ new WeakMap();
28387
+ function evaluate(selector) {
28388
+ return untrack2(() => {
28389
+ const deps = [];
28390
+ const seen = /* @__PURE__ */ new Set();
28391
+ const envelopeLeaves = /* @__PURE__ */ new Map();
28392
+ const collapsed = /* @__PURE__ */ new Set();
28393
+ const recordLeaf = (path) => {
28394
+ const k = pathKey(path);
28395
+ if (!seen.has(k)) {
28396
+ seen.add(k);
28397
+ deps.push(path);
28398
+ }
28399
+ };
28400
+ const recordEnvelope = (env) => {
28401
+ if (env.length === 0) return;
28402
+ const k = pathKey(env);
28403
+ const count = (envelopeLeaves.get(k) ?? 0) + 1;
28404
+ envelopeLeaves.set(k, count);
28405
+ if (count >= COLLAPSE_THRESHOLD) collapsed.add(k);
28406
+ recordLeaf(env);
28407
+ };
28408
+ const isPlain = (value) => value !== null && typeof value === "object" && (Array.isArray(value) || Object.prototype.toString.call(value) === "[object Object]");
28409
+ const wrap = (value, base) => {
28410
+ if (!isPlain(value)) return value;
28411
+ const proxy = new Proxy(value, {
28412
+ get(target, prop, receiver) {
28413
+ if (typeof prop === "symbol") return Reflect.get(target, prop, receiver);
28414
+ const array = Array.isArray(target);
28415
+ const segment = array && isDigits(String(prop)) ? Number(prop) : String(prop);
28416
+ const child = base.concat(segment);
28417
+ const v = Reflect.get(target, prop, receiver);
28418
+ if (isPlain(v)) return wrap(v, child);
28419
+ if (typeof v === "function") return v;
28420
+ recordLeaf(child);
28421
+ if (array) recordEnvelope(base);
28422
+ return v;
28423
+ },
28424
+ set() {
28425
+ throw new Error("Path store: derived selectors must be pure \u2014 no writes.");
28426
+ }
28427
+ });
28428
+ proxyTargets.set(proxy, value);
28429
+ return proxy;
28430
+ };
28431
+ const unwrap = (value) => {
28432
+ if (value === null || typeof value !== "object") return value;
28433
+ const target = proxyTargets.get(value);
28434
+ if (target !== void 0) return unwrap(target);
28435
+ if (Array.isArray(value)) {
28436
+ let changed2 = false;
28437
+ const out2 = [];
28438
+ for (const item of value) {
28439
+ const next = unwrap(item);
28440
+ if (next !== item) changed2 = true;
28441
+ out2.push(next);
28442
+ }
28443
+ return changed2 ? out2 : value;
28444
+ }
28445
+ let changed = false;
28446
+ const out = {};
28447
+ for (const key of Object.keys(value)) {
28448
+ const next = unwrap(value[key]);
28449
+ if (next !== value[key]) changed = true;
28450
+ out[key] = next;
28451
+ }
28452
+ return changed ? out : value;
28453
+ };
28454
+ const result = selector(wrap(state, []));
28455
+ const finalDeps = collapsed.size === 0 ? deps : deps.filter((d) => {
28456
+ for (const envKey of collapsed) {
28457
+ if (isStrictPrefix(tokensOfKey(envKey), d)) return false;
28458
+ }
28459
+ return true;
28460
+ });
28461
+ return { value: unwrap(result), deps: finalDeps };
28462
+ });
28463
+ }
28464
+ function recomputeDerived(changes, version3) {
28465
+ const queue = [];
28466
+ const queued = /* @__PURE__ */ new Set();
28467
+ const collect = (tokens) => {
28468
+ for (const def of derivedsRelatedTo(tokens, /* @__PURE__ */ new Set())) {
28469
+ if (!queued.has(def)) {
28470
+ queued.add(def);
28471
+ queue.push(def);
28472
+ }
28473
+ }
28474
+ };
28475
+ for (const change of changes) collect(tokensOfKey(change.path));
28476
+ while (queue.length > 0) {
28477
+ const def = queue.pop();
28478
+ unregisterDef(def);
28479
+ const { value, deps } = evaluate(def.selector);
28480
+ def.deps = deps;
28481
+ registerDef(def);
28482
+ const before = def.cell.get();
28483
+ if (!def.equals(before, value)) {
28484
+ def.cell.set(value);
28485
+ def.lastTrigger = changes.map((c) => tokensOfKey(c.path));
28486
+ def.lastTriggerVersion = version3;
28487
+ mergedDirty = true;
28488
+ const change = { path: def.path, before, after: value };
28489
+ changes.push(change);
28490
+ collect(def.tokens);
28491
+ }
28492
+ }
28493
+ }
28494
+ let mergedCache = null;
28495
+ let mergedDirty = true;
28496
+ function invalidateMerged() {
28497
+ mergedCache = null;
28498
+ mergedDirty = true;
28499
+ }
28500
+ function buildMerged() {
28501
+ if (!mergedDirty && mergedCache !== null) return mergedCache;
28502
+ const base = rootCell.get();
28503
+ if (derivedDefs.size === 0) {
28504
+ mergedCache = base;
28505
+ mergedDirty = false;
28506
+ return base;
28507
+ }
28508
+ let acc = base;
28509
+ for (const def of derivedDefs.values()) {
28510
+ acc = setIn(acc, def.tokens, def.cell.get());
28511
+ }
28512
+ mergedCache = acc;
28513
+ mergedDirty = false;
28514
+ return acc;
28515
+ }
28516
+ const events = [];
28517
+ let version2 = 0;
28518
+ let undoStack = [];
28519
+ let redoStack = [];
28520
+ const lastCause = /* @__PURE__ */ new Map();
28521
+ function recordCause(changes, action, atVersion) {
28522
+ for (const change of changes) {
28523
+ lastCause.set(change.path, { action, version: atVersion });
28524
+ }
28525
+ }
28526
+ function commit(next, action, touched) {
28527
+ untrack2(() => {
28528
+ if (Object.is(next, state)) return;
28529
+ const changes = [];
28530
+ if (touched !== null) {
28531
+ shallowDiff(getIn(state, touched), getIn(next, touched), touched, changes);
28532
+ } else {
28533
+ shallowDiff(state, next, [], changes);
28534
+ }
28535
+ if (changes.length === 0) return;
28536
+ undoStack.push(state);
28537
+ if (undoStack.length > historyLimit) undoStack.shift();
28538
+ redoStack = [];
28539
+ state = next;
28540
+ rootCell.set(state);
28541
+ invalidateMerged();
28542
+ const nextVersion = version2 + 1;
28543
+ recordCause(changes, action, nextVersion);
28544
+ recomputeDerived(changes, nextVersion);
28545
+ syncPathCells(touched);
28546
+ dispatchAll();
28547
+ persistToStorage();
28548
+ version2 = nextVersion;
28549
+ events.push({ version: version2, action, at: Date.now(), changes });
28550
+ if (events.length > historyLimit) events.shift();
28551
+ });
28552
+ }
28553
+ function restore(snapshot, action) {
28554
+ const changes = [];
28555
+ untrack2(() => {
28556
+ shallowDiff(state, snapshot, [], changes);
28557
+ state = snapshot;
28558
+ rootCell.set(state);
28559
+ invalidateMerged();
28560
+ const nextVersion = version2 + 1;
28561
+ recordCause(changes, action, nextVersion);
28562
+ recomputeDerived(changes, nextVersion);
28563
+ syncPathCells(null);
28564
+ if (changes.length > 0) dispatchAll();
28565
+ persistToStorage();
28566
+ version2 = nextVersion;
28567
+ events.push({ version: version2, action, at: Date.now(), changes });
28568
+ if (events.length > historyLimit) events.shift();
28569
+ });
28570
+ return changes;
28571
+ }
28572
+ function persistToStorage() {
28573
+ if (!persist || !storageKey) return;
28574
+ try {
28575
+ writePersistedStorage(storageKey, JSON.stringify(state));
28576
+ } catch {
28577
+ }
28578
+ }
28579
+ const subscribers = /* @__PURE__ */ new Set();
28580
+ const watchers = /* @__PURE__ */ new Set();
28581
+ function dispatchAll() {
28582
+ const current3 = buildMerged();
28583
+ for (const wrapper of subscribers) wrapper(current3);
28584
+ for (const wrapper of watchers) wrapper();
28585
+ }
28586
+ function whyAt(tokens, depth = 0, versionNow = version2) {
28587
+ const path = pathKey(tokens);
28588
+ const value = getIn(state, tokens);
28589
+ if (depth > 64) return { path, value, cause: "initial" };
28590
+ const def = derivedDefs.get(path);
28591
+ if (def) {
28592
+ const node = {
28593
+ path,
28594
+ value: def.cell.get(),
28595
+ cause: "derived",
28596
+ from: def.deps.map((dep) => whyAt(dep, depth + 1))
28597
+ };
28598
+ if (def.lastTrigger) {
28599
+ node.changedBy = def.lastTrigger.map((trigger, i) => ({
28600
+ path: pathKey(trigger),
28601
+ value: getIn(state, trigger),
28602
+ cause: "action",
28603
+ action: i === 0 ? void 0 : void 0,
28604
+ // filled below from events
28605
+ version: def.lastTriggerVersion
28606
+ }));
28607
+ const first = def.lastTrigger[0];
28608
+ const ev = events.slice().reverse().find((e) => e.changes.some((c) => c.path === pathKey(first)));
28609
+ if (ev) {
28610
+ node.changedBy[0].action = ev.action;
28611
+ node.changedBy[0].version = ev.version;
28612
+ node.version = ev.version;
28613
+ }
28614
+ }
28615
+ void versionNow;
28616
+ return node;
28617
+ }
28618
+ const cause = lastCause.get(path);
28619
+ if (cause) {
28620
+ if (cause.action === "undo" || cause.action === "redo") {
28621
+ return { path, value, cause: "time-travel", action: cause.action, version: cause.version };
28622
+ }
28623
+ return { path, value, cause: "action", action: cause.action, version: cause.version };
28624
+ }
28625
+ return { path, value, cause: "initial" };
28626
+ }
28627
+ function renderExplanation(node, indent4 = 0) {
28628
+ const pad = " ".repeat(indent4);
28629
+ const lines = [];
28630
+ const tag = node.cause === "derived" ? "derived" : node.cause === "action" ? `${node.action ?? "action"} \xB7 v${node.version ?? "?"}` : node.cause === "time-travel" ? `time-travel \xB7 v${node.version ?? "?"}` : "initial";
28631
+ lines.push(`${pad}${node.path} = ${JSON.stringify(node.value)} (${tag})`);
28632
+ if (node.changedBy && node.changedBy.length > 0) {
28633
+ lines.push(`${pad} recomputed after:`);
28634
+ for (const change of node.changedBy) {
28635
+ lines.push(renderExplanation({ ...change, from: void 0 }, indent4 + 2));
28636
+ }
28637
+ } else if (node.from && node.from.length > 0) {
28638
+ for (const child of node.from) lines.push(renderExplanation(child, indent4 + 1));
28639
+ }
28640
+ return lines.join("\n");
28641
+ }
28642
+ function derivedHandle(def, displayPath2) {
28643
+ return {
28644
+ path: def.path,
28645
+ get deps() {
28646
+ return def.deps.map((dep) => dep.join("."));
28647
+ },
28648
+ get() {
28649
+ return def.cell.get();
28650
+ },
28651
+ subscribe(cb) {
28652
+ let prev = def.cell.get();
28653
+ return store.subscribe(() => {
28654
+ const next = def.cell.get();
28655
+ if (!Object.is(prev, next)) {
28656
+ prev = next;
28657
+ cb(next);
28658
+ }
28659
+ });
28660
+ }
28661
+ };
28662
+ void displayPath2;
28663
+ }
28664
+ const store = {
28665
+ /** Reactive whole-state read — re-runs on any commit. Includes derived
28666
+ * values at their registered paths (derived wins over a raw key). */
28667
+ get() {
28668
+ rootCell.get();
28669
+ return buildMerged();
28670
+ },
28671
+ /** A fine-grained, causally-aware handle for one nested path. When a
28672
+ * derived is registered at this path, the handle reads/writes the
28673
+ * derived (set/update then throw read-only). */
28674
+ at(path) {
28675
+ const tokens = parseStorePath(path);
28676
+ const key = pathKey(tokens);
28677
+ const def = derivedDefs.get(key);
28678
+ if (def) {
28679
+ const handle2 = derivedHandle(def, path);
28680
+ return {
28681
+ path: key,
28682
+ get: handle2.get,
28683
+ set() {
28684
+ throw new Error(`Path store: derived path "${path}" is read-only.`);
28685
+ },
28686
+ update() {
28687
+ throw new Error(`Path store: derived path "${path}" is read-only.`);
28688
+ },
28689
+ subscribe: handle2.subscribe
28690
+ };
28691
+ }
28692
+ return {
28693
+ path: key,
28694
+ get() {
28695
+ return cellFor(tokens).get();
28696
+ },
28697
+ set(value, action = "set") {
28698
+ commit(setIn(state, tokens, cloneValue(value)), action, tokens);
28699
+ },
28700
+ update(fn, action = "update") {
28701
+ commit(updateIn(state, tokens, fn), action, tokens);
28702
+ },
28703
+ subscribe(cb) {
28704
+ let prev = cellFor(tokens).get();
28705
+ return store.subscribe(() => {
28706
+ const next = cellFor(tokens).get();
28707
+ if (!Object.is(prev, next)) {
28708
+ prev = next;
28709
+ cb(next);
28710
+ }
28711
+ });
28712
+ }
28713
+ };
28714
+ },
28715
+ /** Replace the whole state (attributed to `action`). */
28716
+ set(next, action = "set") {
28717
+ commit(cloneValue(next), action, null);
28718
+ },
28719
+ /** Shallow merge a partial (or `(prev) => partial`) into the root. */
28720
+ update(patch, action = "update") {
28721
+ const partial = typeof patch === "function" ? patch(state) : patch;
28722
+ commit({ ...state, ...cloneValue(partial) }, action, null);
28723
+ },
28724
+ setIn(path, value, action = "setIn") {
28725
+ const tokens = typeof path === "string" ? parseStorePath(path) : path;
28726
+ commit(setIn(state, tokens, cloneValue(value)), action, tokens);
28727
+ },
28728
+ updateIn(path, fn, action = "updateIn") {
28729
+ const tokens = typeof path === "string" ? parseStorePath(path) : path;
28730
+ commit(updateIn(state, tokens, fn), action, tokens);
28731
+ },
28732
+ /**
28733
+ * Register a derived node at `path`. The selector is evaluated inside
28734
+ * `untrack` against a read-recording proxy, so its source paths are
28735
+ * captured automatically — including array envelopes, which make
28736
+ * aggregate deriveds re-run when the array's membership changes.
28737
+ */
28738
+ derived(path, selector, equals = Object.is) {
28739
+ const tokens = parseStorePath(path);
28740
+ const key = pathKey(tokens);
28741
+ const first = evaluate(selector);
28742
+ const def = {
28743
+ path: key,
28744
+ tokens,
28745
+ selector,
28746
+ equals,
28747
+ cell: track(first.value),
28748
+ deps: first.deps,
28749
+ lastTrigger: null,
28750
+ lastTriggerVersion: 0
28751
+ };
28752
+ derivedDefs.set(key, def);
28753
+ registerDef(def);
28754
+ mergedDirty = true;
28755
+ return derivedHandle(def, path);
28756
+ },
28757
+ subscribe(fn, selector, equals) {
28758
+ const eq = equals ?? Object.is;
28759
+ let hasPrev = false;
28760
+ let prev;
28761
+ const wrapper = selector ? () => {
28762
+ const selected = selector(buildMerged());
28763
+ if (!hasPrev || !eq(selected, prev)) {
28764
+ hasPrev = true;
28765
+ prev = selected;
28766
+ fn(selected);
28767
+ }
28768
+ } : (current3) => fn(current3);
28769
+ subscribers.add(wrapper);
28770
+ wrapper(buildMerged());
28771
+ return () => {
28772
+ subscribers.delete(wrapper);
28773
+ };
28774
+ },
28775
+ watch(selector, callback) {
28776
+ let prev = selector(buildMerged());
28777
+ const wrapper = () => {
28778
+ const next = selector(buildMerged());
28779
+ if (!Object.is(prev, next)) {
28780
+ const old = prev;
28781
+ prev = next;
28782
+ callback(next, old);
28783
+ }
28784
+ };
28785
+ watchers.add(wrapper);
28786
+ return () => {
28787
+ watchers.delete(wrapper);
28788
+ };
28789
+ },
28790
+ /** Causal explanation for the current value at `path`. */
28791
+ why(path) {
28792
+ return whyAt(parseStorePath(path));
28793
+ },
28794
+ /** A printable causal chain for devtools / tests. */
28795
+ explain(path) {
28796
+ return renderExplanation(whyAt(parseStorePath(path)));
28797
+ },
28798
+ /** The recorded events, oldest first. */
28799
+ get events() {
28800
+ return events;
28801
+ },
28802
+ get version() {
28803
+ return version2;
28804
+ },
28805
+ canUndo() {
28806
+ return undoStack.length > 0;
28807
+ },
28808
+ canRedo() {
28809
+ return redoStack.length > 0;
28810
+ },
28811
+ undo() {
28812
+ const prev = undoStack.pop();
28813
+ if (prev === void 0) return false;
28814
+ redoStack.push(state);
28815
+ restore(prev, "undo");
28816
+ return true;
28817
+ },
28818
+ redo() {
28819
+ const next = redoStack.pop();
28820
+ if (next === void 0) return false;
28821
+ undoStack.push(state);
28822
+ restore(next, "redo");
28823
+ return true;
28824
+ },
28825
+ /** A JSON-safe snapshot of the current merged state. */
28826
+ toJSON() {
28827
+ return plainClone(buildMerged());
28828
+ }
28829
+ };
28830
+ return store;
28831
+ }
28832
+ var init_path_store = __esm({
28833
+ "../runtime/src/path-store.ts"() {
28834
+ "use strict";
28835
+ init_ripple_runtime();
28836
+ init_nested_update();
28837
+ init_store_persistence();
28838
+ }
28839
+ });
28840
+
27758
28841
  // ../runtime/src/index-server.ts
27759
28842
  var index_server_exports = {};
27760
28843
  __export(index_server_exports, {
@@ -27809,8 +28892,10 @@ __export(index_server_exports, {
27809
28892
  createContext: () => createContext,
27810
28893
  createFileRouter: () => createFileRouter,
27811
28894
  createLocals: () => createLocals,
28895
+ createPathStore: () => createPathStore,
27812
28896
  createResource: () => createResource,
27813
28897
  createRouter: () => createRouter,
28898
+ createStore: () => createStore,
27814
28899
  create_component_ctx: () => create_component_ctx,
27815
28900
  create_try_block: () => create_try_block,
27816
28901
  custom: () => custom,
@@ -27936,6 +29021,8 @@ var init_index_server = __esm({
27936
29021
  init_action();
27937
29022
  init_metadata();
27938
29023
  init_nested_update();
29024
+ init_store();
29025
+ init_path_store();
27939
29026
  }
27940
29027
  });
27941
29028
 
@@ -33707,8 +34794,8 @@ function isThenable(value) {
33707
34794
  return typeof value?.then === "function";
33708
34795
  }
33709
34796
  function withSsrStore(fn) {
33710
- const existing = storage.getStore();
33711
- if (existing) return fn();
34797
+ const existing2 = storage.getStore();
34798
+ if (existing2) return fn();
33712
34799
  const store = createSsrStore();
33713
34800
  keepSsrSlot(store.token);
33714
34801
  let result;
@@ -33750,15 +34837,15 @@ function dropSsrSlot(token) {
33750
34837
  function isSsrSlotLive(token) {
33751
34838
  return liveSlots.has(token);
33752
34839
  }
33753
- var TOKEN_KEY, IMPL_KEY, g2, impl, storage, liveSlots, ssrSink2;
34840
+ var TOKEN_KEY, IMPL_KEY, g3, impl, storage, liveSlots, ssrSink2;
33754
34841
  var init_ssr_store = __esm({
33755
34842
  "../compiler/src/ssr-store.ts"() {
33756
34843
  "use strict";
33757
34844
  init_index_server();
33758
34845
  TOKEN_KEY = "__vsk_ssr_token";
33759
34846
  IMPL_KEY = "__vsk_ssr_store_impl";
33760
- g2 = globalThis;
33761
- impl = g2[IMPL_KEY] ?? (g2[IMPL_KEY] = {
34847
+ g3 = globalThis;
34848
+ impl = g3[IMPL_KEY] ?? (g3[IMPL_KEY] = {
33762
34849
  storage: new AsyncLocalStorage(),
33763
34850
  liveSlots: /* @__PURE__ */ new Map(),
33764
34851
  // Only the copy that created the implementation installs the token
@@ -34065,17 +35152,17 @@ async function settleSsrPromises(token) {
34065
35152
  }
34066
35153
  }
34067
35154
  function pruneSsrDataSlots() {
34068
- const g4 = globalThis;
35155
+ const g5 = globalThis;
34069
35156
  const prefix = "__vsk_ssr_data_";
34070
35157
  const stale = [];
34071
- for (const k of Object.keys(g4)) {
35158
+ for (const k of Object.keys(g5)) {
34072
35159
  if (typeof k !== "string" || !k.startsWith(prefix)) continue;
34073
35160
  if (isSsrSlotLive(k.slice(prefix.length))) continue;
34074
35161
  stale.push(k);
34075
35162
  }
34076
35163
  if (stale.length <= 40) return;
34077
35164
  stale.sort().slice(0, stale.length - 40).forEach((k) => {
34078
- delete g4[k];
35165
+ delete g5[k];
34079
35166
  });
34080
35167
  }
34081
35168
  async function applyHeadPlugins(headHtml, plugins, ctx2) {
@@ -34804,9 +35891,9 @@ function getPluginRecords(appDir, veskDir, configPluginNames) {
34804
35891
  }
34805
35892
  function setPluginActive(veskDir, name, active) {
34806
35893
  const state = readPluginState(veskDir);
34807
- const existing = state.plugins.find((p) => eqIgnoreCase(p.name, name));
34808
- if (existing) {
34809
- existing.active = active;
35894
+ const existing2 = state.plugins.find((p) => eqIgnoreCase(p.name, name));
35895
+ if (existing2) {
35896
+ existing2.active = active;
34810
35897
  } else {
34811
35898
  state.plugins.push({ name, package: name, active });
34812
35899
  }
@@ -34886,13 +35973,13 @@ async function installPlugin(appDir, veskDir, pkg) {
34886
35973
  }
34887
35974
  const state = readPluginState(veskDir);
34888
35975
  const name = probe.packageJson?.name || pkg;
34889
- const existing = state.plugins.find(
35976
+ const existing2 = state.plugins.find(
34890
35977
  (p) => eqIgnoreCase(p.package, pkg) || eqIgnoreCase(p.name, name)
34891
35978
  );
34892
- if (existing) {
34893
- existing.package = pkg;
34894
- existing.name = name;
34895
- existing.active = true;
35979
+ if (existing2) {
35980
+ existing2.package = pkg;
35981
+ existing2.name = name;
35982
+ existing2.active = true;
34896
35983
  } else {
34897
35984
  state.plugins.push({ name, package: pkg, active: true });
34898
35985
  }
@@ -34930,12 +36017,12 @@ async function updatePlugin(appDir, veskDir, pkg) {
34930
36017
  const probe = resolvePackage(appDir, pkg);
34931
36018
  const state = readPluginState(veskDir);
34932
36019
  const name = probe.packageJson?.name || pkg;
34933
- const existing = state.plugins.find(
36020
+ const existing2 = state.plugins.find(
34934
36021
  (p) => eqIgnoreCase(p.package, pkg) || eqIgnoreCase(p.name, name)
34935
36022
  );
34936
- if (existing) {
34937
- existing.package = pkg;
34938
- existing.name = name;
36023
+ if (existing2) {
36024
+ existing2.package = pkg;
36025
+ existing2.name = name;
34939
36026
  } else {
34940
36027
  state.plugins.push({ name, package: pkg, active: true });
34941
36028
  }
@@ -34944,7 +36031,7 @@ async function updatePlugin(appDir, veskDir, pkg) {
34944
36031
  name,
34945
36032
  pkg,
34946
36033
  source: "state",
34947
- activeRaw: existing ? existing.active : true,
36034
+ activeRaw: existing2 ? existing2.active : true,
34948
36035
  error: null
34949
36036
  }, appDir);
34950
36037
  }
@@ -36153,16 +37240,21 @@ function __matchPath(pattern, pathname) {
36153
37240
  let pi = 0, pp = 0;
36154
37241
  const params = {};
36155
37242
  while (pi < pathParts.length && pp < patternParts.length) {
36156
- if (patternParts[pp].startsWith(':')) {
36157
- const name = patternParts[pp].slice(1);
36158
- params[name] = pathParts[pi];
37243
+ const seg = patternParts[pp];
37244
+ // A "*name" segment is a catch-all and absorbs the rest of the path.
37245
+ if (seg.startsWith('*')) { params[seg.slice(1)] = pathParts.slice(pi).join('/'); pi = pathParts.length; pp++; }
37246
+ else if (seg.startsWith(':')) {
37247
+ params[seg.slice(1)] = pathParts[pi];
36159
37248
  pi++; pp++;
36160
- } else if (patternParts[pp] === pathParts[pi]) {
37249
+ } else if (seg === pathParts[pi]) {
36161
37250
  pi++; pp++;
36162
37251
  } else {
36163
37252
  return null;
36164
37253
  }
36165
37254
  }
37255
+ // A trailing catch-all still matches an empty tail; the loop above exits as
37256
+ // soon as the URL is exhausted, so without this it was never reached.
37257
+ if (pp === patternParts.length - 1 && patternParts[pp].startsWith('*')) { params[patternParts[pp].slice(1)] = pathParts.slice(pi).join('/'); pp++; }
36166
37258
  if (pp === patternParts.length && pi === pathParts.length) return params;
36167
37259
  return null;
36168
37260
  }
@@ -39112,9 +40204,9 @@ function Md2(props, _registry, hydrate) {
39112
40204
  if (hydrate && typeof hydrate.nextElement === "function") {
39113
40205
  let el = hydrate.nextElement("div");
39114
40206
  if (el && !el.parentNode && hydrate.root) {
39115
- const existing = hydrate.root.querySelector("div");
39116
- if (existing)
39117
- el = existing;
40207
+ const existing2 = hydrate.root.querySelector("div");
40208
+ if (existing2)
40209
+ el = existing2;
39118
40210
  }
39119
40211
  const claimed = !!el.parentNode;
39120
40212
  if (pathMode && claimed) {
@@ -40089,9 +41181,9 @@ function getJSXTagName2(el) {
40089
41181
  if (name.type === "JSXNamespacedName") return name.namespace.name + ":" + name.name.name;
40090
41182
  return null;
40091
41183
  }
40092
- function emitJSXText(g4, text, start, end) {
41184
+ function emitJSXText(g5, text, start, end) {
40093
41185
  if (text.indexOf("<") === -1 && text.indexOf(">") === -1 && text.indexOf("&") === -1 && text.indexOf("{") === -1 && text.indexOf("}") === -1) {
40094
- g4.add(text, start, end);
41186
+ g5.add(text, start, end);
40095
41187
  return;
40096
41188
  }
40097
41189
  let out = "";
@@ -40104,7 +41196,7 @@ function emitJSXText(g4, text, start, end) {
40104
41196
  else if (c === "}") out += "&#125;";
40105
41197
  else out += c;
40106
41198
  }
40107
- g4.add(out, start, end);
41199
+ g5.add(out, start, end);
40108
41200
  }
40109
41201
  function collapseWithMap(value) {
40110
41202
  let out = "";
@@ -40261,31 +41353,31 @@ function stripCallTypeArgs(text) {
40261
41353
  }
40262
41354
  return text;
40263
41355
  }
40264
- function emitTrackDeclStatement(g4, source, stmt, indent4, isLast, opts) {
41356
+ function emitTrackDeclStatement(g5, source, stmt, indent4, isLast, opts) {
40265
41357
  const fullText = stripTrailingSemicolons(source.slice(stmt.start, stmt.end).trimEnd());
40266
41358
  const text = fullText + (!fullText.endsWith("}") && !isLast ? ";" : "");
40267
41359
  const decls = stmt.declarations || [];
40268
- g4.add(indent4);
41360
+ g5.add(indent4);
40269
41361
  let prevEnd = stmt.start;
40270
41362
  for (let di = 0; di < decls.length; di++) {
40271
41363
  const decl = decls[di];
40272
41364
  const id = decl.id;
40273
41365
  const isLazy = id && id.type === "ArrayPattern" && id.lazy === true && decl.init;
40274
41366
  if (!isLazy) {
40275
- g4.addRaw(source.slice(prevEnd, decl.start));
40276
- g4.add(source.slice(decl.start, decl.end), decl.start, decl.end);
41367
+ g5.addRaw(source.slice(prevEnd, decl.start));
41368
+ g5.add(source.slice(decl.start, decl.end), decl.start, decl.end);
40277
41369
  prevEnd = decl.end;
40278
41370
  continue;
40279
41371
  }
40280
- if (di > 0) g4.addRaw(source.slice(prevEnd, decl.start));
41372
+ if (di > 0) g5.addRaw(source.slice(prevEnd, decl.start));
40281
41373
  const ch = text[decl.end - stmt.start] ?? " ";
40282
41374
  const elements = id.elements || [];
40283
41375
  const names = elements.map((el) => el ? el.name : null).filter((n) => typeof n === "string");
40284
41376
  const initText = source.slice(decl.init.start, decl.init.end);
40285
41377
  if (names.length === 0) {
40286
- g4.add("let _ = ");
40287
- g4.add(initText, decl.init.start, decl.init.end);
40288
- if (ch !== ";") g4.addRaw(";");
41378
+ g5.add("let _ = ");
41379
+ g5.add(initText, decl.init.start, decl.init.end);
41380
+ if (ch !== ";") g5.addRaw(";");
40289
41381
  prevEnd = decl.end;
40290
41382
  continue;
40291
41383
  }
@@ -40296,133 +41388,133 @@ function emitTrackDeclStatement(g4, source, stmt, indent4, isLast, opts) {
40296
41388
  const firstRange = [elements[0].start, elements[0].end];
40297
41389
  const dropLastSemi = ch === ";";
40298
41390
  if (opts.typedCells) {
40299
- const cellName = g4.cellCount === 0 ? "__cell" : `__cell${g4.cellCount}`;
40300
- g4.cellCount++;
41391
+ const cellName = g5.cellCount === 0 ? "__cell" : `__cell${g5.cellCount}`;
41392
+ g5.cellCount++;
40301
41393
  if (annotation) {
40302
- g4.add(`const ${cellName}: Tracked<`);
40303
- g4.add(annotation, annStart, annEnd);
40304
- g4.add("> = ");
41394
+ g5.add(`const ${cellName}: Tracked<`);
41395
+ g5.add(annotation, annStart, annEnd);
41396
+ g5.add("> = ");
40305
41397
  } else {
40306
- g4.add(`const ${cellName} = `);
41398
+ g5.add(`const ${cellName} = `);
40307
41399
  }
40308
41400
  const cellInit = annotation ? stripCallTypeArgs(initText) : initText;
40309
- g4.add(cellInit, decl.init.start, decl.init.end);
40310
- g4.add(";");
40311
- g4.add(" let ");
40312
- g4.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
41401
+ g5.add(cellInit, decl.init.start, decl.init.end);
41402
+ g5.add(";");
41403
+ g5.add(" let ");
41404
+ g5.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
40313
41405
  if (annotation) {
40314
- g4.add(": ");
40315
- g4.add(annotation, annStart, annEnd);
41406
+ g5.add(": ");
41407
+ g5.add(annotation, annStart, annEnd);
40316
41408
  }
40317
- g4.add(` = ${cellName}.get();`);
41409
+ g5.add(` = ${cellName}.get();`);
40318
41410
  for (let n = 1; n < names.length; n++) {
40319
- g4.add(" let ");
40320
- g4.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
40321
- g4.add(` = ${cellName};`);
41411
+ g5.add(" let ");
41412
+ g5.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
41413
+ g5.add(` = ${cellName};`);
40322
41414
  }
40323
- if (dropLastSemi) g4.code = g4.code.slice(0, -1);
41415
+ if (dropLastSemi) g5.code = g5.code.slice(0, -1);
40324
41416
  } else {
40325
41417
  if (annotation) {
40326
- g4.add("let ");
40327
- g4.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
40328
- g4.add(": ");
40329
- g4.add(annotation, annStart, annEnd);
40330
- g4.add(" = (");
40331
- g4.add(stripCallTypeArgs(initText), decl.init.start, decl.init.end);
40332
- g4.add(" as unknown as ");
40333
- g4.add(annotation, annStart, annEnd);
40334
- g4.add(");");
41418
+ g5.add("let ");
41419
+ g5.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
41420
+ g5.add(": ");
41421
+ g5.add(annotation, annStart, annEnd);
41422
+ g5.add(" = (");
41423
+ g5.add(stripCallTypeArgs(initText), decl.init.start, decl.init.end);
41424
+ g5.add(" as unknown as ");
41425
+ g5.add(annotation, annStart, annEnd);
41426
+ g5.add(");");
40335
41427
  } else {
40336
- const cellName = g4.cellCount === 0 ? "__cell" : `__cell${g4.cellCount}`;
40337
- g4.cellCount++;
40338
- g4.add(`const ${cellName} = `);
40339
- g4.add(initText, decl.init.start, decl.init.end);
40340
- g4.add("; let ");
40341
- g4.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
40342
- g4.add(` = ${cellName}.get();`);
41428
+ const cellName = g5.cellCount === 0 ? "__cell" : `__cell${g5.cellCount}`;
41429
+ g5.cellCount++;
41430
+ g5.add(`const ${cellName} = `);
41431
+ g5.add(initText, decl.init.start, decl.init.end);
41432
+ g5.add("; let ");
41433
+ g5.add(first, firstRange[0], firstRange[1], REACTIVE_DATA);
41434
+ g5.add(` = ${cellName}.get();`);
40343
41435
  }
40344
41436
  for (let n = 1; n < names.length; n++) {
40345
- g4.add(" let ");
40346
- g4.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
40347
- g4.add(": any = ");
40348
- g4.add(first, firstRange[0], firstRange[1]);
40349
- g4.add(";");
40350
- if (n === names.length - 1 && dropLastSemi) g4.code = g4.code.slice(0, -1);
41437
+ g5.add(" let ");
41438
+ g5.add(names[n], elements[n].start, elements[n].end, REACTIVE_DATA);
41439
+ g5.add(": any = ");
41440
+ g5.add(first, firstRange[0], firstRange[1]);
41441
+ g5.add(";");
41442
+ if (n === names.length - 1 && dropLastSemi) g5.code = g5.code.slice(0, -1);
40351
41443
  }
40352
- if (names.length === 1 && dropLastSemi) g4.code = g4.code.slice(0, -1);
41444
+ if (names.length === 1 && dropLastSemi) g5.code = g5.code.slice(0, -1);
40353
41445
  }
40354
41446
  prevEnd = decl.end;
40355
41447
  }
40356
- if (!isLast) g4.addRaw(";");
41448
+ if (!isLast) g5.addRaw(";");
40357
41449
  }
40358
- function emitBlock(g4, source, body, indent4, opts) {
41450
+ function emitBlock(g5, source, body, indent4, opts) {
40359
41451
  const stmts = body && body.type === "BlockStatement" ? body.body : body ? Array.isArray(body) ? body : [body] : [];
40360
- g4.addRaw("{\n");
40361
- emitBody(g4, source, stmts, indent4 + " ", opts);
40362
- g4.addRaw("\n");
40363
- g4.add(indent4);
40364
- g4.addRaw("}");
41452
+ g5.addRaw("{\n");
41453
+ emitBody(g5, source, stmts, indent4 + " ", opts);
41454
+ g5.addRaw("\n");
41455
+ g5.add(indent4);
41456
+ g5.addRaw("}");
40365
41457
  }
40366
- function emitJSXAttr(g4, source, attr) {
41458
+ function emitJSXAttr(g5, source, attr) {
40367
41459
  if (attr.type === "JSXSpreadAttribute") {
40368
- g4.add(source.slice(attr.start, attr.end), attr.start, attr.end);
41460
+ g5.add(source.slice(attr.start, attr.end), attr.start, attr.end);
40369
41461
  return;
40370
41462
  }
40371
41463
  const name = attr.name;
40372
- g4.add(source.slice(name.start, name.end), name.start, name.end);
41464
+ g5.add(source.slice(name.start, name.end), name.start, name.end);
40373
41465
  const v = attr.value;
40374
41466
  if (!v) return;
40375
- g4.add(source.slice(name.end, v.start), name.end, v.start);
41467
+ g5.add(source.slice(name.end, v.start), name.end, v.start);
40376
41468
  if (v.type === "JSXExpressionContainer") {
40377
- g4.add(source.slice(v.start, v.expression.start), v.start, v.expression.start);
40378
- g4.add(source.slice(v.expression.start, v.expression.end), v.expression.start, v.expression.end);
40379
- g4.add(source.slice(v.expression.end, v.end), v.expression.end, v.end);
41469
+ g5.add(source.slice(v.start, v.expression.start), v.start, v.expression.start);
41470
+ g5.add(source.slice(v.expression.start, v.expression.end), v.expression.start, v.expression.end);
41471
+ g5.add(source.slice(v.expression.end, v.end), v.expression.end, v.end);
40380
41472
  } else {
40381
- g4.add(source.slice(v.start, v.end), v.start, v.end);
41473
+ g5.add(source.slice(v.start, v.end), v.start, v.end);
40382
41474
  }
40383
41475
  }
40384
- function emitJSXElement(g4, source, el, opts, hoist) {
41476
+ function emitJSXElement(g5, source, el, opts, hoist) {
40385
41477
  const op = el.openingElement;
40386
41478
  const name = op.name;
40387
41479
  let prev;
40388
41480
  if (name) {
40389
- g4.add(source.slice(op.start, name.start), op.start, name.start);
40390
- g4.add(source.slice(name.start, name.end), name.start, name.end);
41481
+ g5.add(source.slice(op.start, name.start), op.start, name.start);
41482
+ g5.add(source.slice(name.start, name.end), name.start, name.end);
40391
41483
  prev = name.end;
40392
41484
  } else {
40393
41485
  prev = op.start + 1;
40394
41486
  }
40395
41487
  for (const attr of op.attributes ?? []) {
40396
- g4.add(source.slice(prev, attr.start), prev, attr.start);
40397
- emitJSXAttr(g4, source, attr);
41488
+ g5.add(source.slice(prev, attr.start), prev, attr.start);
41489
+ emitJSXAttr(g5, source, attr);
40398
41490
  prev = attr.end;
40399
41491
  }
40400
41492
  const tail = source.slice(prev, op.end);
40401
41493
  if (op.selfClosing && !tail.includes("/")) {
40402
41494
  const gt = tail.lastIndexOf(">");
40403
41495
  const head = gt === -1 ? tail : tail.slice(0, gt);
40404
- if (head) g4.add(head, prev, prev + head.length);
40405
- g4.addRaw("/>");
41496
+ if (head) g5.add(head, prev, prev + head.length);
41497
+ g5.addRaw("/>");
40406
41498
  } else {
40407
- g4.add(tail, prev, op.end);
41499
+ g5.add(tail, prev, op.end);
40408
41500
  }
40409
41501
  if (op.selfClosing) return;
40410
- emitJSXChildren(g4, source, el.children ?? [], opts, hoist);
41502
+ emitJSXChildren(g5, source, el.children ?? [], opts, hoist);
40411
41503
  if (el.closingElement) {
40412
- g4.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
41504
+ g5.add(source.slice(el.closingElement.start, el.closingElement.end), el.closingElement.start, el.closingElement.end);
40413
41505
  }
40414
41506
  }
40415
- function emitJSXExprBody(g4, source, expr, opts) {
40416
- if (expr.type === "JSXElement") return emitJSXElement(g4, source, expr, opts);
40417
- if (expr.type === "JSXFragment") return emitJSXFragment(g4, source, expr, opts);
40418
- g4.add(source.slice(expr.start, expr.end), expr.start, expr.end);
41507
+ function emitJSXExprBody(g5, source, expr, opts) {
41508
+ if (expr.type === "JSXElement") return emitJSXElement(g5, source, expr, opts);
41509
+ if (expr.type === "JSXFragment") return emitJSXFragment(g5, source, expr, opts);
41510
+ g5.add(source.slice(expr.start, expr.end), expr.start, expr.end);
40419
41511
  }
40420
- function emitJSXFragment(g4, source, frag, opts, hoist) {
40421
- g4.addRaw("<>");
40422
- emitJSXChildren(g4, source, frag.children ?? [], opts, hoist);
40423
- g4.addRaw("</>");
41512
+ function emitJSXFragment(g5, source, frag, opts, hoist) {
41513
+ g5.addRaw("<>");
41514
+ emitJSXChildren(g5, source, frag.children ?? [], opts, hoist);
41515
+ g5.addRaw("</>");
40424
41516
  }
40425
- function emitForClauseMap(g4, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
41517
+ function emitForClauseMap(g5, source, child, text, map, clauseStart, bodyEmit, emptyEmit) {
40426
41518
  const clauseEnd = findBalancedEnd(text, clauseStart - 1);
40427
41519
  const clause = text.slice(clauseStart, clauseEnd);
40428
41520
  const ofIdx = findTopLevelSep(clause, "of");
@@ -40439,38 +41531,38 @@ function emitForClauseMap(g4, source, child, text, map, clauseStart, bodyEmit, e
40439
41531
  const itemVar = stripDeclKeyword(lhs).trim();
40440
41532
  if (ofIdx !== -1) {
40441
41533
  if (emptyEmit) {
40442
- g4.addRaw("{ (() => { const _v = ");
40443
- g4.add(arrExpr, arrStart, arrEnd);
40444
- g4.addRaw("; return _v.length === 0 ? (");
41534
+ g5.addRaw("{ (() => { const _v = ");
41535
+ g5.add(arrExpr, arrStart, arrEnd);
41536
+ g5.addRaw("; return _v.length === 0 ? (");
40445
41537
  emptyEmit();
40446
- g4.addRaw(") : _v.map((");
40447
- g4.addRaw(itemVar);
40448
- g4.addRaw(": (typeof _v)[number]) => (");
41538
+ g5.addRaw(") : _v.map((");
41539
+ g5.addRaw(itemVar);
41540
+ g5.addRaw(": (typeof _v)[number]) => (");
40449
41541
  bodyEmit();
40450
- g4.addRaw(")); })() }");
41542
+ g5.addRaw(")); })() }");
40451
41543
  } else {
40452
- g4.addRaw("{ ");
40453
- g4.add(arrExpr, arrStart, arrEnd);
40454
- g4.addRaw(".map((");
40455
- g4.addRaw(itemVar);
40456
- g4.addRaw(": (typeof ");
40457
- g4.add(arrExpr, arrStart, arrEnd);
40458
- g4.addRaw(")[number]) => (");
41544
+ g5.addRaw("{ ");
41545
+ g5.add(arrExpr, arrStart, arrEnd);
41546
+ g5.addRaw(".map((");
41547
+ g5.addRaw(itemVar);
41548
+ g5.addRaw(": (typeof ");
41549
+ g5.add(arrExpr, arrStart, arrEnd);
41550
+ g5.addRaw(")[number]) => (");
40459
41551
  bodyEmit();
40460
- g4.addRaw(")) }");
41552
+ g5.addRaw(")) }");
40461
41553
  }
40462
41554
  } else {
40463
- g4.addRaw("{ Object.keys(");
40464
- g4.add(arrExpr, arrStart, arrEnd);
40465
- g4.addRaw(").map((");
40466
- g4.addRaw(itemVar);
40467
- g4.addRaw(") => (");
41555
+ g5.addRaw("{ Object.keys(");
41556
+ g5.add(arrExpr, arrStart, arrEnd);
41557
+ g5.addRaw(").map((");
41558
+ g5.addRaw(itemVar);
41559
+ g5.addRaw(") => (");
40468
41560
  bodyEmit();
40469
- g4.addRaw(")) }");
41561
+ g5.addRaw(")) }");
40470
41562
  }
40471
41563
  return true;
40472
41564
  }
40473
- function emitJSXChildren(g4, source, children, opts, hoist) {
41565
+ function emitJSXChildren(g5, source, children, opts, hoist) {
40474
41566
  let i = 0;
40475
41567
  let forPending = false;
40476
41568
  while (i < children.length) {
@@ -40496,46 +41588,46 @@ function emitJSXChildren(g4, source, children, opts, hoist) {
40496
41588
  const emptyContainer = children[i + 3];
40497
41589
  if (emptyTextNode && emptyTextNode.type === "JSXText" && ["#empty", "empty"].includes(emptyTextNode.value.trim()) && emptyContainer && emptyContainer.type === "JSXExpressionContainer" && emptyContainer.expression.type !== "JSXEmptyExpression") {
40498
41590
  consumed = 4;
40499
- emptyEmit = () => emitJSXExprBody(g4, source, emptyContainer.expression, opts);
41591
+ emptyEmit = () => emitJSXExprBody(g5, source, emptyContainer.expression, opts);
40500
41592
  }
40501
41593
  let matched = false;
40502
41594
  if (nextChild.type === "JSXExpressionContainer") {
40503
41595
  const exprNode = nextChild.expression;
40504
41596
  if (exprNode.type === "JSXEmptyExpression") {
40505
- g4.add(text, child.start, child.end);
41597
+ g5.add(text, child.start, child.end);
40506
41598
  i++;
40507
41599
  continue;
40508
41600
  }
40509
41601
  matched = emitForClauseMap(
40510
- g4,
41602
+ g5,
40511
41603
  source,
40512
41604
  child,
40513
41605
  text,
40514
41606
  map,
40515
41607
  clauseStartCollapsed,
40516
- () => emitJSXExprBody(g4, source, exprNode, opts),
41608
+ () => emitJSXExprBody(g5, source, exprNode, opts),
40517
41609
  emptyEmit
40518
41610
  );
40519
41611
  } else if (nextChild.type === "JSXFragment") {
40520
41612
  matched = emitForClauseMap(
40521
- g4,
41613
+ g5,
40522
41614
  source,
40523
41615
  child,
40524
41616
  text,
40525
41617
  map,
40526
41618
  clauseStartCollapsed,
40527
- () => emitJSXFragment(g4, source, nextChild, opts),
41619
+ () => emitJSXFragment(g5, source, nextChild, opts),
40528
41620
  emptyEmit
40529
41621
  );
40530
41622
  } else {
40531
41623
  matched = emitForClauseMap(
40532
- g4,
41624
+ g5,
40533
41625
  source,
40534
41626
  child,
40535
41627
  text,
40536
41628
  map,
40537
41629
  clauseStartCollapsed,
40538
- () => emitJSXElement(g4, source, nextChild, opts),
41630
+ () => emitJSXElement(g5, source, nextChild, opts),
40539
41631
  emptyEmit
40540
41632
  );
40541
41633
  }
@@ -40552,184 +41644,184 @@ function emitJSXChildren(g4, source, children, opts, hoist) {
40552
41644
  continue;
40553
41645
  }
40554
41646
  forPending = false;
40555
- emitJSXText(g4, text, child.start, child.end);
41647
+ emitJSXText(g5, text, child.start, child.end);
40556
41648
  i++;
40557
41649
  } else if (child.type === "JSXExpressionContainer") {
40558
41650
  if (child.expression.type === "JSXEmptyExpression") {
40559
41651
  i++;
40560
41652
  continue;
40561
41653
  }
40562
- g4.addRaw("{");
40563
- g4.add(source.slice(child.expression.start, child.expression.end), child.expression.start, child.expression.end);
40564
- g4.addRaw("}");
41654
+ g5.addRaw("{");
41655
+ g5.add(source.slice(child.expression.start, child.expression.end), child.expression.start, child.expression.end);
41656
+ g5.addRaw("}");
40565
41657
  i++;
40566
41658
  } else if (child.type === "JSXElement") {
40567
41659
  if (getJSXTagName2(child) === "style") {
40568
41660
  const openEnd = child.openingElement?.end ?? child.start;
40569
41661
  const closeStart = child.closingElement?.start ?? child.end;
40570
- g4.recordStyle(child.start, child.end, source.slice(openEnd, closeStart));
41662
+ g5.recordStyle(child.start, child.end, source.slice(openEnd, closeStart));
40571
41663
  i++;
40572
41664
  continue;
40573
41665
  }
40574
- emitJSXElement(g4, source, child, opts, hoist);
41666
+ emitJSXElement(g5, source, child, opts, hoist);
40575
41667
  i++;
40576
41668
  } else if (child.type === "JSXFragment") {
40577
- emitJSXFragment(g4, source, child, opts, hoist);
41669
+ emitJSXFragment(g5, source, child, opts, hoist);
40578
41670
  i++;
40579
41671
  } else if (child.type === "IfStatement" || child.type === "ForOfStatement" || child.type === "ForStatement" || child.type === "ForInStatement" || child.type === "WhileStatement" || child.type === "DoWhileStatement" || child.type === "SwitchStatement" || child.type === "TryStatement" || child.type === "VariableDeclaration" || child.type === "ExpressionStatement") {
40580
41672
  if (hoist && hoist.set.has(child)) {
40581
41673
  i++;
40582
41674
  continue;
40583
41675
  }
40584
- g4.addRaw("{(() => { ");
40585
- emitBody(g4, source, [child], "", opts);
40586
- g4.addRaw(" })()}");
41676
+ g5.addRaw("{(() => { ");
41677
+ emitBody(g5, source, [child], "", opts);
41678
+ g5.addRaw(" })()}");
40587
41679
  i++;
40588
41680
  } else {
40589
41681
  i++;
40590
41682
  }
40591
41683
  }
40592
41684
  }
40593
- function emitIf(g4, source, stmt, indent4, opts) {
40594
- g4.add(indent4);
40595
- g4.addRaw("if (");
40596
- g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
40597
- g4.addRaw(") ");
40598
- emitBlock(g4, source, stmt.consequent, indent4, opts);
41685
+ function emitIf(g5, source, stmt, indent4, opts) {
41686
+ g5.add(indent4);
41687
+ g5.addRaw("if (");
41688
+ g5.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
41689
+ g5.addRaw(") ");
41690
+ emitBlock(g5, source, stmt.consequent, indent4, opts);
40599
41691
  if (stmt.alternate) {
40600
- g4.addRaw(" else ");
40601
- emitBlock(g4, source, stmt.alternate, indent4, opts);
41692
+ g5.addRaw(" else ");
41693
+ emitBlock(g5, source, stmt.alternate, indent4, opts);
40602
41694
  }
40603
41695
  }
40604
- function emitLoopVariable(g4, source, left) {
41696
+ function emitLoopVariable(g5, source, left) {
40605
41697
  if (left && left.type === "Identifier") {
40606
- g4.addRaw("const ");
40607
- g4.add(source.slice(left.start, left.end), left.start, left.end);
41698
+ g5.addRaw("const ");
41699
+ g5.add(source.slice(left.start, left.end), left.start, left.end);
40608
41700
  return;
40609
41701
  }
40610
- g4.add(source.slice(left.start, left.end), left.start, left.end);
40611
- }
40612
- function emitForOf(g4, source, stmt, indent4, opts) {
40613
- g4.add(indent4);
40614
- g4.addRaw("for (");
40615
- emitLoopVariable(g4, source, stmt.left);
40616
- g4.addRaw(" of ");
40617
- g4.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
40618
- g4.addRaw(") ");
40619
- emitBlock(g4, source, stmt.body, indent4, opts);
40620
- }
40621
- function emitForIn(g4, source, stmt, indent4, opts) {
40622
- g4.add(indent4);
40623
- g4.addRaw("for (");
40624
- emitLoopVariable(g4, source, stmt.left);
40625
- g4.addRaw(" in ");
40626
- g4.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
40627
- g4.addRaw(") ");
40628
- emitBlock(g4, source, stmt.body, indent4, opts);
40629
- }
40630
- function emitFor(g4, source, stmt, indent4, opts) {
40631
- g4.add(indent4);
40632
- g4.addRaw("for (");
40633
- if (stmt.init) g4.add(source.slice(stmt.init.start, stmt.init.end), stmt.init.start, stmt.init.end);
40634
- g4.addRaw("; ");
40635
- if (stmt.test) g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
40636
- g4.addRaw("; ");
40637
- if (stmt.update) g4.add(source.slice(stmt.update.start, stmt.update.end), stmt.update.start, stmt.update.end);
40638
- g4.addRaw(") ");
40639
- emitBlock(g4, source, stmt.body, indent4, opts);
40640
- }
40641
- function emitWhile(g4, source, stmt, indent4, opts) {
40642
- g4.add(indent4);
40643
- g4.addRaw("while (");
40644
- g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
40645
- g4.addRaw(") ");
40646
- emitBlock(g4, source, stmt.body, indent4, opts);
40647
- }
40648
- function emitDoWhile(g4, source, stmt, indent4, opts) {
40649
- g4.add(indent4);
40650
- g4.addRaw("do ");
40651
- emitBlock(g4, source, stmt.body, indent4, opts);
40652
- g4.addRaw(" while (");
40653
- g4.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
40654
- g4.addRaw(");");
40655
- }
40656
- function emitSwitch(g4, source, stmt, indent4, opts) {
40657
- g4.add(indent4);
40658
- g4.addRaw("switch (");
40659
- g4.add(source.slice(stmt.discriminant.start, stmt.discriminant.end), stmt.discriminant.start, stmt.discriminant.end);
40660
- g4.addRaw(") {");
41702
+ g5.add(source.slice(left.start, left.end), left.start, left.end);
41703
+ }
41704
+ function emitForOf(g5, source, stmt, indent4, opts) {
41705
+ g5.add(indent4);
41706
+ g5.addRaw("for (");
41707
+ emitLoopVariable(g5, source, stmt.left);
41708
+ g5.addRaw(" of ");
41709
+ g5.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
41710
+ g5.addRaw(") ");
41711
+ emitBlock(g5, source, stmt.body, indent4, opts);
41712
+ }
41713
+ function emitForIn(g5, source, stmt, indent4, opts) {
41714
+ g5.add(indent4);
41715
+ g5.addRaw("for (");
41716
+ emitLoopVariable(g5, source, stmt.left);
41717
+ g5.addRaw(" in ");
41718
+ g5.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
41719
+ g5.addRaw(") ");
41720
+ emitBlock(g5, source, stmt.body, indent4, opts);
41721
+ }
41722
+ function emitFor(g5, source, stmt, indent4, opts) {
41723
+ g5.add(indent4);
41724
+ g5.addRaw("for (");
41725
+ if (stmt.init) g5.add(source.slice(stmt.init.start, stmt.init.end), stmt.init.start, stmt.init.end);
41726
+ g5.addRaw("; ");
41727
+ if (stmt.test) g5.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
41728
+ g5.addRaw("; ");
41729
+ if (stmt.update) g5.add(source.slice(stmt.update.start, stmt.update.end), stmt.update.start, stmt.update.end);
41730
+ g5.addRaw(") ");
41731
+ emitBlock(g5, source, stmt.body, indent4, opts);
41732
+ }
41733
+ function emitWhile(g5, source, stmt, indent4, opts) {
41734
+ g5.add(indent4);
41735
+ g5.addRaw("while (");
41736
+ g5.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
41737
+ g5.addRaw(") ");
41738
+ emitBlock(g5, source, stmt.body, indent4, opts);
41739
+ }
41740
+ function emitDoWhile(g5, source, stmt, indent4, opts) {
41741
+ g5.add(indent4);
41742
+ g5.addRaw("do ");
41743
+ emitBlock(g5, source, stmt.body, indent4, opts);
41744
+ g5.addRaw(" while (");
41745
+ g5.add(source.slice(stmt.test.start, stmt.test.end), stmt.test.start, stmt.test.end);
41746
+ g5.addRaw(");");
41747
+ }
41748
+ function emitSwitch(g5, source, stmt, indent4, opts) {
41749
+ g5.add(indent4);
41750
+ g5.addRaw("switch (");
41751
+ g5.add(source.slice(stmt.discriminant.start, stmt.discriminant.end), stmt.discriminant.start, stmt.discriminant.end);
41752
+ g5.addRaw(") {");
40661
41753
  let firstCase = true;
40662
41754
  for (const c of stmt.cases ?? []) {
40663
- g4.addRaw(firstCase ? "\n" : "\n");
41755
+ g5.addRaw(firstCase ? "\n" : "\n");
40664
41756
  firstCase = false;
40665
- g4.add(indent4);
40666
- g4.addRaw(" ");
41757
+ g5.add(indent4);
41758
+ g5.addRaw(" ");
40667
41759
  if (c.test) {
40668
- g4.addRaw("case ");
40669
- g4.add(source.slice(c.test.start, c.test.end), c.test.start, c.test.end);
40670
- g4.addRaw(":");
41760
+ g5.addRaw("case ");
41761
+ g5.add(source.slice(c.test.start, c.test.end), c.test.start, c.test.end);
41762
+ g5.addRaw(":");
40671
41763
  } else {
40672
- g4.addRaw("default:");
41764
+ g5.addRaw("default:");
40673
41765
  }
40674
- const before = g4.code.length;
40675
- emitBody(g4, source, c.consequent, indent4 + " ", opts);
40676
- if (g4.code.length > before) g4.addRaw("\n");
41766
+ const before = g5.code.length;
41767
+ emitBody(g5, source, c.consequent, indent4 + " ", opts);
41768
+ if (g5.code.length > before) g5.addRaw("\n");
40677
41769
  }
40678
- g4.addRaw("\n");
40679
- g4.add(indent4);
40680
- g4.addRaw("}");
41770
+ g5.addRaw("\n");
41771
+ g5.add(indent4);
41772
+ g5.addRaw("}");
40681
41773
  }
40682
- function emitTry(g4, source, stmt, indent4, opts) {
40683
- g4.add(indent4);
40684
- g4.addRaw("try ");
40685
- emitBlock(g4, source, stmt.block, indent4, opts);
41774
+ function emitTry(g5, source, stmt, indent4, opts) {
41775
+ g5.add(indent4);
41776
+ g5.addRaw("try ");
41777
+ emitBlock(g5, source, stmt.block, indent4, opts);
40686
41778
  if (stmt.handler) {
40687
- g4.addRaw(" catch");
41779
+ g5.addRaw(" catch");
40688
41780
  if (stmt.handler.param) {
40689
- g4.addRaw(" (");
40690
- g4.add(source.slice(stmt.handler.param.start, stmt.handler.param.end), stmt.handler.param.start, stmt.handler.param.end);
40691
- g4.addRaw(")");
41781
+ g5.addRaw(" (");
41782
+ g5.add(source.slice(stmt.handler.param.start, stmt.handler.param.end), stmt.handler.param.start, stmt.handler.param.end);
41783
+ g5.addRaw(")");
40692
41784
  }
40693
- g4.addRaw(" ");
40694
- emitBlock(g4, source, stmt.handler.body, indent4, opts);
41785
+ g5.addRaw(" ");
41786
+ emitBlock(g5, source, stmt.handler.body, indent4, opts);
40695
41787
  }
40696
41788
  if (stmt.finalizer) {
40697
- g4.addRaw(" finally ");
40698
- emitBlock(g4, source, stmt.finalizer, indent4, opts);
41789
+ g5.addRaw(" finally ");
41790
+ emitBlock(g5, source, stmt.finalizer, indent4, opts);
40699
41791
  }
40700
41792
  }
40701
- function emitPlainStatement(g4, source, stmt, indent4, isLast) {
41793
+ function emitPlainStatement(g5, source, stmt, indent4, isLast) {
40702
41794
  let text = stripTrailingSemicolons(source.slice(stmt.start, stmt.end).trimEnd());
40703
41795
  if (text === "") return;
40704
- g4.add(indent4);
40705
- g4.add(text, stmt.start, stmt.end);
40706
- if (!text.endsWith("}") && !isLast) g4.addRaw(";");
41796
+ g5.add(indent4);
41797
+ g5.add(text, stmt.start, stmt.end);
41798
+ if (!text.endsWith("}") && !isLast) g5.addRaw(";");
40707
41799
  }
40708
- function emitStatement(g4, source, stmt, indent4, isLast, opts, hoist) {
41800
+ function emitStatement(g5, source, stmt, indent4, isLast, opts, hoist) {
40709
41801
  switch (stmt.type) {
40710
41802
  case "JSXElement":
40711
41803
  if (getJSXTagName2(stmt) === "style") {
40712
41804
  const openEnd = stmt.openingElement?.end ?? stmt.start;
40713
41805
  const closeStart = stmt.closingElement?.start ?? stmt.end;
40714
- g4.recordStyle(stmt.start, stmt.end, source.slice(openEnd, closeStart));
41806
+ g5.recordStyle(stmt.start, stmt.end, source.slice(openEnd, closeStart));
40715
41807
  return;
40716
41808
  }
40717
- g4.add(indent4);
40718
- emitJSXElement(g4, source, stmt, opts, hoist);
40719
- if (!isLast) g4.addRaw(";");
41809
+ g5.add(indent4);
41810
+ emitJSXElement(g5, source, stmt, opts, hoist);
41811
+ if (!isLast) g5.addRaw(";");
40720
41812
  return;
40721
41813
  case "JSXFragment":
40722
- g4.add(indent4);
40723
- emitJSXFragment(g4, source, stmt, opts, hoist);
40724
- if (!isLast) g4.addRaw(";");
41814
+ g5.add(indent4);
41815
+ emitJSXFragment(g5, source, stmt, opts, hoist);
41816
+ if (!isLast) g5.addRaw(";");
40725
41817
  return;
40726
41818
  case "JSXExpressionContainer": {
40727
41819
  if (stmt.expression.type === "JSXEmptyExpression") return;
40728
- g4.add(indent4);
40729
- g4.addRaw("{");
40730
- g4.add(source.slice(stmt.expression.start, stmt.expression.end), stmt.expression.start, stmt.expression.end);
40731
- g4.addRaw("}");
40732
- if (!isLast) g4.addRaw(";");
41820
+ g5.add(indent4);
41821
+ g5.addRaw("{");
41822
+ g5.add(source.slice(stmt.expression.start, stmt.expression.end), stmt.expression.start, stmt.expression.end);
41823
+ g5.addRaw("}");
41824
+ if (!isLast) g5.addRaw(";");
40733
41825
  return;
40734
41826
  }
40735
41827
  case "VeskBlock": {
@@ -40737,10 +41829,10 @@ function emitStatement(g4, source, stmt, indent4, isLast, opts, hoist) {
40737
41829
  const innerStmts = stmt.body ?? [];
40738
41830
  let firstLine = true;
40739
41831
  for (let i = 0; i < innerStmts.length; i++) {
40740
- const before = g4.code.length;
40741
- emitStatement(g4, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts, hoist);
40742
- if (g4.code.length > before) {
40743
- if (!firstLine) g4.addRaw("\n");
41832
+ const before = g5.code.length;
41833
+ emitStatement(g5, source, innerStmts[i], indent4, isLast && i === innerStmts.length - 1, opts, hoist);
41834
+ if (g5.code.length > before) {
41835
+ if (!firstLine) g5.addRaw("\n");
40744
41836
  firstLine = false;
40745
41837
  }
40746
41838
  }
@@ -40748,38 +41840,38 @@ function emitStatement(g4, source, stmt, indent4, isLast, opts, hoist) {
40748
41840
  }
40749
41841
  case "VariableDeclaration":
40750
41842
  if (isTrackDeclStatement(stmt)) {
40751
- emitTrackDeclStatement(g4, source, stmt, indent4, isLast, opts);
41843
+ emitTrackDeclStatement(g5, source, stmt, indent4, isLast, opts);
40752
41844
  return;
40753
41845
  }
40754
- return emitPlainStatement(g4, source, stmt, indent4, isLast);
41846
+ return emitPlainStatement(g5, source, stmt, indent4, isLast);
40755
41847
  case "IfStatement":
40756
- return emitIf(g4, source, stmt, indent4, opts);
41848
+ return emitIf(g5, source, stmt, indent4, opts);
40757
41849
  case "ForOfStatement":
40758
- return emitForOf(g4, source, stmt, indent4, opts);
41850
+ return emitForOf(g5, source, stmt, indent4, opts);
40759
41851
  case "ForInStatement":
40760
- return emitForIn(g4, source, stmt, indent4, opts);
41852
+ return emitForIn(g5, source, stmt, indent4, opts);
40761
41853
  case "ForStatement":
40762
- return emitFor(g4, source, stmt, indent4, opts);
41854
+ return emitFor(g5, source, stmt, indent4, opts);
40763
41855
  case "WhileStatement":
40764
- return emitWhile(g4, source, stmt, indent4, opts);
41856
+ return emitWhile(g5, source, stmt, indent4, opts);
40765
41857
  case "DoWhileStatement":
40766
- return emitDoWhile(g4, source, stmt, indent4, opts);
41858
+ return emitDoWhile(g5, source, stmt, indent4, opts);
40767
41859
  case "SwitchStatement":
40768
- return emitSwitch(g4, source, stmt, indent4, opts);
41860
+ return emitSwitch(g5, source, stmt, indent4, opts);
40769
41861
  case "TryStatement":
40770
- return emitTry(g4, source, stmt, indent4, opts);
41862
+ return emitTry(g5, source, stmt, indent4, opts);
40771
41863
  case "LabeledStatement": {
40772
- g4.add(indent4);
40773
- g4.add(stmt.label.name, stmt.label.start, stmt.label.end);
40774
- g4.addRaw(":\n");
40775
- emitStatement(g4, source, stmt.body, indent4, isLast, opts);
41864
+ g5.add(indent4);
41865
+ g5.add(stmt.label.name, stmt.label.start, stmt.label.end);
41866
+ g5.addRaw(":\n");
41867
+ emitStatement(g5, source, stmt.body, indent4, isLast, opts);
40776
41868
  return;
40777
41869
  }
40778
41870
  default:
40779
- return emitPlainStatement(g4, source, stmt, indent4, isLast);
41871
+ return emitPlainStatement(g5, source, stmt, indent4, isLast);
40780
41872
  }
40781
41873
  }
40782
- function emitBody(g4, source, stmts, indent4, opts, hoist) {
41874
+ function emitBody(g5, source, stmts, indent4, opts, hoist) {
40783
41875
  let firstLine = true;
40784
41876
  let i = 0;
40785
41877
  while (i < stmts.length) {
@@ -40787,34 +41879,34 @@ function emitBody(g4, source, stmts, indent4, opts, hoist) {
40787
41879
  const isLast = i === stmts.length - 1;
40788
41880
  if (stmt.type === "ForOfStatement" && stmts[i + 1] && stmts[i + 1].type === "VeskBlock" && stmts[i + 1].tag === "empty") {
40789
41881
  const empty2 = stmts[i + 1];
40790
- if (!firstLine) g4.addRaw("\n");
41882
+ if (!firstLine) g5.addRaw("\n");
40791
41883
  firstLine = false;
40792
- emitForOf(g4, source, stmt, indent4, opts);
41884
+ emitForOf(g5, source, stmt, indent4, opts);
40793
41885
  const inner = empty2.body ?? [];
40794
41886
  if (inner.length > 0) {
40795
- g4.addRaw("\n");
40796
- g4.add(indent4);
40797
- g4.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
40798
- g4.addRaw(".length === 0 && (() => {");
40799
- g4.addRaw("\n");
40800
- emitBody(g4, source, inner, indent4 + " ", opts);
40801
- g4.addRaw("\n");
40802
- g4.add(indent4);
40803
- g4.addRaw("})();");
41887
+ g5.addRaw("\n");
41888
+ g5.add(indent4);
41889
+ g5.add(source.slice(stmt.right.start, stmt.right.end), stmt.right.start, stmt.right.end);
41890
+ g5.addRaw(".length === 0 && (() => {");
41891
+ g5.addRaw("\n");
41892
+ emitBody(g5, source, inner, indent4 + " ", opts);
41893
+ g5.addRaw("\n");
41894
+ g5.add(indent4);
41895
+ g5.addRaw("})();");
40804
41896
  }
40805
41897
  i += 2;
40806
41898
  continue;
40807
41899
  }
40808
- const before = g4.code.length;
40809
- emitStatement(g4, source, stmt, indent4, isLast, opts, hoist);
40810
- if (g4.code.length > before) {
40811
- if (!firstLine) g4.addRaw("\n");
41900
+ const before = g5.code.length;
41901
+ emitStatement(g5, source, stmt, indent4, isLast, opts, hoist);
41902
+ if (g5.code.length > before) {
41903
+ if (!firstLine) g5.addRaw("\n");
40812
41904
  firstLine = false;
40813
41905
  }
40814
41906
  i++;
40815
41907
  }
40816
41908
  }
40817
- function emitChunkMapped(g4, source, start, end) {
41909
+ function emitChunkMapped(g5, source, start, end) {
40818
41910
  if (end <= start) return;
40819
41911
  let pos = start;
40820
41912
  let i = start;
@@ -40826,8 +41918,8 @@ function emitChunkMapped(g4, source, start, end) {
40826
41918
  if (openEnd !== -1 && openEnd <= end) {
40827
41919
  const closeIdx = source.indexOf("</style>", openEnd);
40828
41920
  if (closeIdx !== -1 && closeIdx + 8 <= end) {
40829
- g4.add(source.slice(pos, i), pos, i);
40830
- g4.recordStyle(i, closeIdx + 8, source.slice(openEnd, closeIdx));
41921
+ g5.add(source.slice(pos, i), pos, i);
41922
+ g5.recordStyle(i, closeIdx + 8, source.slice(openEnd, closeIdx));
40831
41923
  pos = closeIdx + 8;
40832
41924
  i = closeIdx + 8;
40833
41925
  continue;
@@ -40837,20 +41929,20 @@ function emitChunkMapped(g4, source, start, end) {
40837
41929
  }
40838
41930
  i++;
40839
41931
  }
40840
- g4.add(source.slice(pos, end), pos, end);
41932
+ g5.add(source.slice(pos, end), pos, end);
40841
41933
  }
40842
- function emitReturn(g4, source, stmt, opts) {
40843
- g4.add(source.slice(stmt.start, stmt.start + 6), stmt.start, stmt.start + 6);
41934
+ function emitReturn(g5, source, stmt, opts) {
41935
+ g5.add(source.slice(stmt.start, stmt.start + 6), stmt.start, stmt.start + 6);
40844
41936
  const arg = stmt.argument;
40845
41937
  if (!arg) {
40846
- emitChunkMapped(g4, source, stmt.start + 6, stmt.end);
41938
+ emitChunkMapped(g5, source, stmt.start + 6, stmt.end);
40847
41939
  return;
40848
41940
  }
40849
- emitChunkMapped(g4, source, stmt.start + 6, arg.start);
40850
- if (arg.type === "JSXElement") emitJSXElement(g4, source, arg, opts);
40851
- else if (arg.type === "JSXFragment") emitJSXFragment(g4, source, arg, opts);
40852
- else emitChunkMapped(g4, source, arg.start, arg.end);
40853
- emitChunkMapped(g4, source, arg.end, stmt.end);
41941
+ emitChunkMapped(g5, source, stmt.start + 6, arg.start);
41942
+ if (arg.type === "JSXElement") emitJSXElement(g5, source, arg, opts);
41943
+ else if (arg.type === "JSXFragment") emitJSXFragment(g5, source, arg, opts);
41944
+ else emitChunkMapped(g5, source, arg.start, arg.end);
41945
+ emitChunkMapped(g5, source, arg.end, stmt.end);
40854
41946
  }
40855
41947
  function collectHoistEligible(children, set2, list) {
40856
41948
  for (const child of children ?? []) {
@@ -40870,7 +41962,7 @@ function collectHoistEligible(children, set2, list) {
40870
41962
  }
40871
41963
  }
40872
41964
  }
40873
- function emitBodyCore(g4, source, stmts, opts) {
41965
+ function emitBodyCore(g5, source, stmts, opts) {
40874
41966
  const hoistSet = /* @__PURE__ */ new Set();
40875
41967
  const byRoot = /* @__PURE__ */ new Map();
40876
41968
  const collectRoot = (root3) => {
@@ -40921,107 +42013,107 @@ function emitBodyCore(g4, source, stmts, opts) {
40921
42013
  byRoot.delete(u.node);
40922
42014
  const n = list.length;
40923
42015
  for (let k = 0; k < n; k++) {
40924
- const before2 = g4.code.length;
40925
- emitStatement(g4, source, list[k], "", false, opts, ctx2);
40926
- if (g4.code.length > before2) g4.addRaw("\n");
42016
+ const before2 = g5.code.length;
42017
+ emitStatement(g5, source, list[k], "", false, opts, ctx2);
42018
+ if (g5.code.length > before2) g5.addRaw("\n");
40927
42019
  }
40928
42020
  }
40929
42021
  }
40930
42022
  if (u.empty !== void 0) {
40931
- emitForOf(g4, source, u.node, "", opts);
42023
+ emitForOf(g5, source, u.node, "", opts);
40932
42024
  const inner = u.empty.body ?? [];
40933
42025
  if (inner.length > 0) {
40934
- g4.addRaw("\n");
40935
- g4.add("");
40936
- g4.add(
42026
+ g5.addRaw("\n");
42027
+ g5.add("");
42028
+ g5.add(
40937
42029
  source.slice(u.node.right.start, u.node.right.end),
40938
42030
  u.node.right.start,
40939
42031
  u.node.right.end
40940
42032
  );
40941
- g4.addRaw(".length === 0 && (() => {");
40942
- g4.addRaw("\n");
40943
- emitBody(g4, source, inner, " ", opts);
40944
- g4.addRaw("\n");
40945
- g4.add("");
40946
- g4.addRaw("})();");
42033
+ g5.addRaw(".length === 0 && (() => {");
42034
+ g5.addRaw("\n");
42035
+ emitBody(g5, source, inner, " ", opts);
42036
+ g5.addRaw("\n");
42037
+ g5.add("");
42038
+ g5.addRaw("})();");
40947
42039
  }
40948
42040
  return;
40949
42041
  }
40950
- const before = g4.code.length;
40951
- emitStatement(g4, source, u.node, "", isLast, opts, ctx2);
40952
- if (g4.code.length > before && !isLast) g4.addRaw("\n");
42042
+ const before = g5.code.length;
42043
+ emitStatement(g5, source, u.node, "", isLast, opts, ctx2);
42044
+ if (g5.code.length > before && !isLast) g5.addRaw("\n");
40953
42045
  };
40954
42046
  for (let i = 0; i < units.length; i++) {
40955
42047
  emitUnit(units[i], i === units.length - 1);
40956
42048
  }
40957
42049
  }
40958
- function emitExpressionBody(g4, source, coreStart, coreEnd, stmts, opts) {
42050
+ function emitExpressionBody(g5, source, coreStart, coreEnd, stmts, opts) {
40959
42051
  let pos = coreStart;
40960
42052
  for (const stmt of stmts) {
40961
42053
  if (!stmt) continue;
40962
- emitChunkMapped(g4, source, pos, stmt.start);
42054
+ emitChunkMapped(g5, source, pos, stmt.start);
40963
42055
  pos = stmt.start;
40964
42056
  if (isTrackDeclStatement(stmt)) {
40965
- emitTrackDeclStatement(g4, source, stmt, "", true, opts);
42057
+ emitTrackDeclStatement(g5, source, stmt, "", true, opts);
40966
42058
  } else if (stmt.type === "ReturnStatement") {
40967
- emitReturn(g4, source, stmt, opts);
42059
+ emitReturn(g5, source, stmt, opts);
40968
42060
  } else {
40969
- emitChunkMapped(g4, source, stmt.start, stmt.end);
42061
+ emitChunkMapped(g5, source, stmt.start, stmt.end);
40970
42062
  }
40971
42063
  pos = stmt.end;
40972
42064
  }
40973
- emitChunkMapped(g4, source, pos, coreEnd);
42065
+ emitChunkMapped(g5, source, pos, coreEnd);
40974
42066
  }
40975
- function emitRestMapped(g4, text, base, end) {
42067
+ function emitRestMapped(g5, text, base, end) {
40976
42068
  let i = 0;
40977
42069
  while (i < text.length && !isIdentStart(text[i])) i++;
40978
42070
  if (i >= text.length) {
40979
- g4.add(text, base, end);
42071
+ g5.add(text, base, end);
40980
42072
  return;
40981
42073
  }
40982
42074
  let j = i + 1;
40983
42075
  while (j < text.length && isIdentChar(text[j])) j++;
40984
- g4.add(text.slice(0, i), base, base + i);
40985
- g4.add(text.slice(i, j), base + i, base + j);
40986
- g4.add(text.slice(j), base + j, end);
42076
+ g5.add(text.slice(0, i), base, base + i);
42077
+ g5.add(text.slice(i, j), base + i, base + j);
42078
+ g5.add(text.slice(j), base + j, end);
40987
42079
  }
40988
- function emitComponentHeader(g4, source, start, bodyStart) {
42080
+ function emitComponentHeader(g5, source, start, bodyStart) {
40989
42081
  const h = source.slice(start, bodyStart);
40990
42082
  const k = findFirstKeyword(h, "component");
40991
42083
  if (k === -1) {
40992
42084
  const { text, end: end2 } = stripTrailingClientRange(h);
40993
42085
  if (!text.includes("(")) {
40994
42086
  const trimmed = text.trimEnd();
40995
- g4.add(trimmed, start, start + end2 - (text.length - trimmed.length));
40996
- g4.addRaw("() ");
42087
+ g5.add(trimmed, start, start + end2 - (text.length - trimmed.length));
42088
+ g5.addRaw("() ");
40997
42089
  } else {
40998
- g4.add(text, start, start + end2);
42090
+ g5.add(text, start, start + end2);
40999
42091
  }
41000
42092
  return;
41001
42093
  }
41002
- g4.add(h.slice(0, k), start, start + k);
41003
- g4.add("function", start + k, start + k + "component".length);
42094
+ g5.add(h.slice(0, k), start, start + k);
42095
+ g5.add("function", start + k, start + k + "component".length);
41004
42096
  const restBase = start + k + "component".length;
41005
42097
  const { text: rest, end } = stripTrailingClientRange(h.slice(k + "component".length));
41006
42098
  const transformed = h.slice(0, k) + "function" + rest;
41007
42099
  if (!transformed.includes("(")) {
41008
42100
  const trimmed = rest.trimEnd();
41009
- emitRestMapped(g4, trimmed, restBase, restBase + end - (rest.length - trimmed.length));
41010
- g4.addRaw("() ");
42101
+ emitRestMapped(g5, trimmed, restBase, restBase + end - (rest.length - trimmed.length));
42102
+ g5.addRaw("() ");
41011
42103
  } else {
41012
- emitRestMapped(g4, rest, restBase, restBase + end);
42104
+ emitRestMapped(g5, rest, restBase, restBase + end);
41013
42105
  }
41014
42106
  }
41015
- function emitComponent(g4, source, node, start, opts) {
42107
+ function emitComponent(g5, source, node, start, opts) {
41016
42108
  const body = node.body;
41017
42109
  if (!body || body.start == null || body.end == null) return;
41018
- emitComponentHeader(g4, source, start, body.start);
42110
+ emitComponentHeader(g5, source, start, body.start);
41019
42111
  const statementMode = isStatementMode2(node);
41020
42112
  const stmts = body.body ?? [];
41021
42113
  if (statementMode) {
41022
- g4.addRaw("{ ");
41023
- emitBodyCore(g4, source, stmts, opts);
41024
- g4.addRaw(" }");
42114
+ g5.addRaw("{ ");
42115
+ emitBodyCore(g5, source, stmts, opts);
42116
+ g5.addRaw(" }");
41025
42117
  } else {
41026
42118
  const raw2 = source.slice(body.start, body.end);
41027
42119
  const rawLen = raw2.length;
@@ -41041,9 +42133,9 @@ function emitComponent(g4, source, node, start, opts) {
41041
42133
  }
41042
42134
  while (coreStart < coreEnd && isWhitespaceChar(source[coreStart])) coreStart++;
41043
42135
  while (coreEnd > coreStart && isWhitespaceChar(source[coreEnd - 1])) coreEnd--;
41044
- if (hasBraces) g4.addRaw("{ ");
41045
- emitExpressionBody(g4, source, coreStart, coreEnd, stmts, opts);
41046
- if (hasBraces) g4.addRaw(" }");
42136
+ if (hasBraces) g5.addRaw("{ ");
42137
+ emitExpressionBody(g5, source, coreStart, coreEnd, stmts, opts);
42138
+ if (hasBraces) g5.addRaw(" }");
41047
42139
  }
41048
42140
  }
41049
42141
  function isModuleAst(ast) {
@@ -41073,26 +42165,26 @@ function compileVskCodegen(source, opts = {}) {
41073
42165
  };
41074
42166
  }
41075
42167
  const clean = blankForClauses(source, ast);
41076
- const g4 = new VskGen();
42168
+ const g5 = new VskGen();
41077
42169
  const components = getComponents(ast).sort((a, b) => a.start - b.start);
41078
42170
  let pos = 0;
41079
42171
  for (const { node, start } of components) {
41080
42172
  const body = node.body;
41081
42173
  if (!body || body.start == null || body.end == null) continue;
41082
- g4.add(clean.slice(pos, start), pos, start);
41083
- emitComponent(g4, clean, node, start, opts);
42174
+ g5.add(clean.slice(pos, start), pos, start);
42175
+ emitComponent(g5, clean, node, start, opts);
41084
42176
  pos = body.end;
41085
42177
  }
41086
- g4.add(clean.slice(pos), pos, source.length);
41087
- let code = g4.code;
42178
+ g5.add(clean.slice(pos), pos, source.length);
42179
+ let code = g5.code;
41088
42180
  if (isModuleAst(ast) && containsIdentifier(code, "Head") && !isIdentifierImported(code, "Head")) {
41089
- g4.prepend("declare const Head: (props: { children?: Component }) => Component;\n");
41090
- code = g4.code;
42181
+ g5.prepend("declare const Head: (props: { children?: Component }) => Component;\n");
42182
+ code = g5.code;
41091
42183
  }
41092
42184
  if (!isModuleAst(ast)) {
41093
42185
  code += "\nexport {};\n";
41094
42186
  }
41095
- return { code, mappings: g4.mappings, styleRegions: g4.styleRegions, errors: [] };
42187
+ return { code, mappings: g5.mappings, styleRegions: g5.styleRegions, errors: [] };
41096
42188
  }
41097
42189
  function isTypeDecl(stmt) {
41098
42190
  return stmt.type === "TSInterfaceDeclaration" || stmt.type === "TSTypeAliasDeclaration" || stmt.type === "ExportNamedDeclaration" && (stmt.declaration?.type === "TSInterfaceDeclaration" || stmt.declaration?.type === "TSTypeAliasDeclaration");
@@ -47797,25 +48889,25 @@ function runMigrate(options) {
47797
48889
  }
47798
48890
  const applicable = codemods.filter((c) => c.appliesTo(abs));
47799
48891
  if (applicable.length === 0) continue;
47800
- let current2 = source;
48892
+ let current3 = source;
47801
48893
  let changed = false;
47802
48894
  for (const codemod of applicable) {
47803
48895
  let result;
47804
48896
  try {
47805
- result = codemod.run(current2, ctx2);
48897
+ result = codemod.run(current3, ctx2);
47806
48898
  } catch (e) {
47807
48899
  report.skipped.push(`${relPath}: ${codemod.id} failed (${e.message})`);
47808
48900
  continue;
47809
48901
  }
47810
48902
  report.notes.push(...result.notes);
47811
- if (result.code !== null && result.code !== current2) {
47812
- current2 = result.code;
48903
+ if (result.code !== null && result.code !== current3) {
48904
+ current3 = result.code;
47813
48905
  changed = true;
47814
48906
  }
47815
48907
  }
47816
48908
  if (!changed) continue;
47817
48909
  report.filesChanged.push(relPath);
47818
- if (!options.dryRun) writeFileSync22(abs, current2, "utf-8");
48910
+ if (!options.dryRun) writeFileSync22(abs, current3, "utf-8");
47819
48911
  }
47820
48912
  return report;
47821
48913
  }
@@ -50212,9 +51304,9 @@ var ChunkImports = class {
50212
51304
  this.fail(`nameless named-import from '${source}' in ${filePath}`, code);
50213
51305
  return false;
50214
51306
  }
50215
- const existing = group.named.get(imported);
50216
- if (existing && existing.local !== local) {
50217
- this.fail(`'${imported}' from '${source}' bound to both '${existing.local}' and '${local}' in ${filePath}`, code);
51307
+ const existing2 = group.named.get(imported);
51308
+ if (existing2 && existing2.local !== local) {
51309
+ this.fail(`'${imported}' from '${source}' bound to both '${existing2.local}' and '${local}' in ${filePath}`, code);
50218
51310
  return false;
50219
51311
  }
50220
51312
  group.named.set(imported, { kind: "named", local, imported });
@@ -50249,11 +51341,11 @@ var ChunkImports = class {
50249
51341
  const lines = [];
50250
51342
  const sources = [...this.bySource.keys()].sort();
50251
51343
  for (const src2 of sources) {
50252
- const g4 = this.bySource.get(src2);
51344
+ const g5 = this.bySource.get(src2);
50253
51345
  const parts = [];
50254
- if (g4.default) parts.push(`import ${g4.default.local} from ${JSON.stringify(src2)}`);
50255
- if (g4.namespace) parts.push(`import * as ${g4.namespace.local} from ${JSON.stringify(src2)}`);
50256
- const named = [...g4.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
51346
+ if (g5.default) parts.push(`import ${g5.default.local} from ${JSON.stringify(src2)}`);
51347
+ if (g5.namespace) parts.push(`import * as ${g5.namespace.local} from ${JSON.stringify(src2)}`);
51348
+ const named = [...g5.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
50257
51349
  if (named.length > 0) {
50258
51350
  const specs = named.map((sp) => sp.imported === sp.local ? sp.local : `${sp.imported} as ${sp.local}`).join(", ");
50259
51351
  parts.push(`import { ${specs} } from ${JSON.stringify(src2)}`);
@@ -50924,10 +52016,17 @@ async function buildTreeShakenRuntimeNow(runtimeDir, usedNames) {
50924
52016
  const missing = unique.filter((n) => !available.has(n));
50925
52017
  if (missing.length > 0) {
50926
52018
  console.error(`vesk: runtime names not exported \u2014 ${missing.join(", ")}; falling back to full runtime`);
52019
+ const full = await bundleRuntimeNames(runtimeDir, [...available]);
52020
+ if (full) return full;
50927
52021
  return buildRuntimeCode(runtimeDir);
50928
52022
  }
52023
+ return await bundleRuntimeNames(runtimeDir, unique, true) ?? buildRuntimeCode(runtimeDir);
52024
+ }
52025
+ async function bundleRuntimeNames(runtimeDir, names, strict = false) {
52026
+ if (names.length === 0) return null;
50929
52027
  const entry = runtimeTreeShakeEntry();
50930
52028
  const indexClient = esbuildPath(join7(runtimeDir, "index-client.js"));
52029
+ const unique = [...new Set(names)];
50931
52030
  try {
50932
52031
  try {
50933
52032
  mkdirSync3(dirname8(entry), { recursive: true });
@@ -50964,8 +52063,8 @@ const { ${unique.join(", ")} } = __veskRuntime;
50964
52063
  export { ${unique.join(", ")} };
50965
52064
  `;
50966
52065
  } catch (e) {
50967
- console.error("vesk: runtime tree-shake failed, falling back to full runtime:", e.message);
50968
- return buildRuntimeCode(runtimeDir);
52066
+ if (strict) console.error("vesk: runtime tree-shake failed, falling back to full runtime:", e.message);
52067
+ return null;
50969
52068
  } finally {
50970
52069
  try {
50971
52070
  unlinkSync3(entry);
@@ -51072,6 +52171,18 @@ if (typeof document !== 'undefined') __router.start();
51072
52171
  }
51073
52172
 
51074
52173
  // ../adapter/src/manifest.ts
52174
+ function specificityKey(path) {
52175
+ return path.split("/").filter(Boolean).map((seg) => seg.startsWith("*") ? "2" + seg : seg.startsWith(":") ? "1" + seg : "0" + seg);
52176
+ }
52177
+ function compareSpecificity(a, b) {
52178
+ const ka = specificityKey(a);
52179
+ const kb = specificityKey(b);
52180
+ const len = Math.min(ka.length, kb.length);
52181
+ for (let i = 0; i < len; i++) {
52182
+ if (ka[i] !== kb[i]) return ka[i] < kb[i] ? -1 : 1;
52183
+ }
52184
+ return kb.length - ka.length;
52185
+ }
51075
52186
  function generateManifest(routes, ssrRoutes, apiRoutes, staticRoutes, middlewareEnabled, actionMap, headExtra, eventsEnabled = false) {
51076
52187
  const routeEntries = [];
51077
52188
  for (const r of ssrRoutes) {
@@ -51086,15 +52197,23 @@ function generateManifest(routes, ssrRoutes, apiRoutes, staticRoutes, middleware
51086
52197
  if (r._isrTags) entry.tags = r._isrTags;
51087
52198
  routeEntries.push(entry);
51088
52199
  }
52200
+ const apiEntries = [];
51089
52201
  for (const r of apiRoutes) {
51090
52202
  const urlParts = r.fullPath.split("/").filter(Boolean);
51091
- const name = urlParts.map((s) => s.startsWith(":") ? s.slice(1) || "param" : s).join("_") || "index";
51092
- routeEntries.push({
51093
- path: `/api${r.fullPath}`,
52203
+ const parts = urlParts.map((s, i) => {
52204
+ const last = i === urlParts.length - 1;
52205
+ if (last && r.isCatchAll && s.startsWith(":")) return "*" + s.slice(1);
52206
+ return s;
52207
+ });
52208
+ const name = parts.map((s) => s.startsWith(":") || s.startsWith("*") ? s.slice(1) || "param" : s).join("_") || "index";
52209
+ apiEntries.push({
52210
+ path: parts.length ? `/api/${parts.join("/")}` : "/api",
51094
52211
  type: "api",
51095
52212
  function: `server/api/${name}.js`
51096
52213
  });
51097
52214
  }
52215
+ apiEntries.sort((a, b) => compareSpecificity(a.path, b.path));
52216
+ routeEntries.push(...apiEntries);
51098
52217
  const ssgEntries = [];
51099
52218
  for (const r of staticRoutes) {
51100
52219
  ssgEntries.push({
@@ -51423,18 +52542,27 @@ async function startProdServer(outDir, options) {
51423
52542
  let pi = 0, pp2 = 0;
51424
52543
  const params = {};
51425
52544
  while (pi < pathParts.length && pp2 < patternParts.length) {
51426
- if (patternParts[pp2].startsWith(":")) {
51427
- const name = patternParts[pp2].slice(1);
52545
+ const seg = patternParts[pp2];
52546
+ if (seg.startsWith("*")) {
52547
+ params[seg.slice(1)] = pathParts.slice(pi).join("/");
52548
+ pi = pathParts.length;
52549
+ pp2++;
52550
+ } else if (seg.startsWith(":")) {
52551
+ const name = seg.slice(1);
51428
52552
  params[name] = pathParts[pi];
51429
52553
  pi++;
51430
52554
  pp2++;
51431
- } else if (patternParts[pp2] === pathParts[pi]) {
52555
+ } else if (seg === pathParts[pi]) {
51432
52556
  pi++;
51433
52557
  pp2++;
51434
52558
  } else {
51435
52559
  return null;
51436
52560
  }
51437
52561
  }
52562
+ if (pp2 === patternParts.length - 1 && patternParts[pp2].startsWith("*")) {
52563
+ params[patternParts[pp2].slice(1)] = pathParts.slice(pi).join("/");
52564
+ pp2++;
52565
+ }
51438
52566
  if (pp2 === patternParts.length && pi === pathParts.length) return params;
51439
52567
  return null;
51440
52568
  }
@@ -51468,6 +52596,34 @@ async function startProdServer(outDir, options) {
51468
52596
  }
51469
52597
  return origWriteHead(statusCode, headers2);
51470
52598
  });
52599
+ const securityBridge = globalThis.__vesk_security;
52600
+ const securityRun = securityBridge?.run;
52601
+ const withSecurityScope = securityRun ? (fn) => securityRun(fn) : (fn) => fn();
52602
+ const applyOverrideHeaders = (headers2) => {
52603
+ const overrides = securityBridge?.get?.();
52604
+ if (!overrides) return headers2;
52605
+ const next = { ...headers2 };
52606
+ if (typeof overrides.contentSecurityPolicy === "string") {
52607
+ next["Content-Security-Policy"] = overrides.contentSecurityPolicy;
52608
+ }
52609
+ const custom2 = overrides.customHeaders;
52610
+ if (custom2) {
52611
+ for (const [name, value] of Object.entries(custom2)) {
52612
+ if (value === false) delete next[name];
52613
+ else next[name] = value;
52614
+ }
52615
+ }
52616
+ return next;
52617
+ };
52618
+ const origWriteHead2 = res.writeHead.bind(res);
52619
+ let overridesApplied = false;
52620
+ res.writeHead = ((statusCode, headers2) => {
52621
+ if (!overridesApplied) {
52622
+ overridesApplied = true;
52623
+ headers2 = applyOverrideHeaders(headers2 || {});
52624
+ }
52625
+ return origWriteHead2(statusCode, headers2);
52626
+ });
51471
52627
  const publicDir = resolve13(staticDir, "public");
51472
52628
  const rootFile = url.pathname.length > 1 ? resolveWithin(publicDir, url.pathname.slice(1)) : null;
51473
52629
  if (rootFile && existsSync15(rootFile) && statSync6(rootFile).isFile()) {
@@ -51607,7 +52763,8 @@ async function startProdServer(outDir, options) {
51607
52763
  }
51608
52764
  try {
51609
52765
  const webRequest = makeWebRequest(req, url.href, maxBodyBytes);
51610
- const response = await mod.handleAction(webRequest, actionId);
52766
+ const handleAction = mod.handleAction.bind(mod);
52767
+ const response = await withSecurityScope(() => handleAction(webRequest, actionId));
51611
52768
  await deliverResponse(res, response);
51612
52769
  } catch (e) {
51613
52770
  const status = errorStatus(e, 500);
@@ -51626,7 +52783,7 @@ async function startProdServer(outDir, options) {
51626
52783
  if (mod) {
51627
52784
  try {
51628
52785
  const webRequest = makeWebRequest(req, url.href, maxBodyBytes);
51629
- const response = await mod.handle(webRequest);
52786
+ const response = await withSecurityScope(() => mod.handle(webRequest));
51630
52787
  await deliverResponse(res, response);
51631
52788
  return;
51632
52789
  } catch (e) {
@@ -51668,7 +52825,7 @@ async function startProdServer(outDir, options) {
51668
52825
  if (route.revalidate && route.revalidate > 0) {
51669
52826
  const { pageIsr: pageIsr2 } = await Promise.resolve().then(() => (init_index_server(), index_server_exports));
51670
52827
  cachedResult = await pageIsr2(url.pathname, async () => {
51671
- const response2 = await mod.handle(webRequest);
52828
+ const response2 = await withSecurityScope(() => mod.handle(webRequest));
51672
52829
  return { html: await response2.text(), headers: Object.fromEntries(response2.headers) };
51673
52830
  }, { revalidate: route.revalidate, tags: route.tags || [] });
51674
52831
  }
@@ -51677,7 +52834,7 @@ async function startProdServer(outDir, options) {
51677
52834
  res.end(cachedResult.html);
51678
52835
  return;
51679
52836
  }
51680
- const response = await mod.handle(webRequest);
52837
+ const response = await withSecurityScope(() => mod.handle(webRequest));
51681
52838
  const headers2 = Object.fromEntries(response.headers);
51682
52839
  if (!headers2["content-type"] && !headers2["Content-Type"]) headers2["Content-Type"] = "text/html";
51683
52840
  if (response.body && typeof response.body.getReader === "function") {
@@ -52432,8 +53589,8 @@ init_index_server();
52432
53589
  import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
52433
53590
  var TOKEN_KEY2 = "__vsk_ssr_token";
52434
53591
  var IMPL_KEY2 = "__vsk_ssr_store_impl";
52435
- var g3 = globalThis;
52436
- var impl2 = g3[IMPL_KEY2] ?? (g3[IMPL_KEY2] = {
53592
+ var g4 = globalThis;
53593
+ var impl2 = g4[IMPL_KEY2] ?? (g4[IMPL_KEY2] = {
52437
53594
  storage: new AsyncLocalStorage2(),
52438
53595
  liveSlots: /* @__PURE__ */ new Map(),
52439
53596
  // Only the copy that created the implementation installs the token
@@ -52452,8 +53609,8 @@ function isThenable2(value) {
52452
53609
  return typeof value?.then === "function";
52453
53610
  }
52454
53611
  function withSsrStore2(fn) {
52455
- const existing = storage2.getStore();
52456
- if (existing)
53612
+ const existing2 = storage2.getStore();
53613
+ if (existing2)
52457
53614
  return fn();
52458
53615
  const store = createSsrStore3();
52459
53616
  keepSsrSlot2(store.token);
@@ -55372,6 +56529,20 @@ function collectSources(tree) {
55372
56529
  walk9(tree);
55373
56530
  return map;
55374
56531
  }
56532
+ function segmentRank(node) {
56533
+ if (node.isGroup || node.fullPath === "/")
56534
+ return 0;
56535
+ if (node.isCatchAll)
56536
+ return 3;
56537
+ if (node.isDynamic)
56538
+ return 2;
56539
+ return 1;
56540
+ }
56541
+ function bySegmentPrecedence(nodes) {
56542
+ if (nodes.length < 2)
56543
+ return nodes;
56544
+ return nodes.map((node, index) => ({ node, index, rank: segmentRank(node) })).sort((a, b) => a.rank - b.rank || a.index - b.index).map((entry) => entry.node);
56545
+ }
55375
56546
  function matchUrl(tree, pathname) {
55376
56547
  const parts = pathname.split("/").filter(Boolean);
55377
56548
  const chain = [];
@@ -55387,7 +56558,7 @@ function matchUrl(tree, pathname) {
55387
56558
  chain.push(node);
55388
56559
  }
55389
56560
  function matchNodes(nodes, partIndex) {
55390
- for (const node of nodes) {
56561
+ for (const node of bySegmentPrecedence(nodes)) {
55391
56562
  if (node.isGroup) {
55392
56563
  const marker = chain.length;
55393
56564
  if (node.layout || node.page)
@@ -55560,6 +56731,20 @@ function scanApiDir(rootDir, dir, parentPath) {
55560
56731
  }
55561
56732
  return nodes;
55562
56733
  }
56734
+ function specificityRank(node) {
56735
+ if (node.fullPath === "/")
56736
+ return 0;
56737
+ if (node.isCatchAll)
56738
+ return 3;
56739
+ if (node.isDynamic)
56740
+ return 2;
56741
+ return 1;
56742
+ }
56743
+ function bySpecificity(nodes) {
56744
+ if (nodes.length < 2)
56745
+ return nodes;
56746
+ return nodes.map((node, index) => ({ node, index, rank: specificityRank(node) })).sort((a, b) => a.rank - b.rank || a.index - b.index).map((entry) => entry.node);
56747
+ }
55563
56748
  function matchApiUrl(tree, pathname) {
55564
56749
  let normalized = pathname.split("?")[0].split("#")[0];
55565
56750
  if (normalized === "/api") {
@@ -55569,31 +56754,40 @@ function matchApiUrl(tree, pathname) {
55569
56754
  }
55570
56755
  const parts = normalized.split("/").filter(Boolean);
55571
56756
  const params = {};
56757
+ function restoreParams(snapshot) {
56758
+ for (const key of Object.keys(params)) {
56759
+ if (!(key in snapshot))
56760
+ delete params[key];
56761
+ }
56762
+ for (const key of Object.keys(snapshot))
56763
+ params[key] = snapshot[key];
56764
+ }
55572
56765
  function matchNodes(nodes, partIndex) {
55573
- for (const node of nodes) {
56766
+ for (const node of bySpecificity(nodes)) {
55574
56767
  if (node.fullPath === "/") {
55575
56768
  if (partIndex >= parts.length && node.filePath)
55576
56769
  return node;
55577
56770
  return matchNodes(node.children, partIndex);
55578
56771
  }
55579
- if (partIndex >= parts.length) {
55580
- if (node.filePath)
55581
- return node;
55582
- continue;
55583
- }
55584
- const part = parts[partIndex];
56772
+ const part = partIndex < parts.length ? parts[partIndex] : void 0;
55585
56773
  if (node.isCatchAll) {
56774
+ if (!node.filePath)
56775
+ continue;
55586
56776
  const paramName = node.path.startsWith(":") ? node.path.slice(1) : node.path;
55587
56777
  params[paramName] = parts.slice(partIndex).map(decodeURIComponent).join("/");
55588
56778
  return node;
55589
56779
  }
56780
+ if (part === void 0)
56781
+ continue;
55590
56782
  if (node.isDynamic) {
55591
56783
  const paramName = node.path.startsWith(":") ? node.path.slice(1) : node.path;
55592
56784
  params[paramName] = decodeURIComponent(part);
55593
56785
  if (node.children.length > 0) {
56786
+ const snapshot = { ...params };
55594
56787
  const result = matchNodes(node.children, partIndex + 1);
55595
56788
  if (result)
55596
56789
  return result;
56790
+ restoreParams(snapshot);
55597
56791
  }
55598
56792
  if (node.filePath)
55599
56793
  return node;
@@ -55601,10 +56795,14 @@ function matchApiUrl(tree, pathname) {
55601
56795
  continue;
55602
56796
  }
55603
56797
  if (node.path === part) {
56798
+ if (partIndex + 1 >= parts.length && node.filePath)
56799
+ return node;
55604
56800
  if (node.children.length > 0) {
56801
+ const snapshot = { ...params };
55605
56802
  const result = matchNodes(node.children, partIndex + 1);
55606
56803
  if (result)
55607
56804
  return result;
56805
+ restoreParams(snapshot);
55608
56806
  }
55609
56807
  if (node.filePath)
55610
56808
  return node;
@@ -56599,9 +57797,9 @@ var ChunkImports2 = class {
56599
57797
  this.fail(`nameless named-import from '${source}' in ${filePath}`, code);
56600
57798
  return false;
56601
57799
  }
56602
- const existing = group.named.get(imported);
56603
- if (existing && existing.local !== local) {
56604
- this.fail(`'${imported}' from '${source}' bound to both '${existing.local}' and '${local}' in ${filePath}`, code);
57800
+ const existing2 = group.named.get(imported);
57801
+ if (existing2 && existing2.local !== local) {
57802
+ this.fail(`'${imported}' from '${source}' bound to both '${existing2.local}' and '${local}' in ${filePath}`, code);
56605
57803
  return false;
56606
57804
  }
56607
57805
  group.named.set(imported, { kind: "named", local, imported });
@@ -56638,13 +57836,13 @@ var ChunkImports2 = class {
56638
57836
  const lines = [];
56639
57837
  const sources = [...this.bySource.keys()].sort();
56640
57838
  for (const src2 of sources) {
56641
- const g4 = this.bySource.get(src2);
57839
+ const g5 = this.bySource.get(src2);
56642
57840
  const parts = [];
56643
- if (g4.default)
56644
- parts.push(`import ${g4.default.local} from ${JSON.stringify(src2)}`);
56645
- if (g4.namespace)
56646
- parts.push(`import * as ${g4.namespace.local} from ${JSON.stringify(src2)}`);
56647
- const named = [...g4.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
57841
+ if (g5.default)
57842
+ parts.push(`import ${g5.default.local} from ${JSON.stringify(src2)}`);
57843
+ if (g5.namespace)
57844
+ parts.push(`import * as ${g5.namespace.local} from ${JSON.stringify(src2)}`);
57845
+ const named = [...g5.named.values()].sort((a, b) => a.imported < b.imported ? -1 : 1);
56648
57846
  if (named.length > 0) {
56649
57847
  const specs = named.map((sp) => sp.imported === sp.local ? sp.local : `${sp.imported} as ${sp.local}`).join(", ");
56650
57848
  parts.push(`import { ${specs} } from ${JSON.stringify(src2)}`);
@@ -57367,10 +58565,19 @@ async function buildTreeShakenRuntimeNow2(runtimeDir, usedNames) {
57367
58565
  const missing = unique.filter((n) => !available.has(n));
57368
58566
  if (missing.length > 0) {
57369
58567
  console.error(`vesk: runtime names not exported \u2014 ${missing.join(", ")}; falling back to full runtime`);
58568
+ const full = await bundleRuntimeNames2(runtimeDir, [...available]);
58569
+ if (full)
58570
+ return full;
57370
58571
  return buildRuntimeCode2(runtimeDir);
57371
58572
  }
58573
+ return await bundleRuntimeNames2(runtimeDir, unique, true) ?? buildRuntimeCode2(runtimeDir);
58574
+ }
58575
+ async function bundleRuntimeNames2(runtimeDir, names, strict = false) {
58576
+ if (names.length === 0)
58577
+ return null;
57372
58578
  const entry = runtimeTreeShakeEntry2();
57373
58579
  const indexClient = esbuildPath2(join20(runtimeDir, "index-client.js"));
58580
+ const unique = [...new Set(names)];
57374
58581
  try {
57375
58582
  try {
57376
58583
  mkdirSync12(dirname18(entry), { recursive: true });
@@ -57407,8 +58614,9 @@ const { ${unique.join(", ")} } = __veskRuntime;
57407
58614
  export { ${unique.join(", ")} };
57408
58615
  `;
57409
58616
  } catch (e) {
57410
- console.error("vesk: runtime tree-shake failed, falling back to full runtime:", e.message);
57411
- return buildRuntimeCode2(runtimeDir);
58617
+ if (strict)
58618
+ console.error("vesk: runtime tree-shake failed, falling back to full runtime:", e.message);
58619
+ return null;
57412
58620
  } finally {
57413
58621
  try {
57414
58622
  unlinkSync4(entry);
@@ -57853,9 +59061,9 @@ function getPluginRecords2(appDir, veskDir, configPluginNames) {
57853
59061
  }
57854
59062
  function setPluginActive2(veskDir, name, active) {
57855
59063
  const state = readPluginState2(veskDir);
57856
- const existing = state.plugins.find((p) => eqIgnoreCase2(p.name, name));
57857
- if (existing) {
57858
- existing.active = active;
59064
+ const existing2 = state.plugins.find((p) => eqIgnoreCase2(p.name, name));
59065
+ if (existing2) {
59066
+ existing2.active = active;
57859
59067
  } else {
57860
59068
  state.plugins.push({ name, package: name, active });
57861
59069
  }
@@ -57942,11 +59150,11 @@ async function installPlugin2(appDir, veskDir, pkg) {
57942
59150
  }
57943
59151
  const state = readPluginState2(veskDir);
57944
59152
  const name = probe.packageJson?.name || pkg;
57945
- const existing = state.plugins.find((p) => eqIgnoreCase2(p.package, pkg) || eqIgnoreCase2(p.name, name));
57946
- if (existing) {
57947
- existing.package = pkg;
57948
- existing.name = name;
57949
- existing.active = true;
59153
+ const existing2 = state.plugins.find((p) => eqIgnoreCase2(p.package, pkg) || eqIgnoreCase2(p.name, name));
59154
+ if (existing2) {
59155
+ existing2.package = pkg;
59156
+ existing2.name = name;
59157
+ existing2.active = true;
57950
59158
  } else {
57951
59159
  state.plugins.push({ name, package: pkg, active: true });
57952
59160
  }
@@ -57978,10 +59186,10 @@ async function updatePlugin2(appDir, veskDir, pkg) {
57978
59186
  const probe = resolvePackage2(appDir, pkg);
57979
59187
  const state = readPluginState2(veskDir);
57980
59188
  const name = probe.packageJson?.name || pkg;
57981
- const existing = state.plugins.find((p) => eqIgnoreCase2(p.package, pkg) || eqIgnoreCase2(p.name, name));
57982
- if (existing) {
57983
- existing.package = pkg;
57984
- existing.name = name;
59189
+ const existing2 = state.plugins.find((p) => eqIgnoreCase2(p.package, pkg) || eqIgnoreCase2(p.name, name));
59190
+ if (existing2) {
59191
+ existing2.package = pkg;
59192
+ existing2.name = name;
57985
59193
  } else {
57986
59194
  state.plugins.push({ name, package: pkg, active: true });
57987
59195
  }
@@ -57990,7 +59198,7 @@ async function updatePlugin2(appDir, veskDir, pkg) {
57990
59198
  name,
57991
59199
  pkg,
57992
59200
  source: "state",
57993
- activeRaw: existing ? existing.active : true,
59201
+ activeRaw: existing2 ? existing2.active : true,
57994
59202
  error: null
57995
59203
  }, appDir);
57996
59204
  }
@@ -60325,8 +61533,8 @@ function loadAgenticConfig(projectDir) {
60325
61533
  }
60326
61534
  function saveAgenticConfig(projectDir, patch) {
60327
61535
  const p = configPath(projectDir);
60328
- const current2 = loadAgenticConfig(projectDir);
60329
- const next = { ...DEFAULT_CONFIG, ...current2, ...patch };
61536
+ const current3 = loadAgenticConfig(projectDir);
61537
+ const next = { ...DEFAULT_CONFIG, ...current3, ...patch };
60330
61538
  const toWrite = { provider: next.provider, model: next.model, mode: next.mode, maxSteps: next.maxSteps };
60331
61539
  if (next.baseUrl)
60332
61540
  toWrite.baseUrl = next.baseUrl;
@@ -62066,11 +63274,11 @@ function createVeskTools(deps) {
62066
63274
  const contained = resolveWithin3(projectDir, info.path.slice(projectDir.length + 1));
62067
63275
  if (!contained)
62068
63276
  return jsonError("path escapes project root");
62069
- const current2 = readFileSync32(info.path, "utf-8");
62070
- const patched = applySimpleConfigToggle(current2, key, a.value);
63277
+ const current3 = readFileSync32(info.path, "utf-8");
63278
+ const patched = applySimpleConfigToggle(current3, key, a.value);
62071
63279
  if (patched === null)
62072
63280
  return jsonError("could not safely edit the config object; use the source editor");
62073
- if (patched === current2)
63281
+ if (patched === current3)
62074
63282
  return jsonOk({ ok: true, path: info.path, source: patched, unchanged: true });
62075
63283
  writeFileSync18(info.path, patched, "utf-8");
62076
63284
  return jsonOk({ ok: true, path: info.path, source: patched });
@@ -62200,11 +63408,11 @@ function createVeskTools(deps) {
62200
63408
  const at2 = pkg.lastIndexOf("@");
62201
63409
  if (at2 > 0)
62202
63410
  name = pkg.slice(0, at2);
62203
- const existing = state.plugins.find((p) => eqIgnoreCase3(p.package, pkg) || eqIgnoreCase3(p.package, name) || eqIgnoreCase3(p.name, name));
62204
- if (existing) {
62205
- existing.package = pkg;
62206
- existing.name = name;
62207
- existing.active = true;
63411
+ const existing2 = state.plugins.find((p) => eqIgnoreCase3(p.package, pkg) || eqIgnoreCase3(p.package, name) || eqIgnoreCase3(p.name, name));
63412
+ if (existing2) {
63413
+ existing2.package = pkg;
63414
+ existing2.name = name;
63415
+ existing2.active = true;
62208
63416
  } else {
62209
63417
  state.plugins.push({ name, package: pkg, active: true });
62210
63418
  }
@@ -62265,9 +63473,9 @@ function createVeskTools(deps) {
62265
63473
  if (!name)
62266
63474
  return jsonError('missing "name" in body');
62267
63475
  const state = readPluginState3(veskDir);
62268
- const existing = state.plugins.find((p) => eqIgnoreCase3(p.name, name) || eqIgnoreCase3(p.package, name));
62269
- if (existing) {
62270
- existing.active = true;
63476
+ const existing2 = state.plugins.find((p) => eqIgnoreCase3(p.name, name) || eqIgnoreCase3(p.package, name));
63477
+ if (existing2) {
63478
+ existing2.active = true;
62271
63479
  } else {
62272
63480
  state.plugins.push({ name, package: name, active: true });
62273
63481
  }
@@ -62297,9 +63505,9 @@ function createVeskTools(deps) {
62297
63505
  if (!name)
62298
63506
  return jsonError('missing "name" in body');
62299
63507
  const state = readPluginState3(veskDir);
62300
- const existing = state.plugins.find((p) => eqIgnoreCase3(p.name, name) || eqIgnoreCase3(p.package, name));
62301
- if (existing) {
62302
- existing.active = false;
63508
+ const existing2 = state.plugins.find((p) => eqIgnoreCase3(p.name, name) || eqIgnoreCase3(p.package, name));
63509
+ if (existing2) {
63510
+ existing2.active = false;
62303
63511
  } else {
62304
63512
  state.plugins.push({ name, package: name, active: false });
62305
63513
  }
@@ -62374,8 +63582,8 @@ function createVeskTools(deps) {
62374
63582
  return jsonError("invalid checkpointId");
62375
63583
  }
62376
63584
  try {
62377
- const existing = getCheckpoint(projectDir, checkpointId);
62378
- if (existing) {
63585
+ const existing2 = getCheckpoint(projectDir, checkpointId);
63586
+ if (existing2) {
62379
63587
  const rolled = rollback(projectDir, checkpointId);
62380
63588
  if (rolled)
62381
63589
  return jsonOk({ ok: true, checkpointId, checkpoint: rolled, rolledBack: true });
@@ -63310,10 +64518,10 @@ function parseCookies3(str3) {
63310
64518
  // ../runtime/dist/action.js
63311
64519
  var registryKey2 = "__vesk_actions";
63312
64520
  function getActionRegistry2() {
63313
- const g4 = globalThis;
63314
- if (!g4[registryKey2])
63315
- g4[registryKey2] = {};
63316
- return g4[registryKey2];
64521
+ const g5 = globalThis;
64522
+ if (!g5[registryKey2])
64523
+ g5[registryKey2] = {};
64524
+ return g5[registryKey2];
63317
64525
  }
63318
64526
  function getAction2(id) {
63319
64527
  return getActionRegistry2()[id] || null;
@@ -63969,9 +65177,9 @@ function storeDataScript(payload) {
63969
65177
  return "/_vesk/ssr-data.js?t=" + token;
63970
65178
  }
63971
65179
  function currentSsrData() {
63972
- const g4 = globalThis;
63973
- const token = g4.__vsk_ssr_token;
63974
- const slot = (token ? g4[`__vsk_ssr_data_${token}`] : void 0) || {};
65180
+ const g5 = globalThis;
65181
+ const token = g5.__vsk_ssr_token;
65182
+ const slot = (token ? g5[`__vsk_ssr_data_${token}`] : void 0) || {};
63975
65183
  return { ...ssrSink3.snapshot() || {}, ...slot };
63976
65184
  }
63977
65185
  function countPages(nodes) {
@@ -64064,9 +65272,9 @@ async function startDevServer(port, projectDir, config, host) {
64064
65272
  }
64065
65273
  }
64066
65274
  function eventsStore() {
64067
- const g4 = globalThis;
64068
- if (!g4.__vesk_server_ctx) g4.__vesk_server_ctx = {};
64069
- return g4.__vesk_server_ctx;
65275
+ const g5 = globalThis;
65276
+ if (!g5.__vesk_server_ctx) g5.__vesk_server_ctx = {};
65277
+ return g5.__vesk_server_ctx;
64070
65278
  }
64071
65279
  function makeEventCtx(overrides) {
64072
65280
  const store = eventsStore();
@@ -64362,9 +65570,9 @@ async function startDevServer(port, projectDir, config, host) {
64362
65570
  function updateSourceMapping() {
64363
65571
  sourceToComponents.clear();
64364
65572
  for (const [compName, sourcePath2] of collectSources(routeTree)) {
64365
- const existing = sourceToComponents.get(sourcePath2) || [];
64366
- existing.push(compName);
64367
- sourceToComponents.set(sourcePath2, existing);
65573
+ const existing2 = sourceToComponents.get(sourcePath2) || [];
65574
+ existing2.push(compName);
65575
+ sourceToComponents.set(sourcePath2, existing2);
64368
65576
  }
64369
65577
  }
64370
65578
  updateSourceMapping();
@@ -64564,12 +65772,12 @@ async function startDevServer(port, projectDir, config, host) {
64564
65772
  debounceTimer = setTimeout(async () => {
64565
65773
  const t0 = Date.now();
64566
65774
  try {
64567
- const current2 = fileExists ? readFileSync38(fullPath, "utf-8") : null;
64568
- if (eventType !== "rename" && current2 !== null && lastSeenContent.get(fullPath) === current2) {
65775
+ const current3 = fileExists ? readFileSync38(fullPath, "utf-8") : null;
65776
+ if (eventType !== "rename" && current3 !== null && lastSeenContent.get(fullPath) === current3) {
64569
65777
  LOG.info(`skipped unchanged (${filename})`);
64570
65778
  return;
64571
65779
  }
64572
- lastSeenContent.set(fullPath, current2);
65780
+ lastSeenContent.set(fullPath, current3);
64573
65781
  if (typeof globalThis.__vesk_broadcastHmr === "function") {
64574
65782
  globalThis.__vesk_broadcastHmr({ type: "compiling" });
64575
65783
  }
@@ -64593,8 +65801,8 @@ async function startDevServer(port, projectDir, config, host) {
64593
65801
  if (treeChanged || isOutsideApp || fileDeleted) {
64594
65802
  await buildClientBundle();
64595
65803
  await bundleRuntime2();
64596
- } else if (fileExists && current2 !== null) {
64597
- let source = current2;
65804
+ } else if (fileExists && current3 !== null) {
65805
+ let source = current3;
64598
65806
  if (/content=["'][^"']*\.md["']/i.test(source)) {
64599
65807
  source = inlineMdContentAttrs2(source, dirname26(fullPath), guessProjectRoots2(appDirPath));
64600
65808
  }
@@ -65592,8 +66800,10 @@ __export(index_server_exports2, {
65592
66800
  createContext: () => createContext,
65593
66801
  createFileRouter: () => createFileRouter,
65594
66802
  createLocals: () => createLocals,
66803
+ createPathStore: () => createPathStore,
65595
66804
  createResource: () => createResource,
65596
66805
  createRouter: () => createRouter,
66806
+ createStore: () => createStore,
65597
66807
  create_component_ctx: () => create_component_ctx,
65598
66808
  create_try_block: () => create_try_block,
65599
66809
  custom: () => custom,
@@ -65716,6 +66926,8 @@ init_loading_indicator();
65716
66926
  init_action();
65717
66927
  init_metadata();
65718
66928
  init_nested_update();
66929
+ init_store();
66930
+ init_path_store();
65719
66931
 
65720
66932
  // src/index.ts
65721
66933
  var __filename2 = fileURLToPath9(import.meta.url);