rosetack 0.1.3 → 0.1.5

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.
@@ -1,5 +1,6 @@
1
1
  // src/runtime/index.ts
2
2
  var currentEffect = null;
3
+ var trackingDeps = null;
3
4
  var signalMap = globalThis.__rosetack_signalMap ?? /* @__PURE__ */ new Map();
4
5
  globalThis.__rosetack_signalMap = signalMap;
5
6
  function entry(key, initial) {
@@ -11,22 +12,77 @@ function state(key, initial) {
11
12
  ownerKeys()?.add(key);
12
13
  const e = entry(key, initial);
13
14
  const getter = () => {
14
- if (currentEffect) e.subs.add(currentEffect);
15
+ if (currentEffect) {
16
+ e.subs.add(currentEffect);
17
+ if (trackingDeps) trackingDeps.add(e);
18
+ }
15
19
  return e.value;
16
20
  };
17
21
  const setter = (v) => {
18
- e.value = v;
22
+ const next = typeof v === "function" ? v(e.value) : v;
23
+ e.value = next;
24
+ const prevEffect = currentEffect;
25
+ const prevTracking = trackingDeps;
26
+ currentEffect = null;
27
+ trackingDeps = null;
19
28
  e.subs.forEach((fn) => fn());
29
+ currentEffect = prevEffect;
30
+ trackingDeps = prevTracking;
31
+ if (persistedKeys.has(key)) writeStorage(key, next);
20
32
  };
21
33
  return [getter, setter];
22
34
  }
23
35
  function hasState(key) {
24
36
  return signalMap.has(key);
25
37
  }
38
+ var seededKeys = /* @__PURE__ */ new Set();
39
+ function isSeeded(key) {
40
+ return seededKeys.has(key);
41
+ }
42
+ function markSeeded(key) {
43
+ seededKeys.add(key);
44
+ }
26
45
  function setState(key, value) {
27
46
  const e = entry(key, value);
28
47
  e.value = value;
48
+ const prevEffect = currentEffect;
49
+ const prevTracking = trackingDeps;
50
+ currentEffect = null;
51
+ trackingDeps = null;
29
52
  e.subs.forEach((fn) => fn());
53
+ currentEffect = prevEffect;
54
+ trackingDeps = prevTracking;
55
+ if (persistedKeys.has(key)) writeStorage(key, value);
56
+ }
57
+ var persistedKeys = /* @__PURE__ */ new Set();
58
+ function writeStorage(key, v) {
59
+ try {
60
+ globalThis.localStorage?.setItem("rosetack:" + key, JSON.stringify(v));
61
+ } catch {
62
+ }
63
+ }
64
+ function persistState(key, initial) {
65
+ persistedKeys.add(key);
66
+ let seeded = initial;
67
+ let hasStored = false;
68
+ try {
69
+ const raw = globalThis.localStorage?.getItem("rosetack:" + key);
70
+ if (raw != null) {
71
+ seeded = JSON.parse(raw);
72
+ hasStored = true;
73
+ }
74
+ } catch {
75
+ }
76
+ const [get, set] = state(key, seeded);
77
+ if (hasStored) set(seeded);
78
+ return [get, set];
79
+ }
80
+ var lastBoundaryError = null;
81
+ function $setBoundaryError(e) {
82
+ lastBoundaryError = e instanceof Error ? e : new Error(String(e));
83
+ }
84
+ function $boundaryError() {
85
+ return lastBoundaryError;
30
86
  }
31
87
  var cleanups = /* @__PURE__ */ new Set();
32
88
  var fxOwner = null;
@@ -64,7 +120,7 @@ function resetContainerFx(container) {
64
120
  keys.forEach((k) => signalMap.delete(k));
65
121
  keysByOwner.delete(container);
66
122
  }
67
- dataCache.clear();
123
+ renderMaps().data.clear();
68
124
  pendingDeltas.clear();
69
125
  }
