@aevantec/litevue 0.5.11 → 0.5.13

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.
@@ -0,0 +1,249 @@
1
+ var LiteVueNavigate = (function(exports) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ /** Selector matching every scope root, deferred or not. */
4
+ var SCOPE_SELECTOR = ["[v-scope]", ...[
5
+ "visible",
6
+ "idle",
7
+ "interaction"
8
+ ].map((m) => `[v-scope\\.${m}]`)].join(",");
9
+ //#endregion
10
+ //#region src/plugins/navigate/index.ts
11
+ var STATUS_ID = "litevue-navigate-status";
12
+ var HOVER_DELAY = 100;
13
+ var PREFETCH_TTL = 1e4;
14
+ var isLocal = (url) => url.origin === location.origin;
15
+ var pathOf = (url) => url.pathname + url.search;
16
+ var optedOut = (el) => !!el.closest("[data-navigate=\"false\"]");
17
+ var encode = (data) => new URLSearchParams([...data].map(([k, v]) => [k, v.name ?? v]));
18
+ var emit = (name, detail, cancelable = false) => document.dispatchEvent(new CustomEvent("navigate:" + name, {
19
+ detail,
20
+ cancelable
21
+ }));
22
+ var assets = (doc) => [...doc.head.querySelectorAll("[data-navigate-track]")].map((el) => el.getAttribute("src") || el.getAttribute("href")).sort().join();
23
+ /**
24
+ * Adds the next page's head elements and returns a function dropping the
25
+ * current page's, run after the swap so the old styles hold until then.
26
+ * Scripts are left out both ways: fetched ones never run, and removing a
27
+ * script does not unload it. New stylesheets load before the swap.
28
+ */
29
+ var mergeHead = async (doc) => {
30
+ const sel = "link,style,meta";
31
+ const live = [...document.head.querySelectorAll(sel)];
32
+ const loads = [];
33
+ for (const el of doc.head.querySelectorAll(sel)) {
34
+ const i = live.findIndex((l) => l.isEqualNode(el));
35
+ if (i > -1) {
36
+ live.splice(i, 1);
37
+ continue;
38
+ }
39
+ const fresh = document.importNode(el, true);
40
+ if (fresh.matches("link[rel=stylesheet]")) loads.push(new Promise((r) => {
41
+ fresh.addEventListener("load", r);
42
+ fresh.addEventListener("error", r);
43
+ }));
44
+ document.head.append(fresh);
45
+ }
46
+ await Promise.all(loads);
47
+ return () => live.forEach((el) => el.matches("[data-navigate-preserve]") || el.remove());
48
+ };
49
+ var hasCtxAbove = (el) => {
50
+ for (; el; el = el.parentElement) if (el.__ctx) return true;
51
+ return false;
52
+ };
53
+ /**
54
+ * Morph with the app's roots kept in step. Under a mounted scope morph binds
55
+ * and releases nodes itself; at page level there is no scope, so roots the
56
+ * page removes are unmounted and roots it adds are mounted here.
57
+ */
58
+ var render = (app, patch, from, to) => {
59
+ const roots = [from, ...from.querySelectorAll("*")].filter((el) => el.__ctx && !hasCtxAbove(el.parentElement));
60
+ const added = [];
61
+ patch(from, to, { beforeNodeAdded: (node) => {
62
+ node.nodeType === 1 && added.push(node);
63
+ } });
64
+ roots.forEach((el) => el.isConnected || app.unmount(el));
65
+ added.forEach((el) => el.isConnected && !hasCtxAbove(el) && (el.matches(SCOPE_SELECTOR) || el.querySelector(SCOPE_SELECTOR)) && app.mount(el));
66
+ };
67
+ var navigate = (app, options = {}) => {
68
+ const target = options.target || "body";
69
+ let controller;
70
+ let rendered = pathOf(location);
71
+ const posting = /* @__PURE__ */ new WeakSet();
72
+ let busy = [];
73
+ let pre;
74
+ let timer;
75
+ const fresh = (href) => pre?.href === href && Date.now() - pre.at < PREFETCH_TTL;
76
+ const setBusy = (els) => {
77
+ busy.forEach((el) => el.removeAttribute("aria-busy"));
78
+ (busy = els).forEach((el) => el.setAttribute("aria-busy", "true"));
79
+ };
80
+ const restoration = history.scrollRestoration;
81
+ history.scrollRestoration = "manual";
82
+ const status = document.createElement("div");
83
+ status.id = STATUS_ID;
84
+ status.setAttribute("aria-live", "polite");
85
+ status.setAttribute("data-morph-preserve", "");
86
+ status.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)";
87
+ document.body.append(status);
88
+ const show = (from, doc, url, push, dropOld, y) => {
89
+ if (push) history[url.href === location.href ? "replaceState" : "pushState"]({}, "", url.href);
90
+ rendered = pathOf(location);
91
+ document.title = doc.title;
92
+ render(app, app.scope.$morph, from, doc.querySelector(target));
93
+ dropOld();
94
+ if (options.scroll !== false) {
95
+ const anchor = y == null && url.hash && document.getElementById(url.hash.slice(1));
96
+ anchor ? anchor.scrollIntoView() : scrollTo(0, y || 0);
97
+ }
98
+ const auto = from.querySelector("[autofocus]");
99
+ if (auto) auto.focus();
100
+ else if (from === document.body) document.activeElement?.blur?.();
101
+ else {
102
+ from.hasAttribute("tabindex") || from.setAttribute("tabindex", "-1");
103
+ from.focus({ preventScroll: true });
104
+ }
105
+ status.textContent = document.title || document.querySelector("h1")?.textContent?.trim() || location.pathname;
106
+ emit("after", { url: url.href });
107
+ };
108
+ const go = async (href, init = {}, form, y) => {
109
+ if (!emit("before", { url: href }, y == null)) return;
110
+ controller?.abort();
111
+ const c = controller = new AbortController();
112
+ setBusy([document.documentElement, form].filter(Boolean));
113
+ const post = init.method === "POST";
114
+ if (y == null) history.replaceState({
115
+ ...history.state,
116
+ y: scrollY
117
+ }, "");
118
+ try {
119
+ if (!app.scope.$morph) {
120
+ console.error("[navigate] needs the morph plugin: app.use(morphPlugin).use(navigate)");
121
+ throw new Error("navigate needs the morph plugin");
122
+ }
123
+ const res = await (!init.method && fresh(href) ? pre.res : fetch(href, {
124
+ ...init,
125
+ signal: c.signal,
126
+ headers: { "X-Requested-With": "litevue" }
127
+ }));
128
+ pre = void 0;
129
+ const url = new URL(res.url || href);
130
+ url.hash ||= new URL(href).hash;
131
+ if (!res.headers.get("content-type")?.includes("text/html") || !isLocal(url) || !res.ok && !post) {
132
+ res.body?.cancel();
133
+ throw new Error(`cannot render ${res.status} from ${url.href}`);
134
+ }
135
+ const html = await res.text();
136
+ if (c !== controller) return;
137
+ const doc = new DOMParser().parseFromString(html, "text/html");
138
+ const from = document.querySelector(target);
139
+ if (!from || !doc.querySelector(target)) throw new Error(`no ${target} in ${url.href}`);
140
+ if (assets(doc) !== assets(document)) throw new Error(`${url.href} loads different scripts or styles`);
141
+ doc.querySelectorAll("script").forEach((s) => s.remove());
142
+ const dropOld = await mergeHead(doc);
143
+ const run = () => c === controller && show(from, doc, url, res.ok && y == null, dropOld, y);
144
+ options.transition && document.startViewTransition ? document.startViewTransition(run) : run();
145
+ } catch (error) {
146
+ if (c.signal.aborted) return;
147
+ emit("error", {
148
+ url: href,
149
+ error
150
+ });
151
+ if (!post) location.assign(href);
152
+ } finally {
153
+ c === controller && setBusy([]);
154
+ }
155
+ };
156
+ /** The URL a link leads to, when navigate would take it over. */
157
+ const linkTo = (e) => {
158
+ const a = e.target.closest?.("a[href]");
159
+ if (!(a instanceof HTMLAnchorElement)) return;
160
+ if (optedOut(a) || a.hasAttribute("download")) return;
161
+ if (a.target && a.target !== "_self") return;
162
+ const url = new URL(a.href, location.href);
163
+ if (!isLocal(url)) return;
164
+ if (url.hash && pathOf(url) === pathOf(location)) return;
165
+ return url;
166
+ };
167
+ const onClick = (e) => {
168
+ if (e.defaultPrevented || e.button || e.metaKey || e.ctrlKey) return;
169
+ if (e.shiftKey || e.altKey) return;
170
+ const url = linkTo(e);
171
+ if (!url) return;
172
+ e.preventDefault();
173
+ go(url.href);
174
+ };
175
+ const prefetch = (e) => {
176
+ const url = linkTo(e);
177
+ if (!url || pathOf(url) === rendered || fresh(url.href)) return;
178
+ pre = {
179
+ href: url.href,
180
+ at: Date.now(),
181
+ res: fetch(url.href, { headers: {
182
+ "X-Requested-With": "litevue",
183
+ "X-Sec-Purpose": "prefetch"
184
+ } })
185
+ };
186
+ pre.res.catch(() => {});
187
+ };
188
+ const onHover = (e) => {
189
+ clearTimeout(timer);
190
+ timer = setTimeout(prefetch, HOVER_DELAY, e);
191
+ };
192
+ const onLeave = () => clearTimeout(timer);
193
+ const hovers = options.prefetch ? [
194
+ ["pointerover", onHover],
195
+ ["focusin", onHover],
196
+ ["pointerout", onLeave],
197
+ ["focusout", onLeave],
198
+ ["pointerdown", prefetch]
199
+ ] : [];
200
+ const onSubmit = (e) => {
201
+ const form = e.target;
202
+ const by = e.submitter;
203
+ const attr = (name) => by?.getAttribute("form" + name) || form.getAttribute(name);
204
+ const method = (attr("method") || "get").toLowerCase();
205
+ const where = attr("target");
206
+ const type = attr("enctype");
207
+ if (e.defaultPrevented || method === "dialog" || optedOut(form)) return;
208
+ if (type === "text/plain") return;
209
+ if (where && where !== "_self") return;
210
+ const url = new URL(attr("action") || location.href, location.href);
211
+ if (!isLocal(url)) return;
212
+ const data = new FormData(form);
213
+ if (by?.name) data.append(by.name, by.value);
214
+ e.preventDefault();
215
+ if (method === "post") {
216
+ if (posting.has(form)) return;
217
+ posting.add(form);
218
+ return go(url.href, {
219
+ method: "POST",
220
+ body: type === "multipart/form-data" ? data : encode(data)
221
+ }, form).finally(() => posting.delete(form));
222
+ }
223
+ url.search = encode(data).toString();
224
+ go(url.href, {}, form);
225
+ };
226
+ const onPop = (e) => {
227
+ if (pathOf(location) === rendered) return;
228
+ go(location.href, {}, void 0, e.state?.y || 0);
229
+ };
230
+ document.addEventListener("click", onClick);
231
+ document.addEventListener("submit", onSubmit);
232
+ hovers.forEach(([type, fn]) => document.addEventListener(type, fn));
233
+ addEventListener("popstate", onPop);
234
+ return () => {
235
+ controller?.abort();
236
+ clearTimeout(timer);
237
+ document.removeEventListener("click", onClick);
238
+ document.removeEventListener("submit", onSubmit);
239
+ hovers.forEach(([type, fn]) => document.removeEventListener(type, fn));
240
+ removeEventListener("popstate", onPop);
241
+ history.scrollRestoration = restoration;
242
+ setBusy([]);
243
+ status.remove();
244
+ };
245
+ };
246
+ //#endregion
247
+ exports.navigate = navigate;
248
+ return exports;
249
+ })({});
@@ -0,0 +1,245 @@
1
+ /** Selector matching every scope root, deferred or not. */
2
+ var SCOPE_SELECTOR = ["[v-scope]", ...[
3
+ "visible",
4
+ "idle",
5
+ "interaction"
6
+ ].map((m) => `[v-scope\\.${m}]`)].join(",");
7
+ //#endregion
8
+ //#region src/plugins/navigate/index.ts
9
+ var STATUS_ID = "litevue-navigate-status";
10
+ var HOVER_DELAY = 100;
11
+ var PREFETCH_TTL = 1e4;
12
+ var isLocal = (url) => url.origin === location.origin;
13
+ var pathOf = (url) => url.pathname + url.search;
14
+ var optedOut = (el) => !!el.closest("[data-navigate=\"false\"]");
15
+ var encode = (data) => new URLSearchParams([...data].map(([k, v]) => [k, v.name ?? v]));
16
+ var emit = (name, detail, cancelable = false) => document.dispatchEvent(new CustomEvent("navigate:" + name, {
17
+ detail,
18
+ cancelable
19
+ }));
20
+ var assets = (doc) => [...doc.head.querySelectorAll("[data-navigate-track]")].map((el) => el.getAttribute("src") || el.getAttribute("href")).sort().join();
21
+ /**
22
+ * Adds the next page's head elements and returns a function dropping the
23
+ * current page's, run after the swap so the old styles hold until then.
24
+ * Scripts are left out both ways: fetched ones never run, and removing a
25
+ * script does not unload it. New stylesheets load before the swap.
26
+ */
27
+ var mergeHead = async (doc) => {
28
+ const sel = "link,style,meta";
29
+ const live = [...document.head.querySelectorAll(sel)];
30
+ const loads = [];
31
+ for (const el of doc.head.querySelectorAll(sel)) {
32
+ const i = live.findIndex((l) => l.isEqualNode(el));
33
+ if (i > -1) {
34
+ live.splice(i, 1);
35
+ continue;
36
+ }
37
+ const fresh = document.importNode(el, true);
38
+ if (fresh.matches("link[rel=stylesheet]")) loads.push(new Promise((r) => {
39
+ fresh.addEventListener("load", r);
40
+ fresh.addEventListener("error", r);
41
+ }));
42
+ document.head.append(fresh);
43
+ }
44
+ await Promise.all(loads);
45
+ return () => live.forEach((el) => el.matches("[data-navigate-preserve]") || el.remove());
46
+ };
47
+ var hasCtxAbove = (el) => {
48
+ for (; el; el = el.parentElement) if (el.__ctx) return true;
49
+ return false;
50
+ };
51
+ /**
52
+ * Morph with the app's roots kept in step. Under a mounted scope morph binds
53
+ * and releases nodes itself; at page level there is no scope, so roots the
54
+ * page removes are unmounted and roots it adds are mounted here.
55
+ */
56
+ var render = (app, patch, from, to) => {
57
+ const roots = [from, ...from.querySelectorAll("*")].filter((el) => el.__ctx && !hasCtxAbove(el.parentElement));
58
+ const added = [];
59
+ patch(from, to, { beforeNodeAdded: (node) => {
60
+ node.nodeType === 1 && added.push(node);
61
+ } });
62
+ roots.forEach((el) => el.isConnected || app.unmount(el));
63
+ added.forEach((el) => el.isConnected && !hasCtxAbove(el) && (el.matches(SCOPE_SELECTOR) || el.querySelector(SCOPE_SELECTOR)) && app.mount(el));
64
+ };
65
+ var navigate = (app, options = {}) => {
66
+ const target = options.target || "body";
67
+ let controller;
68
+ let rendered = pathOf(location);
69
+ const posting = /* @__PURE__ */ new WeakSet();
70
+ let busy = [];
71
+ let pre;
72
+ let timer;
73
+ const fresh = (href) => pre?.href === href && Date.now() - pre.at < PREFETCH_TTL;
74
+ const setBusy = (els) => {
75
+ busy.forEach((el) => el.removeAttribute("aria-busy"));
76
+ (busy = els).forEach((el) => el.setAttribute("aria-busy", "true"));
77
+ };
78
+ const restoration = history.scrollRestoration;
79
+ history.scrollRestoration = "manual";
80
+ const status = document.createElement("div");
81
+ status.id = STATUS_ID;
82
+ status.setAttribute("aria-live", "polite");
83
+ status.setAttribute("data-morph-preserve", "");
84
+ status.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)";
85
+ document.body.append(status);
86
+ const show = (from, doc, url, push, dropOld, y) => {
87
+ if (push) history[url.href === location.href ? "replaceState" : "pushState"]({}, "", url.href);
88
+ rendered = pathOf(location);
89
+ document.title = doc.title;
90
+ render(app, app.scope.$morph, from, doc.querySelector(target));
91
+ dropOld();
92
+ if (options.scroll !== false) {
93
+ const anchor = y == null && url.hash && document.getElementById(url.hash.slice(1));
94
+ anchor ? anchor.scrollIntoView() : scrollTo(0, y || 0);
95
+ }
96
+ const auto = from.querySelector("[autofocus]");
97
+ if (auto) auto.focus();
98
+ else if (from === document.body) document.activeElement?.blur?.();
99
+ else {
100
+ from.hasAttribute("tabindex") || from.setAttribute("tabindex", "-1");
101
+ from.focus({ preventScroll: true });
102
+ }
103
+ status.textContent = document.title || document.querySelector("h1")?.textContent?.trim() || location.pathname;
104
+ emit("after", { url: url.href });
105
+ };
106
+ const go = async (href, init = {}, form, y) => {
107
+ if (!emit("before", { url: href }, y == null)) return;
108
+ controller?.abort();
109
+ const c = controller = new AbortController();
110
+ setBusy([document.documentElement, form].filter(Boolean));
111
+ const post = init.method === "POST";
112
+ if (y == null) history.replaceState({
113
+ ...history.state,
114
+ y: scrollY
115
+ }, "");
116
+ try {
117
+ if (!app.scope.$morph) {
118
+ console.error("[navigate] needs the morph plugin: app.use(morphPlugin).use(navigate)");
119
+ throw new Error("navigate needs the morph plugin");
120
+ }
121
+ const res = await (!init.method && fresh(href) ? pre.res : fetch(href, {
122
+ ...init,
123
+ signal: c.signal,
124
+ headers: { "X-Requested-With": "litevue" }
125
+ }));
126
+ pre = void 0;
127
+ const url = new URL(res.url || href);
128
+ url.hash ||= new URL(href).hash;
129
+ if (!res.headers.get("content-type")?.includes("text/html") || !isLocal(url) || !res.ok && !post) {
130
+ res.body?.cancel();
131
+ throw new Error(`cannot render ${res.status} from ${url.href}`);
132
+ }
133
+ const html = await res.text();
134
+ if (c !== controller) return;
135
+ const doc = new DOMParser().parseFromString(html, "text/html");
136
+ const from = document.querySelector(target);
137
+ if (!from || !doc.querySelector(target)) throw new Error(`no ${target} in ${url.href}`);
138
+ if (assets(doc) !== assets(document)) throw new Error(`${url.href} loads different scripts or styles`);
139
+ doc.querySelectorAll("script").forEach((s) => s.remove());
140
+ const dropOld = await mergeHead(doc);
141
+ const run = () => c === controller && show(from, doc, url, res.ok && y == null, dropOld, y);
142
+ options.transition && document.startViewTransition ? document.startViewTransition(run) : run();
143
+ } catch (error) {
144
+ if (c.signal.aborted) return;
145
+ emit("error", {
146
+ url: href,
147
+ error
148
+ });
149
+ if (!post) location.assign(href);
150
+ } finally {
151
+ c === controller && setBusy([]);
152
+ }
153
+ };
154
+ /** The URL a link leads to, when navigate would take it over. */
155
+ const linkTo = (e) => {
156
+ const a = e.target.closest?.("a[href]");
157
+ if (!(a instanceof HTMLAnchorElement)) return;
158
+ if (optedOut(a) || a.hasAttribute("download")) return;
159
+ if (a.target && a.target !== "_self") return;
160
+ const url = new URL(a.href, location.href);
161
+ if (!isLocal(url)) return;
162
+ if (url.hash && pathOf(url) === pathOf(location)) return;
163
+ return url;
164
+ };
165
+ const onClick = (e) => {
166
+ if (e.defaultPrevented || e.button || e.metaKey || e.ctrlKey) return;
167
+ if (e.shiftKey || e.altKey) return;
168
+ const url = linkTo(e);
169
+ if (!url) return;
170
+ e.preventDefault();
171
+ go(url.href);
172
+ };
173
+ const prefetch = (e) => {
174
+ const url = linkTo(e);
175
+ if (!url || pathOf(url) === rendered || fresh(url.href)) return;
176
+ pre = {
177
+ href: url.href,
178
+ at: Date.now(),
179
+ res: fetch(url.href, { headers: {
180
+ "X-Requested-With": "litevue",
181
+ "X-Sec-Purpose": "prefetch"
182
+ } })
183
+ };
184
+ pre.res.catch(() => {});
185
+ };
186
+ const onHover = (e) => {
187
+ clearTimeout(timer);
188
+ timer = setTimeout(prefetch, HOVER_DELAY, e);
189
+ };
190
+ const onLeave = () => clearTimeout(timer);
191
+ const hovers = options.prefetch ? [
192
+ ["pointerover", onHover],
193
+ ["focusin", onHover],
194
+ ["pointerout", onLeave],
195
+ ["focusout", onLeave],
196
+ ["pointerdown", prefetch]
197
+ ] : [];
198
+ const onSubmit = (e) => {
199
+ const form = e.target;
200
+ const by = e.submitter;
201
+ const attr = (name) => by?.getAttribute("form" + name) || form.getAttribute(name);
202
+ const method = (attr("method") || "get").toLowerCase();
203
+ const where = attr("target");
204
+ const type = attr("enctype");
205
+ if (e.defaultPrevented || method === "dialog" || optedOut(form)) return;
206
+ if (type === "text/plain") return;
207
+ if (where && where !== "_self") return;
208
+ const url = new URL(attr("action") || location.href, location.href);
209
+ if (!isLocal(url)) return;
210
+ const data = new FormData(form);
211
+ if (by?.name) data.append(by.name, by.value);
212
+ e.preventDefault();
213
+ if (method === "post") {
214
+ if (posting.has(form)) return;
215
+ posting.add(form);
216
+ return go(url.href, {
217
+ method: "POST",
218
+ body: type === "multipart/form-data" ? data : encode(data)
219
+ }, form).finally(() => posting.delete(form));
220
+ }
221
+ url.search = encode(data).toString();
222
+ go(url.href, {}, form);
223
+ };
224
+ const onPop = (e) => {
225
+ if (pathOf(location) === rendered) return;
226
+ go(location.href, {}, void 0, e.state?.y || 0);
227
+ };
228
+ document.addEventListener("click", onClick);
229
+ document.addEventListener("submit", onSubmit);
230
+ hovers.forEach(([type, fn]) => document.addEventListener(type, fn));
231
+ addEventListener("popstate", onPop);
232
+ return () => {
233
+ controller?.abort();
234
+ clearTimeout(timer);
235
+ document.removeEventListener("click", onClick);
236
+ document.removeEventListener("submit", onSubmit);
237
+ hovers.forEach(([type, fn]) => document.removeEventListener(type, fn));
238
+ removeEventListener("popstate", onPop);
239
+ history.scrollRestoration = restoration;
240
+ setBusy([]);
241
+ status.remove();
242
+ };
243
+ };
244
+ //#endregion
245
+ export { navigate };
@@ -0,0 +1 @@
1
+ var LiteVueNavigate=function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t=["[v-scope]",...["visible","idle","interaction"].map(e=>`[v-scope\\.${e}]`)].join(","),r=e=>e.origin===location.origin,o=e=>e.pathname+e.search,n=e=>!!e.closest('[data-navigate="false"]'),a=e=>new URLSearchParams([...e].map(([e,t])=>[e,t.name??t])),i=(e,t,r=!1)=>document.dispatchEvent(new CustomEvent("navigate:"+e,{detail:t,cancelable:r})),s=e=>[...e.head.querySelectorAll("[data-navigate-track]")].map(e=>e.getAttribute("src")||e.getAttribute("href")).sort().join(),c=e=>{for(;e;e=e.parentElement)if(e.__ctx)return!0;return!1};return e.navigate=(e,l={})=>{const u=l.target||"body";let d,h=o(location);const f=new WeakSet;let m,p,v=[];const y=e=>m?.href===e&&Date.now()-m.at<1e4,b=e=>{v.forEach(e=>e.removeAttribute("aria-busy")),(v=e).forEach(e=>e.setAttribute("aria-busy","true"))},g=history.scrollRestoration;history.scrollRestoration="manual";const w=document.createElement("div");w.id="litevue-navigate-status",w.setAttribute("aria-live","polite"),w.setAttribute("data-morph-preserve",""),w.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)",document.body.append(w);const E=(r,n,a,s,d,f)=>{if(s&&history[a.href===location.href?"replaceState":"pushState"]({},"",a.href),h=o(location),document.title=n.title,((e,r,o,n)=>{const a=[o,...o.querySelectorAll("*")].filter(e=>e.__ctx&&!c(e.parentElement)),i=[];r(o,n,{beforeNodeAdded:e=>{1===e.nodeType&&i.push(e)}}),a.forEach(t=>t.isConnected||e.unmount(t)),i.forEach(r=>r.isConnected&&!c(r)&&(r.matches(t)||r.querySelector(t))&&e.mount(r))})(e,e.scope.$morph,r,n.querySelector(u)),d(),!1!==l.scroll){const e=null==f&&a.hash&&document.getElementById(a.hash.slice(1));e?e.scrollIntoView():scrollTo(0,f||0)}const m=r.querySelector("[autofocus]");m?m.focus():r===document.body?document.activeElement?.blur?.():(r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0})),w.textContent=document.title||document.querySelector("h1")?.textContent?.trim()||location.pathname,i("after",{url:a.href})},S=async(t,o={},n,a)=>{if(!i("before",{url:t},null==a))return;d?.abort();const c=d=new AbortController;b([document.documentElement,n].filter(Boolean));const h="POST"===o.method;null==a&&history.replaceState({...history.state,y:scrollY},"");try{if(!e.scope.$morph)throw new Error("navigate needs the morph plugin");const n=await(!o.method&&y(t)?m.res:fetch(t,{...o,signal:c.signal,headers:{"X-Requested-With":"litevue"}}));m=void 0;const i=new URL(n.url||t);if(i.hash||=new URL(t).hash,!n.headers.get("content-type")?.includes("text/html")||!r(i)||!n.ok&&!h)throw n.body?.cancel(),new Error(`cannot render ${n.status} from ${i.href}`);const f=await n.text();if(c!==d)return;const p=(new DOMParser).parseFromString(f,"text/html"),v=document.querySelector(u);if(!v||!p.querySelector(u))throw new Error(`no ${u} in ${i.href}`);if(s(p)!==s(document))throw new Error(`${i.href} loads different scripts or styles`);p.querySelectorAll("script").forEach(e=>e.remove());const b=await(async e=>{const t="link,style,meta",r=[...document.head.querySelectorAll(t)],o=[];for(const n of e.head.querySelectorAll(t)){const e=r.findIndex(e=>e.isEqualNode(n));if(e>-1){r.splice(e,1);continue}const t=document.importNode(n,!0);t.matches("link[rel=stylesheet]")&&o.push(new Promise(e=>{t.addEventListener("load",e),t.addEventListener("error",e)})),document.head.append(t)}return await Promise.all(o),()=>r.forEach(e=>e.matches("[data-navigate-preserve]")||e.remove())})(p),g=()=>c===d&&E(v,p,i,n.ok&&null==a,b,a);l.transition&&document.startViewTransition?document.startViewTransition(g):g()}catch(f){if(c.signal.aborted)return;i("error",{url:t,error:f}),h||location.assign(t)}finally{c===d&&b([])}},A=e=>{const t=e.target.closest?.("a[href]");if(!(t instanceof HTMLAnchorElement))return;if(n(t)||t.hasAttribute("download"))return;if(t.target&&"_self"!==t.target)return;const a=new URL(t.href,location.href);return!r(a)||a.hash&&o(a)===o(location)?void 0:a},L=e=>{if(e.defaultPrevented||e.button||e.metaKey||e.ctrlKey)return;if(e.shiftKey||e.altKey)return;const t=A(e);t&&(e.preventDefault(),S(t.href))},q=e=>{const t=A(e);t&&o(t)!==h&&!y(t.href)&&(m={href:t.href,at:Date.now(),res:fetch(t.href,{headers:{"X-Requested-With":"litevue","X-Sec-Purpose":"prefetch"}})},m.res.catch(()=>{}))},x=e=>{clearTimeout(p),p=setTimeout(q,100,e)},T=()=>clearTimeout(p),P=l.prefetch?[["pointerover",x],["focusin",x],["pointerout",T],["focusout",T],["pointerdown",q]]:[],R=e=>{const t=e.target,o=e.submitter,i=e=>o?.getAttribute("form"+e)||t.getAttribute(e),s=(i("method")||"get").toLowerCase(),c=i("target"),l=i("enctype");if(e.defaultPrevented||"dialog"===s||n(t))return;if("text/plain"===l)return;if(c&&"_self"!==c)return;const u=new URL(i("action")||location.href,location.href);if(!r(u))return;const d=new FormData(t);if(o?.name&&d.append(o.name,o.value),e.preventDefault(),"post"===s){if(f.has(t))return;return f.add(t),S(u.href,{method:"POST",body:"multipart/form-data"===l?d:a(d)},t).finally(()=>f.delete(t))}u.search=a(d).toString(),S(u.href,{},t)},k=e=>{o(location)!==h&&S(location.href,{},void 0,e.state?.y||0)};return document.addEventListener("click",L),document.addEventListener("submit",R),P.forEach(([e,t])=>document.addEventListener(e,t)),addEventListener("popstate",k),()=>{d?.abort(),clearTimeout(p),document.removeEventListener("click",L),document.removeEventListener("submit",R),P.forEach(([e,t])=>document.removeEventListener(e,t)),removeEventListener("popstate",k),history.scrollRestoration=g,b([]),w.remove()}},e}({});
@@ -0,0 +1 @@
1
+ var e=["[v-scope]",...["visible","idle","interaction"].map(e=>`[v-scope\\.${e}]`)].join(","),t=e=>e.origin===location.origin,r=e=>e.pathname+e.search,o=e=>!!e.closest('[data-navigate="false"]'),n=e=>new URLSearchParams([...e].map(([e,t])=>[e,t.name??t])),a=(e,t,r=!1)=>document.dispatchEvent(new CustomEvent("navigate:"+e,{detail:t,cancelable:r})),i=e=>[...e.head.querySelectorAll("[data-navigate-track]")].map(e=>e.getAttribute("src")||e.getAttribute("href")).sort().join(),s=e=>{for(;e;e=e.parentElement)if(e.__ctx)return!0;return!1},c=(c,l={})=>{const u=l.target||"body";let d,h=r(location);const f=/* @__PURE__ */new WeakSet;let m,p,v=[];const y=e=>m?.href===e&&Date.now()-m.at<1e4,b=e=>{v.forEach(e=>e.removeAttribute("aria-busy")),(v=e).forEach(e=>e.setAttribute("aria-busy","true"))},w=history.scrollRestoration;history.scrollRestoration="manual";const E=document.createElement("div");E.id="litevue-navigate-status",E.setAttribute("aria-live","polite"),E.setAttribute("data-morph-preserve",""),E.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)",document.body.append(E);const g=(t,o,n,i,d,f)=>{if(i&&history[n.href===location.href?"replaceState":"pushState"]({},"",n.href),h=r(location),document.title=o.title,((t,r,o,n)=>{const a=[o,...o.querySelectorAll("*")].filter(e=>e.__ctx&&!s(e.parentElement)),i=[];r(o,n,{beforeNodeAdded:e=>{1===e.nodeType&&i.push(e)}}),a.forEach(e=>e.isConnected||t.unmount(e)),i.forEach(r=>r.isConnected&&!s(r)&&(r.matches(e)||r.querySelector(e))&&t.mount(r))})(c,c.scope.$morph,t,o.querySelector(u)),d(),!1!==l.scroll){const e=null==f&&n.hash&&document.getElementById(n.hash.slice(1));e?e.scrollIntoView():scrollTo(0,f||0)}const m=t.querySelector("[autofocus]");m?m.focus():t===document.body?document.activeElement?.blur?.():(t.hasAttribute("tabindex")||t.setAttribute("tabindex","-1"),t.focus({preventScroll:!0})),E.textContent=document.title||document.querySelector("h1")?.textContent?.trim()||location.pathname,a("after",{url:n.href})},S=async(e,r={},o,n)=>{if(!a("before",{url:e},null==n))return;d?.abort();const s=d=new AbortController;b([document.documentElement,o].filter(Boolean));const h="POST"===r.method;null==n&&history.replaceState({...history.state,y:scrollY},"");try{if(!c.scope.$morph)throw new Error("navigate needs the morph plugin");const o=await(!r.method&&y(e)?m.res:fetch(e,{...r,signal:s.signal,headers:{"X-Requested-With":"litevue"}}));m=void 0;const a=new URL(o.url||e);if(a.hash||=new URL(e).hash,!o.headers.get("content-type")?.includes("text/html")||!t(a)||!o.ok&&!h)throw o.body?.cancel(),new Error(`cannot render ${o.status} from ${a.href}`);const f=await o.text();if(s!==d)return;const p=(new DOMParser).parseFromString(f,"text/html"),v=document.querySelector(u);if(!v||!p.querySelector(u))throw new Error(`no ${u} in ${a.href}`);if(i(p)!==i(document))throw new Error(`${a.href} loads different scripts or styles`);p.querySelectorAll("script").forEach(e=>e.remove());const b=await(async e=>{const t="link,style,meta",r=[...document.head.querySelectorAll(t)],o=[];for(const n of e.head.querySelectorAll(t)){const e=r.findIndex(e=>e.isEqualNode(n));if(e>-1){r.splice(e,1);continue}const t=document.importNode(n,!0);t.matches("link[rel=stylesheet]")&&o.push(new Promise(e=>{t.addEventListener("load",e),t.addEventListener("error",e)})),document.head.append(t)}return await Promise.all(o),()=>r.forEach(e=>e.matches("[data-navigate-preserve]")||e.remove())})(p),w=()=>s===d&&g(v,p,a,o.ok&&null==n,b,n);l.transition&&document.startViewTransition?document.startViewTransition(w):w()}catch(f){if(s.signal.aborted)return;a("error",{url:e,error:f}),h||location.assign(e)}finally{s===d&&b([])}},A=e=>{const n=e.target.closest?.("a[href]");if(!(n instanceof HTMLAnchorElement))return;if(o(n)||n.hasAttribute("download"))return;if(n.target&&"_self"!==n.target)return;const a=new URL(n.href,location.href);return!t(a)||a.hash&&r(a)===r(location)?void 0:a},L=e=>{if(e.defaultPrevented||e.button||e.metaKey||e.ctrlKey)return;if(e.shiftKey||e.altKey)return;const t=A(e);t&&(e.preventDefault(),S(t.href))},x=e=>{const t=A(e);t&&r(t)!==h&&!y(t.href)&&(m={href:t.href,at:Date.now(),res:fetch(t.href,{headers:{"X-Requested-With":"litevue","X-Sec-Purpose":"prefetch"}})},m.res.catch(()=>{}))},q=e=>{clearTimeout(p),p=setTimeout(x,100,e)},T=()=>clearTimeout(p),R=l.prefetch?[["pointerover",q],["focusin",q],["pointerout",T],["focusout",T],["pointerdown",x]]:[],P=e=>{const r=e.target,a=e.submitter,i=e=>a?.getAttribute("form"+e)||r.getAttribute(e),s=(i("method")||"get").toLowerCase(),c=i("target"),l=i("enctype");if(e.defaultPrevented||"dialog"===s||o(r))return;if("text/plain"===l)return;if(c&&"_self"!==c)return;const u=new URL(i("action")||location.href,location.href);if(!t(u))return;const d=new FormData(r);if(a?.name&&d.append(a.name,a.value),e.preventDefault(),"post"===s){if(f.has(r))return;return f.add(r),S(u.href,{method:"POST",body:"multipart/form-data"===l?d:n(d)},r).finally(()=>f.delete(r))}u.search=n(d).toString(),S(u.href,{},r)},k=e=>{r(location)!==h&&S(location.href,{},void 0,e.state?.y||0)};return document.addEventListener("click",L),document.addEventListener("submit",P),R.forEach(([e,t])=>document.addEventListener(e,t)),addEventListener("popstate",k),()=>{d?.abort(),clearTimeout(p),document.removeEventListener("click",L),document.removeEventListener("submit",P),R.forEach(([e,t])=>document.removeEventListener(e,t)),removeEventListener("popstate",k),history.scrollRestoration=w,b([]),E.remove()}};export{c as navigate};
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LiteVueNavigate={})}(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var t=["[v-scope]",...["visible","idle","interaction"].map(e=>`[v-scope\\.${e}]`)].join(","),r=e=>e.origin===location.origin,o=e=>e.pathname+e.search,n=e=>!!e.closest('[data-navigate="false"]'),a=e=>new URLSearchParams([...e].map(([e,t])=>[e,t.name??t])),i=(e,t,r=!1)=>document.dispatchEvent(new CustomEvent("navigate:"+e,{detail:t,cancelable:r})),s=e=>[...e.head.querySelectorAll("[data-navigate-track]")].map(e=>e.getAttribute("src")||e.getAttribute("href")).sort().join(),c=e=>{for(;e;e=e.parentElement)if(e.__ctx)return!0;return!1};e.navigate=(e,l={})=>{const u=l.target||"body";let d,h=o(location);const f=new WeakSet;let m,p,v=[];const y=e=>m?.href===e&&Date.now()-m.at<1e4,b=e=>{v.forEach(e=>e.removeAttribute("aria-busy")),(v=e).forEach(e=>e.setAttribute("aria-busy","true"))},g=history.scrollRestoration;history.scrollRestoration="manual";const w=document.createElement("div");w.id="litevue-navigate-status",w.setAttribute("aria-live","polite"),w.setAttribute("data-morph-preserve",""),w.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)",document.body.append(w);const E=(r,n,a,s,d,f)=>{if(s&&history[a.href===location.href?"replaceState":"pushState"]({},"",a.href),h=o(location),document.title=n.title,((e,r,o,n)=>{const a=[o,...o.querySelectorAll("*")].filter(e=>e.__ctx&&!c(e.parentElement)),i=[];r(o,n,{beforeNodeAdded:e=>{1===e.nodeType&&i.push(e)}}),a.forEach(t=>t.isConnected||e.unmount(t)),i.forEach(r=>r.isConnected&&!c(r)&&(r.matches(t)||r.querySelector(t))&&e.mount(r))})(e,e.scope.$morph,r,n.querySelector(u)),d(),!1!==l.scroll){const e=null==f&&a.hash&&document.getElementById(a.hash.slice(1));e?e.scrollIntoView():scrollTo(0,f||0)}const m=r.querySelector("[autofocus]");m?m.focus():r===document.body?document.activeElement?.blur?.():(r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0})),w.textContent=document.title||document.querySelector("h1")?.textContent?.trim()||location.pathname,i("after",{url:a.href})},S=async(t,o={},n,a)=>{if(!i("before",{url:t},null==a))return;d?.abort();const c=d=new AbortController;b([document.documentElement,n].filter(Boolean));const h="POST"===o.method;null==a&&history.replaceState({...history.state,y:scrollY},"");try{if(!e.scope.$morph)throw new Error("navigate needs the morph plugin");const n=await(!o.method&&y(t)?m.res:fetch(t,{...o,signal:c.signal,headers:{"X-Requested-With":"litevue"}}));m=void 0;const i=new URL(n.url||t);if(i.hash||=new URL(t).hash,!n.headers.get("content-type")?.includes("text/html")||!r(i)||!n.ok&&!h)throw n.body?.cancel(),new Error(`cannot render ${n.status} from ${i.href}`);const f=await n.text();if(c!==d)return;const p=(new DOMParser).parseFromString(f,"text/html"),v=document.querySelector(u);if(!v||!p.querySelector(u))throw new Error(`no ${u} in ${i.href}`);if(s(p)!==s(document))throw new Error(`${i.href} loads different scripts or styles`);p.querySelectorAll("script").forEach(e=>e.remove());const b=await(async e=>{const t="link,style,meta",r=[...document.head.querySelectorAll(t)],o=[];for(const n of e.head.querySelectorAll(t)){const e=r.findIndex(e=>e.isEqualNode(n));if(e>-1){r.splice(e,1);continue}const t=document.importNode(n,!0);t.matches("link[rel=stylesheet]")&&o.push(new Promise(e=>{t.addEventListener("load",e),t.addEventListener("error",e)})),document.head.append(t)}return await Promise.all(o),()=>r.forEach(e=>e.matches("[data-navigate-preserve]")||e.remove())})(p),g=()=>c===d&&E(v,p,i,n.ok&&null==a,b,a);l.transition&&document.startViewTransition?document.startViewTransition(g):g()}catch(f){if(c.signal.aborted)return;i("error",{url:t,error:f}),h||location.assign(t)}finally{c===d&&b([])}},A=e=>{const t=e.target.closest?.("a[href]");if(!(t instanceof HTMLAnchorElement))return;if(n(t)||t.hasAttribute("download"))return;if(t.target&&"_self"!==t.target)return;const a=new URL(t.href,location.href);return!r(a)||a.hash&&o(a)===o(location)?void 0:a},L=e=>{if(e.defaultPrevented||e.button||e.metaKey||e.ctrlKey)return;if(e.shiftKey||e.altKey)return;const t=A(e);t&&(e.preventDefault(),S(t.href))},x=e=>{const t=A(e);t&&o(t)!==h&&!y(t.href)&&(m={href:t.href,at:Date.now(),res:fetch(t.href,{headers:{"X-Requested-With":"litevue","X-Sec-Purpose":"prefetch"}})},m.res.catch(()=>{}))},T=e=>{clearTimeout(p),p=setTimeout(x,100,e)},q=()=>clearTimeout(p),P=l.prefetch?[["pointerover",T],["focusin",T],["pointerout",q],["focusout",q],["pointerdown",x]]:[],R=e=>{const t=e.target,o=e.submitter,i=e=>o?.getAttribute("form"+e)||t.getAttribute(e),s=(i("method")||"get").toLowerCase(),c=i("target"),l=i("enctype");if(e.defaultPrevented||"dialog"===s||n(t))return;if("text/plain"===l)return;if(c&&"_self"!==c)return;const u=new URL(i("action")||location.href,location.href);if(!r(u))return;const d=new FormData(t);if(o?.name&&d.append(o.name,o.value),e.preventDefault(),"post"===s){if(f.has(t))return;return f.add(t),S(u.href,{method:"POST",body:"multipart/form-data"===l?d:a(d)},t).finally(()=>f.delete(t))}u.search=a(d).toString(),S(u.href,{},t)},k=e=>{o(location)!==h&&S(location.href,{},void 0,e.state?.y||0)};return document.addEventListener("click",L),document.addEventListener("submit",R),P.forEach(([e,t])=>document.addEventListener(e,t)),addEventListener("popstate",k),()=>{d?.abort(),clearTimeout(p),document.removeEventListener("click",L),document.removeEventListener("submit",R),P.forEach(([e,t])=>document.removeEventListener(e,t)),removeEventListener("popstate",k),history.scrollRestoration=g,b([]),w.remove()}}});
@@ -1 +1 @@
1
- var LiteVuePopover=function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var e={top:"top","top-start":"top span-right","top-end":"top span-left",bottom:"bottom","bottom-start":"bottom span-right","bottom-end":"bottom span-left",left:"left","left-start":"left span-bottom","left-end":"left span-top",right:"right","right-start":"right span-bottom","right-end":"right span-top"},o={top:"bottom",bottom:"top",left:"right",right:"left"},r=0;return t.popover=t=>{t.directive("popover",({el:t,get:e,effect:o,exp:r})=>{const n=t;n.popover||(n.popover="auto");const s=e(`(val) => { ${r} = val }`),i=t=>s("open"===t.newState);return n.addEventListener("toggle",i),o(()=>{const t=!!e();t!==n.matches(":popover-open")&&(t?n.showPopover():n.hidePopover())}),()=>n.removeEventListener("toggle",i)}),t.directive("anchor",({el:t,get:n,effect:s,modifiers:i})=>{const p=t;let l="bottom",a=0;for(const o in i||{}){o in e&&(l=o);const t=/^offset-(\d+)$/.exec(o);t&&(a=+t[1])}const f=p.style.cssText,c=/^(top|bottom)/.test(l);let g;if(p.style.position="fixed",p.style.inset="auto",p.style.margin="0",CSS.supports("anchor-name: --a")){const t="--litevue-anchor-"+ ++r;return p.style.margin=c?`${a}px 0`:`0 ${a}px`,p.style.setProperty("position-anchor",t),p.style.setProperty("position-area",e[l]),p.style.setProperty("position-try-fallbacks","flip-block, flip-inline"),s(()=>{g?.style.removeProperty("anchor-name"),g=n(),g?.style.setProperty("anchor-name",t)}),()=>{g?.style.removeProperty("anchor-name"),p.style.cssText=f}}const h=()=>{!g||p.popover&&!p.matches(":popover-open")||((t,e,r,n)=>{const[s,i]=r.split("-"),p=e.getBoundingClientRect(),l=t.offsetWidth+n,a=t.offsetHeight+n,f={top:p.top-a,bottom:innerHeight-p.bottom-a,left:p.left-l,right:innerWidth-p.right-l},c=f[s]<0&&f[o[s]]>=0?o[s]:s,g="top"===c||"bottom"===c,[h,m,v]=g?[p.left,p.width,t.offsetWidth]:[p.top,p.height,t.offsetHeight],d="start"===i?h:"end"===i?h+m-v:h+(m-v)/2,y="top"===c?p.top-a:"bottom"===c?p.bottom+n:"left"===c?p.left-l:p.right+n;t.style.left=(g?d:y)+"px",t.style.top=(g?y:d)+"px"})(p,g,l,a)};return s(()=>{g=n(),h()}),addEventListener("scroll",h,!0),addEventListener("resize",h),p.addEventListener("toggle",h),()=>{removeEventListener("scroll",h,!0),removeEventListener("resize",h),p.removeEventListener("toggle",h),p.style.cssText=f}})},t}({});
1
+ var LiteVuePopover=function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var e={top:"top","top-start":"top span-right","top-end":"top span-left",bottom:"bottom","bottom-start":"bottom span-right","bottom-end":"bottom span-left",left:"left","left-start":"left span-bottom","left-end":"left span-top",right:"right","right-start":"right span-bottom","right-end":"right span-top"},o={top:"bottom",bottom:"top",left:"right",right:"left"},r=0,s=(t,e,o)=>{if(!t)return;const r=t.style.getPropertyValue("anchor-name").split(/\s*,\s*/).filter(t=>t&&t!==e);o&&r.push(e),t.style.setProperty("anchor-name",r.join())};return t.popover=t=>{t.directive("popover",({el:t,get:e,effect:o,exp:r})=>{const s=t;s.popover||(s.popover="auto");const n=e(`(val) => { ${r} = val }`),i=t=>n("open"===t.newState);return s.addEventListener("toggle",i),o(()=>{const t=!!e();t!==s.matches(":popover-open")&&(t?s.showPopover():s.hidePopover())}),()=>s.removeEventListener("toggle",i)}),t.directive("anchor",({el:t,get:n,effect:i,modifiers:p})=>{const l=t;let a="bottom",f=0;for(const o in p||{}){o in e&&(a=o);const t=/^offset-(\d+)$/.exec(o);t&&(f=+t[1])}const c=l.style.cssText,g=/^(top|bottom)/.test(a);let h;if(l.style.position="fixed",l.style.inset="auto",l.style.margin="0",CSS.supports("anchor-name: --a")){const t="--litevue-anchor-"+ ++r;return l.hasAttribute("popover")||(l.style.position="absolute"),l.style.margin=g?`${f}px 0`:`0 ${f}px`,l.style.setProperty("position-anchor",t),l.style.setProperty("position-area",e[a]),l.style.setProperty("position-try-fallbacks","flip-block, flip-inline"),i(()=>{s(h,t,!1),h=n(),s(h,t,!0)}),()=>{s(h,t,!1),l.style.cssText=c}}const v=()=>{!h||l.popover&&!l.matches(":popover-open")||((t,e,r,s)=>{const[n,i]=r.split("-"),p=e.getBoundingClientRect(),l=t.offsetWidth+s,a=t.offsetHeight+s,f={top:p.top-a,bottom:innerHeight-p.bottom-a,left:p.left-l,right:innerWidth-p.right-l},c=f[n]<0&&f[o[n]]>=0?o[n]:n,g="top"===c||"bottom"===c,[h,v,m]=g?[p.left,p.width,t.offsetWidth]:[p.top,p.height,t.offsetHeight],d="start"===i?h:"end"===i?h+v-m:h+(v-m)/2,b="top"===c?p.top-a:"bottom"===c?p.bottom+s:"left"===c?p.left-l:p.right+s;t.style.left=(g?d:b)+"px",t.style.top=(g?b:d)+"px"})(l,h,a,f)};return i(()=>{h=n(),v()}),addEventListener("scroll",v,!0),addEventListener("resize",v),l.addEventListener("toggle",v),()=>{removeEventListener("scroll",v,!0),removeEventListener("resize",v),l.removeEventListener("toggle",v),l.style.cssText=c}})},t}({});
@@ -1 +1 @@
1
- var t={top:"top","top-start":"top span-right","top-end":"top span-left",bottom:"bottom","bottom-start":"bottom span-right","bottom-end":"bottom span-left",left:"left","left-start":"left span-bottom","left-end":"left span-top",right:"right","right-start":"right span-bottom","right-end":"right span-top"},e={top:"bottom",bottom:"top",left:"right",right:"left"},o=0,r=r=>{r.directive("popover",({el:t,get:e,effect:o,exp:r})=>{const s=t;s.popover||(s.popover="auto");const n=e(`(val) => { ${r} = val }`),p=t=>n("open"===t.newState);return s.addEventListener("toggle",p),o(()=>{const t=!!e();t!==s.matches(":popover-open")&&(t?s.showPopover():s.hidePopover())}),()=>s.removeEventListener("toggle",p)}),r.directive("anchor",({el:r,get:s,effect:n,modifiers:p})=>{const i=r;let l="bottom",a=0;for(const e in p||{}){e in t&&(l=e);const o=/^offset-(\d+)$/.exec(e);o&&(a=+o[1])}const f=i.style.cssText,h=/^(top|bottom)/.test(l);let c;if(i.style.position="fixed",i.style.inset="auto",i.style.margin="0",CSS.supports("anchor-name: --a")){const e="--litevue-anchor-"+ ++o;return i.style.margin=h?`${a}px 0`:`0 ${a}px`,i.style.setProperty("position-anchor",e),i.style.setProperty("position-area",t[l]),i.style.setProperty("position-try-fallbacks","flip-block, flip-inline"),n(()=>{c?.style.removeProperty("anchor-name"),c=s(),c?.style.setProperty("anchor-name",e)}),()=>{c?.style.removeProperty("anchor-name"),i.style.cssText=f}}const m=()=>{!c||i.popover&&!i.matches(":popover-open")||((t,o,r,s)=>{const[n,p]=r.split("-"),i=o.getBoundingClientRect(),l=t.offsetWidth+s,a=t.offsetHeight+s,f={top:i.top-a,bottom:innerHeight-i.bottom-a,left:i.left-l,right:innerWidth-i.right-l},h=f[n]<0&&f[e[n]]>=0?e[n]:n,c="top"===h||"bottom"===h,[m,g,v]=c?[i.left,i.width,t.offsetWidth]:[i.top,i.height,t.offsetHeight],d="start"===p?m:"end"===p?m+g-v:m+(g-v)/2,y="top"===h?i.top-a:"bottom"===h?i.bottom+s:"left"===h?i.left-l:i.right+s;t.style.left=(c?d:y)+"px",t.style.top=(c?y:d)+"px"})(i,c,l,a)};return n(()=>{c=s(),m()}),addEventListener("scroll",m,!0),addEventListener("resize",m),i.addEventListener("toggle",m),()=>{removeEventListener("scroll",m,!0),removeEventListener("resize",m),i.removeEventListener("toggle",m),i.style.cssText=f}})};export{r as popover};
1
+ var t={top:"top","top-start":"top span-right","top-end":"top span-left",bottom:"bottom","bottom-start":"bottom span-right","bottom-end":"bottom span-left",left:"left","left-start":"left span-bottom","left-end":"left span-top",right:"right","right-start":"right span-bottom","right-end":"right span-top"},e={top:"bottom",bottom:"top",left:"right",right:"left"},o=0,s=(t,e,o)=>{if(!t)return;const s=t.style.getPropertyValue("anchor-name").split(/\s*,\s*/).filter(t=>t&&t!==e);o&&s.push(e),t.style.setProperty("anchor-name",s.join())},r=r=>{r.directive("popover",({el:t,get:e,effect:o,exp:s})=>{const r=t;r.popover||(r.popover="auto");const n=e(`(val) => { ${s} = val }`),i=t=>n("open"===t.newState);return r.addEventListener("toggle",i),o(()=>{const t=!!e();t!==r.matches(":popover-open")&&(t?r.showPopover():r.hidePopover())}),()=>r.removeEventListener("toggle",i)}),r.directive("anchor",({el:r,get:n,effect:i,modifiers:p})=>{const l=r;let a="bottom",f=0;for(const e in p||{}){e in t&&(a=e);const o=/^offset-(\d+)$/.exec(e);o&&(f=+o[1])}const h=l.style.cssText,c=/^(top|bottom)/.test(a);let g;if(l.style.position="fixed",l.style.inset="auto",l.style.margin="0",CSS.supports("anchor-name: --a")){const e="--litevue-anchor-"+ ++o;return l.hasAttribute("popover")||(l.style.position="absolute"),l.style.margin=c?`${f}px 0`:`0 ${f}px`,l.style.setProperty("position-anchor",e),l.style.setProperty("position-area",t[a]),l.style.setProperty("position-try-fallbacks","flip-block, flip-inline"),i(()=>{s(g,e,!1),g=n(),s(g,e,!0)}),()=>{s(g,e,!1),l.style.cssText=h}}const m=()=>{!g||l.popover&&!l.matches(":popover-open")||((t,o,s,r)=>{const[n,i]=s.split("-"),p=o.getBoundingClientRect(),l=t.offsetWidth+r,a=t.offsetHeight+r,f={top:p.top-a,bottom:innerHeight-p.bottom-a,left:p.left-l,right:innerWidth-p.right-l},h=f[n]<0&&f[e[n]]>=0?e[n]:n,c="top"===h||"bottom"===h,[g,m,v]=c?[p.left,p.width,t.offsetWidth]:[p.top,p.height,t.offsetHeight],d="start"===i?g:"end"===i?g+m-v:g+(m-v)/2,b="top"===h?p.top-a:"bottom"===h?p.bottom+r:"left"===h?p.left-l:p.right+r;t.style.left=(c?d:b)+"px",t.style.top=(c?b:d)+"px"})(l,g,a,f)};return i(()=>{g=n(),m()}),addEventListener("scroll",m,!0),addEventListener("resize",m),l.addEventListener("toggle",m),()=>{removeEventListener("scroll",m,!0),removeEventListener("resize",m),l.removeEventListener("toggle",m),l.style.cssText=h}})};export{r as popover};
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LiteVuePopover={})}(this,function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var e={top:"top","top-start":"top span-right","top-end":"top span-left",bottom:"bottom","bottom-start":"bottom span-right","bottom-end":"bottom span-left",left:"left","left-start":"left span-bottom","left-end":"left span-top",right:"right","right-start":"right span-bottom","right-end":"right span-top"},o={top:"bottom",bottom:"top",left:"right",right:"left"},n=0;t.popover=t=>{t.directive("popover",({el:t,get:e,effect:o,exp:n})=>{const r=t;r.popover||(r.popover="auto");const s=e(`(val) => { ${n} = val }`),i=t=>s("open"===t.newState);return r.addEventListener("toggle",i),o(()=>{const t=!!e();t!==r.matches(":popover-open")&&(t?r.showPopover():r.hidePopover())}),()=>r.removeEventListener("toggle",i)}),t.directive("anchor",({el:t,get:r,effect:s,modifiers:i})=>{const p=t;let l="bottom",f=0;for(const o in i||{}){o in e&&(l=o);const t=/^offset-(\d+)$/.exec(o);t&&(f=+t[1])}const a=p.style.cssText,c=/^(top|bottom)/.test(l);let h;if(p.style.position="fixed",p.style.inset="auto",p.style.margin="0",CSS.supports("anchor-name: --a")){const t="--litevue-anchor-"+ ++n;return p.style.margin=c?`${f}px 0`:`0 ${f}px`,p.style.setProperty("position-anchor",t),p.style.setProperty("position-area",e[l]),p.style.setProperty("position-try-fallbacks","flip-block, flip-inline"),s(()=>{h?.style.removeProperty("anchor-name"),h=r(),h?.style.setProperty("anchor-name",t)}),()=>{h?.style.removeProperty("anchor-name"),p.style.cssText=a}}const d=()=>{!h||p.popover&&!p.matches(":popover-open")||((t,e,n,r)=>{const[s,i]=n.split("-"),p=e.getBoundingClientRect(),l=t.offsetWidth+r,f=t.offsetHeight+r,a={top:p.top-f,bottom:innerHeight-p.bottom-f,left:p.left-l,right:innerWidth-p.right-l},c=a[s]<0&&a[o[s]]>=0?o[s]:s,h="top"===c||"bottom"===c,[d,g,m]=h?[p.left,p.width,t.offsetWidth]:[p.top,p.height,t.offsetHeight],v="start"===i?d:"end"===i?d+g-m:d+(g-m)/2,y="top"===c?p.top-f:"bottom"===c?p.bottom+r:"left"===c?p.left-l:p.right+r;t.style.left=(h?v:y)+"px",t.style.top=(h?y:v)+"px"})(p,h,l,f)};return s(()=>{h=r(),d()}),addEventListener("scroll",d,!0),addEventListener("resize",d),p.addEventListener("toggle",d),()=>{removeEventListener("scroll",d,!0),removeEventListener("resize",d),p.removeEventListener("toggle",d),p.style.cssText=a}})}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).LiteVuePopover={})}(this,function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var e={top:"top","top-start":"top span-right","top-end":"top span-left",bottom:"bottom","bottom-start":"bottom span-right","bottom-end":"bottom span-left",left:"left","left-start":"left span-bottom","left-end":"left span-top",right:"right","right-start":"right span-bottom","right-end":"right span-top"},o={top:"bottom",bottom:"top",left:"right",right:"left"},s=0,n=(t,e,o)=>{if(!t)return;const s=t.style.getPropertyValue("anchor-name").split(/\s*,\s*/).filter(t=>t&&t!==e);o&&s.push(e),t.style.setProperty("anchor-name",s.join())};t.popover=t=>{t.directive("popover",({el:t,get:e,effect:o,exp:s})=>{const n=t;n.popover||(n.popover="auto");const r=e(`(val) => { ${s} = val }`),i=t=>r("open"===t.newState);return n.addEventListener("toggle",i),o(()=>{const t=!!e();t!==n.matches(":popover-open")&&(t?n.showPopover():n.hidePopover())}),()=>n.removeEventListener("toggle",i)}),t.directive("anchor",({el:t,get:r,effect:i,modifiers:p})=>{const l=t;let f="bottom",a=0;for(const o in p||{}){o in e&&(f=o);const t=/^offset-(\d+)$/.exec(o);t&&(a=+t[1])}const c=l.style.cssText,h=/^(top|bottom)/.test(f);let g;if(l.style.position="fixed",l.style.inset="auto",l.style.margin="0",CSS.supports("anchor-name: --a")){const t="--litevue-anchor-"+ ++s;return l.hasAttribute("popover")||(l.style.position="absolute"),l.style.margin=h?`${a}px 0`:`0 ${a}px`,l.style.setProperty("position-anchor",t),l.style.setProperty("position-area",e[f]),l.style.setProperty("position-try-fallbacks","flip-block, flip-inline"),i(()=>{n(g,t,!1),g=r(),n(g,t,!0)}),()=>{n(g,t,!1),l.style.cssText=c}}const d=()=>{!g||l.popover&&!l.matches(":popover-open")||((t,e,s,n)=>{const[r,i]=s.split("-"),p=e.getBoundingClientRect(),l=t.offsetWidth+n,f=t.offsetHeight+n,a={top:p.top-f,bottom:innerHeight-p.bottom-f,left:p.left-l,right:innerWidth-p.right-l},c=a[r]<0&&a[o[r]]>=0?o[r]:r,h="top"===c||"bottom"===c,[g,d,m]=h?[p.left,p.width,t.offsetWidth]:[p.top,p.height,t.offsetHeight],v="start"===i?g:"end"===i?g+d-m:g+(d-m)/2,y="top"===c?p.top-f:"bottom"===c?p.bottom+n:"left"===c?p.left-l:p.right+n;t.style.left=(h?v:y)+"px",t.style.top=(h?y:v)+"px"})(l,g,f,a)};return i(()=>{g=r(),d()}),addEventListener("scroll",d,!0),addEventListener("resize",d),l.addEventListener("toggle",d),()=>{removeEventListener("scroll",d,!0),removeEventListener("resize",d),l.removeEventListener("toggle",d),l.style.cssText=c}})}});
@@ -0,0 +1,21 @@
1
+ import type { Plugin } from '../../app.mjs';
2
+ /**
3
+ * Same-origin links and forms fetch the next page and morph it into this one,
4
+ * so scopes the two pages share keep their state. Anything it cannot do
5
+ * safely falls back to a full load: a non-HTML response, another origin, a
6
+ * missing target, or different [data-navigate-track] scripts or styles.
7
+ *
8
+ * Needs the morph plugin installed too; it is not bundled, so a page loading
9
+ * both carries one copy. Opt out per region with data-navigate="false".
10
+ */
11
+ export interface NavigateOptions {
12
+ /** Selector of the region to morph. Default `body`. */
13
+ target?: string;
14
+ /** Run each navigation inside `document.startViewTransition()`. */
15
+ transition?: boolean;
16
+ /** Scroll to the top, or the URL's hash, after navigating. Default true. */
17
+ scroll?: boolean;
18
+ /** Fetch a link on hover, focus or pointerdown, ahead of the click. */
19
+ prefetch?: boolean;
20
+ }
21
+ export declare const navigate: Plugin<NavigateOptions>;
@@ -0,0 +1,21 @@
1
+ import type { Plugin } from '../../app';
2
+ /**
3
+ * Same-origin links and forms fetch the next page and morph it into this one,
4
+ * so scopes the two pages share keep their state. Anything it cannot do
5
+ * safely falls back to a full load: a non-HTML response, another origin, a
6
+ * missing target, or different [data-navigate-track] scripts or styles.
7
+ *
8
+ * Needs the morph plugin installed too; it is not bundled, so a page loading
9
+ * both carries one copy. Opt out per region with data-navigate="false".
10
+ */
11
+ export interface NavigateOptions {
12
+ /** Selector of the region to morph. Default `body`. */
13
+ target?: string;
14
+ /** Run each navigation inside `document.startViewTransition()`. */
15
+ transition?: boolean;
16
+ /** Scroll to the top, or the URL's hash, after navigating. Default true. */
17
+ scroll?: boolean;
18
+ /** Fetch a link on hover, focus or pointerdown, ahead of the click. */
19
+ prefetch?: boolean;
20
+ }
21
+ export declare const navigate: Plugin<NavigateOptions>;