@aevantec/litevue 0.5.0
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/LICENSE +22 -0
- package/README.md +73 -0
- package/dist/litevue-devtools.iife.js +1 -0
- package/dist/litevue-devtools.mjs +841 -0
- package/dist/litevue-devtools.umd.js +1 -0
- package/dist/litevue-plugins.iife.js +14 -0
- package/dist/litevue-plugins.mjs +1282 -0
- package/dist/litevue-plugins.umd.js +14 -0
- package/dist/litevue.iife.js +12 -0
- package/dist/litevue.mjs +1781 -0
- package/dist/litevue.umd.js +12 -0
- package/dist/types/app.d.mts +21 -0
- package/dist/types/app.d.ts +21 -0
- package/dist/types/block.d.mts +15 -0
- package/dist/types/block.d.ts +15 -0
- package/dist/types/context.d.mts +17 -0
- package/dist/types/context.d.ts +17 -0
- package/dist/types/devtools-panel.d.mts +1 -0
- package/dist/types/devtools-panel.d.ts +1 -0
- package/dist/types/devtools.d.mts +62 -0
- package/dist/types/devtools.d.ts +62 -0
- package/dist/types/directives/bind.d.mts +4 -0
- package/dist/types/directives/bind.d.ts +4 -0
- package/dist/types/directives/effect.d.mts +2 -0
- package/dist/types/directives/effect.d.ts +2 -0
- package/dist/types/directives/for.d.mts +2 -0
- package/dist/types/directives/for.d.ts +2 -0
- package/dist/types/directives/html.d.mts +2 -0
- package/dist/types/directives/html.d.ts +2 -0
- package/dist/types/directives/if.d.mts +2 -0
- package/dist/types/directives/if.d.ts +2 -0
- package/dist/types/directives/index.d.mts +15 -0
- package/dist/types/directives/index.d.ts +15 -0
- package/dist/types/directives/model.d.mts +2 -0
- package/dist/types/directives/model.d.ts +2 -0
- package/dist/types/directives/on.d.mts +2 -0
- package/dist/types/directives/on.d.ts +2 -0
- package/dist/types/directives/ref.d.mts +2 -0
- package/dist/types/directives/ref.d.ts +2 -0
- package/dist/types/directives/show.d.mts +2 -0
- package/dist/types/directives/show.d.ts +2 -0
- package/dist/types/directives/text.d.mts +3 -0
- package/dist/types/directives/text.d.ts +3 -0
- package/dist/types/effect.d.mts +15 -0
- package/dist/types/effect.d.ts +15 -0
- package/dist/types/eval.d.mts +2 -0
- package/dist/types/eval.d.ts +2 -0
- package/dist/types/index.d.mts +8 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/magics.d.mts +13 -0
- package/dist/types/magics.d.ts +13 -0
- package/dist/types/plugins/collapse.d.mts +10 -0
- package/dist/types/plugins/collapse.d.ts +10 -0
- package/dist/types/plugins/focus.d.mts +15 -0
- package/dist/types/plugins/focus.d.ts +15 -0
- package/dist/types/plugins/index.d.mts +7 -0
- package/dist/types/plugins/index.d.ts +7 -0
- package/dist/types/plugins/intersect.d.mts +11 -0
- package/dist/types/plugins/intersect.d.ts +11 -0
- package/dist/types/plugins/mask.d.mts +8 -0
- package/dist/types/plugins/mask.d.ts +8 -0
- package/dist/types/plugins/persist.d.mts +59 -0
- package/dist/types/plugins/persist.d.ts +59 -0
- package/dist/types/plugins/transition.d.mts +17 -0
- package/dist/types/plugins/transition.d.ts +17 -0
- package/dist/types/scheduler.d.mts +2 -0
- package/dist/types/scheduler.d.ts +2 -0
- package/dist/types/store.d.mts +10 -0
- package/dist/types/store.d.ts +10 -0
- package/dist/types/utils.d.mts +2 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/walk.d.mts +3 -0
- package/dist/types/walk.d.ts +3 -0
- package/package.json +124 -0
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
const css = `
|
|
2
|
+
:host {
|
|
3
|
+
all: initial;
|
|
4
|
+
--bg: #1e1e1e;
|
|
5
|
+
--bg2: #252526;
|
|
6
|
+
--hover: #2a2d2e;
|
|
7
|
+
--border: #3c3c3c;
|
|
8
|
+
--fg: #d4d4d4;
|
|
9
|
+
--muted: #808080;
|
|
10
|
+
--accent: #42b883;
|
|
11
|
+
--sel: #094771;
|
|
12
|
+
--key: #9cdcfe;
|
|
13
|
+
--val: #ce9178;
|
|
14
|
+
--exp: #6a9955;
|
|
15
|
+
}
|
|
16
|
+
:host(.light) {
|
|
17
|
+
--bg: #ffffff;
|
|
18
|
+
--bg2: #f3f3f3;
|
|
19
|
+
--hover: #ececec;
|
|
20
|
+
--border: #d0d0d0;
|
|
21
|
+
--fg: #383a42;
|
|
22
|
+
--muted: #8e8e90;
|
|
23
|
+
--sel: #d2e5f5;
|
|
24
|
+
--key: #0451a5;
|
|
25
|
+
--val: #a31515;
|
|
26
|
+
--exp: #22863a;
|
|
27
|
+
}
|
|
28
|
+
* {
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
}
|
|
31
|
+
.pill, .panel {
|
|
32
|
+
position: fixed;
|
|
33
|
+
right: 12px;
|
|
34
|
+
bottom: 12px;
|
|
35
|
+
z-index: 2147483646;
|
|
36
|
+
font: 11px/1.5 ui-monospace, Menlo, Consolas, monospace;
|
|
37
|
+
color: var(--fg);
|
|
38
|
+
}
|
|
39
|
+
.pill {
|
|
40
|
+
background: var(--bg);
|
|
41
|
+
border: 1px solid var(--border);
|
|
42
|
+
border-radius: 999px;
|
|
43
|
+
padding: 4px 10px;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
user-select: none;
|
|
46
|
+
}
|
|
47
|
+
.pill:hover {
|
|
48
|
+
border-color: var(--accent);
|
|
49
|
+
}
|
|
50
|
+
.panel {
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
width: 640px;
|
|
54
|
+
max-width: calc(100vw - 24px);
|
|
55
|
+
height: 440px;
|
|
56
|
+
max-height: calc(100vh - 24px);
|
|
57
|
+
min-width: 320px;
|
|
58
|
+
min-height: 200px;
|
|
59
|
+
background: var(--bg);
|
|
60
|
+
border: 1px solid var(--border);
|
|
61
|
+
border-radius: 6px;
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
resize: both;
|
|
64
|
+
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
|
|
65
|
+
}
|
|
66
|
+
.header {
|
|
67
|
+
display: flex;
|
|
68
|
+
align-items: center;
|
|
69
|
+
gap: 8px;
|
|
70
|
+
padding: 4px 8px;
|
|
71
|
+
background: var(--bg2);
|
|
72
|
+
border-bottom: 1px solid var(--border);
|
|
73
|
+
user-select: none;
|
|
74
|
+
cursor: move;
|
|
75
|
+
}
|
|
76
|
+
.title {
|
|
77
|
+
color: var(--accent);
|
|
78
|
+
font-weight: bold;
|
|
79
|
+
margin-right: auto;
|
|
80
|
+
}
|
|
81
|
+
.btn {
|
|
82
|
+
display: flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
background: none;
|
|
85
|
+
border: 1px solid var(--border);
|
|
86
|
+
border-radius: 3px;
|
|
87
|
+
color: var(--fg);
|
|
88
|
+
font: inherit;
|
|
89
|
+
padding: 3px 7px;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
}
|
|
92
|
+
.btn svg {
|
|
93
|
+
display: block;
|
|
94
|
+
}
|
|
95
|
+
.btn:hover {
|
|
96
|
+
border-color: var(--accent);
|
|
97
|
+
}
|
|
98
|
+
.btn.active {
|
|
99
|
+
background: var(--accent);
|
|
100
|
+
border-color: var(--accent);
|
|
101
|
+
color: var(--bg);
|
|
102
|
+
}
|
|
103
|
+
.body {
|
|
104
|
+
display: flex;
|
|
105
|
+
flex: 1;
|
|
106
|
+
min-height: 0;
|
|
107
|
+
}
|
|
108
|
+
.side {
|
|
109
|
+
display: flex;
|
|
110
|
+
flex-direction: column;
|
|
111
|
+
width: 40%;
|
|
112
|
+
min-width: 0;
|
|
113
|
+
border-right: 1px solid var(--border);
|
|
114
|
+
}
|
|
115
|
+
.tabs {
|
|
116
|
+
display: flex;
|
|
117
|
+
border-bottom: 1px solid var(--border);
|
|
118
|
+
user-select: none;
|
|
119
|
+
}
|
|
120
|
+
.tab {
|
|
121
|
+
flex: 1;
|
|
122
|
+
padding: 4px 0;
|
|
123
|
+
text-align: center;
|
|
124
|
+
color: var(--muted);
|
|
125
|
+
border-bottom: 2px solid transparent;
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
}
|
|
128
|
+
.tab:hover {
|
|
129
|
+
color: var(--fg);
|
|
130
|
+
}
|
|
131
|
+
.tab.active {
|
|
132
|
+
color: var(--fg);
|
|
133
|
+
border-bottom-color: var(--accent);
|
|
134
|
+
}
|
|
135
|
+
.filter {
|
|
136
|
+
margin: 6px 6px 2px;
|
|
137
|
+
background: var(--bg2);
|
|
138
|
+
border: 1px solid var(--border);
|
|
139
|
+
border-radius: 3px;
|
|
140
|
+
color: var(--fg);
|
|
141
|
+
font: inherit;
|
|
142
|
+
padding: 2px 6px;
|
|
143
|
+
outline: none;
|
|
144
|
+
}
|
|
145
|
+
.filter:focus {
|
|
146
|
+
border-color: var(--accent);
|
|
147
|
+
}
|
|
148
|
+
.filter::placeholder {
|
|
149
|
+
color: var(--muted);
|
|
150
|
+
}
|
|
151
|
+
.tree {
|
|
152
|
+
flex: 1;
|
|
153
|
+
overflow: auto;
|
|
154
|
+
padding: 4px 0;
|
|
155
|
+
}
|
|
156
|
+
.state {
|
|
157
|
+
flex: 1;
|
|
158
|
+
overflow: auto;
|
|
159
|
+
padding: 4px 0;
|
|
160
|
+
}
|
|
161
|
+
.row {
|
|
162
|
+
padding: 2px 8px;
|
|
163
|
+
white-space: nowrap;
|
|
164
|
+
overflow: hidden;
|
|
165
|
+
text-overflow: ellipsis;
|
|
166
|
+
cursor: pointer;
|
|
167
|
+
}
|
|
168
|
+
.row:hover {
|
|
169
|
+
background: var(--hover);
|
|
170
|
+
}
|
|
171
|
+
.row.sel {
|
|
172
|
+
background: var(--sel);
|
|
173
|
+
}
|
|
174
|
+
.row .name {
|
|
175
|
+
color: var(--key);
|
|
176
|
+
}
|
|
177
|
+
.row .punct {
|
|
178
|
+
color: var(--muted);
|
|
179
|
+
}
|
|
180
|
+
.row .exp {
|
|
181
|
+
color: var(--exp);
|
|
182
|
+
}
|
|
183
|
+
.prop {
|
|
184
|
+
display: flex;
|
|
185
|
+
gap: 6px;
|
|
186
|
+
padding: 2px 8px;
|
|
187
|
+
align-items: center;
|
|
188
|
+
}
|
|
189
|
+
.prop .key {
|
|
190
|
+
color: var(--key);
|
|
191
|
+
flex-shrink: 0;
|
|
192
|
+
}
|
|
193
|
+
.arrow {
|
|
194
|
+
width: 12px;
|
|
195
|
+
flex-shrink: 0;
|
|
196
|
+
color: var(--muted);
|
|
197
|
+
font-size: 9px;
|
|
198
|
+
transition: transform 0.1s;
|
|
199
|
+
}
|
|
200
|
+
.arrow.open {
|
|
201
|
+
transform: rotate(90deg);
|
|
202
|
+
}
|
|
203
|
+
.spacer {
|
|
204
|
+
width: 12px;
|
|
205
|
+
flex-shrink: 0;
|
|
206
|
+
}
|
|
207
|
+
.prop.toggle {
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
user-select: none;
|
|
210
|
+
}
|
|
211
|
+
.prop.toggle:hover {
|
|
212
|
+
background: var(--hover);
|
|
213
|
+
}
|
|
214
|
+
.preview {
|
|
215
|
+
flex: 1;
|
|
216
|
+
min-width: 0;
|
|
217
|
+
color: var(--muted);
|
|
218
|
+
white-space: nowrap;
|
|
219
|
+
overflow: hidden;
|
|
220
|
+
text-overflow: ellipsis;
|
|
221
|
+
}
|
|
222
|
+
.muted {
|
|
223
|
+
color: var(--muted);
|
|
224
|
+
padding: 2px 8px;
|
|
225
|
+
}
|
|
226
|
+
.check {
|
|
227
|
+
margin: 0;
|
|
228
|
+
flex-shrink: 0;
|
|
229
|
+
accent-color: var(--accent);
|
|
230
|
+
cursor: pointer;
|
|
231
|
+
}
|
|
232
|
+
.del {
|
|
233
|
+
visibility: hidden;
|
|
234
|
+
flex-shrink: 0;
|
|
235
|
+
background: none;
|
|
236
|
+
border: none;
|
|
237
|
+
padding: 0 2px;
|
|
238
|
+
color: var(--muted);
|
|
239
|
+
font: inherit;
|
|
240
|
+
cursor: pointer;
|
|
241
|
+
}
|
|
242
|
+
.prop:hover .del {
|
|
243
|
+
visibility: visible;
|
|
244
|
+
}
|
|
245
|
+
.del:hover {
|
|
246
|
+
color: #e5534b;
|
|
247
|
+
}
|
|
248
|
+
.adder .key-in {
|
|
249
|
+
flex: 0 0 30%;
|
|
250
|
+
color: var(--key);
|
|
251
|
+
}
|
|
252
|
+
.adder input::placeholder {
|
|
253
|
+
color: var(--muted);
|
|
254
|
+
}
|
|
255
|
+
.adder input {
|
|
256
|
+
border-color: var(--border);
|
|
257
|
+
}
|
|
258
|
+
.bool {
|
|
259
|
+
color: var(--val);
|
|
260
|
+
}
|
|
261
|
+
.prop.inherited .key {
|
|
262
|
+
color: var(--muted);
|
|
263
|
+
}
|
|
264
|
+
.prop .val {
|
|
265
|
+
flex: 1;
|
|
266
|
+
min-width: 0;
|
|
267
|
+
background: none;
|
|
268
|
+
border: 1px solid transparent;
|
|
269
|
+
border-radius: 3px;
|
|
270
|
+
color: var(--val);
|
|
271
|
+
font: inherit;
|
|
272
|
+
padding: 0 3px;
|
|
273
|
+
white-space: nowrap;
|
|
274
|
+
overflow: hidden;
|
|
275
|
+
text-overflow: ellipsis;
|
|
276
|
+
}
|
|
277
|
+
input.val:hover, input.val:focus {
|
|
278
|
+
border-color: var(--border);
|
|
279
|
+
outline: none;
|
|
280
|
+
background: var(--bg2);
|
|
281
|
+
}
|
|
282
|
+
.divider {
|
|
283
|
+
padding: 4px 8px 1px;
|
|
284
|
+
color: var(--muted);
|
|
285
|
+
font-size: 10px;
|
|
286
|
+
text-transform: uppercase;
|
|
287
|
+
user-select: none;
|
|
288
|
+
}
|
|
289
|
+
.empty {
|
|
290
|
+
padding: 8px;
|
|
291
|
+
color: var(--muted);
|
|
292
|
+
}
|
|
293
|
+
.highlight {
|
|
294
|
+
position: fixed;
|
|
295
|
+
z-index: 2147483645;
|
|
296
|
+
background: rgba(66, 184, 131, 0.25);
|
|
297
|
+
border: 1px solid var(--accent);
|
|
298
|
+
pointer-events: none;
|
|
299
|
+
display: none;
|
|
300
|
+
}
|
|
301
|
+
`;
|
|
302
|
+
let devtools;
|
|
303
|
+
let shadow;
|
|
304
|
+
let panelEl;
|
|
305
|
+
let pillEl;
|
|
306
|
+
let treeEl;
|
|
307
|
+
let stateEl;
|
|
308
|
+
let pickBtn;
|
|
309
|
+
let themeBtn;
|
|
310
|
+
let highlightEl;
|
|
311
|
+
let selected = null;
|
|
312
|
+
let selectedStore = null;
|
|
313
|
+
let picking = false;
|
|
314
|
+
let filterText = "";
|
|
315
|
+
let activeTab = "Elements";
|
|
316
|
+
let elementsTab;
|
|
317
|
+
let storesTab;
|
|
318
|
+
const icon = (paths) => '<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">' + paths + "</svg>";
|
|
319
|
+
const THEME_KEY = "litevue-devtools-theme";
|
|
320
|
+
const UI_KEY = "litevue-devtools-ui";
|
|
321
|
+
const loadUi = () => {
|
|
322
|
+
try {
|
|
323
|
+
return JSON.parse(localStorage.getItem(UI_KEY) || "{}");
|
|
324
|
+
} catch {
|
|
325
|
+
return {};
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const saveUi = (patch) => {
|
|
329
|
+
try {
|
|
330
|
+
localStorage.setItem(UI_KEY, JSON.stringify({ ...loadUi(), ...patch }));
|
|
331
|
+
} catch {
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const themeIcons = {
|
|
335
|
+
dark: icon('<path d="M21 12.8A9 9 0 1 1 11.2 3 7 7 0 0 0 21 12.8z"/>'),
|
|
336
|
+
light: icon(
|
|
337
|
+
'<circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.2" y1="4.2" x2="5.6" y2="5.6"/><line x1="18.4" y1="18.4" x2="19.8" y2="19.8"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.2" y1="19.8" x2="5.6" y2="18.4"/><line x1="18.4" y1="5.6" x2="19.8" y2="4.2"/>'
|
|
338
|
+
),
|
|
339
|
+
system: icon(
|
|
340
|
+
'<rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/>'
|
|
341
|
+
)
|
|
342
|
+
};
|
|
343
|
+
const nextTheme = {
|
|
344
|
+
dark: "light",
|
|
345
|
+
light: "system",
|
|
346
|
+
system: "dark"
|
|
347
|
+
};
|
|
348
|
+
let theme = "dark";
|
|
349
|
+
try {
|
|
350
|
+
const saved = localStorage.getItem(THEME_KEY);
|
|
351
|
+
if (saved === "light" || saved === "system") theme = saved;
|
|
352
|
+
} catch {
|
|
353
|
+
}
|
|
354
|
+
const prefersLight = matchMedia("(prefers-color-scheme: light)");
|
|
355
|
+
const applyTheme = () => {
|
|
356
|
+
const light = theme === "light" || theme === "system" && prefersLight.matches;
|
|
357
|
+
shadow.host.classList.toggle("light", light);
|
|
358
|
+
themeBtn.innerHTML = themeIcons[theme];
|
|
359
|
+
themeBtn.title = "theme: " + theme;
|
|
360
|
+
};
|
|
361
|
+
const expandedPaths = /* @__PURE__ */ new Set();
|
|
362
|
+
const h = (tag, className, text) => {
|
|
363
|
+
const el = document.createElement(tag);
|
|
364
|
+
el.className = className;
|
|
365
|
+
if (text != null) el.textContent = text;
|
|
366
|
+
return el;
|
|
367
|
+
};
|
|
368
|
+
const tagOf = (el) => {
|
|
369
|
+
const label = h("span", "label");
|
|
370
|
+
label.appendChild(h("span", "punct", "<"));
|
|
371
|
+
label.appendChild(h("span", "name", nameOf(el)));
|
|
372
|
+
label.appendChild(h("span", "punct", ">"));
|
|
373
|
+
return label;
|
|
374
|
+
};
|
|
375
|
+
const depthOf = (el) => {
|
|
376
|
+
let depth = 0;
|
|
377
|
+
let p = el.parentElement;
|
|
378
|
+
while (p) {
|
|
379
|
+
if (devtools.scopes.has(p)) depth++;
|
|
380
|
+
p = p.parentElement;
|
|
381
|
+
}
|
|
382
|
+
return depth;
|
|
383
|
+
};
|
|
384
|
+
const fmt = (v) => {
|
|
385
|
+
let s;
|
|
386
|
+
try {
|
|
387
|
+
s = v === void 0 ? "undefined" : JSON.stringify(v) ?? String(v);
|
|
388
|
+
} catch (e) {
|
|
389
|
+
s = String(v);
|
|
390
|
+
}
|
|
391
|
+
return s.length > 60 ? s.slice(0, 60) + "…" : s;
|
|
392
|
+
};
|
|
393
|
+
const coerce = (raw, old) => {
|
|
394
|
+
if (typeof old === "number") {
|
|
395
|
+
const n = parseFloat(raw);
|
|
396
|
+
return isNaN(n) ? raw : n;
|
|
397
|
+
}
|
|
398
|
+
return raw;
|
|
399
|
+
};
|
|
400
|
+
const collectProps = (scope) => {
|
|
401
|
+
const isData = (o, k) => k[0] !== "$" && typeof o[k] !== "function";
|
|
402
|
+
const own = Object.keys(scope).filter((k) => isData(scope, k));
|
|
403
|
+
const seen = new Set(own);
|
|
404
|
+
const inherited = [];
|
|
405
|
+
let proto = Object.getPrototypeOf(scope);
|
|
406
|
+
while (proto && proto !== Object.prototype) {
|
|
407
|
+
for (const k of Object.keys(proto)) {
|
|
408
|
+
if (!seen.has(k) && isData(proto, k)) {
|
|
409
|
+
seen.add(k);
|
|
410
|
+
inherited.push(k);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
proto = Object.getPrototypeOf(proto);
|
|
414
|
+
}
|
|
415
|
+
return { own, inherited };
|
|
416
|
+
};
|
|
417
|
+
const showHighlight = (el) => {
|
|
418
|
+
const r = el.getBoundingClientRect();
|
|
419
|
+
highlightEl.style.cssText = `display:block;left:${r.left}px;top:${r.top}px;width:${r.width}px;height:${r.height}px`;
|
|
420
|
+
};
|
|
421
|
+
const hideHighlight = () => {
|
|
422
|
+
highlightEl.style.display = "none";
|
|
423
|
+
};
|
|
424
|
+
const select = (el) => {
|
|
425
|
+
if (el !== selected) expandedPaths.clear();
|
|
426
|
+
selectedStore = null;
|
|
427
|
+
selected = el;
|
|
428
|
+
activeTab = "Elements";
|
|
429
|
+
window.$scope = el ? devtools.scopes.get(el) : void 0;
|
|
430
|
+
renderTree();
|
|
431
|
+
renderState();
|
|
432
|
+
};
|
|
433
|
+
const selectStore = (name) => {
|
|
434
|
+
if (name !== selectedStore) expandedPaths.clear();
|
|
435
|
+
selected = null;
|
|
436
|
+
selectedStore = name;
|
|
437
|
+
activeTab = "Stores";
|
|
438
|
+
window.$scope = devtools.stores.get(name);
|
|
439
|
+
renderTree();
|
|
440
|
+
renderState();
|
|
441
|
+
};
|
|
442
|
+
const switchTab = (tab) => {
|
|
443
|
+
activeTab = tab;
|
|
444
|
+
renderTree();
|
|
445
|
+
};
|
|
446
|
+
const nameOf = (el) => devtools.names.get(el) || el.id || el.tagName.toLowerCase();
|
|
447
|
+
const renderTabs = () => {
|
|
448
|
+
const storeCount = devtools.stores ? devtools.stores.size : 0;
|
|
449
|
+
elementsTab.textContent = `Elements (${devtools.scopes.size})`;
|
|
450
|
+
elementsTab.className = activeTab === "Elements" ? "tab active" : "tab";
|
|
451
|
+
storesTab.textContent = `Stores (${storeCount})`;
|
|
452
|
+
storesTab.className = activeTab === "Stores" ? "tab active" : "tab";
|
|
453
|
+
};
|
|
454
|
+
const renderTree = () => {
|
|
455
|
+
renderTabs();
|
|
456
|
+
treeEl.textContent = "";
|
|
457
|
+
if (activeTab === "Elements") {
|
|
458
|
+
const roots = [...devtools.scopes.keys()].filter((el) => nameOf(el).toLowerCase().includes(filterText)).sort(
|
|
459
|
+
(a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
|
|
460
|
+
);
|
|
461
|
+
if (!roots.length) {
|
|
462
|
+
treeEl.appendChild(
|
|
463
|
+
h(
|
|
464
|
+
"div",
|
|
465
|
+
"empty",
|
|
466
|
+
filterText ? "no matching scopes" : "no scopes mounted"
|
|
467
|
+
)
|
|
468
|
+
);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
for (const el of roots) {
|
|
472
|
+
const row = h("div", el === selected ? "row sel" : "row");
|
|
473
|
+
row.style.paddingLeft = 8 + depthOf(el) * 12 + "px";
|
|
474
|
+
row.appendChild(tagOf(el));
|
|
475
|
+
const exp = devtools.exps.get(el);
|
|
476
|
+
if (exp) row.appendChild(h("span", "exp", " " + exp));
|
|
477
|
+
row.onclick = () => select(el);
|
|
478
|
+
row.onmouseenter = () => showHighlight(el);
|
|
479
|
+
row.onmouseleave = hideHighlight;
|
|
480
|
+
treeEl.appendChild(row);
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const storeNames = [
|
|
485
|
+
...devtools.stores ? devtools.stores.keys() : []
|
|
486
|
+
].filter((n) => n.toLowerCase().includes(filterText));
|
|
487
|
+
if (!storeNames.length) {
|
|
488
|
+
treeEl.appendChild(
|
|
489
|
+
h(
|
|
490
|
+
"div",
|
|
491
|
+
"empty",
|
|
492
|
+
filterText ? "no matching stores" : "no stores registered"
|
|
493
|
+
)
|
|
494
|
+
);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
for (const name of storeNames) {
|
|
498
|
+
const row = h("div", name === selectedStore ? "row sel" : "row");
|
|
499
|
+
const label = h("span", "label");
|
|
500
|
+
label.appendChild(h("span", "punct", "$store."));
|
|
501
|
+
label.appendChild(h("span", "name", name));
|
|
502
|
+
row.appendChild(label);
|
|
503
|
+
row.onclick = () => selectStore(name);
|
|
504
|
+
treeEl.appendChild(row);
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const renderState = () => {
|
|
508
|
+
if (stateEl.contains(shadow.activeElement)) return;
|
|
509
|
+
stateEl.textContent = "";
|
|
510
|
+
const scope = selectedStore ? devtools.stores.get(selectedStore) : selected ? devtools.scopes.get(selected) : void 0;
|
|
511
|
+
if (!scope) {
|
|
512
|
+
stateEl.appendChild(h("div", "empty", "Select a scope"));
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const { own, inherited } = collectProps(scope);
|
|
516
|
+
own.forEach((k) => addNode(k, scope, k, 0, "prop", []));
|
|
517
|
+
if (inherited.length) {
|
|
518
|
+
stateEl.appendChild(h("div", "divider", "inherited"));
|
|
519
|
+
inherited.forEach((k) => addNode(k, scope, k, 0, "prop inherited", []));
|
|
520
|
+
}
|
|
521
|
+
if (!own.length && !inherited.length) {
|
|
522
|
+
stateEl.appendChild(h("div", "empty", "empty scope"));
|
|
523
|
+
}
|
|
524
|
+
stateEl.appendChild(buildAdder(scope));
|
|
525
|
+
};
|
|
526
|
+
const buildAdder = (scope) => {
|
|
527
|
+
const row = h("div", "prop adder");
|
|
528
|
+
row.appendChild(h("span", "spacer"));
|
|
529
|
+
const keyIn = h("input", "val key-in");
|
|
530
|
+
keyIn.placeholder = "key";
|
|
531
|
+
const valIn = h("input", "val");
|
|
532
|
+
valIn.placeholder = "value";
|
|
533
|
+
const commit = () => {
|
|
534
|
+
const k = keyIn.value.trim();
|
|
535
|
+
if (!k) return;
|
|
536
|
+
const raw = valIn.value;
|
|
537
|
+
let v = raw;
|
|
538
|
+
if (raw === "true") v = true;
|
|
539
|
+
else if (raw === "false") v = false;
|
|
540
|
+
else if (raw !== "" && !isNaN(+raw)) v = +raw;
|
|
541
|
+
scope[k] = v;
|
|
542
|
+
keyIn.blur();
|
|
543
|
+
valIn.blur();
|
|
544
|
+
scheduleRender();
|
|
545
|
+
setTimeout(() => {
|
|
546
|
+
const next = stateEl.querySelector(".adder .key-in");
|
|
547
|
+
if (next) next.focus();
|
|
548
|
+
});
|
|
549
|
+
};
|
|
550
|
+
keyIn.onkeydown = valIn.onkeydown = (e) => {
|
|
551
|
+
if (e.key === "Enter") commit();
|
|
552
|
+
};
|
|
553
|
+
row.appendChild(keyIn);
|
|
554
|
+
row.appendChild(valIn);
|
|
555
|
+
return row;
|
|
556
|
+
};
|
|
557
|
+
const previewOf = (v) => Array.isArray(v) ? `(${v.length}) ${fmt(v)}` : fmt(v);
|
|
558
|
+
const addNode = (key, container, path, depth, cls, ancestors) => {
|
|
559
|
+
const v = container[key];
|
|
560
|
+
const row = h("div", cls);
|
|
561
|
+
row.style.paddingLeft = 8 + depth * 14 + "px";
|
|
562
|
+
if (v !== null && typeof v === "object") {
|
|
563
|
+
const circular = ancestors.indexOf(v) > -1;
|
|
564
|
+
const open = !circular && expandedPaths.has(path);
|
|
565
|
+
row.appendChild(h("span", open ? "arrow open" : "arrow", "▶"));
|
|
566
|
+
row.appendChild(h("span", "key", key));
|
|
567
|
+
row.appendChild(
|
|
568
|
+
h("span", "preview", circular ? "(circular)" : previewOf(v))
|
|
569
|
+
);
|
|
570
|
+
if (!circular) {
|
|
571
|
+
row.classList.add("toggle");
|
|
572
|
+
row.onclick = () => {
|
|
573
|
+
open ? expandedPaths.delete(path) : expandedPaths.add(path);
|
|
574
|
+
renderState();
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
appendDelete(row, container, key, depth, cls);
|
|
578
|
+
stateEl.appendChild(row);
|
|
579
|
+
if (open) {
|
|
580
|
+
const keys = Object.keys(v);
|
|
581
|
+
if (!keys.length) {
|
|
582
|
+
const empty = h("div", "muted", "(empty)");
|
|
583
|
+
empty.style.paddingLeft = 22 + (depth + 1) * 14 + "px";
|
|
584
|
+
stateEl.appendChild(empty);
|
|
585
|
+
}
|
|
586
|
+
for (const k of keys) {
|
|
587
|
+
addNode(k, v, path + "." + k, depth + 1, cls, ancestors.concat([v]));
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
row.appendChild(h("span", "spacer"));
|
|
593
|
+
row.appendChild(h("span", "key", key));
|
|
594
|
+
const desc = Object.getOwnPropertyDescriptor(container, key);
|
|
595
|
+
if (typeof v === "function") {
|
|
596
|
+
row.appendChild(h("span", "preview", "ƒ"));
|
|
597
|
+
} else if (desc && desc.get && !desc.set) {
|
|
598
|
+
row.appendChild(h("span", "preview", fmt(v)));
|
|
599
|
+
} else if (typeof v === "boolean") {
|
|
600
|
+
row.appendChild(h("span", "bool", String(v)));
|
|
601
|
+
const cb = h("input", "check");
|
|
602
|
+
cb.type = "checkbox";
|
|
603
|
+
cb.checked = v;
|
|
604
|
+
cb.onchange = () => {
|
|
605
|
+
container[key] = cb.checked;
|
|
606
|
+
cb.blur();
|
|
607
|
+
scheduleRender();
|
|
608
|
+
};
|
|
609
|
+
row.appendChild(cb);
|
|
610
|
+
} else {
|
|
611
|
+
const input = h("input", "val");
|
|
612
|
+
input.value = fmt(v);
|
|
613
|
+
input.onfocus = () => {
|
|
614
|
+
input.value = typeof v === "string" ? v : String(v);
|
|
615
|
+
};
|
|
616
|
+
input.onkeydown = (e) => {
|
|
617
|
+
if (e.key === "Enter") input.blur();
|
|
618
|
+
if (e.key === "Escape") {
|
|
619
|
+
input.value = fmt(v);
|
|
620
|
+
input.blur();
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
input.onblur = () => {
|
|
624
|
+
const next = coerce(input.value, v);
|
|
625
|
+
if (next !== v) {
|
|
626
|
+
container[key] = next;
|
|
627
|
+
scheduleRender();
|
|
628
|
+
} else {
|
|
629
|
+
input.value = fmt(v);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
row.appendChild(input);
|
|
633
|
+
}
|
|
634
|
+
appendDelete(row, container, key, depth, cls);
|
|
635
|
+
stateEl.appendChild(row);
|
|
636
|
+
};
|
|
637
|
+
const appendDelete = (row, container, key, depth, cls) => {
|
|
638
|
+
if (depth !== 0 || cls !== "prop") return;
|
|
639
|
+
const desc = Object.getOwnPropertyDescriptor(container, key);
|
|
640
|
+
if (desc && desc.get) return;
|
|
641
|
+
const del = h("button", "del", "✕");
|
|
642
|
+
del.title = `delete "${key}"`;
|
|
643
|
+
del.onclick = (e) => {
|
|
644
|
+
e.stopPropagation();
|
|
645
|
+
const active = shadow.activeElement;
|
|
646
|
+
if (active && active.blur) active.blur();
|
|
647
|
+
delete container[key];
|
|
648
|
+
scheduleRender();
|
|
649
|
+
};
|
|
650
|
+
row.appendChild(del);
|
|
651
|
+
};
|
|
652
|
+
const onPickClick = (e) => {
|
|
653
|
+
const target = e.target;
|
|
654
|
+
if (target === shadow.host) return;
|
|
655
|
+
e.preventDefault();
|
|
656
|
+
e.stopPropagation();
|
|
657
|
+
stopPicking();
|
|
658
|
+
let el = target;
|
|
659
|
+
while (el && !devtools.scopes.has(el)) el = el.parentElement;
|
|
660
|
+
if (el) select(el);
|
|
661
|
+
};
|
|
662
|
+
const onPickMove = (e) => {
|
|
663
|
+
let el = e.target;
|
|
664
|
+
if (el === shadow.host) return;
|
|
665
|
+
while (el && !devtools.scopes.has(el)) el = el.parentElement;
|
|
666
|
+
el ? showHighlight(el) : hideHighlight();
|
|
667
|
+
};
|
|
668
|
+
const startPicking = () => {
|
|
669
|
+
picking = true;
|
|
670
|
+
pickBtn.classList.add("active");
|
|
671
|
+
document.addEventListener("click", onPickClick, true);
|
|
672
|
+
document.addEventListener("mousemove", onPickMove, true);
|
|
673
|
+
};
|
|
674
|
+
const stopPicking = () => {
|
|
675
|
+
picking = false;
|
|
676
|
+
pickBtn.classList.remove("active");
|
|
677
|
+
hideHighlight();
|
|
678
|
+
document.removeEventListener("click", onPickClick, true);
|
|
679
|
+
document.removeEventListener("mousemove", onPickMove, true);
|
|
680
|
+
};
|
|
681
|
+
let renderQueued = false;
|
|
682
|
+
const scheduleRender = () => {
|
|
683
|
+
if (renderQueued) return;
|
|
684
|
+
renderQueued = true;
|
|
685
|
+
setTimeout(() => {
|
|
686
|
+
renderQueued = false;
|
|
687
|
+
if (panelEl.style.display === "none") return;
|
|
688
|
+
renderTree();
|
|
689
|
+
renderState();
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
const build = () => {
|
|
693
|
+
const host = document.createElement("div");
|
|
694
|
+
shadow = host.attachShadow({ mode: "open" });
|
|
695
|
+
const style = document.createElement("style");
|
|
696
|
+
style.textContent = css;
|
|
697
|
+
shadow.appendChild(style);
|
|
698
|
+
highlightEl = h("div", "highlight");
|
|
699
|
+
shadow.appendChild(highlightEl);
|
|
700
|
+
pillEl = h("div", "pill", "⚡ LiteVue");
|
|
701
|
+
pillEl.onclick = () => {
|
|
702
|
+
pillEl.style.display = "none";
|
|
703
|
+
panelEl.style.display = "flex";
|
|
704
|
+
saveUi({ open: true });
|
|
705
|
+
scheduleRender();
|
|
706
|
+
};
|
|
707
|
+
shadow.appendChild(pillEl);
|
|
708
|
+
panelEl = h("div", "panel");
|
|
709
|
+
panelEl.style.display = "none";
|
|
710
|
+
const header = h("div", "header");
|
|
711
|
+
header.appendChild(h("span", "title", "⚡ LiteVue"));
|
|
712
|
+
header.addEventListener("mousedown", (e) => {
|
|
713
|
+
if (e.target.closest(".btn")) return;
|
|
714
|
+
e.preventDefault();
|
|
715
|
+
const rect = panelEl.getBoundingClientRect();
|
|
716
|
+
const startRight = window.innerWidth - rect.right;
|
|
717
|
+
const startBottom = window.innerHeight - rect.bottom;
|
|
718
|
+
const startX = e.clientX;
|
|
719
|
+
const startY = e.clientY;
|
|
720
|
+
const move = (ev) => {
|
|
721
|
+
panelEl.style.right = Math.max(0, startRight - (ev.clientX - startX)) + "px";
|
|
722
|
+
panelEl.style.bottom = Math.max(0, startBottom - (ev.clientY - startY)) + "px";
|
|
723
|
+
};
|
|
724
|
+
const up = () => {
|
|
725
|
+
document.removeEventListener("mousemove", move);
|
|
726
|
+
document.removeEventListener("mouseup", up);
|
|
727
|
+
saveUi({
|
|
728
|
+
right: parseInt(panelEl.style.right) || 12,
|
|
729
|
+
bottom: parseInt(panelEl.style.bottom) || 12
|
|
730
|
+
});
|
|
731
|
+
};
|
|
732
|
+
document.addEventListener("mousemove", move);
|
|
733
|
+
document.addEventListener("mouseup", up);
|
|
734
|
+
});
|
|
735
|
+
themeBtn = h("button", "btn");
|
|
736
|
+
themeBtn.onclick = () => {
|
|
737
|
+
theme = nextTheme[theme];
|
|
738
|
+
try {
|
|
739
|
+
localStorage.setItem(THEME_KEY, theme);
|
|
740
|
+
} catch {
|
|
741
|
+
}
|
|
742
|
+
applyTheme();
|
|
743
|
+
};
|
|
744
|
+
header.appendChild(themeBtn);
|
|
745
|
+
prefersLight.addEventListener("change", () => {
|
|
746
|
+
if (theme === "system") applyTheme();
|
|
747
|
+
});
|
|
748
|
+
applyTheme();
|
|
749
|
+
pickBtn = h("button", "btn");
|
|
750
|
+
pickBtn.title = "pick an element on the page";
|
|
751
|
+
pickBtn.innerHTML = icon(
|
|
752
|
+
'<circle cx="12" cy="12" r="7"/><line x1="12" y1="1" x2="12" y2="6"/><line x1="12" y1="18" x2="12" y2="23"/><line x1="1" y1="12" x2="6" y2="12"/><line x1="18" y1="12" x2="23" y2="12"/>'
|
|
753
|
+
);
|
|
754
|
+
pickBtn.onclick = () => picking ? stopPicking() : startPicking();
|
|
755
|
+
header.appendChild(pickBtn);
|
|
756
|
+
const closeBtn = h("button", "btn", "✕");
|
|
757
|
+
closeBtn.onclick = () => {
|
|
758
|
+
if (picking) stopPicking();
|
|
759
|
+
panelEl.style.display = "none";
|
|
760
|
+
pillEl.style.display = "";
|
|
761
|
+
saveUi({ open: false });
|
|
762
|
+
};
|
|
763
|
+
header.appendChild(closeBtn);
|
|
764
|
+
panelEl.appendChild(header);
|
|
765
|
+
const body = h("div", "body");
|
|
766
|
+
const side = h("div", "side");
|
|
767
|
+
const tabs = h("div", "tabs");
|
|
768
|
+
elementsTab = h("div", "tab active");
|
|
769
|
+
elementsTab.onclick = () => switchTab("Elements");
|
|
770
|
+
storesTab = h("div", "tab");
|
|
771
|
+
storesTab.onclick = () => switchTab("Stores");
|
|
772
|
+
tabs.appendChild(elementsTab);
|
|
773
|
+
tabs.appendChild(storesTab);
|
|
774
|
+
side.appendChild(tabs);
|
|
775
|
+
const filterInput = h("input", "filter");
|
|
776
|
+
filterInput.placeholder = "Filter by name";
|
|
777
|
+
filterInput.oninput = () => {
|
|
778
|
+
filterText = filterInput.value.trim().toLowerCase();
|
|
779
|
+
renderTree();
|
|
780
|
+
};
|
|
781
|
+
filterInput.onkeydown = (e) => {
|
|
782
|
+
if (e.key === "Escape") {
|
|
783
|
+
filterInput.value = "";
|
|
784
|
+
filterText = "";
|
|
785
|
+
renderTree();
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
side.appendChild(filterInput);
|
|
789
|
+
treeEl = h("div", "tree");
|
|
790
|
+
side.appendChild(treeEl);
|
|
791
|
+
stateEl = h("div", "state");
|
|
792
|
+
body.appendChild(side);
|
|
793
|
+
body.appendChild(stateEl);
|
|
794
|
+
panelEl.appendChild(body);
|
|
795
|
+
shadow.appendChild(panelEl);
|
|
796
|
+
const ui = loadUi();
|
|
797
|
+
if (ui.right != null) panelEl.style.right = ui.right + "px";
|
|
798
|
+
if (ui.bottom != null) panelEl.style.bottom = ui.bottom + "px";
|
|
799
|
+
if (ui.w) panelEl.style.width = ui.w + "px";
|
|
800
|
+
if (ui.h) panelEl.style.height = ui.h + "px";
|
|
801
|
+
if (ui.open) {
|
|
802
|
+
pillEl.style.display = "none";
|
|
803
|
+
panelEl.style.display = "flex";
|
|
804
|
+
scheduleRender();
|
|
805
|
+
}
|
|
806
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
807
|
+
let t;
|
|
808
|
+
new ResizeObserver(() => {
|
|
809
|
+
clearTimeout(t);
|
|
810
|
+
t = setTimeout(() => {
|
|
811
|
+
if (panelEl.style.display !== "none" && panelEl.offsetWidth) {
|
|
812
|
+
saveUi({ w: panelEl.offsetWidth, h: panelEl.offsetHeight });
|
|
813
|
+
}
|
|
814
|
+
}, 300);
|
|
815
|
+
}).observe(panelEl);
|
|
816
|
+
}
|
|
817
|
+
document.body.appendChild(host);
|
|
818
|
+
devtools.on("scope:mount", scheduleRender);
|
|
819
|
+
devtools.on("scope:unmount", (el) => {
|
|
820
|
+
if (el === selected) selected = null;
|
|
821
|
+
scheduleRender();
|
|
822
|
+
});
|
|
823
|
+
if (devtools.stores) {
|
|
824
|
+
devtools.on("store:register", scheduleRender);
|
|
825
|
+
}
|
|
826
|
+
devtools.on("flush", scheduleRender);
|
|
827
|
+
};
|
|
828
|
+
const init = () => {
|
|
829
|
+
const d = window.__LITE_VUE__;
|
|
830
|
+
if (!d) {
|
|
831
|
+
console.warn(
|
|
832
|
+
"[LiteVue devtools] window.__LITE_VUE__ not found — load LiteVue before the devtools panel script."
|
|
833
|
+
);
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
devtools = d;
|
|
837
|
+
document.body ? build() : addEventListener("DOMContentLoaded", build);
|
|
838
|
+
};
|
|
839
|
+
init();
|
|
840
|
+
|
|
841
|
+
export { init };
|