70
126
  function effect(fn) {
@@ -85,6 +141,61 @@ function effect(fn) {
85
141
  fxSet().add(cleanup);
86
142
  return cleanup;
87
143
  }
144
+ function $effect(fn) {
145
+ if (typeof document === "undefined") return () => {
146
+ };
147
+ const deps = /* @__PURE__ */ new Set();
148
+ let cleanup;
149
+ let scheduled = false;
150
+ let disposed = false;
151
+ const detach = () => {
152
+ deps.forEach((e) => e.subs.delete(wrapped));
153
+ deps.clear();
154
+ };
155
+ const run = () => {
156
+ if (disposed) return;
157
+ scheduled = true;
158
+ detach();
159
+ if (typeof cleanup === "function") {
160
+ try {
161
+ cleanup();
162
+ } catch {
163
+ }
164
+ }
165
+ const prevEffect = currentEffect;
166
+ const prevTracking = trackingDeps;
167
+ currentEffect = wrapped;
168
+ trackingDeps = deps;
169
+ try {
170
+ const ret = fn();
171
+ cleanup = typeof ret === "function" ? ret : void 0;
172
+ } catch {
173
+ }
174
+ currentEffect = prevEffect;
175
+ trackingDeps = prevTracking;
176
+ scheduled = false;
177
+ };
178
+ const wrapped = () => {
179
+ if (scheduled || disposed) return;
180
+ scheduled = true;
181
+ queueMicrotask(run);
182
+ };
183
+ const owner = fxSet();
184
+ const dispose = () => {
185
+ disposed = true;
186
+ detach();
187
+ if (typeof cleanup === "function") {
188
+ try {
189
+ cleanup();
190
+ } catch {
191
+ }
192
+ }
193
+ owner.delete(dispose);
194
+ };
195
+ owner.add(dispose);
196
+ queueMicrotask(run);
197
+ return dispose;
198
+ }
88
199
  var ESC_MAP = {
89
200
  "&": "&",
90
201
  "<": "&lt;",
@@ -99,9 +210,26 @@ function textMark(closes, fn, pair, arg) {
99
210
  const i = closes.push(fn) - 1;
100
211
  return `<!--\u27E6m:${i}\u27E7-->` + esc(fn(arg)) + (pair ? `<!--\u27E6/m:${i}\u27E7-->` : "");
101
212
  }
213
+ function attrValueString(name, v) {
214
+ if (v == null) return "";
215
+ if (typeof v === "object") {
216
+ if (name === "class") {
217
+ return Object.entries(v).filter(([, x]) => x).map(([k]) => k).join(" ");
218
+ }
219
+ if (name === "style") {
220
+ return Object.entries(v).filter(([, x]) => x != null && x !== false && x !== "").map(([k, x]) => `${k}: ${x}`).join("; ");
221
+ }
222
+ return JSON.stringify(v);
223
+ }
224
+ return String(v);
225
+ }
102
226
  function attrMark(closes, fn, name, arg) {
103
227
  const i = closes.push(fn) - 1;
104
- return `${name}="${esc(fn(arg))}" data-b="${i}:${name}"`;
228
+ return `${name}="${esc(attrValueString(name, fn(arg)))}" data-b${i}="${name}"`;
229
+ }
230
+ function boolAttrMark(closes, fn, name, arg) {
231
+ const i = closes.push(fn) - 1;
232
+ return (fn(arg) ? ` ${name}=""` : "") + ` data-b${i}="!${name}"`;
105
233
  }
106
234
  function ifMark(closes, cond, fn, scope) {
107
235
  let snap = null;
@@ -118,9 +246,12 @@ function ifMark(closes, cond, fn, scope) {
118
246
  const r = closes[i]();
119
247
  return `<!--\u27E6i:${i}\u27E7-->` + (r ? r.html : "") + `<!--\u27E6/i:${i}\u27E7-->`;
120
248
  }
121
- function eachMark(closes, items, fn) {
122
- const i = closes.push(() => items().map((v) => {
123
- return { html: String(fn(v, closes)), closes, scope: v };
249
+ var EACH_REUSE_FORBID = /data-(?:on|use|bind-this|transition|animate)|data-rosetack-c|data-rv-island/;
250
+ var EACH_HTML_NORM = (h) => h.replace(/\u27e6\/?[a-z]+:\d+\u27e7/g, "").replace(/data-b\d+/g, "data-b");
251
+ var normHtml = (row) => row.norm ??= EACH_HTML_NORM(row.html);
252
+ function eachMark(closes, items, fn, key) {
253
+ const i = closes.push(() => items().map((v, vi) => {
254
+ return { html: String(fn(v, closes, vi)), closes, scope: v, keyed: !!key, key: key ? String(key(v, vi)) : void 0 };
124
255
  })) - 1;
125
256
  let h = `<!--\u27E6l:${i}\u27E7-->`;
126
257
  for (const r of closes[i]()) h += r.html;
@@ -146,6 +277,7 @@ function slotBlockMark(closes, hit) {
146
277
  var MARK_RE = /^\u27e6([milh]):(\d+)\u27e7$/;
147
278
  var END_RE = /^\u27e6\/([milh]):(\d+)\u27e7$/;
148
279
  var wired = /* @__PURE__ */ new WeakSet();
280
+ var pendingIslandObservers = /* @__PURE__ */ new Set();
149
281
  function tpl(html) {
150
282
  const t = document.createElement("template");
151
283
  t.innerHTML = html;
@@ -153,6 +285,13 @@ function tpl(html) {
153
285
  }
154
286
  var HEAD_ATTR = "data-rosetack-head";
155
287
  var handlers = globalThis.__rosetack_handlers ??= {};
288
+ var actionDispatch = null;
289
+ function setActionDispatcher(fn) {
290
+ actionDispatch = fn;
291
+ }
292
+ var directBound = /* @__PURE__ */ new WeakMap();
293
+ var directives = globalThis.__rosetack_directives ??= {};
294
+ var actionRecords = /* @__PURE__ */ new WeakMap();
156
295
  function applyHead(html) {
157
296
  const seen = /* @__PURE__ */ new Set();
158
297
  const positional = /* @__PURE__ */ new Map();
@@ -188,6 +327,36 @@ function applyHead(html) {
188
327
  function clearHead() {
189
328
  document.head.querySelectorAll(`[${HEAD_ATTR}]`).forEach((el) => el.remove());
190
329
  }
330
+ var TRANSITION_POSES = {
331
+ fade: { opacity: "0" },
332
+ slide: { transform: "translateY(20px)", opacity: "0" },
333
+ fly: { transform: "translateX(-30px) rotate(-5deg)", opacity: "0" },
334
+ zoom: { transform: "scale(0.8)", opacity: "0" },
335
+ "slide-up": { transform: "translateY(30px)", opacity: "0" },
336
+ "slide-down": { transform: "translateY(-30px)", opacity: "0" },
337
+ "slide-left": { transform: "translateX(30px)", opacity: "0" },
338
+ "slide-right": { transform: "translateX(-30px)", opacity: "0" },
339
+ scale: { transform: "scale(0.7)", opacity: "0" },
340
+ spin: { transform: "rotate(-90deg)", opacity: "0" },
341
+ blur: { filter: "blur(8px)", opacity: "0" },
342
+ stagger: { transform: "translateY(10px)", opacity: "0" }
343
+ };
344
+ function parseTransitionParams(pstr) {
345
+ const out = {};
346
+ if (!pstr) return out;
347
+ const trimmed = pstr.trim();
348
+ if (/^\d+$/.test(trimmed)) {
349
+ out.duration = Number(trimmed);
350
+ return out;
351
+ }
352
+ const dM = /duration\s*:\s*(\d+)/.exec(pstr);
353
+ if (dM) out.duration = Number(dM[1]);
354
+ const dlM = /delay\s*:\s*(\d+)/.exec(pstr);
355
+ if (dlM) out.delay = Number(dlM[1]);
356
+ const eM = /easing\s*:\s*(['"])(.*?)\1/.exec(pstr);
357
+ if (eM) out.easing = eM[2];
358
+ return out;
359
+ }
191
360
  function wire(root, closes, scope) {
192
361
  let holder = root;
193
362
  if (root.nodeType === 11) {
@@ -238,12 +407,39 @@ function wire(root, closes, scope) {
238
407
  }
239
408
  const headBlocks = [];
240
409
  const ownsHead = root === document.getElementById("app");
410
+ let islandSkip = false;
411
+ if (ownsHead) {
412
+ const islandEls = Array.from(
413
+ holder.querySelectorAll("[data-rv-island]")
414
+ ).filter((el) => !(el.parentElement && el.parentElement.closest("[data-rv-island]")));
415
+ islandSkip = islandEls.length > 0;
416
+ for (const isl of islandEls) {
417
+ const fire = () => wire(isl, closes, scope);
418
+ const mode = isl.getAttribute("data-rv-island-hydrate");
419
+ if (mode === "visible" && typeof IntersectionObserver !== "undefined") {
420
+ const io = new IntersectionObserver((entries) => {
421
+ if (entries.some((en) => en.isIntersecting)) {
422
+ io.disconnect();
423
+ pendingIslandObservers.delete(io);
424
+ fire();
425
+ }
426
+ });
427
+ io.observe(isl);
428
+ pendingIslandObservers.add(io);
429
+ } else if (mode === "idle" && typeof globalThis.requestIdleCallback === "function") {
430
+ globalThis.requestIdleCallback(() => fire());
431
+ } else {
432
+ fire();
433
+ }
434
+ }
435
+ }
241
436
  for (const c of comments) {
242
437
  if (nested.has(c) || wired.has(c) || !c.parentNode) continue;
243
438
  const m = (c.nodeValue ?? "").match(MARK_RE);
244
439
  if (!m) continue;
245
440
  const kind = m[1];
246
441
  const idx = +m[2];
442
+ if (islandSkip && kind !== "h" && c.parentNode.closest?.("[data-rv-island]")) continue;
247
443
  if (kind === "h" && !ownsHead) continue;
248
444
  wired.add(c);
249
445
  if (kind === "h") {
@@ -322,13 +518,61 @@ function wire(root, closes, scope) {
322
518
  st.__disp = void 0;
323
519
  }
324
520
  const items = closes[idx](scope);
521
+ const parent = start.parentNode;
522
+ const keyed = items.length > 0 && items.every((r) => r.keyed);
523
+ if (keyed) {
524
+ const prev = st.__kmap ?? /* @__PURE__ */ new Map();
525
+ const counts = /* @__PURE__ */ new Map();
526
+ for (const r of items) counts.set(r.key, (counts.get(r.key) ?? 0) + 1);
527
+ const keep = /* @__PURE__ */ new Set();
528
+ const nextMap = /* @__PURE__ */ new Map();
529
+ const used = /* @__PURE__ */ new Set();
530
+ const decisions = [];
531
+ for (const r of items) {
532
+ const k = r.key;
533
+ let keepRow;
534
+ if (counts.get(k) === 1 && !used.has(k)) {
535
+ const cand = prev.get(k);
536
+ if (cand && normHtml(cand) === normHtml(r) && !EACH_REUSE_FORBID.test(r.html)) {
537
+ keepRow = cand;
538
+ used.add(k);
539
+ }
540
+ }
541
+ decisions.push({ row: r, keepRow });
542
+ if (keepRow) for (const nd of keepRow.nodes ?? []) keep.add(nd);
543
+ }
544
+ let n2 = start.nextSibling;
545
+ while (n2 && n2 !== end) {
546
+ const nx = n2.nextSibling;
547
+ if (!keep.has(n2)) n2.remove();
548
+ n2 = nx;
549
+ }
550
+ const disps2 = [];
551
+ for (const d of decisions) {
552
+ if (d.keepRow) {
553
+ disps2.push(d.keepRow.disp);
554
+ nextMap.set(d.row.key, d.keepRow);
555
+ for (const nd of d.keepRow.nodes ?? []) parent.insertBefore(nd, end);
556
+ } else {
557
+ const frag = tpl(d.row.html);
558
+ const disp = wire(frag, d.row.closes, d.row.scope);
559
+ disps2.push(disp);
560
+ const nodes = Array.from(frag.childNodes);
561
+ for (const nd of nodes) parent.insertBefore(nd, end);
562
+ if (counts.get(d.row.key) === 1) nextMap.set(d.row.key, { ...d.row, nodes, disp });
563
+ }
564
+ }
565
+ st.__kmap = nextMap;
566
+ st.__disp = () => disps2.forEach((d) => d());
567
+ return;
568
+ }
569
+ st.__kmap = void 0;
325
570
  let n = start.nextSibling;
326
571
  while (n && n !== end) {
327
572
  const nx = n.nextSibling;
328
573
  n.remove();
329
574
  n = nx;
330
575
  }
331
- const parent = start.parentNode;
332
576
  const disps = [];
333
577
  for (const r of items) {
334
578
  const frag = tpl(r.html);
@@ -354,17 +598,553 @@ function wire(root, closes, scope) {
354
598
  }
355
599
  } else if (root.nodeType !== 11) clearHead();
356
600
  }
357
- const els = holder.querySelectorAll("[data-b]");
358
- els.forEach((el) => {
359
- const spec = el.getAttribute("data-b");
360
- const sep = spec.indexOf(":");
361
- const idx = +spec.slice(0, sep);
362
- const attr = spec.slice(sep + 1);
363
- el.removeAttribute("data-b");
364
- weff(() => {
365
- el.setAttribute(attr, String(closes[idx](scope)));
366
- });
601
+ const all = holder.querySelectorAll("*");
602
+ all.forEach((el) => {
603
+ if (islandSkip && el.closest("[data-rv-island]")) return;
604
+ for (const an of el.getAttributeNames()) {
605
+ if (!an.startsWith("data-b")) continue;
606
+ const idx = Number(an.slice(6));
607
+ if (!Number.isFinite(idx)) continue;
608
+ const attr = el.getAttribute(an);
609
+ el.removeAttribute(an);
610
+ const effect2 = () => String(closes[idx](scope));
611
+ if (attr === "data-use-param") {
612
+ weff(() => {
613
+ const raw = effect2();
614
+ let p = raw;
615
+ try {
616
+ p = JSON.parse(raw);
617
+ } catch {
618
+ }
619
+ actionRecords.get(el)?.update?.(p);
620
+ });
621
+ continue;
622
+ }
623
+ if (attr === "value") {
624
+ weff(() => {
625
+ const v = effect2();
626
+ const out = v == null ? "" : v;
627
+ const inp = el;
628
+ if (inp.value !== out) inp.value = out;
629
+ });
630
+ } else if (attr === "data-selmulti") {
631
+ weff(() => {
632
+ const vals = effect2().split(",");
633
+ for (const o of Array.from(el.options)) {
634
+ o.selected = vals.includes(o.value);
635
+ }
636
+ });
637
+ } else if (attr.startsWith("!")) {
638
+ const name = attr.slice(1);
639
+ weff(() => {
640
+ const v = closes[idx](scope);
641
+ const live = !(v === false || v == null || v === "" || v === "false" || v === 0);
642
+ const target = el;
643
+ if (target[name] !== live) target[name] = live;
644
+ if (live) el.setAttribute(name, "");
645
+ else el.removeAttribute(name);
646
+ });
647
+ } else {
648
+ weff(() => {
649
+ const out = attrValueString(attr, closes[idx](scope));
650
+ if (el.getAttribute(attr) !== out) el.setAttribute(attr, out);
651
+ });
652
+ }
653
+ }
367
654
  });
655
+ const uses = holder.querySelectorAll("[data-use]");
656
+ uses.forEach((el) => {
657
+ if (islandSkip && el.closest("[data-rv-island]")) return;
658
+ const name = el.getAttribute("data-use");
659
+ const fn = directives[name];
660
+ if (!fn) return;
661
+ const rawParam = el.getAttribute("data-use-param");
662
+ let initial = rawParam ?? void 0;
663
+ if (typeof initial === "string") {
664
+ try {
665
+ initial = JSON.parse(initial);
666
+ } catch {
667
+ }
668
+ }
669
+ const ret = fn(el, initial);
670
+ if (typeof ret === "function") created.push(ret);
671
+ else if (ret && typeof ret === "object") {
672
+ actionRecords.set(el, { update: ret.update, destroy: ret.destroy });
673
+ if (ret.destroy) created.push(ret.destroy);
674
+ }
675
+ });
676
+ const refs = holder.querySelectorAll("[data-bind-this]");
677
+ refs.forEach((el) => {
678
+ if (islandSkip && el.closest("[data-rv-island]")) return;
679
+ const key = el.getAttribute("data-bind-this");
680
+ setState(key, el);
681
+ created.push(() => setState(key, null));
682
+ });
683
+ if (holder.querySelectorAll("[data-transition]").length > 0) {
684
+ const trans = holder.querySelectorAll("[data-transition]");
685
+ trans.forEach((el) => {
686
+ if (islandSkip && el.closest("[data-rv-island]")) return;
687
+ const transAttr = el.getAttribute("data-transition");
688
+ const parts = transAttr.split("|");
689
+ for (const part of parts) {
690
+ const segs = part.split(":");
691
+ const dir = segs[0] === "in" || segs[0] === "out" ? segs[0] : "";
692
+ const name = (dir ? segs[1] : segs[0]) ?? "";
693
+ const pstr = (dir ? segs.slice(2) : segs.slice(1)).join(":");
694
+ const params = parseTransitionParams(pstr);
695
+ const duration = params.duration != null ? Number(params.duration) : 300;
696
+ if (dir === "out") {
697
+ const pose2 = TRANSITION_POSES[name];
698
+ if (pose2) {
699
+ const parent = el.parentElement;
700
+ const idx = parent ? Math.max(0, Array.from(parent.children).indexOf(el)) : 0;
701
+ const vDelay = params.delay != null ? Number(params.delay) : null;
702
+ const delay = name === "stagger" ? vDelay != null ? Math.max(0, vDelay) : idx * (duration / 10) : vDelay != null ? vDelay : 0;
703
+ const easing = params.easing || "ease";
704
+ created.push(() => {
705
+ const parts2 = [pose2.transform ? `transform ${duration}ms ${easing} ${delay}ms` : "", pose2.filter ? `filter ${duration}ms ${easing} ${delay}ms` : "", `opacity ${duration}ms ${easing} ${delay}ms`].filter(Boolean);
706
+ el.style.transition = parts2.join(", ");
707
+ if (pose2.transform) el.style.transform = pose2.transform;
708
+ if (pose2.filter) el.style.filter = pose2.filter;
709
+ el.style.opacity = pose2.opacity;
710
+ setTimeout(() => {
711
+ el.style.transform = "";
712
+ el.style.filter = "";
713
+ el.style.opacity = "";
714
+ el.style.transition = "";
715
+ }, duration + delay);
716
+ });
717
+ } else {
718
+ const custom = globalThis.__rosetackTransitions?.[name];
719
+ if (custom) {
720
+ const ret = custom(el, duration, "out");
721
+ if (typeof ret === "function") created.push(ret);
722
+ }
723
+ }
724
+ continue;
725
+ }
726
+ const exitStart = created.length;
727
+ const pose = TRANSITION_POSES[name];
728
+ if (pose) {
729
+ const parent = el.parentElement;
730
+ const idx = parent ? Math.max(0, Array.from(parent.children).indexOf(el)) : 0;
731
+ const vDelay = params.delay != null ? Number(params.delay) : null;
732
+ const delay = name === "stagger" ? vDelay != null ? Math.max(0, vDelay) : idx * (duration / 10) : vDelay != null ? vDelay : 0;
733
+ const easing = params.easing || "ease";
734
+ const cssParts = [];
735
+ if (pose.transform) cssParts.push(`transform ${duration}ms ${easing} ${delay}ms`);
736
+ if (pose.filter) cssParts.push(`filter ${duration}ms ${easing} ${delay}ms`);
737
+ cssParts.push(`opacity ${duration}ms ${easing} ${delay}ms`);
738
+ const tcss = cssParts.join(", ");
739
+ el.style.opacity = "0";
740
+ if (pose.transform) el.style.transform = pose.transform;
741
+ if (pose.filter) el.style.filter = pose.filter;
742
+ el.style.transition = tcss;
743
+ requestAnimationFrame(() => {
744
+ requestAnimationFrame(() => {
745
+ el.style.transform = "";
746
+ el.style.filter = "";
747
+ el.style.opacity = "1";
748
+ });
749
+ });
750
+ created.push(() => {
751
+ el.style.opacity = "0";
752
+ if (pose.transform) el.style.transform = pose.transform;
753
+ if (pose.filter) el.style.filter = pose.filter;
754
+ setTimeout(() => {
755
+ el.style.opacity = "";
756
+ el.style.transform = "";
757
+ el.style.filter = "";
758
+ el.style.transition = "";
759
+ }, duration + delay);
760
+ });
761
+ } else {
762
+ const custom = globalThis.__rosetackTransitions?.[name];
763
+ if (custom) {
764
+ const ret = custom(el, duration, dir || "both");
765
+ if (typeof ret === "function") created.push(ret);
766
+ }
767
+ }
768
+ if (dir === "in") created.length = exitStart;
769
+ }
770
+ });
771
+ }
772
+ if (holder.querySelectorAll("[data-animate]").length > 0) {
773
+ const anim = holder.querySelectorAll("[data-animate]");
774
+ anim.forEach((el) => {
775
+ if (islandSkip && el.closest("[data-rv-island]")) return;
776
+ const animAttr = el.getAttribute("data-animate");
777
+ const parts = animAttr.split("|");
778
+ for (const part of parts) {
779
+ const [name] = part.split(":");
780
+ const rest = part.slice(name.length + 1);
781
+ const duration = Number((/(\d+)\s*\}?\s*$/.exec(rest) ?? [])[1]) || 300;
782
+ if (name === "flip") {
783
+ const firstRect = el.getBoundingClientRect();
784
+ const firstTop = firstRect.top;
785
+ const firstLeft = firstRect.left;
786
+ requestAnimationFrame(() => {
787
+ requestAnimationFrame(() => {
788
+ const lastRect = el.getBoundingClientRect();
789
+ const deltaTop = lastRect.top - firstTop;
790
+ const deltaLeft = lastRect.left - firstLeft;
791
+ if (Math.abs(deltaTop) < 0.5 && Math.abs(deltaLeft) < 0.5) return;
792
+ el.style.transform = `translate(${-deltaLeft}px, ${-deltaTop}px)`;
793
+ el.style.transition = "none";
794
+ requestAnimationFrame(() => {
795
+ requestAnimationFrame(() => {
796
+ el.style.transition = `transform ${duration}ms ease`;
797
+ el.style.transform = "";
798
+ });
799
+ });
800
+ });
801
+ });
802
+ } else if (name === "pulse") {
803
+ el.style.transform = "scale(1)";
804
+ el.style.transition = `transform ${duration}ms ease`;
805
+ requestAnimationFrame(() => {
806
+ requestAnimationFrame(() => {
807
+ el.style.transform = "scale(1.1)";
808
+ setTimeout(() => {
809
+ el.style.transform = "scale(1)";
810
+ }, duration);
811
+ });
812
+ });
813
+ } else if (name === "bounce") {
814
+ el.style.transform = "translateY(0)";
815
+ el.style.transition = `transform ${duration}ms ease`;
816
+ requestAnimationFrame(() => {
817
+ requestAnimationFrame(() => {
818
+ el.style.transform = "translateY(-15px)";
819
+ setTimeout(() => {
820
+ el.style.transform = "translateY(0)";
821
+ }, duration);
822
+ });
823
+ });
824
+ } else if (name === "shake") {
825
+ el.style.transform = "translateX(0)";
826
+ el.style.transition = `transform ${duration / 4}ms ease-in-out`;
827
+ requestAnimationFrame(() => {
828
+ requestAnimationFrame(() => {
829
+ el.style.transform = "translateX(-8px)";
830
+ setTimeout(() => {
831
+ el.style.transform = "translateX(8px)";
832
+ setTimeout(() => {
833
+ el.style.transform = "translateX(-8px)";
834
+ setTimeout(() => {
835
+ el.style.transform = "translateX(8px)";
836
+ setTimeout(() => {
837
+ el.style.transform = "translateX(0)";
838
+ el.style.transition = "";
839
+ }, duration / 4);
840
+ }, duration / 4);
841
+ }, duration / 4);
842
+ }, duration / 4);
843
+ }, duration / 4);
844
+ });
845
+ } else if (name === "scale") {
846
+ el.style.transform = "scale(0.5)";
847
+ el.style.opacity = "0";
848
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
849
+ requestAnimationFrame(() => {
850
+ requestAnimationFrame(() => {
851
+ el.style.transform = "";
852
+ el.style.opacity = "1";
853
+ });
854
+ });
855
+ created.push(() => {
856
+ el.style.transform = "scale(0.5)";
857
+ el.style.opacity = "0";
858
+ setTimeout(() => {
859
+ el.style.transform = "";
860
+ el.style.opacity = "";
861
+ el.style.transition = "";
862
+ }, duration);
863
+ });
864
+ } else if (name === "rotate") {
865
+ el.style.transform = "rotate(-180deg)";
866
+ el.style.opacity = "0";
867
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
868
+ requestAnimationFrame(() => {
869
+ requestAnimationFrame(() => {
870
+ el.style.transform = "";
871
+ el.style.opacity = "1";
872
+ });
873
+ });
874
+ created.push(() => {
875
+ el.style.transform = "rotate(-180deg)";
876
+ el.style.opacity = "0";
877
+ setTimeout(() => {
878
+ el.style.transform = "";
879
+ el.style.opacity = "";
880
+ el.style.transition = "";
881
+ }, duration);
882
+ });
883
+ } else if (name === "fade-in") {
884
+ el.style.opacity = "0";
885
+ el.style.transition = `opacity ${duration}ms ease`;
886
+ requestAnimationFrame(() => {
887
+ requestAnimationFrame(() => {
888
+ el.style.opacity = "1";
889
+ });
890
+ });
891
+ created.push(() => {
892
+ el.style.opacity = "0";
893
+ setTimeout(() => {
894
+ el.style.opacity = "";
895
+ el.style.transition = "";
896
+ }, duration);
897
+ });
898
+ } else if (name === "fade-out") {
899
+ el.style.opacity = "1";
900
+ el.style.transition = `opacity ${duration}ms ease`;
901
+ requestAnimationFrame(() => {
902
+ requestAnimationFrame(() => {
903
+ el.style.opacity = "0";
904
+ });
905
+ });
906
+ created.push(() => {
907
+ el.style.opacity = "1";
908
+ setTimeout(() => {
909
+ el.style.opacity = "";
910
+ el.style.transition = "";
911
+ }, duration);
912
+ });
913
+ } else if (name === "stagger") {
914
+ const parent = el.parentElement;
915
+ if (parent) {
916
+ const siblings = Array.from(parent.children);
917
+ const index = siblings.indexOf(el);
918
+ const delay = index * (duration / 10);
919
+ el.style.opacity = "0";
920
+ el.style.transform = "translateY(10px)";
921
+ el.style.transition = `opacity ${duration}ms ease ${delay}ms, transform ${duration}ms ease ${delay}ms`;
922
+ requestAnimationFrame(() => {
923
+ requestAnimationFrame(() => {
924
+ el.style.opacity = "1";
925
+ el.style.transform = "";
926
+ });
927
+ });
928
+ created.push(() => {
929
+ el.style.opacity = "0";
930
+ el.style.transform = "translateY(10px)";
931
+ setTimeout(() => {
932
+ el.style.opacity = "";
933
+ el.style.transform = "";
934
+ el.style.transition = "";
935
+ }, duration + delay);
936
+ });
937
+ }
938
+ } else if (name === "zoom-in") {
939
+ el.style.transform = "scale(0)";
940
+ el.style.opacity = "0";
941
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
942
+ requestAnimationFrame(() => {
943
+ requestAnimationFrame(() => {
944
+ el.style.transform = "";
945
+ el.style.opacity = "1";
946
+ });
947
+ });
948
+ created.push(() => {
949
+ el.style.transform = "scale(0)";
950
+ el.style.opacity = "0";
951
+ setTimeout(() => {
952
+ el.style.transform = "";
953
+ el.style.opacity = "";
954
+ el.style.transition = "";
955
+ }, duration);
956
+ });
957
+ } else if (name === "zoom-out") {
958
+ el.style.transform = "scale(1)";
959
+ el.style.opacity = "1";
960
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
961
+ requestAnimationFrame(() => {
962
+ requestAnimationFrame(() => {
963
+ el.style.transform = "scale(0)";
964
+ el.style.opacity = "0";
965
+ });
966
+ });
967
+ created.push(() => {
968
+ el.style.transform = "scale(1)";
969
+ el.style.opacity = "1";
970
+ setTimeout(() => {
971
+ el.style.transform = "";
972
+ el.style.opacity = "";
973
+ el.style.transition = "";
974
+ }, duration);
975
+ });
976
+ } else if (name === "slide-up-fade") {
977
+ el.style.transform = "translateY(30px)";
978
+ el.style.opacity = "0";
979
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
980
+ requestAnimationFrame(() => {
981
+ requestAnimationFrame(() => {
982
+ el.style.transform = "";
983
+ el.style.opacity = "1";
984
+ });
985
+ });
986
+ created.push(() => {
987
+ el.style.transform = "translateY(30px)";
988
+ el.style.opacity = "0";
989
+ setTimeout(() => {
990
+ el.style.transform = "";
991
+ el.style.opacity = "";
992
+ el.style.transition = "";
993
+ }, duration);
994
+ });
995
+ } else if (name === "slide-down-fade") {
996
+ el.style.transform = "translateY(-30px)";
997
+ el.style.opacity = "0";
998
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
999
+ requestAnimationFrame(() => {
1000
+ requestAnimationFrame(() => {
1001
+ el.style.transform = "";
1002
+ el.style.opacity = "1";
1003
+ });
1004
+ });
1005
+ created.push(() => {
1006
+ el.style.transform = "translateY(-30px)";
1007
+ el.style.opacity = "0";
1008
+ setTimeout(() => {
1009
+ el.style.transform = "";
1010
+ el.style.opacity = "";
1011
+ el.style.transition = "";
1012
+ }, duration);
1013
+ });
1014
+ } else if (name === "flip-x") {
1015
+ el.style.transform = "rotateX(90deg)";
1016
+ el.style.opacity = "0";
1017
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
1018
+ requestAnimationFrame(() => {
1019
+ requestAnimationFrame(() => {
1020
+ el.style.transform = "";
1021
+ el.style.opacity = "1";
1022
+ });
1023
+ });
1024
+ created.push(() => {
1025
+ el.style.transform = "rotateX(90deg)";
1026
+ el.style.opacity = "0";
1027
+ setTimeout(() => {
1028
+ el.style.transform = "";
1029
+ el.style.opacity = "";
1030
+ el.style.transition = "";
1031
+ }, duration);
1032
+ });
1033
+ } else if (name === "flip-y") {
1034
+ el.style.transform = "rotateY(90deg)";
1035
+ el.style.opacity = "0";
1036
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
1037
+ requestAnimationFrame(() => {
1038
+ requestAnimationFrame(() => {
1039
+ el.style.transform = "";
1040
+ el.style.opacity = "1";
1041
+ });
1042
+ });
1043
+ created.push(() => {
1044
+ el.style.transform = "rotateY(90deg)";
1045
+ el.style.opacity = "0";
1046
+ setTimeout(() => {
1047
+ el.style.transform = "";
1048
+ el.style.opacity = "";
1049
+ el.style.transition = "";
1050
+ }, duration);
1051
+ });
1052
+ } else if (name === "spin") {
1053
+ el.style.transform = "rotate(-360deg)";
1054
+ el.style.opacity = "0";
1055
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
1056
+ requestAnimationFrame(() => {
1057
+ requestAnimationFrame(() => {
1058
+ el.style.transform = "";
1059
+ el.style.opacity = "1";
1060
+ });
1061
+ });
1062
+ created.push(() => {
1063
+ el.style.transform = "rotate(-360deg)";
1064
+ el.style.opacity = "0";
1065
+ setTimeout(() => {
1066
+ el.style.transform = "";
1067
+ el.style.opacity = "";
1068
+ el.style.transition = "";
1069
+ }, duration);
1070
+ });
1071
+ } else if (name === "pop") {
1072
+ el.style.transform = "scale(0.3)";
1073
+ el.style.opacity = "0";
1074
+ el.style.transition = `transform ${duration}ms ease, opacity ${duration}ms ease`;
1075
+ requestAnimationFrame(() => {
1076
+ requestAnimationFrame(() => {
1077
+ el.style.transform = "scale(1.1)";
1078
+ setTimeout(() => {
1079
+ el.style.transform = "";
1080
+ }, duration / 3);
1081
+ });
1082
+ });
1083
+ created.push(() => {
1084
+ el.style.transform = "scale(0.3)";
1085
+ el.style.opacity = "0";
1086
+ setTimeout(() => {
1087
+ el.style.transform = "";
1088
+ el.style.opacity = "";
1089
+ el.style.transition = "";
1090
+ }, duration);
1091
+ });
1092
+ } else if (name === "blink") {
1093
+ el.style.opacity = "0";
1094
+ el.style.transition = `opacity ${duration}ms ease`;
1095
+ requestAnimationFrame(() => {
1096
+ requestAnimationFrame(() => {
1097
+ el.style.opacity = "1";
1098
+ });
1099
+ });
1100
+ created.push(() => {
1101
+ el.style.opacity = "0";
1102
+ setTimeout(() => {
1103
+ el.style.opacity = "";
1104
+ el.style.transition = "";
1105
+ }, duration);
1106
+ });
1107
+ }
1108
+ }
1109
+ });
1110
+ }
1111
+ const DELEGATED_SET = /* @__PURE__ */ new Set(["click", "input", "change", "submit"]);
1112
+ const evRoot = holder;
1113
+ const evTargets = [evRoot, ...Array.from(evRoot.querySelectorAll("*"))];
1114
+ for (const el of evTargets) {
1115
+ if (!el.getAttributeNames) continue;
1116
+ if (islandSkip && el.closest && el.closest("[data-rv-island]")) continue;
1117
+ for (const an of el.getAttributeNames()) {
1118
+ const mm = /^data-on(w|d)?-(.+)$/.exec(an);
1119
+ if (!mm) continue;
1120
+ const ev = mm[2];
1121
+ if (!mm[1] && DELEGATED_SET.has(ev)) continue;
1122
+ const g = globalThis;
1123
+ const win = g.window ?? g.document?.defaultView;
1124
+ const target = mm[1] === "w" ? win : mm[1] === "d" ? g.document : el;
1125
+ if (!target) continue;
1126
+ let seen = directBound.get(el);
1127
+ if (!seen) directBound.set(el, seen = /* @__PURE__ */ new Set());
1128
+ if (seen.has(ev)) continue;
1129
+ seen.add(ev);
1130
+ const spec = el.getAttribute(an);
1131
+ const listener = (e) => {
1132
+ if (!el.hasAttribute(an)) return;
1133
+ if (spec.startsWith("$action:")) {
1134
+ if (actionDispatch) actionDispatch(spec.slice("$action:".length), e);
1135
+ return;
1136
+ }
1137
+ const h = handlers[spec];
1138
+ if (h) h(e);
1139
+ };
1140
+ target.addEventListener(ev, listener, ev === "scroll" ? { passive: true } : void 0);
1141
+ created.push(() => {
1142
+ target.removeEventListener(ev, listener);
1143
+ const s = directBound.get(el);
1144
+ if (s) s.delete(ev);
1145
+ });
1146
+ }
1147
+ }
368
1148
  if (holder !== root) {
369
1149
  while (holder.firstChild) root.appendChild(holder.firstChild);
370
1150
  }
@@ -373,21 +1153,37 @@ function wire(root, closes, scope) {
373
1153
  function resetEffects() {
374
1154
  cleanups.forEach((fn) => fn());
375
1155
  cleanups.clear();
1156
+ pendingIslandObservers.forEach((io) => io.disconnect());
1157
+ pendingIslandObservers.clear();
376
1158
  }
377
- var dataCache = /* @__PURE__ */ new Map();
378
1159
  function $data(fn) {
1160
+ const cache = renderMaps().data;
379
1161
  const key = fn.toString();
380
- let p = dataCache.get(key);
1162
+ let p = cache.get(key);
381
1163
  if (!p) {
382
1164
  p = Promise.resolve(fn());
383
- dataCache.set(key, p);
1165
+ cache.set(key, p);
384
1166
  }
385
1167
  return p;
386
1168
  }
387
1169
  function clearRequestState() {
388
1170
  signalMap.clear();
389
- dataCache.clear();
1171
+ renderMaps().data.clear();
390
1172
  pendingDeltas.clear();
1173
+ seededKeys = /* @__PURE__ */ new Set();
1174
+ }
1175
+ async function isolateRender(fn) {
1176
+ const savedSignals = signalMap;
1177
+ const savedSeeded = seededKeys;
1178
+ signalMap = /* @__PURE__ */ new Map();
1179
+ seededKeys = /* @__PURE__ */ new Set();
1180
+ renderMaps().data.clear();
1181
+ try {
1182
+ return await fn();
1183
+ } finally {
1184
+ signalMap = savedSignals;
1185
+ seededKeys = savedSeeded;
1186
+ }
391
1187
  }
392
1188
  var requestQuery = {};
393
1189
  var prefetchOverride = null;
@@ -407,22 +1203,55 @@ function setPrefetchOverride(q) {
407
1203
  prefetchOverride = q;
408
1204
  }
409
1205
  var requestContext = {};
1206
+ var contextStore = null;
1207
+ var RENDER_MAPS = Symbol("renderMaps");
1208
+ var fallbackRenderMaps = { data: /* @__PURE__ */ new Map(), signals: /* @__PURE__ */ new Map(), seeded: /* @__PURE__ */ new Set() };
1209
+ function renderMaps() {
1210
+ const scoped = contextStore?.getStore();
1211
+ if (!scoped) return fallbackRenderMaps;
1212
+ let m = scoped[RENDER_MAPS];
1213
+ if (!m) {
1214
+ m = { data: /* @__PURE__ */ new Map(), signals: /* @__PURE__ */ new Map(), seeded: /* @__PURE__ */ new Set() };
1215
+ scoped[RENDER_MAPS] = m;
1216
+ }
1217
+ return m;
1218
+ }
1219
+ function installContextStore(store) {
1220
+ contextStore = store;
1221
+ }
410
1222
  function getContext() {
411
- return requestContext;
1223
+ const scoped = contextStore?.getStore();
1224
+ return scoped ?? requestContext;
412
1225
  }
413
1226
  function resetRequestContext() {
1227
+ if (contextStore) {
1228
+ const scoped = contextStore.getStore();
1229
+ if (scoped) {
1230
+ for (const k of Object.keys(scoped)) delete scoped[k];
1231
+ return;
1232
+ }
1233
+ }
1234
+ requestContext = {};
1235
+ }
1236
+ function runWithContext(fn) {
1237
+ if (contextStore) return contextStore.run({}, fn);
1238
+ const saved = requestContext;
414
1239
  requestContext = {};
1240
+ try {
1241
+ return fn();
1242
+ } finally {
1243
+ requestContext = saved;
1244
+ }
415
1245
  }
416
1246
  async function isolateStateAsync(fn) {
417
1247
  const savedSignals = signalMap;
418
- const savedData = dataCache;
419
1248
  const savedDeltas = new Map(pendingDeltas);
420
1249
  pendingDeltas.clear();
421
1250
  const savedMounts = mountQueue.splice(0, mountQueue.length);
422
1251
  const savedCleanups = new Set(cleanups);
423
1252
  cleanups.clear();
424
1253
  signalMap = /* @__PURE__ */ new Map();
425
- dataCache = /* @__PURE__ */ new Map();
1254
+ renderMaps().data.clear();
426
1255
  try {
427
1256
  const result = await fn();
428
1257
  return {
@@ -433,7 +1262,6 @@ async function isolateStateAsync(fn) {
433
1262
  };
434
1263
  } finally {
435
1264
  signalMap = savedSignals;
436
- dataCache = savedData;
437
1265
  pendingDeltas.clear();
438
1266
  savedDeltas.forEach((d, k) => pendingDeltas.set(k, d));
439
1267
  mountQueue.splice(0, 0, ...savedMounts);
@@ -455,6 +1283,7 @@ function resumeState(json) {
455
1283
  const obj = JSON.parse(json);
456
1284
  Object.entries(obj).forEach(([k, v]) => {
457
1285
  entry(k, v).value = v;
1286
+ seededKeys.add(k);
458
1287
  });
459
1288
  } catch {
460
1289
  }
@@ -614,10 +1443,17 @@ var ActionError = class extends Error {
614
1443
  this.field = field;
615
1444
  }
616
1445
  };
1446
+ function $actionPending() {
1447
+ const entry2 = signalMap.get("actionPending");
1448
+ return entry2 ? entry2.value === true : false;
1449
+ }
617
1450
  function $actionError() {
618
1451
  const e = signalMap.get("actionError");
619
1452
  if (!e) return null;
620
- if (currentEffect) e.subs.add(currentEffect);
1453
+ if (currentEffect) {
1454
+ e.subs.add(currentEffect);
1455
+ if (trackingDeps) trackingDeps.add(e);
1456
+ }
621
1457
  return e.value ?? null;
622
1458
  }
623
1459
  function $actionErrorOrThrow() {
@@ -634,9 +1470,9 @@ var StateDelta = class {
634
1470
  this.value = value;
635
1471
  }
636
1472
  };
637
- var $append = (value) => new StateDelta("append", value);
638
- var $prepend = (value) => new StateDelta("prepend", value);
639
- var $merge = (value) => new StateDelta("merge", value);
1473
+ var $append = (value) => new StateDelta("a", value);
1474
+ var $prepend = (value) => new StateDelta("p", value);
1475
+ var $merge = (value) => new StateDelta("m", value);
640
1476
  var pendingDeltas = /* @__PURE__ */ new Map();
641
1477
  function setStateDelta(key, delta) {
642
1478
  pendingDeltas.set(key, delta);
@@ -650,12 +1486,12 @@ function applyStateDeltas() {
650
1486
  }
651
1487
  function applyStateDelta(key, delta) {
652
1488
  const cur = signalMap.get(key)?.value;
653
- if (delta.op === "merge") {
1489
+ if (delta.op === "m") {
654
1490
  setState(key, { ...cur, ...delta.value });
655
1491
  return;
656
1492
  }
657
1493
  const list = (v) => v == null ? [] : Array.isArray(v) ? v : [v];
658
- const merged = delta.op === "append" ? [...list(cur), ...list(delta.value)] : [...list(delta.value), ...list(cur)];
1494
+ const merged = delta.op === "a" ? [...list(cur), ...list(delta.value)] : [...list(delta.value), ...list(cur)];
659
1495
  setState(key, merged);
660
1496
  }
661
1497
  function $cookies(request) {
@@ -715,14 +1551,18 @@ function reportVitals() {
715
1551
  export {
716
1552
  $actionError,
717
1553
  $actionErrorOrThrow,
1554
+ $actionPending,
718
1555
  $append,
1556
+ $boundaryError,
719
1557
  $boundaryFallback,
720
1558
  $cookies,
721
1559
  $data,
1560
+ $effect,
722
1561
  $merge,
723
1562
  $prepend,
724
1563
  $query,
725
1564
  $sessionCookie,
1565
+ $setBoundaryError,
726
1566
  $store,
727
1567
  $t,
728
1568
  ActionError,
@@ -735,10 +1575,13 @@ export {
735
1575
  applyStateDeltas,
736
1576
  applyStorePatch,
737
1577
  attrMark,
1578
+ attrValueString,
738
1579
  bestLocale,
1580
+ boolAttrMark,
739
1581
  clearHead,
740
1582
  clearMounts,
741
1583
  clearRequestState,
1584
+ directives,
742
1585
  eachMark,
743
1586
  effect,
744
1587
  ensureLocale,
@@ -749,14 +1592,19 @@ export {
749
1592
  hasState,
750
1593
  headMark,
751
1594
  ifMark,
1595
+ installContextStore,
752
1596
  isLocale,
1597
+ isSeeded,
1598
+ isolateRender,
753
1599
  isolateStateAsync,
754
1600
  loadLocale,
755
1601
  localeDir,
756
1602
  localeList,
1603
+ markSeeded,
757
1604
  notFound,
758
1605
  onCleanup,
759
1606
  onMount,
1607
+ persistState,
760
1608
  rawMark,
761
1609
  redirect,
762
1610
  refresh,
@@ -766,7 +1614,9 @@ export {
766
1614
  resetRequestContext,
767
1615
  restoreState,
768
1616
  resumeState,
1617
+ runWithContext,
769
1618
  serializeState,
1619
+ setActionDispatcher,
770
1620
  setFxOwner,
771
1621
  setLocalePacks,
772
1622
  setLocales,