@aevantec/litevue 0.5.2 → 0.5.4

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 (66) hide show
  1. package/README.md +5 -4
  2. package/dist/litevue-devtools.iife.js +1 -1
  3. package/dist/litevue-devtools.mjs +14 -2
  4. package/dist/litevue-devtools.umd.js +1 -1
  5. package/dist/litevue-plugins.iife.js +1 -1
  6. package/dist/litevue-plugins.mjs +409 -8
  7. package/dist/litevue-plugins.umd.js +1 -1
  8. package/dist/litevue.iife.js +2 -2
  9. package/dist/litevue.mjs +126 -17
  10. package/dist/litevue.umd.js +2 -2
  11. package/dist/plugins/collapse.iife.js +1 -0
  12. package/dist/plugins/collapse.mjs +46 -0
  13. package/dist/plugins/collapse.umd.js +1 -0
  14. package/dist/plugins/focus.iife.js +1 -0
  15. package/dist/plugins/focus.mjs +69 -0
  16. package/dist/plugins/focus.umd.js +1 -0
  17. package/dist/plugins/intersect.iife.js +1 -0
  18. package/dist/plugins/intersect.mjs +20 -0
  19. package/dist/plugins/intersect.umd.js +1 -0
  20. package/dist/plugins/mask.iife.js +1 -0
  21. package/dist/plugins/mask.mjs +37 -0
  22. package/dist/plugins/mask.umd.js +1 -0
  23. package/dist/plugins/media.iife.js +1 -0
  24. package/dist/plugins/media.mjs +204 -0
  25. package/dist/plugins/media.umd.js +1 -0
  26. package/dist/plugins/morph.iife.js +1 -0
  27. package/dist/plugins/morph.mjs +174 -0
  28. package/dist/plugins/morph.umd.js +1 -0
  29. package/dist/plugins/persist.iife.js +1 -0
  30. package/dist/plugins/persist.mjs +86 -0
  31. package/dist/plugins/persist.umd.js +1 -0
  32. package/dist/plugins/resize.iife.js +1 -0
  33. package/dist/plugins/resize.mjs +15 -0
  34. package/dist/plugins/resize.umd.js +1 -0
  35. package/dist/plugins/transition.iife.js +1 -0
  36. package/dist/plugins/transition.mjs +76 -0
  37. package/dist/plugins/transition.umd.js +1 -0
  38. package/dist/types/app.d.mts +5 -1
  39. package/dist/types/app.d.ts +5 -1
  40. package/dist/types/context.d.mts +7 -0
  41. package/dist/types/context.d.ts +7 -0
  42. package/dist/types/index.d.mts +2 -1
  43. package/dist/types/index.d.ts +2 -1
  44. package/dist/types/plugins/{collapse.d.mts → collapse/index.d.mts} +1 -1
  45. package/dist/types/plugins/{collapse.d.ts → collapse/index.d.ts} +1 -1
  46. package/dist/types/plugins/{focus.d.mts → focus/index.d.mts} +1 -1
  47. package/dist/types/plugins/{focus.d.ts → focus/index.d.ts} +1 -1
  48. package/dist/types/plugins/index.d.mts +12 -7
  49. package/dist/types/plugins/index.d.ts +5 -0
  50. package/dist/types/plugins/{intersect.d.mts → intersect/index.d.mts} +1 -1
  51. package/dist/types/plugins/{intersect.d.ts → intersect/index.d.ts} +1 -1
  52. package/dist/types/plugins/{mask.d.mts → mask/index.d.mts} +1 -1
  53. package/dist/types/plugins/{mask.d.ts → mask/index.d.ts} +1 -1
  54. package/dist/types/plugins/media/index.d.mts +46 -0
  55. package/dist/types/plugins/media/index.d.ts +46 -0
  56. package/dist/types/plugins/morph/index.d.mts +34 -0
  57. package/dist/types/plugins/morph/index.d.ts +34 -0
  58. package/dist/types/plugins/{persist.d.mts → persist/index.d.mts} +1 -1
  59. package/dist/types/plugins/{persist.d.ts → persist/index.d.ts} +1 -1
  60. package/dist/types/plugins/resize/index.d.mts +12 -0
  61. package/dist/types/plugins/resize/index.d.ts +12 -0
  62. package/dist/types/plugins/{transition.d.mts → transition/index.d.mts} +1 -1
  63. package/dist/types/plugins/{transition.d.ts → transition/index.d.ts} +1 -1
  64. package/dist/types/utils.d.mts +6 -1
  65. package/dist/types/utils.d.ts +6 -1
  66. package/package.json +120 -4
