@aevantec/litevue 0.5.4 → 0.5.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.
Files changed (53) hide show
  1. package/dist/litevue-devtools.iife.js +1 -1
  2. package/dist/litevue-devtools.mjs +1 -853
  3. package/dist/litevue-devtools.umd.js +1 -1
  4. package/dist/litevue-plugins.iife.js +1 -1
  5. package/dist/litevue-plugins.mjs +1 -717
  6. package/dist/litevue-plugins.umd.js +1 -1
  7. package/dist/litevue.iife.js +1 -12
  8. package/dist/litevue.mjs +1 -1890
  9. package/dist/litevue.umd.js +1 -12
  10. package/dist/plugins/collapse.iife.js +1 -1
  11. package/dist/plugins/collapse.mjs +1 -46
  12. package/dist/plugins/collapse.umd.js +1 -1
  13. package/dist/plugins/focus.iife.js +1 -1
  14. package/dist/plugins/focus.mjs +1 -69
  15. package/dist/plugins/focus.umd.js +1 -1
  16. package/dist/plugins/intersect.iife.js +1 -1
  17. package/dist/plugins/intersect.mjs +1 -20
  18. package/dist/plugins/intersect.umd.js +1 -1
  19. package/dist/plugins/mask.iife.js +1 -1
  20. package/dist/plugins/mask.mjs +1 -37
  21. package/dist/plugins/mask.umd.js +1 -1
  22. package/dist/plugins/media.iife.js +1 -1
  23. package/dist/plugins/media.mjs +1 -204
  24. package/dist/plugins/media.umd.js +1 -1
  25. package/dist/plugins/morph.iife.js +1 -1
  26. package/dist/plugins/morph.mjs +1 -174
  27. package/dist/plugins/morph.umd.js +1 -1
  28. package/dist/plugins/persist.iife.js +1 -1
  29. package/dist/plugins/persist.mjs +1 -86
  30. package/dist/plugins/persist.umd.js +1 -1
  31. package/dist/plugins/resize.iife.js +1 -1
  32. package/dist/plugins/resize.mjs +1 -15
  33. package/dist/plugins/resize.umd.js +1 -1
  34. package/dist/plugins/transition.iife.js +1 -1
  35. package/dist/plugins/transition.mjs +1 -76
  36. package/dist/plugins/transition.umd.js +1 -1
  37. package/dist/types/app.d.mts +30 -2
  38. package/dist/types/app.d.ts +30 -2
  39. package/dist/types/block.d.mts +7 -0
  40. package/dist/types/block.d.ts +7 -0
  41. package/dist/types/context.d.mts +7 -0
  42. package/dist/types/context.d.ts +7 -0
  43. package/dist/types/index.d.mts +1 -1
  44. package/dist/types/index.d.ts +1 -1
  45. package/dist/types/ownership.d.mts +30 -0
  46. package/dist/types/ownership.d.ts +30 -0
  47. package/dist/types/plugins/media/index.d.mts +0 -4
  48. package/dist/types/plugins/media/index.d.ts +0 -4
  49. package/dist/types/scheduler.d.mts +3 -0
  50. package/dist/types/scheduler.d.ts +3 -0
  51. package/dist/types/warn.d.mts +16 -0
  52. package/dist/types/warn.d.ts +16 -0
  53. package/package.json +15 -8
