@aevantec/litevue 0.5.5 → 0.5.7
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.
- package/README.md +10 -7
- package/dist/litevue-devtools.iife.js +1 -1
- package/dist/litevue-devtools.mjs +1 -1
- package/dist/litevue-devtools.umd.js +1 -1
- package/dist/litevue-plugins.dev.iife.js +898 -0
- package/dist/litevue-plugins.dev.mjs +880 -0
- package/dist/litevue-plugins.iife.js +1 -1
- package/dist/litevue-plugins.mjs +1 -1
- package/dist/litevue-plugins.umd.js +1 -1
- package/dist/litevue.dev.iife.js +2103 -0
- package/dist/litevue.dev.mjs +2092 -0
- package/dist/litevue.iife.js +1 -1
- package/dist/litevue.mjs +1 -1
- package/dist/litevue.umd.js +1 -1
- package/dist/plugins/collapse.iife.js +1 -1
- package/dist/plugins/collapse.mjs +1 -1
- package/dist/plugins/collapse.umd.js +1 -1
- package/dist/plugins/media.dev.iife.js +249 -0
- package/dist/plugins/media.dev.mjs +243 -0
- package/dist/plugins/morph.dev.iife.js +217 -0
- package/dist/plugins/morph.dev.mjs +212 -0
- package/dist/plugins/morph.iife.js +1 -1
- package/dist/plugins/morph.mjs +1 -1
- package/dist/plugins/morph.umd.js +1 -1
- package/dist/plugins/persist.dev.iife.js +126 -0
- package/dist/plugins/persist.dev.mjs +120 -0
- package/dist/types/app.d.mts +15 -18
- package/dist/types/app.d.ts +15 -18
- package/dist/types/block.d.mts +1 -2
- package/dist/types/block.d.ts +1 -2
- package/dist/types/context.d.mts +5 -8
- package/dist/types/context.d.ts +5 -8
- package/dist/types/devtools.d.mts +7 -0
- package/dist/types/devtools.d.ts +7 -0
- package/dist/types/effect.d.mts +6 -10
- package/dist/types/effect.d.ts +6 -10
- package/dist/types/errors.d.mts +36 -0
- package/dist/types/errors.d.ts +36 -0
- package/dist/types/eval.d.mts +8 -2
- package/dist/types/eval.d.ts +8 -2
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/magics.d.mts +5 -6
- package/dist/types/magics.d.ts +5 -6
- package/dist/types/ownership.d.mts +9 -16
- package/dist/types/ownership.d.ts +9 -16
- package/dist/types/plugins/focus/index.d.mts +6 -8
- package/dist/types/plugins/focus/index.d.ts +6 -8
- package/dist/types/plugins/media/index.d.mts +6 -7
- package/dist/types/plugins/media/index.d.ts +6 -7
- package/dist/types/plugins/morph/index.d.mts +23 -11
- package/dist/types/plugins/morph/index.d.ts +23 -11
- package/dist/types/plugins/persist/index.d.mts +12 -19
- package/dist/types/plugins/persist/index.d.ts +12 -19
- package/dist/types/plugins/resize/index.d.mts +5 -7
- package/dist/types/plugins/resize/index.d.ts +5 -7
- package/dist/types/plugins/transition/index.d.mts +7 -12
- package/dist/types/plugins/transition/index.d.ts +7 -12
- package/dist/types/store.d.mts +3 -6
- package/dist/types/store.d.ts +3 -6
- package/dist/types/utils.d.mts +3 -3
- package/dist/types/utils.d.ts +3 -3
- package/dist/types/warn.d.mts +6 -8
- package/dist/types/warn.d.ts +6 -8
- package/package.json +11 -2
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
var LiteVueMedia = (function(exports, _aevantec_litevue) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region src/plugins/media/index.ts
|
|
4
|
+
var DEFAULT_BREAKPOINTS = {
|
|
5
|
+
sm: 640,
|
|
6
|
+
md: 768,
|
|
7
|
+
lg: 1024,
|
|
8
|
+
xl: 1280,
|
|
9
|
+
"2xl": 1536
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The scale in use until `configure()` runs. Exported because `configure()`
|
|
13
|
+
* replaces rather than merges, so adjusting one breakpoint means spreading
|
|
14
|
+
* this rather than retyping all five.
|
|
15
|
+
*/
|
|
16
|
+
var defaultBreakpoints = Object.freeze({ ...DEFAULT_BREAKPOINTS });
|
|
17
|
+
var ALIASES = {
|
|
18
|
+
mobile: "base",
|
|
19
|
+
tablet: "md",
|
|
20
|
+
desktop: "lg"
|
|
21
|
+
};
|
|
22
|
+
var NUMERIC = /^\d+$/;
|
|
23
|
+
/**
|
|
24
|
+
* Two reactive primitives, deliberately:
|
|
25
|
+
*
|
|
26
|
+
* - `bp`, one string, so named keys / `atLeast` / `device` cost each consumer
|
|
27
|
+
* a single dependency however many responsive maps the page declares.
|
|
28
|
+
* - `tick`, for arbitrary `match()` queries. Their results are read off the
|
|
29
|
+
* MediaQueryList rather than mirrored, since registering a query inside a
|
|
30
|
+
* running effect would write a dependency it just read and re-run it.
|
|
31
|
+
*/
|
|
32
|
+
var state = (0, _aevantec_litevue.reactive)({
|
|
33
|
+
bp: "base",
|
|
34
|
+
tick: 0
|
|
35
|
+
});
|
|
36
|
+
var installedScale;
|
|
37
|
+
var scale = { ...DEFAULT_BREAKPOINTS };
|
|
38
|
+
var order = ["base"];
|
|
39
|
+
var active = false;
|
|
40
|
+
var scaleSubs = [];
|
|
41
|
+
var querySubs = /* @__PURE__ */ new Map();
|
|
42
|
+
var supported = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
43
|
+
var subscribe = (mql, cb) => {
|
|
44
|
+
if (mql.addEventListener) {
|
|
45
|
+
mql.addEventListener("change", cb);
|
|
46
|
+
return {
|
|
47
|
+
mql,
|
|
48
|
+
off: () => mql.removeEventListener("change", cb)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
mql.addListener(cb);
|
|
52
|
+
return {
|
|
53
|
+
mql,
|
|
54
|
+
off: () => mql.removeListener(cb)
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
var currentBp = () => {
|
|
58
|
+
for (let i = scaleSubs.length - 1; i >= 0; i--) if (scaleSubs[i].mql.matches) return order[i + 1];
|
|
59
|
+
return "base";
|
|
60
|
+
};
|
|
61
|
+
var buildScale = () => {
|
|
62
|
+
scaleSubs.forEach((s) => s.off());
|
|
63
|
+
scaleSubs = [];
|
|
64
|
+
const names = Object.keys(scale).filter((n) => scale[n] > 0).sort((a, b) => scale[a] - scale[b]);
|
|
65
|
+
order = ["base", ...names];
|
|
66
|
+
if (!supported()) return;
|
|
67
|
+
scaleSubs = names.map((name) => {
|
|
68
|
+
return subscribe(window.matchMedia(`(min-width: ${scale[name]}px)`), () => {
|
|
69
|
+
state.bp = currentBp();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
state.bp = currentBp();
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Started by the first read, not by `app.use()`, so `mq` works in a plain
|
|
76
|
+
* module with no app mounted — otherwise it would report a frozen 'base'.
|
|
77
|
+
*/
|
|
78
|
+
var activate = () => {
|
|
79
|
+
if (active) return;
|
|
80
|
+
active = true;
|
|
81
|
+
buildScale();
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Entry point for every public read: activates, and depends on `tick` so
|
|
85
|
+
* `configure()` can invalidate all of them. `bp` alone is not enough — a key
|
|
86
|
+
* absent from the current scale returns false without touching reactive state,
|
|
87
|
+
* so that effect could never recover once a later scale defined the key.
|
|
88
|
+
*/
|
|
89
|
+
var trackAll = () => {
|
|
90
|
+
activate();
|
|
91
|
+
state.tick;
|
|
92
|
+
};
|
|
93
|
+
/** SSR and jsdom have no matchMedia; every query reads false and bp stays base. */
|
|
94
|
+
var rawMatch = (query) => {
|
|
95
|
+
if (!supported()) return false;
|
|
96
|
+
let sub = querySubs.get(query);
|
|
97
|
+
if (!sub) {
|
|
98
|
+
sub = subscribe(window.matchMedia(query), () => state.tick++);
|
|
99
|
+
querySubs.set(query, sub);
|
|
100
|
+
}
|
|
101
|
+
return sub.mql.matches;
|
|
102
|
+
};
|
|
103
|
+
/** A key's lower bound in pixels, or undefined if it names nothing. */
|
|
104
|
+
var keyToPx = (key) => {
|
|
105
|
+
if (typeof key === "number") return key;
|
|
106
|
+
if (key === "base") return 0;
|
|
107
|
+
if (NUMERIC.test(key)) return Number(key);
|
|
108
|
+
const alias = ALIASES[key];
|
|
109
|
+
if (alias !== void 0) return alias === "base" ? 0 : scale[alias];
|
|
110
|
+
return scale[key];
|
|
111
|
+
};
|
|
112
|
+
var atLeastPx = (px) => {
|
|
113
|
+
if (px <= 0) return true;
|
|
114
|
+
const i = order.findIndex((n) => n !== "base" && scale[n] === px);
|
|
115
|
+
if (i !== -1) return order.indexOf(state.bp) >= i;
|
|
116
|
+
state.tick;
|
|
117
|
+
return rawMatch(`(min-width: ${px}px)`);
|
|
118
|
+
};
|
|
119
|
+
var warned = /* @__PURE__ */ new Set();
|
|
120
|
+
var warnOnce = (msg) => {
|
|
121
|
+
if (warned.has(msg)) return;
|
|
122
|
+
warned.add(msg);
|
|
123
|
+
console.warn(`[litevue media] ${msg}`);
|
|
124
|
+
};
|
|
125
|
+
var resolve = (map, fallback) => {
|
|
126
|
+
trackAll();
|
|
127
|
+
if (!map || typeof map !== "object") {
|
|
128
|
+
warnOnce(`expected a responsive map object, got ${typeof map}.`);
|
|
129
|
+
return fallback;
|
|
130
|
+
}
|
|
131
|
+
let best;
|
|
132
|
+
let bestPx = -1;
|
|
133
|
+
for (const key of Object.keys(map)) {
|
|
134
|
+
const px = keyToPx(key);
|
|
135
|
+
if (px === void 0) {
|
|
136
|
+
warnOnce(`"${key}" is not a breakpoint. Known: ${order.join(", ")}, plus the aliases ${Object.keys(ALIASES).join(", ")} and raw pixel widths.`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (px >= bestPx && atLeastPx(px)) {
|
|
140
|
+
bestPx = px;
|
|
141
|
+
best = map[key];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return best !== void 0 ? best : fallback;
|
|
145
|
+
};
|
|
146
|
+
var aliasPx = (alias) => {
|
|
147
|
+
const name = ALIASES[alias];
|
|
148
|
+
const px = scale[name];
|
|
149
|
+
if (px !== void 0) return px;
|
|
150
|
+
warnOnce(`$mqDevice needs "${name}" in your breakpoint scale; falling back to ${DEFAULT_BREAKPOINTS[name]}px. Define it, or use $mqAtLeast with your own keys.`);
|
|
151
|
+
return DEFAULT_BREAKPOINTS[name];
|
|
152
|
+
};
|
|
153
|
+
var mqFn = (map, fallback) => resolve(map, fallback);
|
|
154
|
+
var mq = Object.defineProperties(mqFn, {
|
|
155
|
+
props: { value: (maps) => {
|
|
156
|
+
trackAll();
|
|
157
|
+
const out = {};
|
|
158
|
+
for (const key of Object.keys(maps)) out[key] = resolve(maps[key]);
|
|
159
|
+
return out;
|
|
160
|
+
} },
|
|
161
|
+
breakpoint: {
|
|
162
|
+
get() {
|
|
163
|
+
trackAll();
|
|
164
|
+
return state.bp;
|
|
165
|
+
},
|
|
166
|
+
enumerable: true
|
|
167
|
+
},
|
|
168
|
+
device: {
|
|
169
|
+
get() {
|
|
170
|
+
trackAll();
|
|
171
|
+
if (!atLeastPx(aliasPx("tablet"))) return "mobile";
|
|
172
|
+
return atLeastPx(aliasPx("desktop")) ? "desktop" : "tablet";
|
|
173
|
+
},
|
|
174
|
+
enumerable: true
|
|
175
|
+
},
|
|
176
|
+
atLeast: { value: (key) => {
|
|
177
|
+
trackAll();
|
|
178
|
+
const px = keyToPx(key);
|
|
179
|
+
if (px === void 0) {
|
|
180
|
+
warnOnce(`$mqAtLeast("${key}") — unknown breakpoint, treated as false.`);
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return atLeastPx(px);
|
|
184
|
+
} },
|
|
185
|
+
match: { value: (query) => {
|
|
186
|
+
trackAll();
|
|
187
|
+
return rawMatch(query);
|
|
188
|
+
} },
|
|
189
|
+
configure: { value: ({ breakpoints }) => {
|
|
190
|
+
if (!breakpoints) return;
|
|
191
|
+
scale = { ...breakpoints };
|
|
192
|
+
if (active) {
|
|
193
|
+
buildScale();
|
|
194
|
+
state.tick++;
|
|
195
|
+
}
|
|
196
|
+
} }
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* Drops every live subscription; `activate()` rebuilds them on the next read,
|
|
200
|
+
* so this is safe while something still holds `mq`. The scale is deliberately
|
|
201
|
+
* left alone — a page that configured one still wants it.
|
|
202
|
+
*/
|
|
203
|
+
var releaseSubscriptions = () => {
|
|
204
|
+
scaleSubs.forEach((s) => s.off());
|
|
205
|
+
querySubs.forEach((s) => s.off());
|
|
206
|
+
scaleSubs = [];
|
|
207
|
+
querySubs.clear();
|
|
208
|
+
active = false;
|
|
209
|
+
};
|
|
210
|
+
var resetMedia = () => {
|
|
211
|
+
releaseSubscriptions();
|
|
212
|
+
scale = { ...DEFAULT_BREAKPOINTS };
|
|
213
|
+
order = ["base", ...Object.keys(scale).sort((a, b) => scale[a] - scale[b])];
|
|
214
|
+
active = false;
|
|
215
|
+
installedScale = void 0;
|
|
216
|
+
warned.clear();
|
|
217
|
+
state.bp = "base";
|
|
218
|
+
state.tick = 0;
|
|
219
|
+
};
|
|
220
|
+
var media = (app, options) => {
|
|
221
|
+
if (options?.breakpoints) {
|
|
222
|
+
const next = JSON.stringify(options.breakpoints);
|
|
223
|
+
if (installedScale && installedScale !== next) warnOnce("a second app installed media with a different breakpoint scale. The scale is page-wide, so this replaces the first one rather than giving each app its own. Configure it once, or call mq.configure() deliberately if replacing it is what you want.");
|
|
224
|
+
installedScale = next;
|
|
225
|
+
}
|
|
226
|
+
if (options) mq.configure(options);
|
|
227
|
+
app.scope.$mq = mq;
|
|
228
|
+
app.scope.$mqProps = mq.props;
|
|
229
|
+
app.scope.$mqAtLeast = mq.atLeast;
|
|
230
|
+
app.scope.$mqMatch = mq.match;
|
|
231
|
+
Object.defineProperty(app.scope, "$mqBreakpoint", {
|
|
232
|
+
get: () => mq.breakpoint,
|
|
233
|
+
enumerable: true,
|
|
234
|
+
configurable: true
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(app.scope, "$mqDevice", {
|
|
237
|
+
get: () => mq.device,
|
|
238
|
+
enumerable: true,
|
|
239
|
+
configurable: true
|
|
240
|
+
});
|
|
241
|
+
return releaseSubscriptions;
|
|
242
|
+
};
|
|
243
|
+
//#endregion
|
|
244
|
+
exports.defaultBreakpoints = defaultBreakpoints;
|
|
245
|
+
exports.media = media;
|
|
246
|
+
exports.mq = mq;
|
|
247
|
+
exports.resetMedia = resetMedia;
|
|
248
|
+
return exports;
|
|
249
|
+
})({}, LiteVue);
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { reactive } from "@aevantec/litevue";
|
|
2
|
+
//#region src/plugins/media/index.ts
|
|
3
|
+
var DEFAULT_BREAKPOINTS = {
|
|
4
|
+
sm: 640,
|
|
5
|
+
md: 768,
|
|
6
|
+
lg: 1024,
|
|
7
|
+
xl: 1280,
|
|
8
|
+
"2xl": 1536
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The scale in use until `configure()` runs. Exported because `configure()`
|
|
12
|
+
* replaces rather than merges, so adjusting one breakpoint means spreading
|
|
13
|
+
* this rather than retyping all five.
|
|
14
|
+
*/
|
|
15
|
+
var defaultBreakpoints = Object.freeze({ ...DEFAULT_BREAKPOINTS });
|
|
16
|
+
var ALIASES = {
|
|
17
|
+
mobile: "base",
|
|
18
|
+
tablet: "md",
|
|
19
|
+
desktop: "lg"
|
|
20
|
+
};
|
|
21
|
+
var NUMERIC = /^\d+$/;
|
|
22
|
+
/**
|
|
23
|
+
* Two reactive primitives, deliberately:
|
|
24
|
+
*
|
|
25
|
+
* - `bp`, one string, so named keys / `atLeast` / `device` cost each consumer
|
|
26
|
+
* a single dependency however many responsive maps the page declares.
|
|
27
|
+
* - `tick`, for arbitrary `match()` queries. Their results are read off the
|
|
28
|
+
* MediaQueryList rather than mirrored, since registering a query inside a
|
|
29
|
+
* running effect would write a dependency it just read and re-run it.
|
|
30
|
+
*/
|
|
31
|
+
var state = reactive({
|
|
32
|
+
bp: "base",
|
|
33
|
+
tick: 0
|
|
34
|
+
});
|
|
35
|
+
var installedScale;
|
|
36
|
+
var scale = { ...DEFAULT_BREAKPOINTS };
|
|
37
|
+
var order = ["base"];
|
|
38
|
+
var active = false;
|
|
39
|
+
var scaleSubs = [];
|
|
40
|
+
var querySubs = /* @__PURE__ */ new Map();
|
|
41
|
+
var supported = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
42
|
+
var subscribe = (mql, cb) => {
|
|
43
|
+
if (mql.addEventListener) {
|
|
44
|
+
mql.addEventListener("change", cb);
|
|
45
|
+
return {
|
|
46
|
+
mql,
|
|
47
|
+
off: () => mql.removeEventListener("change", cb)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
mql.addListener(cb);
|
|
51
|
+
return {
|
|
52
|
+
mql,
|
|
53
|
+
off: () => mql.removeListener(cb)
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
var currentBp = () => {
|
|
57
|
+
for (let i = scaleSubs.length - 1; i >= 0; i--) if (scaleSubs[i].mql.matches) return order[i + 1];
|
|
58
|
+
return "base";
|
|
59
|
+
};
|
|
60
|
+
var buildScale = () => {
|
|
61
|
+
scaleSubs.forEach((s) => s.off());
|
|
62
|
+
scaleSubs = [];
|
|
63
|
+
const names = Object.keys(scale).filter((n) => scale[n] > 0).sort((a, b) => scale[a] - scale[b]);
|
|
64
|
+
order = ["base", ...names];
|
|
65
|
+
if (!supported()) return;
|
|
66
|
+
scaleSubs = names.map((name) => {
|
|
67
|
+
return subscribe(window.matchMedia(`(min-width: ${scale[name]}px)`), () => {
|
|
68
|
+
state.bp = currentBp();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
state.bp = currentBp();
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Started by the first read, not by `app.use()`, so `mq` works in a plain
|
|
75
|
+
* module with no app mounted — otherwise it would report a frozen 'base'.
|
|
76
|
+
*/
|
|
77
|
+
var activate = () => {
|
|
78
|
+
if (active) return;
|
|
79
|
+
active = true;
|
|
80
|
+
buildScale();
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Entry point for every public read: activates, and depends on `tick` so
|
|
84
|
+
* `configure()` can invalidate all of them. `bp` alone is not enough — a key
|
|
85
|
+
* absent from the current scale returns false without touching reactive state,
|
|
86
|
+
* so that effect could never recover once a later scale defined the key.
|
|
87
|
+
*/
|
|
88
|
+
var trackAll = () => {
|
|
89
|
+
activate();
|
|
90
|
+
state.tick;
|
|
91
|
+
};
|
|
92
|
+
/** SSR and jsdom have no matchMedia; every query reads false and bp stays base. */
|
|
93
|
+
var rawMatch = (query) => {
|
|
94
|
+
if (!supported()) return false;
|
|
95
|
+
let sub = querySubs.get(query);
|
|
96
|
+
if (!sub) {
|
|
97
|
+
sub = subscribe(window.matchMedia(query), () => state.tick++);
|
|
98
|
+
querySubs.set(query, sub);
|
|
99
|
+
}
|
|
100
|
+
return sub.mql.matches;
|
|
101
|
+
};
|
|
102
|
+
/** A key's lower bound in pixels, or undefined if it names nothing. */
|
|
103
|
+
var keyToPx = (key) => {
|
|
104
|
+
if (typeof key === "number") return key;
|
|
105
|
+
if (key === "base") return 0;
|
|
106
|
+
if (NUMERIC.test(key)) return Number(key);
|
|
107
|
+
const alias = ALIASES[key];
|
|
108
|
+
if (alias !== void 0) return alias === "base" ? 0 : scale[alias];
|
|
109
|
+
return scale[key];
|
|
110
|
+
};
|
|
111
|
+
var atLeastPx = (px) => {
|
|
112
|
+
if (px <= 0) return true;
|
|
113
|
+
const i = order.findIndex((n) => n !== "base" && scale[n] === px);
|
|
114
|
+
if (i !== -1) return order.indexOf(state.bp) >= i;
|
|
115
|
+
state.tick;
|
|
116
|
+
return rawMatch(`(min-width: ${px}px)`);
|
|
117
|
+
};
|
|
118
|
+
var warned = /* @__PURE__ */ new Set();
|
|
119
|
+
var warnOnce = (msg) => {
|
|
120
|
+
if (warned.has(msg)) return;
|
|
121
|
+
warned.add(msg);
|
|
122
|
+
console.warn(`[litevue media] ${msg}`);
|
|
123
|
+
};
|
|
124
|
+
var resolve = (map, fallback) => {
|
|
125
|
+
trackAll();
|
|
126
|
+
if (!map || typeof map !== "object") {
|
|
127
|
+
warnOnce(`expected a responsive map object, got ${typeof map}.`);
|
|
128
|
+
return fallback;
|
|
129
|
+
}
|
|
130
|
+
let best;
|
|
131
|
+
let bestPx = -1;
|
|
132
|
+
for (const key of Object.keys(map)) {
|
|
133
|
+
const px = keyToPx(key);
|
|
134
|
+
if (px === void 0) {
|
|
135
|
+
warnOnce(`"${key}" is not a breakpoint. Known: ${order.join(", ")}, plus the aliases ${Object.keys(ALIASES).join(", ")} and raw pixel widths.`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (px >= bestPx && atLeastPx(px)) {
|
|
139
|
+
bestPx = px;
|
|
140
|
+
best = map[key];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return best !== void 0 ? best : fallback;
|
|
144
|
+
};
|
|
145
|
+
var aliasPx = (alias) => {
|
|
146
|
+
const name = ALIASES[alias];
|
|
147
|
+
const px = scale[name];
|
|
148
|
+
if (px !== void 0) return px;
|
|
149
|
+
warnOnce(`$mqDevice needs "${name}" in your breakpoint scale; falling back to ${DEFAULT_BREAKPOINTS[name]}px. Define it, or use $mqAtLeast with your own keys.`);
|
|
150
|
+
return DEFAULT_BREAKPOINTS[name];
|
|
151
|
+
};
|
|
152
|
+
var mqFn = (map, fallback) => resolve(map, fallback);
|
|
153
|
+
var mq = Object.defineProperties(mqFn, {
|
|
154
|
+
props: { value: (maps) => {
|
|
155
|
+
trackAll();
|
|
156
|
+
const out = {};
|
|
157
|
+
for (const key of Object.keys(maps)) out[key] = resolve(maps[key]);
|
|
158
|
+
return out;
|
|
159
|
+
} },
|
|
160
|
+
breakpoint: {
|
|
161
|
+
get() {
|
|
162
|
+
trackAll();
|
|
163
|
+
return state.bp;
|
|
164
|
+
},
|
|
165
|
+
enumerable: true
|
|
166
|
+
},
|
|
167
|
+
device: {
|
|
168
|
+
get() {
|
|
169
|
+
trackAll();
|
|
170
|
+
if (!atLeastPx(aliasPx("tablet"))) return "mobile";
|
|
171
|
+
return atLeastPx(aliasPx("desktop")) ? "desktop" : "tablet";
|
|
172
|
+
},
|
|
173
|
+
enumerable: true
|
|
174
|
+
},
|
|
175
|
+
atLeast: { value: (key) => {
|
|
176
|
+
trackAll();
|
|
177
|
+
const px = keyToPx(key);
|
|
178
|
+
if (px === void 0) {
|
|
179
|
+
warnOnce(`$mqAtLeast("${key}") — unknown breakpoint, treated as false.`);
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
return atLeastPx(px);
|
|
183
|
+
} },
|
|
184
|
+
match: { value: (query) => {
|
|
185
|
+
trackAll();
|
|
186
|
+
return rawMatch(query);
|
|
187
|
+
} },
|
|
188
|
+
configure: { value: ({ breakpoints }) => {
|
|
189
|
+
if (!breakpoints) return;
|
|
190
|
+
scale = { ...breakpoints };
|
|
191
|
+
if (active) {
|
|
192
|
+
buildScale();
|
|
193
|
+
state.tick++;
|
|
194
|
+
}
|
|
195
|
+
} }
|
|
196
|
+
});
|
|
197
|
+
/**
|
|
198
|
+
* Drops every live subscription; `activate()` rebuilds them on the next read,
|
|
199
|
+
* so this is safe while something still holds `mq`. The scale is deliberately
|
|
200
|
+
* left alone — a page that configured one still wants it.
|
|
201
|
+
*/
|
|
202
|
+
var releaseSubscriptions = () => {
|
|
203
|
+
scaleSubs.forEach((s) => s.off());
|
|
204
|
+
querySubs.forEach((s) => s.off());
|
|
205
|
+
scaleSubs = [];
|
|
206
|
+
querySubs.clear();
|
|
207
|
+
active = false;
|
|
208
|
+
};
|
|
209
|
+
var resetMedia = () => {
|
|
210
|
+
releaseSubscriptions();
|
|
211
|
+
scale = { ...DEFAULT_BREAKPOINTS };
|
|
212
|
+
order = ["base", ...Object.keys(scale).sort((a, b) => scale[a] - scale[b])];
|
|
213
|
+
active = false;
|
|
214
|
+
installedScale = void 0;
|
|
215
|
+
warned.clear();
|
|
216
|
+
state.bp = "base";
|
|
217
|
+
state.tick = 0;
|
|
218
|
+
};
|
|
219
|
+
var media = (app, options) => {
|
|
220
|
+
if (options?.breakpoints) {
|
|
221
|
+
const next = JSON.stringify(options.breakpoints);
|
|
222
|
+
if (installedScale && installedScale !== next) warnOnce("a second app installed media with a different breakpoint scale. The scale is page-wide, so this replaces the first one rather than giving each app its own. Configure it once, or call mq.configure() deliberately if replacing it is what you want.");
|
|
223
|
+
installedScale = next;
|
|
224
|
+
}
|
|
225
|
+
if (options) mq.configure(options);
|
|
226
|
+
app.scope.$mq = mq;
|
|
227
|
+
app.scope.$mqProps = mq.props;
|
|
228
|
+
app.scope.$mqAtLeast = mq.atLeast;
|
|
229
|
+
app.scope.$mqMatch = mq.match;
|
|
230
|
+
Object.defineProperty(app.scope, "$mqBreakpoint", {
|
|
231
|
+
get: () => mq.breakpoint,
|
|
232
|
+
enumerable: true,
|
|
233
|
+
configurable: true
|
|
234
|
+
});
|
|
235
|
+
Object.defineProperty(app.scope, "$mqDevice", {
|
|
236
|
+
get: () => mq.device,
|
|
237
|
+
enumerable: true,
|
|
238
|
+
configurable: true
|
|
239
|
+
});
|
|
240
|
+
return releaseSubscriptions;
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { defaultBreakpoints, media, mq, resetMedia };
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
var LiteVueMorph = (function(exports) {
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region src/plugins/morph/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* A `data-` attribute rather than `v-preserve`: an unrecognised `v-` attribute
|
|
6
|
+
* logs an unknown-directive error, and registering one would have the walker
|
|
7
|
+
* strip it, leaving nothing for the next morph. Matches `data-morph-skip`.
|
|
8
|
+
*/
|
|
9
|
+
var preserved = (node, opts) => node.nodeType === 1 && (node.hasAttribute("data-morph-preserve") || !!opts.preserve?.(node));
|
|
10
|
+
var dirRE = /^(?:v-|:|@)/;
|
|
11
|
+
var bindRE = /^(?::|v-bind:)/;
|
|
12
|
+
/**
|
|
13
|
+
* Attributes tried in order when no `key` option is given. All three express
|
|
14
|
+
* identity, so none repeat among siblings the way `name` does on a radio group
|
|
15
|
+
* — hence its absence. The attribute name is part of the key, so `id="5"` and
|
|
16
|
+
* `data-id="5"` stay distinct.
|
|
17
|
+
*/
|
|
18
|
+
var KEY_ATTRS = [
|
|
19
|
+
"id",
|
|
20
|
+
"data-key",
|
|
21
|
+
"data-id"
|
|
22
|
+
];
|
|
23
|
+
var defaultKey = (el) => {
|
|
24
|
+
for (const attr of KEY_ATTRS) {
|
|
25
|
+
const value = el.getAttribute(attr);
|
|
26
|
+
if (value != null) return attr + "=" + value;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The nearest stashed context, walking up from a live node. `v-scope` elements
|
|
32
|
+
* record theirs during walk, so inserted markup binds with the scope it landed
|
|
33
|
+
* in rather than the root.
|
|
34
|
+
*/
|
|
35
|
+
var nearestCtx = (node) => {
|
|
36
|
+
for (let el = node; el; el = el.parentElement) if (el.__ctx) return el.__ctx;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Attributes the client owns, read from the *incoming* markup — it still
|
|
40
|
+
* carries the directives the live DOM had stripped. `:class` there means the
|
|
41
|
+
* live `class` is bound and must survive the server's static value.
|
|
42
|
+
*/
|
|
43
|
+
var boundAttrs = (to) => {
|
|
44
|
+
const owned = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const { name } of to.attributes) if (bindRE.test(name)) owned.add(name.replace(bindRE, "").split(".")[0]);
|
|
46
|
+
else if (name === "v-model") {
|
|
47
|
+
owned.add("value");
|
|
48
|
+
owned.add("checked");
|
|
49
|
+
}
|
|
50
|
+
return owned;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* `v-for` and `v-if` render into Blocks: the live DOM holds anchors plus the
|
|
54
|
+
* clones the data produced, while the server still sends one template. Matched
|
|
55
|
+
* positionally, the rest would be deleted as "no longer sent".
|
|
56
|
+
*/
|
|
57
|
+
var isBlockRoot = (el) => el.hasAttribute("v-for") || el.hasAttribute("v-if") || el.hasAttribute("v-else") || el.hasAttribute("v-else-if");
|
|
58
|
+
/** True when the client, not the server, decides this element's contents. */
|
|
59
|
+
var ownsChildren = (to) => {
|
|
60
|
+
if (to.hasAttribute("v-text") || to.hasAttribute("v-html") || to.hasAttribute("v-pre") || to.hasAttribute("v-once") || isBlockRoot(to)) return true;
|
|
61
|
+
for (let c = to.firstElementChild; c; c = c.nextElementSibling) if (isBlockRoot(c)) return true;
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
64
|
+
var patchAttrs = (from, to) => {
|
|
65
|
+
const owned = boundAttrs(to);
|
|
66
|
+
for (const { name, value } of [...to.attributes]) {
|
|
67
|
+
if (dirRE.test(name) || owned.has(name)) continue;
|
|
68
|
+
if (from.getAttribute(name) !== value) from.setAttribute(name, value);
|
|
69
|
+
}
|
|
70
|
+
for (const { name } of [...from.attributes]) {
|
|
71
|
+
if (owned.has(name) || to.hasAttribute(name)) continue;
|
|
72
|
+
from.removeAttribute(name);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Incoming text still holding `{{ }}` is rendered by a text directive on the
|
|
77
|
+
* live side, so the live value wins.
|
|
78
|
+
*/
|
|
79
|
+
var isInterpolation = (data, ctx) => data.includes(ctx ? ctx.delimiters[0] : "{{");
|
|
80
|
+
var patchNode = (from, to, ctx, opts) => {
|
|
81
|
+
if (from.nodeType !== to.nodeType) return replaceNode(from, to, ctx, opts);
|
|
82
|
+
if (from.nodeType === 3 || from.nodeType === 8) {
|
|
83
|
+
const data = to.data;
|
|
84
|
+
if (isInterpolation(data, ctx)) return;
|
|
85
|
+
if (from.data !== data) from.data = data;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (from.nodeType !== 1) return;
|
|
89
|
+
const a = from;
|
|
90
|
+
const b = to;
|
|
91
|
+
if (a.tagName !== b.tagName) return replaceNode(from, to, ctx, opts);
|
|
92
|
+
if (opts.skip?.(a, b) || a.hasAttribute("data-morph-skip")) return;
|
|
93
|
+
patchAttrs(a, b);
|
|
94
|
+
if (!ownsChildren(b)) patchChildren(a, b, a.__ctx || ctx, opts);
|
|
95
|
+
};
|
|
96
|
+
var replaceNode = (from, to, ctx, opts) => {
|
|
97
|
+
if (preserved(from, opts)) return;
|
|
98
|
+
const fresh = to.cloneNode(true);
|
|
99
|
+
if (opts.beforeNodeAdded?.(fresh) === false) return;
|
|
100
|
+
ctx?.dispose?.(from);
|
|
101
|
+
from.parentNode.replaceChild(fresh, from);
|
|
102
|
+
opts.afterNodeRemoved?.(from);
|
|
103
|
+
mountNew(fresh, ctx);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Bind never-walked markup with the scope it was inserted into. The walker
|
|
107
|
+
* comes off the context, not an import, so this plugin doesn't pull a second
|
|
108
|
+
* copy of the core into the plugins bundle.
|
|
109
|
+
*/
|
|
110
|
+
var mountNew = (node, ctx) => {
|
|
111
|
+
const target = ctx || nearestCtx(node.parentNode);
|
|
112
|
+
target?.walk?.(node, target);
|
|
113
|
+
};
|
|
114
|
+
var patchChildren = (from, to, ctx, opts) => {
|
|
115
|
+
const key = opts.key || defaultKey;
|
|
116
|
+
const keyed = /* @__PURE__ */ new Map();
|
|
117
|
+
for (let n = from.firstChild; n; n = n.nextSibling) if (n.nodeType === 1) {
|
|
118
|
+
const k = key(n);
|
|
119
|
+
if (k == null) continue;
|
|
120
|
+
if (keyed.has(k)) console.warn(`[morph] duplicate key ${JSON.stringify(k)} among siblings; only the last is reusable. Keys must be unique within a parent.`);
|
|
121
|
+
keyed.set(k, n);
|
|
122
|
+
}
|
|
123
|
+
const keyOf = (n) => n && n.nodeType === 1 ? key(n) : null;
|
|
124
|
+
let oldChild = from.firstChild;
|
|
125
|
+
let newChild = to.firstChild;
|
|
126
|
+
const insert = (node) => {
|
|
127
|
+
const fresh = node.cloneNode(true);
|
|
128
|
+
if (opts.beforeNodeAdded?.(fresh) === false) return;
|
|
129
|
+
from.insertBefore(fresh, oldChild);
|
|
130
|
+
mountNew(fresh, ctx);
|
|
131
|
+
};
|
|
132
|
+
while (newChild) {
|
|
133
|
+
const nextNew = newChild.nextSibling;
|
|
134
|
+
const wantKey = keyOf(newChild);
|
|
135
|
+
if (wantKey != null) {
|
|
136
|
+
const match = keyed.get(wantKey);
|
|
137
|
+
if (match) {
|
|
138
|
+
if (match === oldChild) oldChild = oldChild.nextSibling;
|
|
139
|
+
else from.insertBefore(match, oldChild);
|
|
140
|
+
keyed.delete(wantKey);
|
|
141
|
+
patchNode(match, newChild, ctx, opts);
|
|
142
|
+
} else insert(newChild);
|
|
143
|
+
} else if (oldChild && keyOf(oldChild) == null) {
|
|
144
|
+
const nextOld = oldChild.nextSibling;
|
|
145
|
+
patchNode(oldChild, newChild, ctx, opts);
|
|
146
|
+
oldChild = nextOld;
|
|
147
|
+
} else insert(newChild);
|
|
148
|
+
newChild = nextNew;
|
|
149
|
+
}
|
|
150
|
+
while (oldChild) {
|
|
151
|
+
const next = oldChild.nextSibling;
|
|
152
|
+
if (!preserved(oldChild, opts)) {
|
|
153
|
+
ctx?.dispose?.(oldChild);
|
|
154
|
+
from.removeChild(oldChild);
|
|
155
|
+
opts.afterNodeRemoved?.(oldChild);
|
|
156
|
+
}
|
|
157
|
+
oldChild = next;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* morph(from, to) — patch `from` in place so it matches `to`, which may be an
|
|
162
|
+
* element or an HTML string for the *outer* element.
|
|
163
|
+
*/
|
|
164
|
+
var morph = (from, to, opts = {}) => {
|
|
165
|
+
let target;
|
|
166
|
+
if (typeof to === "string") {
|
|
167
|
+
const holder = document.createElement("template");
|
|
168
|
+
holder.innerHTML = to.trim();
|
|
169
|
+
const content = holder.content;
|
|
170
|
+
target = content.childElementCount === 1 ? content.firstElementChild : (() => {
|
|
171
|
+
const wrapper = from.cloneNode(false);
|
|
172
|
+
wrapper.appendChild(content);
|
|
173
|
+
return wrapper;
|
|
174
|
+
})();
|
|
175
|
+
} else target = to;
|
|
176
|
+
if (target) {
|
|
177
|
+
const restore = captureFocus();
|
|
178
|
+
patchNode(from, target, nearestCtx(from), opts);
|
|
179
|
+
restore();
|
|
180
|
+
}
|
|
181
|
+
return from;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* `insertBefore` blurs the node it moves, so a reorder drops focus even though
|
|
185
|
+
* the element survived. Re-focus afterwards and restore the caret. Only
|
|
186
|
+
* observable in a real browser — jsdom does not blur on move.
|
|
187
|
+
*/
|
|
188
|
+
var captureFocus = () => {
|
|
189
|
+
const active = document.activeElement;
|
|
190
|
+
if (!active || active === document.body) return () => {};
|
|
191
|
+
const field = active;
|
|
192
|
+
let start = null;
|
|
193
|
+
let end = null;
|
|
194
|
+
try {
|
|
195
|
+
start = field.selectionStart;
|
|
196
|
+
end = field.selectionEnd;
|
|
197
|
+
} catch {}
|
|
198
|
+
return () => {
|
|
199
|
+
if (active === document.activeElement || !active.isConnected) return;
|
|
200
|
+
active.focus();
|
|
201
|
+
if (start !== null) try {
|
|
202
|
+
field.setSelectionRange(start, end);
|
|
203
|
+
} catch {}
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Registers `$morph`, so a template can update a region from a fetch response
|
|
208
|
+
* without dropping into JavaScript.
|
|
209
|
+
*/
|
|
210
|
+
var morphPlugin = (app) => {
|
|
211
|
+
app.scope.$morph = morph;
|
|
212
|
+
};
|
|
213
|
+
//#endregion
|
|
214
|
+
exports.morph = morph;
|
|
215
|
+
exports.morphPlugin = morphPlugin;
|
|
216
|
+
return exports;
|
|
217
|
+
})({});
|