@@ -0,0 +1,204 @@
1
+ import { reactive } from '@aevantec/litevue';
2
+
3
+ const DEFAULT_BREAKPOINTS = {
4
+ sm: 640,
5
+ md: 768,
6
+ lg: 1024,
7
+ xl: 1280,
8
+ "2xl": 1536
9
+ };
10
+ const defaultBreakpoints = Object.freeze({
11
+ ...DEFAULT_BREAKPOINTS
12
+ });
13
+ const ALIASES = {
14
+ mobile: "base",
15
+ tablet: "md",
16
+ desktop: "lg"
17
+ };
18
+ const NUMERIC = /^\d+$/;
19
+ const state = reactive({ bp: "base", tick: 0 });
20
+ let scale = { ...DEFAULT_BREAKPOINTS };
21
+ let order = ["base"];
22
+ let active = false;
23
+ let scaleSubs = [];
24
+ const querySubs = /* @__PURE__ */ new Map();
25
+ const supported = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
26
+ const subscribe = (mql, cb) => {
27
+ if (mql.addEventListener) {
28
+ mql.addEventListener("change", cb);
29
+ return { mql, off: () => mql.removeEventListener("change", cb) };
30
+ }
31
+ mql.addListener(cb);
32
+ return { mql, off: () => mql.removeListener(cb) };
33
+ };
34
+ const currentBp = () => {
35
+ for (let i = scaleSubs.length - 1; i >= 0; i--) {
36
+ if (scaleSubs[i].mql.matches) return order[i + 1];
37
+ }
38
+ return "base";
39
+ };
40
+ const buildScale = () => {
41
+ scaleSubs.forEach((s) => s.off());
42
+ scaleSubs = [];
43
+ const names = Object.keys(scale).filter((n) => scale[n] > 0).sort((a, b) => scale[a] - scale[b]);
44
+ order = ["base", ...names];
45
+ if (!supported()) return;
46
+ scaleSubs = names.map((name) => {
47
+ const mql = window.matchMedia(`(min-width: ${scale[name]}px)`);
48
+ return subscribe(mql, () => {
49
+ state.bp = currentBp();
50
+ });
51
+ });
52
+ state.bp = currentBp();
53
+ };
54
+ const activate = () => {
55
+ if (active) return;
56
+ active = true;
57
+ buildScale();
58
+ };
59
+ const trackAll = () => {
60
+ activate();
61
+ void state.tick;
62
+ };
63
+ const rawMatch = (query) => {
64
+ if (!supported()) return false;
65
+ let sub = querySubs.get(query);
66
+ if (!sub) {
67
+ const mql = window.matchMedia(query);
68
+ sub = subscribe(mql, () => state.tick++);
69
+ querySubs.set(query, sub);
70
+ }
71
+ return sub.mql.matches;
72
+ };
73
+ const keyToPx = (key) => {
74
+ if (typeof key === "number") return key;
75
+ if (key === "base") return 0;
76
+ if (NUMERIC.test(key)) return Number(key);
77
+ const alias = ALIASES[key];
78
+ if (alias !== void 0) return alias === "base" ? 0 : scale[alias];
79
+ return scale[key];
80
+ };
81
+ const atLeastPx = (px) => {
82
+ if (px <= 0) return true;
83
+ const i = order.findIndex((n) => n !== "base" && scale[n] === px);
84
+ if (i !== -1) return order.indexOf(state.bp) >= i;
85
+ void state.tick;
86
+ return rawMatch(`(min-width: ${px}px)`);
87
+ };
88
+ const warned = /* @__PURE__ */ new Set();
89
+ const warnOnce = (msg) => {
90
+ return;
91
+ };
92
+ const resolve = (map, fallback) => {
93
+ trackAll();
94
+ let best;
95
+ let bestPx = -1;
96
+ for (const key of Object.keys(map)) {
97
+ const px = keyToPx(key);
98
+ if (px === void 0) {
99
+ warnOnce(
100
+ `"${key}" is not a breakpoint. Known: ${order.join(", ")}, plus the aliases ${Object.keys(ALIASES).join(", ")} and raw pixel widths.`
101
+ );
102
+ continue;
103
+ }
104
+ if (px >= bestPx && atLeastPx(px)) {
105
+ bestPx = px;
106
+ best = map[key];
107
+ }
108
+ }
109
+ return best !== void 0 ? best : fallback;
110
+ };
111
+ const aliasPx = (alias) => {
112
+ const name = ALIASES[alias];
113
+ const px = scale[name];
114
+ if (px !== void 0) return px;
115
+ return DEFAULT_BREAKPOINTS[name];
116
+ };
117
+ const mqFn = (map, fallback) => resolve(map, fallback);
118
+ const mq = Object.defineProperties(mqFn, {
119
+ props: {
120
+ value: (maps) => {
121
+ trackAll();
122
+ const out = {};
123
+ for (const key of Object.keys(maps)) out[key] = resolve(maps[key]);
124
+ return out;
125
+ }
126
+ },
127
+ // getters, not methods, so `mq.breakpoint` mirrors `$mqBreakpoint` exactly —
128
+ // one shape to remember across markup and script
129
+ breakpoint: {
130
+ get() {
131
+ trackAll();
132
+ return state.bp;
133
+ },
134
+ enumerable: true
135
+ },
136
+ device: {
137
+ get() {
138
+ trackAll();
139
+ if (!atLeastPx(aliasPx("tablet"))) return "mobile";
140
+ return atLeastPx(aliasPx("desktop")) ? "desktop" : "tablet";
141
+ },
142
+ enumerable: true
143
+ },
144
+ atLeast: {
145
+ value: (key) => {
146
+ trackAll();
147
+ const px = keyToPx(key);
148
+ if (px === void 0) {
149
+ return false;
150
+ }
151
+ return atLeastPx(px);
152
+ }
153
+ },
154
+ match: {
155
+ value: (query) => {
156
+ trackAll();
157
+ return rawMatch(query);
158
+ }
159
+ },
160
+ configure: {
161
+ value: ({ breakpoints }) => {
162
+ if (!breakpoints) return;
163
+ scale = { ...breakpoints };
164
+ if (active) {
165
+ buildScale();
166
+ state.tick++;
167
+ }
168
+ }
169
+ }
170
+ });
171
+ const resetMedia = () => {
172
+ scaleSubs.forEach((s) => s.off());
173
+ querySubs.forEach((s) => s.off());
174
+ scaleSubs = [];
175
+ querySubs.clear();
176
+ scale = { ...DEFAULT_BREAKPOINTS };
177
+ order = ["base", ...Object.keys(scale).sort((a, b) => scale[a] - scale[b])];
178
+ active = false;
179
+ warned.clear();
180
+ state.bp = "base";
181
+ state.tick = 0;
182
+ };
183
+ const media = (app, options) => {
184
+ if (options?.breakpoints) {
185
+ JSON.stringify(options.breakpoints);
186
+ }
187
+ if (options) mq.configure(options);
188
+ app.scope.$mq = mq;
189
+ app.scope.$mqProps = mq.props;
190
+ app.scope.$mqAtLeast = mq.atLeast;
191
+ app.scope.$mqMatch = mq.match;
192
+ Object.defineProperty(app.scope, "$mqBreakpoint", {
193
+ get: () => mq.breakpoint,
194
+ enumerable: true,
195
+ configurable: true
196
+ });
197
+ Object.defineProperty(app.scope, "$mqDevice", {
198
+ get: () => mq.device,
199
+ enumerable: true,
200
+ configurable: true
201
+ });
202
+ };
203
+
204
+ export { defaultBreakpoints, media, mq, resetMedia };
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@aevantec/litevue")):"function"==typeof define&&define.amd?define(["exports","@aevantec/litevue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LiteVueMedia={},e.LiteVue)}(this,function(e,t){"use strict";const n={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},o=Object.freeze({...n}),r={mobile:"base",tablet:"md",desktop:"lg"},i=/^\d+$/,a=t.reactive({bp:"base",tick:0});let s={...n},c=["base"],f=!1,d=[];const b=new Map,u=()=>"undefined"!=typeof window&&"function"==typeof window.matchMedia,p=(e,t)=>e.addEventListener?(e.addEventListener("change",t),{mql:e,off:()=>e.removeEventListener("change",t)}):(e.addListener(t),{mql:e,off:()=>e.removeListener(t)}),l=()=>{for(let e=d.length-1;e>=0;e--)if(d[e].mql.matches)return c[e+1];return"base"},m=()=>{d.forEach(e=>e.off()),d=[];const e=Object.keys(s).filter(e=>s[e]>0).sort((e,t)=>s[e]-s[t]);c=["base",...e],u()&&(d=e.map(e=>{const t=window.matchMedia(`(min-width: ${s[e]}px)`);return p(t,()=>{a.bp=l()})}),a.bp=l())},v=()=>{f||(f=!0,m()),a.tick},k=e=>{if(!u())return!1;let t=b.get(e);if(!t){const n=window.matchMedia(e);t=p(n,()=>a.tick++),b.set(e,t)}return t.mql.matches},g=e=>{if("number"==typeof e)return e;if("base"===e)return 0;if(i.test(e))return Number(e);const t=r[e];return void 0!==t?"base"===t?0:s[t]:s[e]},h=e=>{if(e<=0)return!0;const t=c.findIndex(t=>"base"!==t&&s[t]===e);return-1!==t?c.indexOf(a.bp)>=t:(a.tick,k(`(min-width: ${e}px)`))},y=new Set,j=e=>{},q=(e,t)=>{let n;v();let o=-1;for(const i of Object.keys(e)){const t=g(i);void 0!==t?t>=o&&h(t)&&(o=t,n=e[i]):j((c.join(", "),Object.keys(r).join(", ")))}return void 0!==n?n:t},w=e=>{const t=r[e],o=s[t];return void 0!==o?o:n[t]},O=Object.defineProperties((e,t)=>q(e,t),{props:{value:e=>{v();const t={};for(const n of Object.keys(e))t[n]=q(e[n]);return t}},breakpoint:{get:()=>(v(),a.bp),enumerable:!0},device:{get:()=>(v(),h(w("tablet"))?h(w("desktop"))?"desktop":"tablet":"mobile"),enumerable:!0},atLeast:{value:e=>{v();const t=g(e);return void 0!==t&&h(t)}},match:{value:e=>(v(),k(e))},configure:{value:({breakpoints:e})=>{e&&(s={...e},f&&(m(),a.tick++))}}});e.defaultBreakpoints=o,e.media=(e,t)=>{t?.breakpoints&&JSON.stringify(t.breakpoints),t&&O.configure(t),e.scope.$mq=O,e.scope.$mqProps=O.props,e.scope.$mqAtLeast=O.atLeast,e.scope.$mqMatch=O.match,Object.defineProperty(e.scope,"$mqBreakpoint",{get:()=>O.breakpoint,enumerable:!0,configurable:!0}),Object.defineProperty(e.scope,"$mqDevice",{get:()=>O.device,enumerable:!0,configurable:!0})},e.mq=O,e.resetMedia=()=>{d.forEach(e=>e.off()),b.forEach(e=>e.off()),d=[],b.clear(),s={...n},c=["base",...Object.keys(s).sort((e,t)=>s[e]-s[t])],f=!1,y.clear(),a.bp="base",a.tick=0},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ var LiteVueMorph=function(t){"use strict";const e=/^(?:v-|:|@)/,n=/^(?::|v-bind:)/,r=["id","data-key","data-id"],i=t=>{for(const e of r){const n=t.getAttribute(e);if(null!=n)return e+"="+n}return null},o=t=>{for(let e=t;e;e=e.parentElement)if(e.__ctx)return e.__ctx},l=t=>t.hasAttribute("v-for")||t.hasAttribute("v-if")||t.hasAttribute("v-else")||t.hasAttribute("v-else-if"),s=(t,r)=>{const i=(t=>{const e=new Set;for(const{name:r}of t.attributes)n.test(r)?e.add(r.replace(n,"").split(".")[0]):"v-model"===r&&(e.add("value"),e.add("checked"));return e})(r);for(const{name:n,value:o}of[...r.attributes])e.test(n)||i.has(n)||t.getAttribute(n)!==o&&t.setAttribute(n,o);for(const{name:e}of[...t.attributes])i.has(e)||r.hasAttribute(e)||t.removeAttribute(e)},c=(t,e,n,r)=>{if(t.nodeType!==e.nodeType)return u(t,e,n);if(3===t.nodeType||8===t.nodeType){const r=e.data;if(((t,e)=>t.includes(e?e.delimiters[0]:"{{"))(r,n))return;return void(t.data!==r&&(t.data=r))}if(1!==t.nodeType)return;const i=t,o=e;if(i.tagName!==o.tagName)return u(t,e,n);r.skip?.(i,o)||i.hasAttribute("data-morph-skip")||(s(i,o),(t=>{if(t.hasAttribute("v-text")||t.hasAttribute("v-html")||t.hasAttribute("v-pre")||t.hasAttribute("v-once")||l(t))return!0;for(let e=t.firstElementChild;e;e=e.nextElementSibling)if(l(e))return!0;return!1})(o)||d(i,o,i.__ctx||n,r))},u=(t,e,n)=>{const r=e.cloneNode(!0);t.parentNode.replaceChild(r,t),a(r,n)},a=(t,e)=>{const n=e||o(t.parentNode);n?.walk?.(t,n)},d=(t,e,n,r)=>{const o=r.key||i,l=new Map;for(let i=t.firstChild;i;i=i.nextSibling)if(1===i.nodeType){const t=o(i);if(null==t)continue;l.set(t,i)}const s=t=>t&&1===t.nodeType?o(t):null;let u=t.firstChild,d=e.firstChild;const f=e=>{const r=e.cloneNode(!0);t.insertBefore(r,u),a(r,n)};for(;d;){const e=d.nextSibling,i=s(d);if(null!=i){const e=l.get(i);e?(e===u?u=u.nextSibling:t.insertBefore(e,u),l.delete(i),c(e,d,n,r)):f(d)}else if(u&&null==s(u)){const t=u.nextSibling;c(u,d,n,r),u=t}else f(d);d=e}for(;u;){const e=u.nextSibling;t.removeChild(u),u=e}},f=(t,e,n={})=>{let r;if("string"==typeof e){const n=document.createElement("template");n.innerHTML=e.trim();const i=n.content;r=1===i.childElementCount?i.firstElementChild:(()=>{const e=t.cloneNode(!1);return e.appendChild(i),e})()}else r=e;if(r){const e=h();c(t,r,o(t),n),e()}return t},h=()=>{const t=document.activeElement;if(!t||t===document.body)return()=>{};const e=t;let n=null,r=null;try{n=e.selectionStart,r=e.selectionEnd}catch{}return()=>{if(t!==document.activeElement&&t.isConnected&&(t.focus(),null!==n))try{e.setSelectionRange(n,r)}catch{}}};return t.morph=f,t.morphPlugin=t=>{t.scope.$morph=f},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});
@@ -0,0 +1,174 @@
1
+ const dirRE = /^(?:v-|:|@)/;
2
+ const bindRE = /^(?::|v-bind:)/;
3
+ const KEY_ATTRS = ["id", "data-key", "data-id"];
4
+ const defaultKey = (el) => {
5
+ for (const attr of KEY_ATTRS) {
6
+ const value = el.getAttribute(attr);
7
+ if (value != null) return attr + "=" + value;
8
+ }
9
+ return null;
10
+ };
11
+ const nearestCtx = (node) => {
12
+ for (let el = node; el; el = el.parentElement) {
13
+ if (el.__ctx) return el.__ctx;
14
+ }
15
+ };
16
+ const boundAttrs = (to) => {
17
+ const owned = /* @__PURE__ */ new Set();
18
+ for (const { name } of to.attributes) {
19
+ if (bindRE.test(name)) {
20
+ owned.add(name.replace(bindRE, "").split(".")[0]);
21
+ } else if (name === "v-model") {
22
+ owned.add("value");
23
+ owned.add("checked");
24
+ }
25
+ }
26
+ return owned;
27
+ };
28
+ const isBlockRoot = (el) => el.hasAttribute("v-for") || el.hasAttribute("v-if") || el.hasAttribute("v-else") || el.hasAttribute("v-else-if");
29
+ const ownsChildren = (to) => {
30
+ if (to.hasAttribute("v-text") || to.hasAttribute("v-html") || to.hasAttribute("v-pre") || to.hasAttribute("v-once") || isBlockRoot(to)) {
31
+ return true;
32
+ }
33
+ for (let c = to.firstElementChild; c; c = c.nextElementSibling) {
34
+ if (isBlockRoot(c)) return true;
35
+ }
36
+ return false;
37
+ };
38
+ const patchAttrs = (from, to) => {
39
+ const owned = boundAttrs(to);
40
+ for (const { name, value } of [...to.attributes]) {
41
+ if (dirRE.test(name) || owned.has(name)) continue;
42
+ if (from.getAttribute(name) !== value) from.setAttribute(name, value);
43
+ }
44
+ for (const { name } of [...from.attributes]) {
45
+ if (owned.has(name) || to.hasAttribute(name)) continue;
46
+ from.removeAttribute(name);
47
+ }
48
+ };
49
+ const isInterpolation = (data, ctx) => data.includes(ctx ? ctx.delimiters[0] : "{{");
50
+ const patchNode = (from, to, ctx, opts) => {
51
+ if (from.nodeType !== to.nodeType) return replaceNode(from, to, ctx);
52
+ if (from.nodeType === 3 || from.nodeType === 8) {
53
+ const data = to.data;
54
+ if (isInterpolation(data, ctx)) return;
55
+ if (from.data !== data) from.data = data;
56
+ return;
57
+ }
58
+ if (from.nodeType !== 1) return;
59
+ const a = from;
60
+ const b = to;
61
+ if (a.tagName !== b.tagName) return replaceNode(from, to, ctx);
62
+ if (opts.skip?.(a, b) || a.hasAttribute("data-morph-skip")) return;
63
+ patchAttrs(a, b);
64
+ if (!ownsChildren(b)) {
65
+ patchChildren(a, b, a.__ctx || ctx, opts);
66
+ }
67
+ };
68
+ const replaceNode = (from, to, ctx) => {
69
+ const fresh = to.cloneNode(true);
70
+ from.parentNode.replaceChild(fresh, from);
71
+ mountNew(fresh, ctx);
72
+ };
73
+ const mountNew = (node, ctx) => {
74
+ const target = ctx || nearestCtx(node.parentNode);
75
+ target?.walk?.(node, target);
76
+ };
77
+ const patchChildren = (from, to, ctx, opts) => {
78
+ const key = opts.key || defaultKey;
79
+ const keyed = /* @__PURE__ */ new Map();
80
+ for (let n = from.firstChild; n; n = n.nextSibling) {
81
+ if (n.nodeType === 1) {
82
+ const k = key(n);
83
+ if (k == null) continue;
84
+ keyed.set(k, n);
85
+ }
86
+ }
87
+ const keyOf = (n) => n && n.nodeType === 1 ? key(n) : null;
88
+ let oldChild = from.firstChild;
89
+ let newChild = to.firstChild;
90
+ const insert = (node) => {
91
+ const fresh = node.cloneNode(true);
92
+ from.insertBefore(fresh, oldChild);
93
+ mountNew(fresh, ctx);
94
+ };
95
+ while (newChild) {
96
+ const nextNew = newChild.nextSibling;
97
+ const wantKey = keyOf(newChild);
98
+ if (wantKey != null) {
99
+ const match = keyed.get(wantKey);
100
+ if (match) {
101
+ if (match === oldChild) {
102
+ oldChild = oldChild.nextSibling;
103
+ } else {
104
+ from.insertBefore(match, oldChild);
105
+ }
106
+ keyed.delete(wantKey);
107
+ patchNode(match, newChild, ctx, opts);
108
+ } else {
109
+ insert(newChild);
110
+ }
111
+ } else if (oldChild && keyOf(oldChild) == null) {
112
+ const nextOld = oldChild.nextSibling;
113
+ patchNode(oldChild, newChild, ctx, opts);
114
+ oldChild = nextOld;
115
+ } else {
116
+ insert(newChild);
117
+ }
118
+ newChild = nextNew;
119
+ }
120
+ while (oldChild) {
121
+ const next = oldChild.nextSibling;
122
+ from.removeChild(oldChild);
123
+ oldChild = next;
124
+ }
125
+ };
126
+ const morph = (from, to, opts = {}) => {
127
+ let target;
128
+ if (typeof to === "string") {
129
+ const holder = document.createElement("template");
130
+ holder.innerHTML = to.trim();
131
+ const content = holder.content;
132
+ target = content.childElementCount === 1 ? content.firstElementChild : (() => {
133
+ const wrapper = from.cloneNode(false);
134
+ wrapper.appendChild(content);
135
+ return wrapper;
136
+ })();
137
+ } else {
138
+ target = to;
139
+ }
140
+ if (target) {
141
+ const restore = captureFocus();
142
+ patchNode(from, target, nearestCtx(from), opts);
143
+ restore();
144
+ }
145
+ return from;
146
+ };
147
+ const captureFocus = () => {
148
+ const active = document.activeElement;
149
+ if (!active || active === document.body) return () => {
150
+ };
151
+ const field = active;
152
+ let start = null;
153
+ let end = null;
154
+ try {
155
+ start = field.selectionStart;
156
+ end = field.selectionEnd;
157
+ } catch {
158
+ }
159
+ return () => {
160
+ if (active === document.activeElement || !active.isConnected) return;
161
+ active.focus();
162
+ if (start !== null) {
163
+ try {
164
+ field.setSelectionRange(start, end);
165
+ } catch {
166
+ }
167
+ }
168
+ };
169
+ };
170
+ const morphPlugin = (app) => {
171
+ app.scope.$morph = morph;
172
+ };
173
+
174
+ export { morph, morphPlugin };
@@ -0,0 +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).LiteVueMorph={})}(this,function(t){"use strict";const e=/^(?:v-|:|@)/,n=/^(?::|v-bind:)/,o=["id","data-key","data-id"],i=t=>{for(const e of o){const n=t.getAttribute(e);if(null!=n)return e+"="+n}return null},r=t=>{for(let e=t;e;e=e.parentElement)if(e.__ctx)return e.__ctx},l=t=>t.hasAttribute("v-for")||t.hasAttribute("v-if")||t.hasAttribute("v-else")||t.hasAttribute("v-else-if"),s=(t,o)=>{const i=(t=>{const e=new Set;for(const{name:o}of t.attributes)n.test(o)?e.add(o.replace(n,"").split(".")[0]):"v-model"===o&&(e.add("value"),e.add("checked"));return e})(o);for(const{name:n,value:r}of[...o.attributes])e.test(n)||i.has(n)||t.getAttribute(n)!==r&&t.setAttribute(n,r);for(const{name:e}of[...t.attributes])i.has(e)||o.hasAttribute(e)||t.removeAttribute(e)},c=(t,e,n,o)=>{if(t.nodeType!==e.nodeType)return u(t,e,n);if(3===t.nodeType||8===t.nodeType){const o=e.data;if(((t,e)=>t.includes(e?e.delimiters[0]:"{{"))(o,n))return;return void(t.data!==o&&(t.data=o))}if(1!==t.nodeType)return;const i=t,r=e;if(i.tagName!==r.tagName)return u(t,e,n);o.skip?.(i,r)||i.hasAttribute("data-morph-skip")||(s(i,r),(t=>{if(t.hasAttribute("v-text")||t.hasAttribute("v-html")||t.hasAttribute("v-pre")||t.hasAttribute("v-once")||l(t))return!0;for(let e=t.firstElementChild;e;e=e.nextElementSibling)if(l(e))return!0;return!1})(r)||a(i,r,i.__ctx||n,o))},u=(t,e,n)=>{const o=e.cloneNode(!0);t.parentNode.replaceChild(o,t),d(o,n)},d=(t,e)=>{const n=e||r(t.parentNode);n?.walk?.(t,n)},a=(t,e,n,o)=>{const r=o.key||i,l=new Map;for(let i=t.firstChild;i;i=i.nextSibling)if(1===i.nodeType){const t=r(i);if(null==t)continue;l.set(t,i)}const s=t=>t&&1===t.nodeType?r(t):null;let u=t.firstChild,a=e.firstChild;const f=e=>{const o=e.cloneNode(!0);t.insertBefore(o,u),d(o,n)};for(;a;){const e=a.nextSibling,i=s(a);if(null!=i){const e=l.get(i);e?(e===u?u=u.nextSibling:t.insertBefore(e,u),l.delete(i),c(e,a,n,o)):f(a)}else if(u&&null==s(u)){const t=u.nextSibling;c(u,a,n,o),u=t}else f(a);a=e}for(;u;){const e=u.nextSibling;t.removeChild(u),u=e}},f=(t,e,n={})=>{let o;if("string"==typeof e){const n=document.createElement("template");n.innerHTML=e.trim();const i=n.content;o=1===i.childElementCount?i.firstElementChild:(()=>{const e=t.cloneNode(!1);return e.appendChild(i),e})()}else o=e;if(o){const e=p();c(t,o,r(t),n),e()}return t},p=()=>{const t=document.activeElement;if(!t||t===document.body)return()=>{};const e=t;let n=null,o=null;try{n=e.selectionStart,o=e.selectionEnd}catch{}return()=>{if(t!==document.activeElement&&t.isConnected&&(t.focus(),null!==n))try{e.setSelectionRange(n,o)}catch{}}};t.morph=f,t.morphPlugin=t=>{t.scope.$morph=f},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ var LiteVuePersist=function(t,e){"use strict";const r="litevue:",o=Object.create(null);let s="local";const n=t=>{const e=t??s;return"string"!=typeof e?e:o[e]??(t=>{try{if("local"===t||"localStorage"===t)return localStorage;if("session"===t||"sessionStorage"===t)return sessionStorage}catch{}})(e)},i=(t,e,r,o,s)=>{if(!o)return s(()=>{});const n=((t,e)=>(e??Object.keys(t)).filter(e=>{if("$"===e[0])return!1;const r=Object.getOwnPropertyDescriptor(t,e);if(r&&r.get&&!r.set)return!1;const o=r&&r.value;return(!o||!0!==o.__v_isRef||!0!==o.__v_isReadonly)&&"function"!=typeof t[e]}))(t,r);try{const r=JSON.parse(o.getItem(e)||"null");if(r)for(const e of n)e in r&&(t[e]=r[e])}catch{}return s(()=>{const r={};for(const e of n)r[e]=t[e];try{o.setItem(e,JSON.stringify(r))}catch{}})};return t.persist=t=>{t.directive("persist",({ctx:t,el:e,exp:o,arg:s,modifiers:c,effect:f})=>{const a=r+(o||e.id);let l;for(const r in c||{})if(n(r)){l=r;break}const u=s?s.split(",").map(t=>t.trim()).filter(Boolean):void 0;i(t.scope,a,u,n(l),f)})},t.persistStore=(t,o={})=>{const s=e.store(t);if(!s)return()=>{};const c=n(o.storage);return i(s,r+(o.key??t),o.keys,c,e.watchEffect)},t.registerStorage=(t,e)=>{o[t]=e},t.setDefaultStorage=t=>{s=t},Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({},LiteVue);
@@ -0,0 +1,86 @@
1
+ import { store, watchEffect } from '@aevantec/litevue';
2
+
3
+ const PREFIX = "litevue:";
4
+ const registry = /* @__PURE__ */ Object.create(null);
5
+ let defaultStorage = "local";
6
+ const builtin = (name) => {
7
+ try {
8
+ if (name === "local" || name === "localStorage") return localStorage;
9
+ if (name === "session" || name === "sessionStorage") return sessionStorage;
10
+ } catch {
11
+ }
12
+ };
13
+ const resolve = (storage) => {
14
+ const target = storage ?? defaultStorage;
15
+ if (typeof target !== "string") return target;
16
+ return registry[target] ?? builtin(target);
17
+ };
18
+ const registerStorage = (name, storage) => {
19
+ registry[name] = storage;
20
+ };
21
+ const setDefaultStorage = (storage) => {
22
+ defaultStorage = storage;
23
+ };
24
+ const persistable = (target, keys) => (keys ?? Object.keys(target)).filter((k) => {
25
+ if (k[0] === "$") return false;
26
+ const desc = Object.getOwnPropertyDescriptor(target, k);
27
+ if (desc && desc.get && !desc.set) return false;
28
+ const raw = desc && desc.value;
29
+ if (raw && raw.__v_isRef === true && raw.__v_isReadonly === true) {
30
+ return false;
31
+ }
32
+ return typeof target[k] !== "function";
33
+ });
34
+ const sync = (target, key, keys, storage, run) => {
35
+ if (!storage) return run(() => {
36
+ });
37
+ const fields = persistable(target, keys);
38
+ try {
39
+ const saved = JSON.parse(storage.getItem(key) || "null");
40
+ if (saved) {
41
+ for (const k of fields) {
42
+ if (k in saved) target[k] = saved[k];
43
+ }
44
+ }
45
+ } catch {
46
+ }
47
+ return run(() => {
48
+ const snapshot = {};
49
+ for (const k of fields) snapshot[k] = target[k];
50
+ try {
51
+ storage.setItem(key, JSON.stringify(snapshot));
52
+ } catch {
53
+ }
54
+ });
55
+ };
56
+ const persist = (app) => {
57
+ app.directive("persist", ({ ctx, el, exp, arg, modifiers, effect }) => {
58
+ const key = PREFIX + (exp || el.id);
59
+ let storage;
60
+ for (const name in modifiers || {}) {
61
+ if (resolve(name)) {
62
+ storage = name;
63
+ break;
64
+ }
65
+ }
66
+ const keys = arg ? arg.split(",").map((k) => k.trim()).filter(Boolean) : void 0;
67
+ sync(ctx.scope, key, keys, resolve(storage), effect);
68
+ });
69
+ };
70
+ const persistStore = (name, options = {}) => {
71
+ const target = store(name);
72
+ if (!target) {
73
+ return () => {
74
+ };
75
+ }
76
+ const storage = resolve(options.storage);
77
+ return sync(
78
+ target,
79
+ PREFIX + (options.key ?? name),
80
+ options.keys,
81
+ storage,
82
+ watchEffect
83
+ );
84
+ };
85
+
86
+ export { persist, persistStore, registerStorage, setDefaultStorage };
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@aevantec/litevue")):"function"==typeof define&&define.amd?define(["exports","@aevantec/litevue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LiteVuePersist={},e.LiteVue)}(this,function(e,t){"use strict";const o="litevue:",r=Object.create(null);let s="local";const n=e=>{const t=e??s;return"string"!=typeof t?t:r[t]??(e=>{try{if("local"===e||"localStorage"===e)return localStorage;if("session"===e||"sessionStorage"===e)return sessionStorage}catch{}})(t)},i=(e,t,o,r,s)=>{if(!r)return s(()=>{});const n=((e,t)=>(t??Object.keys(e)).filter(t=>{if("$"===t[0])return!1;const o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get&&!o.set)return!1;const r=o&&o.value;return(!r||!0!==r.__v_isRef||!0!==r.__v_isReadonly)&&"function"!=typeof e[t]}))(e,o);try{const o=JSON.parse(r.getItem(t)||"null");if(o)for(const t of n)t in o&&(e[t]=o[t])}catch{}return s(()=>{const o={};for(const t of n)o[t]=e[t];try{r.setItem(t,JSON.stringify(o))}catch{}})};e.persist=e=>{e.directive("persist",({ctx:e,el:t,exp:r,arg:s,modifiers:c,effect:f})=>{const l=o+(r||t.id);let a;for(const o in c||{})if(n(o)){a=o;break}const u=s?s.split(",").map(e=>e.trim()).filter(Boolean):void 0;i(e.scope,l,u,n(a),f)})},e.persistStore=(e,r={})=>{const s=t.store(e);if(!s)return()=>{};const c=n(r.storage);return i(s,o+(r.key??e),r.keys,c,t.watchEffect)},e.registerStorage=(e,t)=>{r[e]=t},e.setDefaultStorage=e=>{s=e},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ var LiteVueResize=function(e){"use strict";return e.resize=e=>{e.directive("resize",({el:e,get:t,exp:i})=>{const r=t(`(($width, $height) => { ${i} })`),n=new ResizeObserver(e=>{for(const t of e){const e=t.contentRect;r(e.width,e.height)}});return n.observe(e),()=>n.disconnect()})},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
@@ -0,0 +1,15 @@
1
+ const resize = (app) => {
2
+ app.directive("resize", ({ el, get, exp }) => {
3
+ const handler = get(`(($width, $height) => { ${exp} })`);
4
+ const observer = new ResizeObserver((entries) => {
5
+ for (const entry of entries) {
6
+ const box = entry.contentRect;
7
+ handler(box.width, box.height);
8
+ }
9
+ });
10
+ observer.observe(el);
11
+ return () => observer.disconnect();
12
+ });
13
+ };
14
+
15
+ export { resize };
@@ -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).LiteVueResize={})}(this,function(e){"use strict";e.resize=e=>{e.directive("resize",({el:e,get:t,exp:i})=>{const o=t(`(($width, $height) => { ${i} })`),n=new ResizeObserver(e=>{for(const t of e){const e=t.contentRect;o(e.width,e.height)}});return n.observe(e),()=>n.disconnect()})},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ var LiteVueTransition=function(e){"use strict";const t=e=>(parseFloat(e)||0)*(e.includes("ms")?1:1e3),n=(e,n)=>{const i=e.split(","),a=n.split(",");let r=0;for(let s=0;s<i.length;s++)r=Math.max(r,t(i[s])+t(a[s%a.length]));return r};return e.transition=e=>{e.directive("transition",({el:e,get:t,effect:i,arg:a,modifiers:r,exp:s})=>{const o=e,l=a||"v",c=e=>`${l}-${e}`;let v=0,m=!0;const d=()=>{o.classList.remove(c("enter-from"),c("enter-active"),c("enter-to"),c("leave-from"),c("leave-active"),c("leave-to"))},u=(e,t)=>{const i=++v;d(),o.classList.add(c(e+"-from"),c(e+"-active")),o.offsetWidth,o.classList.remove(c(e+"-from")),o.classList.add(c(e+"-to")),setTimeout(()=>{i===v&&(d(),t&&t())},(e=>{const t=getComputedStyle(e);return Math.max(n(t.transitionDuration,t.transitionDelay),n(t.animationDuration,t.animationDelay))})(o))};if(!s)return Promise.resolve().then(()=>u("enter")),o.__leave=()=>new Promise(e=>u("leave",e)),()=>{delete o.__leave};i(()=>{const e=!!t();if(m)return m=!1,o.style.display=e?"":"none",void(e&&r?.appear&&u("enter"));e?(o.style.display="",u("enter")):u("leave",()=>{o.style.display="none"})})})},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
@@ -0,0 +1,76 @@
1
+ const toMs = (v) => (parseFloat(v) || 0) * (v.includes("ms") ? 1 : 1e3);
2
+ const maxOf = (durations, delays) => {
3
+ const ds = durations.split(",");
4
+ const dl = delays.split(",");
5
+ let max = 0;
6
+ for (let i = 0; i < ds.length; i++) {
7
+ max = Math.max(max, toMs(ds[i]) + toMs(dl[i % dl.length]));
8
+ }
9
+ return max;
10
+ };
11
+ const durationOf = (el) => {
12
+ const s = getComputedStyle(el);
13
+ return Math.max(
14
+ maxOf(s.transitionDuration, s.transitionDelay),
15
+ maxOf(s.animationDuration, s.animationDelay)
16
+ );
17
+ };
18
+ const transition = (app) => {
19
+ app.directive("transition", ({ el, get, effect, arg, modifiers, exp }) => {
20
+ const elem = el;
21
+ const name = arg || "v";
22
+ const cls = (phase) => `${name}-${phase}`;
23
+ let seq = 0;
24
+ let first = true;
25
+ const clear = () => {
26
+ elem.classList.remove(
27
+ cls("enter-from"),
28
+ cls("enter-active"),
29
+ cls("enter-to"),
30
+ cls("leave-from"),
31
+ cls("leave-active"),
32
+ cls("leave-to")
33
+ );
34
+ };
35
+ const run = (phase, done) => {
36
+ const id = ++seq;
37
+ clear();
38
+ elem.classList.add(cls(phase + "-from"), cls(phase + "-active"));
39
+ void elem.offsetWidth;
40
+ elem.classList.remove(cls(phase + "-from"));
41
+ elem.classList.add(cls(phase + "-to"));
42
+ setTimeout(() => {
43
+ if (id === seq) {
44
+ clear();
45
+ if (done) done();
46
+ }
47
+ }, durationOf(elem));
48
+ };
49
+ if (!exp) {
50
+ Promise.resolve().then(() => run("enter"));
51
+ elem.__leave = () => new Promise((resolve) => run("leave", resolve));
52
+ return () => {
53
+ delete elem.__leave;
54
+ };
55
+ }
56
+ effect(() => {
57
+ const show = !!get();
58
+ if (first) {
59
+ first = false;
60
+ elem.style.display = show ? "" : "none";
61
+ if (show && modifiers?.appear) run("enter");
62
+ return;
63
+ }
64
+ if (show) {
65
+ elem.style.display = "";
66
+ run("enter");
67
+ } else {
68
+ run("leave", () => {
69
+ elem.style.display = "none";
70
+ });
71
+ }
72
+ });
73
+ });
74
+ };
75
+
76
+ export { transition };
@@ -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).LiteVueTransition={})}(this,function(e){"use strict";const t=e=>(parseFloat(e)||0)*(e.includes("ms")?1:1e3),n=(e,n)=>{const i=e.split(","),o=n.split(",");let s=0;for(let a=0;a<i.length;a++)s=Math.max(s,t(i[a])+t(o[a%o.length]));return s};e.transition=e=>{e.directive("transition",({el:e,get:t,effect:i,arg:o,modifiers:s,exp:a})=>{const r=e,l=o||"v",f=e=>`${l}-${e}`;let d=0,c=!0;const m=()=>{r.classList.remove(f("enter-from"),f("enter-active"),f("enter-to"),f("leave-from"),f("leave-active"),f("leave-to"))},u=(e,t)=>{const i=++d;m(),r.classList.add(f(e+"-from"),f(e+"-active")),r.offsetWidth,r.classList.remove(f(e+"-from")),r.classList.add(f(e+"-to")),setTimeout(()=>{i===d&&(m(),t&&t())},(e=>{const t=getComputedStyle(e);return Math.max(n(t.transitionDuration,t.transitionDelay),n(t.animationDuration,t.animationDelay))})(r))};if(!a)return Promise.resolve().then(()=>u("enter")),r.__leave=()=>new Promise(e=>u("leave",e)),()=>{delete r.__leave};i(()=>{const e=!!t();if(c)return c=!1,r.style.display=e?"":"none",void(e&&s?.appear&&u("enter"));e?(r.style.display="",u("enter")):u("leave",()=>{r.style.display="none"})})})},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
@@ -13,7 +13,11 @@ export interface App {
13
13
  */
14
14
  use<Options>(plugin: Plugin<Options>, options?: Options): App;
15
15
  mount(el?: string | Element | null): App | void;
16
- unmount(): void;
16
+ /**
17
+ * Tear down every mounted root, or — given an element or selector — only the
18
+ * roots at or inside it, leaving the rest of the app running.
19
+ */
20
+ unmount(el?: string | Element | null): void;
17
21
  }
18
22
  export type Plugin<Options = any> = ((app: App, options?: Options) => void) | {
19
23
  install(app: App, options?: Options): void;
@@ -13,7 +13,11 @@ export interface App {
13
13
  */
14
14
  use<Options>(plugin: Plugin<Options>, options?: Options): App;
15
15
  mount(el?: string | Element | null): App | void;
16
- unmount(): void;
16
+ /**
17
+ * Tear down every mounted root, or — given an element or selector — only the
18
+ * roots at or inside it, leaving the rest of the app running.
19
+ */
20
+ unmount(el?: string | Element | null): void;
17
21
  }
18
22
  export type Plugin<Options = any> = ((app: App, options?: Options) => void) | {
19
23
  install(app: App, options?: Options): void;
@@ -11,6 +11,13 @@ export interface Context {
11
11
  cleanups: (() => void)[];
12
12
  delimiters: [string, string];
13
13
  delimitersRE: RegExp;
14
+ /**
15
+ * The framework walker, published on the root context by `mount()` and
16
+ * inherited by every child context through the spreads below. Plugins that
17
+ * insert markup into a live tree (morph) need it to bind that markup, and
18
+ * reading it here keeps them from importing — and re-bundling — the core.
19
+ */
20
+ walk?: (node: Node, ctx: Context) => ChildNode | null | void;
14
21
  }
15
22
  export declare const createContext: (parent?: Context) => Context;
16
23
  export declare const createScopedContext: (ctx: Context, data?: {}) => Context;
@@ -11,6 +11,13 @@ export interface Context {
11
11
  cleanups: (() => void)[];
12
12
  delimiters: [string, string];
13
13
  delimitersRE: RegExp;
14
+ /**
15
+ * The framework walker, published on the root context by `mount()` and
16
+ * inherited by every child context through the spreads below. Plugins that
17
+ * insert markup into a live tree (morph) need it to bind that markup, and
18
+ * reading it here keeps them from importing — and re-bundling — the core.
19
+ */
20
+ walk?: (node: Node, ctx: Context) => ChildNode | null | void;
14
21
  }
15
22
  export declare const createContext: (parent?: Context) => Context;
16
23
  export declare const createScopedContext: (ctx: Context, data?: {}) => Context;