@@ -1,717 +1 @@
1
- import { store, watchEffect, reactive } from '@aevantec/litevue';
2
-
3
- const intersect = (app) => {
4
- app.directive("intersect", ({ el, get, modifiers }) => {
5
- const observer = new IntersectionObserver(
6
- (entries) => {
7
- for (const entry of entries) {
8
- const hit = modifiers?.leave ? !entry.isIntersecting : entry.isIntersecting;
9
- if (hit) {
10
- get();
11
- if (modifiers?.once) observer.disconnect();
12
- }
13
- }
14
- },
15
- { threshold: modifiers?.full ? 1 : 0 }
16
- );
17
- observer.observe(el);
18
- return () => observer.disconnect();
19
- });
20
- };
21
-
22
- const tokens = {
23
- "9": /\d/,
24
- a: /[a-zA-Z]/,
25
- "*": /[a-zA-Z0-9]/
26
- };
27
- const format = (value, mask2) => {
28
- let out = "";
29
- let literals = "";
30
- let vi = 0;
31
- for (let mi = 0; mi < mask2.length; mi++) {
32
- const re = tokens[mask2[mi]];
33
- if (re) {
34
- while (vi < value.length && !re.test(value[vi])) vi++;
35
- if (vi >= value.length) break;
36
- out += literals + value[vi++];
37
- literals = "";
38
- } else {
39
- literals += mask2[mi];
40
- if (value[vi] === mask2[mi]) vi++;
41
- }
42
- }
43
- return out;
44
- };
45
- const mask = (app) => {
46
- app.directive("mask", ({ el, exp }) => {
47
- const input = el;
48
- const apply = () => {
49
- const masked = format(input.value, exp);
50
- if (masked !== input.value) input.value = masked;
51
- };
52
- el.addEventListener("input", apply);
53
- apply();
54
- return () => el.removeEventListener("input", apply);
55
- });
56
- };
57
-
58
- const toMs = (v) => (parseFloat(v) || 0) * (v.includes("ms") ? 1 : 1e3);
59
- const maxOf = (durations, delays) => {
60
- const ds = durations.split(",");
61
- const dl = delays.split(",");
62
- let max = 0;
63
- for (let i = 0; i < ds.length; i++) {
64
- max = Math.max(max, toMs(ds[i]) + toMs(dl[i % dl.length]));
65
- }
66
- return max;
67
- };
68
- const durationOf = (el) => {
69
- const s = getComputedStyle(el);
70
- return Math.max(
71
- maxOf(s.transitionDuration, s.transitionDelay),
72
- maxOf(s.animationDuration, s.animationDelay)
73
- );
74
- };
75
- const transition = (app) => {
76
- app.directive("transition", ({ el, get, effect, arg, modifiers, exp }) => {
77
- const elem = el;
78
- const name = arg || "v";
79
- const cls = (phase) => `${name}-${phase}`;
80
- let seq = 0;
81
- let first = true;
82
- const clear = () => {
83
- elem.classList.remove(
84
- cls("enter-from"),
85
- cls("enter-active"),
86
- cls("enter-to"),
87
- cls("leave-from"),
88
- cls("leave-active"),
89
- cls("leave-to")
90
- );
91
- };
92
- const run = (phase, done) => {
93
- const id = ++seq;
94
- clear();
95
- elem.classList.add(cls(phase + "-from"), cls(phase + "-active"));
96
- void elem.offsetWidth;
97
- elem.classList.remove(cls(phase + "-from"));
98
- elem.classList.add(cls(phase + "-to"));
99
- setTimeout(() => {
100
- if (id === seq) {
101
- clear();
102
- if (done) done();
103
- }
104
- }, durationOf(elem));
105
- };
106
- if (!exp) {
107
- Promise.resolve().then(() => run("enter"));
108
- elem.__leave = () => new Promise((resolve) => run("leave", resolve));
109
- return () => {
110
- delete elem.__leave;
111
- };
112
- }
113
- effect(() => {
114
- const show = !!get();
115
- if (first) {
116
- first = false;
117
- elem.style.display = show ? "" : "none";
118
- if (show && modifiers?.appear) run("enter");
119
- return;
120
- }
121
- if (show) {
122
- elem.style.display = "";
123
- run("enter");
124
- } else {
125
- run("leave", () => {
126
- elem.style.display = "none";
127
- });
128
- }
129
- });
130
- });
131
- };
132
-
133
- const PREFIX = "litevue:";
134
- const registry = /* @__PURE__ */ Object.create(null);
135
- let defaultStorage = "local";
136
- const builtin = (name) => {
137
- try {
138
- if (name === "local" || name === "localStorage") return localStorage;
139
- if (name === "session" || name === "sessionStorage") return sessionStorage;
140
- } catch {
141
- }
142
- };
143
- const resolve$1 = (storage) => {
144
- const target = storage ?? defaultStorage;
145
- if (typeof target !== "string") return target;
146
- return registry[target] ?? builtin(target);
147
- };
148
- const registerStorage = (name, storage) => {
149
- registry[name] = storage;
150
- };
151
- const setDefaultStorage = (storage) => {
152
- defaultStorage = storage;
153
- };
154
- const persistable = (target, keys) => (keys ?? Object.keys(target)).filter((k) => {
155
- if (k[0] === "$") return false;
156
- const desc = Object.getOwnPropertyDescriptor(target, k);
157
- if (desc && desc.get && !desc.set) return false;
158
- const raw = desc && desc.value;
159
- if (raw && raw.__v_isRef === true && raw.__v_isReadonly === true) {
160
- return false;
161
- }
162
- return typeof target[k] !== "function";
163
- });
164
- const sync = (target, key, keys, storage, run) => {
165
- if (!storage) return run(() => {
166
- });
167
- const fields = persistable(target, keys);
168
- try {
169
- const saved = JSON.parse(storage.getItem(key) || "null");
170
- if (saved) {
171
- for (const k of fields) {
172
- if (k in saved) target[k] = saved[k];
173
- }
174
- }
175
- } catch {
176
- }
177
- return run(() => {
178
- const snapshot = {};
179
- for (const k of fields) snapshot[k] = target[k];
180
- try {
181
- storage.setItem(key, JSON.stringify(snapshot));
182
- } catch {
183
- }
184
- });
185
- };
186
- const persist = (app) => {
187
- app.directive("persist", ({ ctx, el, exp, arg, modifiers, effect }) => {
188
- const key = PREFIX + (exp || el.id);
189
- let storage;
190
- for (const name in modifiers || {}) {
191
- if (resolve$1(name)) {
192
- storage = name;
193
- break;
194
- }
195
- }
196
- const keys = arg ? arg.split(",").map((k) => k.trim()).filter(Boolean) : void 0;
197
- sync(ctx.scope, key, keys, resolve$1(storage), effect);
198
- });
199
- };
200
- const persistStore = (name, options = {}) => {
201
- const target = store(name);
202
- if (!target) {
203
- return () => {
204
- };
205
- }
206
- const storage = resolve$1(options.storage);
207
- return sync(
208
- target,
209
- PREFIX + (options.key ?? name),
210
- options.keys,
211
- storage,
212
- watchEffect
213
- );
214
- };
215
-
216
- const FOCUSABLE = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])';
217
- const focus = (app) => {
218
- app.directive("focus", ({ el, get, effect, modifiers }) => {
219
- effect(() => {
220
- const on = !!get();
221
- Promise.resolve().then(() => {
222
- if (on) {
223
- el.focus();
224
- if (modifiers?.select && el.select) {
225
- el.select();
226
- }
227
- }
228
- });
229
- });
230
- });
231
- app.directive("trap", ({ el, get, effect }) => {
232
- let active = false;
233
- let prevFocus = null;
234
- const focusables = () => [...el.querySelectorAll(FOCUSABLE)].filter(
235
- (e) => !e.hasAttribute("disabled")
236
- );
237
- const onKeydown = (e) => {
238
- if (e.key !== "Tab") return;
239
- const els = focusables();
240
- if (!els.length) {
241
- e.preventDefault();
242
- return;
243
- }
244
- const first = els[0];
245
- const last = els[els.length - 1];
246
- const current = document.activeElement;
247
- if (!el.contains(current)) {
248
- e.preventDefault();
249
- first.focus();
250
- } else if (e.shiftKey && current === first) {
251
- e.preventDefault();
252
- last.focus();
253
- } else if (!e.shiftKey && current === last) {
254
- e.preventDefault();
255
- first.focus();
256
- }
257
- };
258
- const release = () => {
259
- active = false;
260
- document.removeEventListener("keydown", onKeydown, true);
261
- if (prevFocus && prevFocus.focus) {
262
- prevFocus.focus();
263
- }
264
- };
265
- effect(() => {
266
- const on = !!get();
267
- if (on && !active) {
268
- active = true;
269
- prevFocus = document.activeElement;
270
- document.addEventListener("keydown", onKeydown, true);
271
- Promise.resolve().then(() => {
272
- if (active) (focusables()[0] || el).focus();
273
- });
274
- } else if (!on && active) {
275
- release();
276
- }
277
- });
278
- return () => {
279
- if (active) release();
280
- };
281
- });
282
- };
283
-
284
- const collapse = (app) => {
285
- app.directive("collapse", ({ el, get, effect, modifiers }) => {
286
- const elem = el;
287
- let duration = 250;
288
- for (const m in modifiers || {}) {
289
- const match = /^duration-(\d+)$/.exec(m);
290
- if (match) duration = +match[1];
291
- }
292
- elem.style.overflow = "hidden";
293
- let first = true;
294
- let seq = 0;
295
- const timers = /* @__PURE__ */ new Set();
296
- const later = (fn, ms) => {
297
- const t = setTimeout(() => {
298
- timers.delete(t);
299
- fn();
300
- }, ms);
301
- timers.add(t);
302
- };
303
- effect(() => {
304
- const show = !!get();
305
- const id = ++seq;
306
- if (first) {
307
- first = false;
308
- if (!show) elem.style.height = "0px";
309
- later(() => {
310
- elem.style.transition = `height ${duration}ms ease`;
311
- });
312
- return;
313
- }
314
- if (show) {
315
- elem.style.height = elem.scrollHeight + "px";
316
- later(() => {
317
- if (id === seq) elem.style.height = "";
318
- }, duration);
319
- } else {
320
- elem.style.height = elem.scrollHeight + "px";
321
- void elem.offsetHeight;
322
- elem.style.height = "0px";
323
- }
324
- });
325
- return () => timers.forEach(clearTimeout);
326
- });
327
- };
328
-
329
- const dirRE = /^(?:v-|:|@)/;
330
- const bindRE = /^(?::|v-bind:)/;
331
- const KEY_ATTRS = ["id", "data-key", "data-id"];
332
- const defaultKey = (el) => {
333
- for (const attr of KEY_ATTRS) {
334
- const value = el.getAttribute(attr);
335
- if (value != null) return attr + "=" + value;
336
- }
337
- return null;
338
- };
339
- const nearestCtx = (node) => {
340
- for (let el = node; el; el = el.parentElement) {
341
- if (el.__ctx) return el.__ctx;
342
- }
343
- };
344
- const boundAttrs = (to) => {
345
- const owned = /* @__PURE__ */ new Set();
346
- for (const { name } of to.attributes) {
347
- if (bindRE.test(name)) {
348
- owned.add(name.replace(bindRE, "").split(".")[0]);
349
- } else if (name === "v-model") {
350
- owned.add("value");
351
- owned.add("checked");
352
- }
353
- }
354
- return owned;
355
- };
356
- const isBlockRoot = (el) => el.hasAttribute("v-for") || el.hasAttribute("v-if") || el.hasAttribute("v-else") || el.hasAttribute("v-else-if");
357
- const ownsChildren = (to) => {
358
- if (to.hasAttribute("v-text") || to.hasAttribute("v-html") || to.hasAttribute("v-pre") || to.hasAttribute("v-once") || isBlockRoot(to)) {
359
- return true;
360
- }
361
- for (let c = to.firstElementChild; c; c = c.nextElementSibling) {
362
- if (isBlockRoot(c)) return true;
363
- }
364
- return false;
365
- };
366
- const patchAttrs = (from, to) => {
367
- const owned = boundAttrs(to);
368
- for (const { name, value } of [...to.attributes]) {
369
- if (dirRE.test(name) || owned.has(name)) continue;
370
- if (from.getAttribute(name) !== value) from.setAttribute(name, value);
371
- }
372
- for (const { name } of [...from.attributes]) {
373
- if (owned.has(name) || to.hasAttribute(name)) continue;
374
- from.removeAttribute(name);
375
- }
376
- };
377
- const isInterpolation = (data, ctx) => data.includes(ctx ? ctx.delimiters[0] : "{{");
378
- const patchNode = (from, to, ctx, opts) => {
379
- if (from.nodeType !== to.nodeType) return replaceNode(from, to, ctx);
380
- if (from.nodeType === 3 || from.nodeType === 8) {
381
- const data = to.data;
382
- if (isInterpolation(data, ctx)) return;
383
- if (from.data !== data) from.data = data;
384
- return;
385
- }
386
- if (from.nodeType !== 1) return;
387
- const a = from;
388
- const b = to;
389
- if (a.tagName !== b.tagName) return replaceNode(from, to, ctx);
390
- if (opts.skip?.(a, b) || a.hasAttribute("data-morph-skip")) return;
391
- patchAttrs(a, b);
392
- if (!ownsChildren(b)) {
393
- patchChildren(a, b, a.__ctx || ctx, opts);
394
- }
395
- };
396
- const replaceNode = (from, to, ctx) => {
397
- const fresh = to.cloneNode(true);
398
- from.parentNode.replaceChild(fresh, from);
399
- mountNew(fresh, ctx);
400
- };
401
- const mountNew = (node, ctx) => {
402
- const target = ctx || nearestCtx(node.parentNode);
403
- target?.walk?.(node, target);
404
- };
405
- const patchChildren = (from, to, ctx, opts) => {
406
- const key = opts.key || defaultKey;
407
- const keyed = /* @__PURE__ */ new Map();
408
- for (let n = from.firstChild; n; n = n.nextSibling) {
409
- if (n.nodeType === 1) {
410
- const k = key(n);
411
- if (k == null) continue;
412
- keyed.set(k, n);
413
- }
414
- }
415
- const keyOf = (n) => n && n.nodeType === 1 ? key(n) : null;
416
- let oldChild = from.firstChild;
417
- let newChild = to.firstChild;
418
- const insert = (node) => {
419
- const fresh = node.cloneNode(true);
420
- from.insertBefore(fresh, oldChild);
421
- mountNew(fresh, ctx);
422
- };
423
- while (newChild) {
424
- const nextNew = newChild.nextSibling;
425
- const wantKey = keyOf(newChild);
426
- if (wantKey != null) {
427
- const match = keyed.get(wantKey);
428
- if (match) {
429
- if (match === oldChild) {
430
- oldChild = oldChild.nextSibling;
431
- } else {
432
- from.insertBefore(match, oldChild);
433
- }
434
- keyed.delete(wantKey);
435
- patchNode(match, newChild, ctx, opts);
436
- } else {
437
- insert(newChild);
438
- }
439
- } else if (oldChild && keyOf(oldChild) == null) {
440
- const nextOld = oldChild.nextSibling;
441
- patchNode(oldChild, newChild, ctx, opts);
442
- oldChild = nextOld;
443
- } else {
444
- insert(newChild);
445
- }
446
- newChild = nextNew;
447
- }
448
- while (oldChild) {
449
- const next = oldChild.nextSibling;
450
- from.removeChild(oldChild);
451
- oldChild = next;
452
- }
453
- };
454
- const morph = (from, to, opts = {}) => {
455
- let target;
456
- if (typeof to === "string") {
457
- const holder = document.createElement("template");
458
- holder.innerHTML = to.trim();
459
- const content = holder.content;
460
- target = content.childElementCount === 1 ? content.firstElementChild : (() => {
461
- const wrapper = from.cloneNode(false);
462
- wrapper.appendChild(content);
463
- return wrapper;
464
- })();
465
- } else {
466
- target = to;
467
- }
468
- if (target) {
469
- const restore = captureFocus();
470
- patchNode(from, target, nearestCtx(from), opts);
471
- restore();
472
- }
473
- return from;
474
- };
475
- const captureFocus = () => {
476
- const active = document.activeElement;
477
- if (!active || active === document.body) return () => {
478
- };
479
- const field = active;
480
- let start = null;
481
- let end = null;
482
- try {
483
- start = field.selectionStart;
484
- end = field.selectionEnd;
485
- } catch {
486
- }
487
- return () => {
488
- if (active === document.activeElement || !active.isConnected) return;
489
- active.focus();
490
- if (start !== null) {
491
- try {
492
- field.setSelectionRange(start, end);
493
- } catch {
494
- }
495
- }
496
- };
497
- };
498
- const morphPlugin = (app) => {
499
- app.scope.$morph = morph;
500
- };
501
-
502
- const DEFAULT_BREAKPOINTS = {
503
- sm: 640,
504
- md: 768,
505
- lg: 1024,
506
- xl: 1280,
507
- "2xl": 1536
508
- };
509
- const defaultBreakpoints = Object.freeze({
510
- ...DEFAULT_BREAKPOINTS
511
- });
512
- const ALIASES = {
513
- mobile: "base",
514
- tablet: "md",
515
- desktop: "lg"
516
- };
517
- const NUMERIC = /^\d+$/;
518
- const state = reactive({ bp: "base", tick: 0 });
519
- let scale = { ...DEFAULT_BREAKPOINTS };
520
- let order = ["base"];
521
- let active = false;
522
- let scaleSubs = [];
523
- const querySubs = /* @__PURE__ */ new Map();
524
- const supported = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
525
- const subscribe = (mql, cb) => {
526
- if (mql.addEventListener) {
527
- mql.addEventListener("change", cb);
528
- return { mql, off: () => mql.removeEventListener("change", cb) };
529
- }
530
- mql.addListener(cb);
531
- return { mql, off: () => mql.removeListener(cb) };
532
- };
533
- const currentBp = () => {
534
- for (let i = scaleSubs.length - 1; i >= 0; i--) {
535
- if (scaleSubs[i].mql.matches) return order[i + 1];
536
- }
537
- return "base";
538
- };
539
- const buildScale = () => {
540
- scaleSubs.forEach((s) => s.off());
541
- scaleSubs = [];
542
- const names = Object.keys(scale).filter((n) => scale[n] > 0).sort((a, b) => scale[a] - scale[b]);
543
- order = ["base", ...names];
544
- if (!supported()) return;
545
- scaleSubs = names.map((name) => {
546
- const mql = window.matchMedia(`(min-width: ${scale[name]}px)`);
547
- return subscribe(mql, () => {
548
- state.bp = currentBp();
549
- });
550
- });
551
- state.bp = currentBp();
552
- };
553
- const activate = () => {
554
- if (active) return;
555
- active = true;
556
- buildScale();
557
- };
558
- const trackAll = () => {
559
- activate();
560
- void state.tick;
561
- };
562
- const rawMatch = (query) => {
563
- if (!supported()) return false;
564
- let sub = querySubs.get(query);
565
- if (!sub) {
566
- const mql = window.matchMedia(query);
567
- sub = subscribe(mql, () => state.tick++);
568
- querySubs.set(query, sub);
569
- }
570
- return sub.mql.matches;
571
- };
572
- const keyToPx = (key) => {
573
- if (typeof key === "number") return key;
574
- if (key === "base") return 0;
575
- if (NUMERIC.test(key)) return Number(key);
576
- const alias = ALIASES[key];
577
- if (alias !== void 0) return alias === "base" ? 0 : scale[alias];
578
- return scale[key];
579
- };
580
- const atLeastPx = (px) => {
581
- if (px <= 0) return true;
582
- const i = order.findIndex((n) => n !== "base" && scale[n] === px);
583
- if (i !== -1) return order.indexOf(state.bp) >= i;
584
- void state.tick;
585
- return rawMatch(`(min-width: ${px}px)`);
586
- };
587
- const warned = /* @__PURE__ */ new Set();
588
- const warnOnce = (msg) => {
589
- return;
590
- };
591
- const resolve = (map, fallback) => {
592
- trackAll();
593
- let best;
594
- let bestPx = -1;
595
- for (const key of Object.keys(map)) {
596
- const px = keyToPx(key);
597
- if (px === void 0) {
598
- warnOnce(
599
- `"${key}" is not a breakpoint. Known: ${order.join(", ")}, plus the aliases ${Object.keys(ALIASES).join(", ")} and raw pixel widths.`
600
- );
601
- continue;
602
- }
603
- if (px >= bestPx && atLeastPx(px)) {
604
- bestPx = px;
605
- best = map[key];
606
- }
607
- }
608
- return best !== void 0 ? best : fallback;
609
- };
610
- const aliasPx = (alias) => {
611
- const name = ALIASES[alias];
612
- const px = scale[name];
613
- if (px !== void 0) return px;
614
- return DEFAULT_BREAKPOINTS[name];
615
- };
616
- const mqFn = (map, fallback) => resolve(map, fallback);
617
- const mq = Object.defineProperties(mqFn, {
618
- props: {
619
- value: (maps) => {
620
- trackAll();
621
- const out = {};
622
- for (const key of Object.keys(maps)) out[key] = resolve(maps[key]);
623
- return out;
624
- }
625
- },
626
- // getters, not methods, so `mq.breakpoint` mirrors `$mqBreakpoint` exactly —
627
- // one shape to remember across markup and script
628
- breakpoint: {
629
- get() {
630
- trackAll();
631
- return state.bp;
632
- },
633
- enumerable: true
634
- },
635
- device: {
636
- get() {
637
- trackAll();
638
- if (!atLeastPx(aliasPx("tablet"))) return "mobile";
639
- return atLeastPx(aliasPx("desktop")) ? "desktop" : "tablet";
640
- },
641
- enumerable: true
642
- },
643
- atLeast: {
644
- value: (key) => {
645
- trackAll();
646
- const px = keyToPx(key);
647
- if (px === void 0) {
648
- return false;
649
- }
650
- return atLeastPx(px);
651
- }
652
- },
653
- match: {
654
- value: (query) => {
655
- trackAll();
656
- return rawMatch(query);
657
- }
658
- },
659
- configure: {
660
- value: ({ breakpoints }) => {
661
- if (!breakpoints) return;
662
- scale = { ...breakpoints };
663
- if (active) {
664
- buildScale();
665
- state.tick++;
666
- }
667
- }
668
- }
669
- });
670
- const resetMedia = () => {
671
- scaleSubs.forEach((s) => s.off());
672
- querySubs.forEach((s) => s.off());
673
- scaleSubs = [];
674
- querySubs.clear();
675
- scale = { ...DEFAULT_BREAKPOINTS };
676
- order = ["base", ...Object.keys(scale).sort((a, b) => scale[a] - scale[b])];
677
- active = false;
678
- warned.clear();
679
- state.bp = "base";
680
- state.tick = 0;
681
- };
682
- const media = (app, options) => {
683
- if (options?.breakpoints) {
684
- JSON.stringify(options.breakpoints);
685
- }
686
- if (options) mq.configure(options);
687
- app.scope.$mq = mq;
688
- app.scope.$mqProps = mq.props;
689
- app.scope.$mqAtLeast = mq.atLeast;
690
- app.scope.$mqMatch = mq.match;
691
- Object.defineProperty(app.scope, "$mqBreakpoint", {
692
- get: () => mq.breakpoint,
693
- enumerable: true,
694
- configurable: true
695
- });
696
- Object.defineProperty(app.scope, "$mqDevice", {
697
- get: () => mq.device,
698
- enumerable: true,
699
- configurable: true
700
- });
701
- };
702
-
703
- const resize = (app) => {
704
- app.directive("resize", ({ el, get, exp }) => {
705
- const handler = get(`(($width, $height) => { ${exp} })`);
706
- const observer = new ResizeObserver((entries) => {
707
- for (const entry of entries) {
708
- const box = entry.contentRect;
709
- handler(box.width, box.height);
710
- }
711
- });
712
- observer.observe(el);
713
- return () => observer.disconnect();
714
- });
715
- };
716
-
717
- export { collapse, defaultBreakpoints, focus, intersect, mask, media, morph, morphPlugin, mq, persist, persistStore, registerStorage, resetMedia, resize, setDefaultStorage, transition };
1
+ import{reactive as e,store as t,watchEffect as n}from"@aevantec/litevue";var r=e=>{e.directive("intersect",({el:e,get:t,modifiers:n})=>{const r=new IntersectionObserver(e=>{for(const o of e)(n?.leave?!o.isIntersecting:o.isIntersecting)&&(t(),n?.once&&r.disconnect())},{threshold:n?.full?1:0});return r.observe(e),()=>r.disconnect()})},o={9:/\d/,a:/[a-zA-Z]/,"*":/[a-zA-Z0-9]/},i=e=>{e.directive("mask",({el:e,exp:t})=>{const n=e,r=()=>{const e=((e,t)=>{let n="",r="",i=0;for(let s=0;s<t.length;s++){const c=o[t[s]];if(c){for(;i<e.length&&!c.test(e[i]);)i++;if(i>=e.length)break;n+=r+e[i++],r=""}else r+=t[s],e[i]===t[s]&&i++}return n})(n.value,t);e!==n.value&&(n.value=e)};return e.addEventListener("input",r),r(),()=>e.removeEventListener("input",r)})},s=e=>(parseFloat(e)||0)*(e.includes("ms")?1:1e3),c=(e,t)=>{const n=e.split(","),r=t.split(",");let o=0;for(let i=0;i<n.length;i++)o=Math.max(o,s(n[i])+s(r[i%r.length]));return o},l=e=>{e.directive("transition",({el:e,get:t,effect:n,arg:r,modifiers:o,exp:i})=>{const s=e,l=r||"v",a=e=>`${l}-${e}`;let f,u=0,d=!0;const m=()=>{s.classList.remove(a("enter-from"),a("enter-active"),a("enter-to"),a("leave-from"),a("leave-active"),a("leave-to"))},p=(e,t)=>{const n=++u;m(),s.classList.add(a(e+"-from"),a(e+"-active")),s.offsetWidth,s.classList.remove(a(e+"-from")),s.classList.add(a(e+"-to")),clearTimeout(f),f=setTimeout(()=>{n===u&&(m(),t&&t())},(e=>{const t=getComputedStyle(e);return Math.max(c(t.transitionDuration,t.transitionDelay),c(t.animationDuration,t.animationDelay))})(s))};if(!i){let e=!0;return Promise.resolve().then(()=>{e&&p("enter")}),s.__leave=()=>new Promise(e=>p("leave",e)),()=>{e=!1,clearTimeout(f),delete s.__leave}}return n(()=>{const e=!!t();if(d)return d=!1,s.style.display=e?"":"none",void(e&&o?.appear&&p("enter"));e?(s.style.display="",p("enter")):p("leave",()=>{s.style.display="none"})}),()=>clearTimeout(f)})},a="litevue:",f=Object.create(null),u="local",d=e=>{const t=e??u;return"string"!=typeof t?t:f[t]??(e=>{try{if("local"===e||"localStorage"===e)return localStorage;if("session"===e||"sessionStorage"===e)return sessionStorage}catch{}})(t)},m=(e,t)=>{f[e]=t},p=e=>{u=e},v=(e,t,n,r,o)=>{if(!r)return o(()=>{});const i=((e,t)=>(t??Object.keys(e)).filter(t=>{if("$"===t[0])return!1;const n=Object.getOwnPropertyDescriptor(e,t);if(n&&n.get&&!n.set)return!1;const r=n&&n.value;return(!r||!0!==r.__v_isRef||!0!==r.__v_isReadonly)&&"function"!=typeof e[t]}))(e,n);try{const n=JSON.parse(r.getItem(t)||"null");if(n)for(const t of i)t in n&&(e[t]=n[t])}catch{}return o(()=>{const n={};for(const t of i)n[t]=e[t];try{r.setItem(t,JSON.stringify(n))}catch{}})},h=e=>{e.directive("persist",({ctx:e,el:t,exp:n,arg:r,modifiers:o,effect:i})=>{const s=a+(n||t.id);let c;for(const a in o||{})if(d(a)){c=a;break}const l=r?r.split(",").map(e=>e.trim()).filter(Boolean):void 0;v(e.scope,s,l,d(c),i)})},b=(e,r={})=>{const o=t(e);if(!o)return()=>{};const i=d(r.storage);return v(o,a+(r.key??e),r.keys,i,n)},g=e=>{e.directive("focus",({el:e,get:t,effect:n,modifiers:r})=>{let o=!0;return n(()=>{const n=!!t();Promise.resolve().then(()=>{o&&n&&(e.focus(),r?.select&&e.select&&e.select())})}),()=>{o=!1}}),e.directive("trap",({el:e,get:t,effect:n})=>{let r=!1,o=null;const i=()=>[...e.querySelectorAll('a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])')].filter(e=>!e.hasAttribute("disabled")),s=t=>{if("Tab"!==t.key)return;const n=i();if(!n.length)return void t.preventDefault();const r=n[0],o=n[n.length-1],s=document.activeElement;e.contains(s)?t.shiftKey&&s===r?(t.preventDefault(),o.focus()):t.shiftKey||s!==o||(t.preventDefault(),r.focus()):(t.preventDefault(),r.focus())},c=()=>{r=!1,document.removeEventListener("keydown",s,!0),o&&o.focus&&o.focus()};return n(()=>{const n=!!t();n&&!r?(r=!0,o=document.activeElement,document.addEventListener("keydown",s,!0),Promise.resolve().then(()=>{r&&(i()[0]||e).focus()})):!n&&r&&c()}),()=>{r&&c()}})},y=e=>{e.directive("collapse",({el:e,get:t,effect:n,modifiers:r})=>{const o=e;let i=250;for(const f in r||{}){const e=/^duration-(\d+)$/.exec(f);e&&(i=+e[1])}o.style.overflow="hidden";let s=!0,c=0;const l=/* @__PURE__ */new Set,a=(e,t)=>{const n=setTimeout(()=>{l.delete(n),e()},t);l.add(n)};return n(()=>{const e=!!t(),n=++c;if(s)return s=!1,e||(o.style.height="0px"),void a(()=>{o.style.transition=`height ${i}ms ease`});e?(o.style.height=o.scrollHeight+"px",a(()=>{n===c&&(o.style.height="")},i)):(o.style.height=o.scrollHeight+"px",o.offsetHeight,o.style.height="0px")}),()=>l.forEach(clearTimeout)})},k=/^(?:v-|:|@)/,x=/^(?::|v-bind:)/,w=["id","data-key","data-id"],E=e=>{for(const t of w){const n=e.getAttribute(t);if(null!=n)return t+"="+n}return null},S=e=>{for(let t=e;t;t=t.parentElement)if(t.__ctx)return t.__ctx},A=e=>e.hasAttribute("v-for")||e.hasAttribute("v-if")||e.hasAttribute("v-else")||e.hasAttribute("v-else-if"),O=(e,t)=>{const n=(e=>{const t=/* @__PURE__ */new Set;for(const{name:n}of e.attributes)x.test(n)?t.add(n.replace(x,"").split(".")[0]):"v-model"===n&&(t.add("value"),t.add("checked"));return t})(t);for(const{name:r,value:o}of[...t.attributes])k.test(r)||n.has(r)||e.getAttribute(r)!==o&&e.setAttribute(r,o);for(const{name:r}of[...e.attributes])n.has(r)||t.hasAttribute(r)||e.removeAttribute(r)},$=(e,t,n,r)=>{if(e.nodeType!==t.nodeType)return L(e,t,n);if(3===e.nodeType||8===e.nodeType){const r=t.data;if(((e,t)=>e.includes(t?t.delimiters[0]:"{{"))(r,n))return;return void(e.data!==r&&(e.data=r))}if(1!==e.nodeType)return;const o=e,i=t;if(o.tagName!==i.tagName)return L(e,t,n);r.skip?.(o,i)||o.hasAttribute("data-morph-skip")||(O(o,i),(e=>{if(e.hasAttribute("v-text")||e.hasAttribute("v-html")||e.hasAttribute("v-pre")||e.hasAttribute("v-once")||A(e))return!0;for(let t=e.firstElementChild;t;t=t.nextElementSibling)if(A(t))return!0;return!1})(i)||T(o,i,o.__ctx||n,r))},L=(e,t,n)=>{const r=t.cloneNode(!0);n?.dispose?.(e),e.parentNode.replaceChild(r,e),_(r,n)},_=(e,t)=>{const n=t||S(e.parentNode);n?.walk?.(e,n)},T=(e,t,n,r)=>{const o=r.key||E,i=/* @__PURE__ */new Map;for(let f=e.firstChild;f;f=f.nextSibling)if(1===f.nodeType){const e=o(f);if(null==e)continue;i.set(e,f)}const s=e=>e&&1===e.nodeType?o(e):null;let c=e.firstChild,l=t.firstChild;const a=t=>{const r=t.cloneNode(!0);e.insertBefore(r,c),_(r,n)};for(;l;){const t=l.nextSibling,o=s(l);if(null!=o){const t=i.get(o);t?(t===c?c=c.nextSibling:e.insertBefore(t,c),i.delete(o),$(t,l,n,r)):a(l)}else if(c&&null==s(c)){const e=c.nextSibling;$(c,l,n,r),c=e}else a(l);l=t}for(;c;){const t=c.nextSibling;n?.dispose?.(c),e.removeChild(c),c=t}},j=(e,t,n={})=>{let r;if("string"==typeof t){const n=document.createElement("template");n.innerHTML=t.trim();const o=n.content;r=1===o.childElementCount?o.firstElementChild:(()=>{const t=e.cloneNode(!1);return t.appendChild(o),t})()}else r=t;if(r){const t=q();$(e,r,S(e),n),t()}return e},q=()=>{const e=document.activeElement;if(!e||e===document.body)return()=>{};const t=e;let n=null,r=null;try{n=t.selectionStart,r=t.selectionEnd}catch{}return()=>{if(e!==document.activeElement&&e.isConnected&&(e.focus(),null!==n))try{t.setSelectionRange(n,r)}catch{}}},C=e=>{e.scope.$morph=j},N={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},D=Object.freeze({...N}),M={mobile:"base",tablet:"md",desktop:"lg"},P=/^\d+$/,I=e({bp:"base",tick:0}),z={...N},R=["base"],B=!1,H=[],J=/* @__PURE__ */new Map,K=()=>"undefined"!=typeof window&&"function"==typeof window.matchMedia,Z=(e,t)=>e.addEventListener?(e.addEventListener("change",t),{mql:e,off:()=>e.removeEventListener("change",t)}):(e.addListener(t),{mql:e,off:()=>e.removeListener(t)}),F=()=>{for(let e=H.length-1;e>=0;e--)if(H[e].mql.matches)return R[e+1];return"base"},W=()=>{H.forEach(e=>e.off()),H=[];const e=Object.keys(z).filter(e=>z[e]>0).sort((e,t)=>z[e]-z[t]);R=["base",...e],K()&&(H=e.map(e=>{const t=window.matchMedia(`(min-width: ${z[e]}px)`);return Z(t,()=>{I.bp=F()})}),I.bp=F())},G=()=>{B||(B=!0,W()),I.tick},Q=e=>{if(!K())return!1;let t=J.get(e);if(!t){const n=window.matchMedia(e);t=Z(n,()=>I.tick++),J.set(e,t)}return t.mql.matches},U=e=>{if("number"==typeof e)return e;if("base"===e)return 0;if(P.test(e))return Number(e);const t=M[e];return void 0!==t?"base"===t?0:z[t]:z[e]},V=e=>{if(e<=0)return!0;const t=R.findIndex(t=>"base"!==t&&z[t]===e);return-1!==t?R.indexOf(I.bp)>=t:(I.tick,Q(`(min-width: ${e}px)`))},X=/* @__PURE__ */new Set,Y=(e,t)=>{let n;G();let r=-1;for(const o of Object.keys(e)){const t=U(o);void 0!==t?t>=r&&V(t)&&(r=t,n=e[o]):(R.join(", "),Object.keys(M).join(", "))}return void 0!==n?n:t},ee=e=>{const t=M[e],n=z[t];return void 0!==n?n:N[t]},te=Object.defineProperties((e,t)=>Y(e,t),{props:{value:e=>{G();const t={};for(const n of Object.keys(e))t[n]=Y(e[n]);return t}},breakpoint:{get:()=>(G(),I.bp),enumerable:!0},device:{get:()=>(G(),V(ee("tablet"))?V(ee("desktop"))?"desktop":"tablet":"mobile"),enumerable:!0},atLeast:{value:e=>{G();const t=U(e);return void 0!==t&&V(t)}},match:{value:e=>(G(),Q(e))},configure:{value:({breakpoints:e})=>{e&&(z={...e},B&&(W(),I.tick++))}}}),ne=()=>{H.forEach(e=>e.off()),J.forEach(e=>e.off()),H=[],J.clear(),B=!1},re=()=>{ne(),z={...N},R=["base",...Object.keys(z).sort((e,t)=>z[e]-z[t])],B=!1,X.clear(),I.bp="base",I.tick=0},oe=(e,t)=>(t?.breakpoints&&JSON.stringify(t.breakpoints),t&&te.configure(t),e.scope.$mq=te,e.scope.$mqProps=te.props,e.scope.$mqAtLeast=te.atLeast,e.scope.$mqMatch=te.match,Object.defineProperty(e.scope,"$mqBreakpoint",{get:()=>te.breakpoint,enumerable:!0,configurable:!0}),Object.defineProperty(e.scope,"$mqDevice",{get:()=>te.device,enumerable:!0,configurable:!0}),ne),ie=e=>{e.directive("resize",({el:e,get:t,exp:n})=>{const r=t(`(($width, $height) => { ${n} })`),o=new ResizeObserver(e=>{for(const t of e){const e=t.contentRect;r(e.width,e.height)}});return o.observe(e),()=>o.disconnect()})};export{y as collapse,D as defaultBreakpoints,g as focus,r as intersect,i as mask,oe as media,j as morph,C as morphPlugin,te as mq,h as persist,b as persistStore,m as registerStorage,re as resetMedia,ie as resize,p as setDefaultStorage,l as transition};