@vue/devtools-api 8.2.1 → 9.0.0-beta.1

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.
@@ -1,1771 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
- value: mod,
21
- enumerable: true
22
- }) : target, mod));
23
- //#endregion
24
- //#region ../shared/src/env.ts
25
- const isBrowser = typeof navigator !== "undefined";
26
- const target = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : typeof global !== "undefined" ? global : {};
27
- typeof target.chrome !== "undefined" && target.chrome.devtools;
28
- isBrowser && (target.self, target.top);
29
- typeof navigator !== "undefined" && navigator.userAgent?.toLowerCase().includes("electron");
30
- typeof window !== "undefined" && window.__NUXT__;
31
- //#endregion
32
- //#region ../shared/src/general.ts
33
- var import_rfdc = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
34
- module.exports = rfdc;
35
- function copyBuffer(cur) {
36
- if (cur instanceof Buffer) return Buffer.from(cur);
37
- return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
38
- }
39
- function rfdc(opts) {
40
- opts = opts || {};
41
- if (opts.circles) return rfdcCircles(opts);
42
- const constructorHandlers = /* @__PURE__ */ new Map();
43
- constructorHandlers.set(Date, (o) => new Date(o));
44
- constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
45
- constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
46
- if (opts.constructorHandlers) for (const handler of opts.constructorHandlers) constructorHandlers.set(handler[0], handler[1]);
47
- let handler = null;
48
- return opts.proto ? cloneProto : clone;
49
- function cloneArray(a, fn) {
50
- const keys = Object.keys(a);
51
- const a2 = new Array(keys.length);
52
- for (let i = 0; i < keys.length; i++) {
53
- const k = keys[i];
54
- const cur = a[k];
55
- if (typeof cur !== "object" || cur === null) a2[k] = cur;
56
- else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
57
- else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
58
- else a2[k] = fn(cur);
59
- }
60
- return a2;
61
- }
62
- function clone(o) {
63
- if (typeof o !== "object" || o === null) return o;
64
- if (Array.isArray(o)) return cloneArray(o, clone);
65
- if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone);
66
- const o2 = {};
67
- for (const k in o) {
68
- if (Object.hasOwnProperty.call(o, k) === false) continue;
69
- const cur = o[k];
70
- if (typeof cur !== "object" || cur === null) o2[k] = cur;
71
- else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone);
72
- else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
73
- else o2[k] = clone(cur);
74
- }
75
- return o2;
76
- }
77
- function cloneProto(o) {
78
- if (typeof o !== "object" || o === null) return o;
79
- if (Array.isArray(o)) return cloneArray(o, cloneProto);
80
- if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
81
- const o2 = {};
82
- for (const k in o) {
83
- const cur = o[k];
84
- if (typeof cur !== "object" || cur === null) o2[k] = cur;
85
- else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
86
- else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
87
- else o2[k] = cloneProto(cur);
88
- }
89
- return o2;
90
- }
91
- }
92
- function rfdcCircles(opts) {
93
- const refs = [];
94
- const refsNew = [];
95
- const constructorHandlers = /* @__PURE__ */ new Map();
96
- constructorHandlers.set(Date, (o) => new Date(o));
97
- constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
98
- constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
99
- if (opts.constructorHandlers) for (const handler of opts.constructorHandlers) constructorHandlers.set(handler[0], handler[1]);
100
- let handler = null;
101
- return opts.proto ? cloneProto : clone;
102
- function cloneArray(a, fn) {
103
- const keys = Object.keys(a);
104
- const a2 = new Array(keys.length);
105
- for (let i = 0; i < keys.length; i++) {
106
- const k = keys[i];
107
- const cur = a[k];
108
- if (typeof cur !== "object" || cur === null) a2[k] = cur;
109
- else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) a2[k] = handler(cur, fn);
110
- else if (ArrayBuffer.isView(cur)) a2[k] = copyBuffer(cur);
111
- else {
112
- const index = refs.indexOf(cur);
113
- if (index !== -1) a2[k] = refsNew[index];
114
- else a2[k] = fn(cur);
115
- }
116
- }
117
- return a2;
118
- }
119
- function clone(o) {
120
- if (typeof o !== "object" || o === null) return o;
121
- if (Array.isArray(o)) return cloneArray(o, clone);
122
- if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, clone);
123
- const o2 = {};
124
- refs.push(o);
125
- refsNew.push(o2);
126
- for (const k in o) {
127
- if (Object.hasOwnProperty.call(o, k) === false) continue;
128
- const cur = o[k];
129
- if (typeof cur !== "object" || cur === null) o2[k] = cur;
130
- else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, clone);
131
- else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
132
- else {
133
- const i = refs.indexOf(cur);
134
- if (i !== -1) o2[k] = refsNew[i];
135
- else o2[k] = clone(cur);
136
- }
137
- }
138
- refs.pop();
139
- refsNew.pop();
140
- return o2;
141
- }
142
- function cloneProto(o) {
143
- if (typeof o !== "object" || o === null) return o;
144
- if (Array.isArray(o)) return cloneArray(o, cloneProto);
145
- if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) return handler(o, cloneProto);
146
- const o2 = {};
147
- refs.push(o);
148
- refsNew.push(o2);
149
- for (const k in o) {
150
- const cur = o[k];
151
- if (typeof cur !== "object" || cur === null) o2[k] = cur;
152
- else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) o2[k] = handler(cur, cloneProto);
153
- else if (ArrayBuffer.isView(cur)) o2[k] = copyBuffer(cur);
154
- else {
155
- const i = refs.indexOf(cur);
156
- if (i !== -1) o2[k] = refsNew[i];
157
- else o2[k] = cloneProto(cur);
158
- }
159
- }
160
- refs.pop();
161
- refsNew.pop();
162
- return o2;
163
- }
164
- }
165
- })))(), 1);
166
- const classifyRE = /(?:^|[-_/])(\w)/g;
167
- function toUpper(_, c) {
168
- return c ? c.toUpperCase() : "";
169
- }
170
- function classify(str) {
171
- return str && `${str}`.replace(classifyRE, toUpper);
172
- }
173
- function basename(filename, ext) {
174
- let normalizedFilename = filename.replace(/^[a-z]:/i, "").replace(/\\/g, "/");
175
- if (normalizedFilename.endsWith(`index${ext}`)) normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext);
176
- const lastSlashIndex = normalizedFilename.lastIndexOf("/");
177
- const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1);
178
- if (ext) {
179
- const extIndex = baseNameWithExt.lastIndexOf(ext);
180
- return baseNameWithExt.substring(0, extIndex);
181
- }
182
- return "";
183
- }
184
- const HTTP_URL_RE = /^https?:\/\//;
185
- /**
186
- * Check a string is start with `/` or a valid http url
187
- */
188
- function isUrlString(str) {
189
- return str.startsWith("/") || HTTP_URL_RE.test(str);
190
- }
191
- /**
192
- * @copyright [rfdc](https://github.com/davidmarkclements/rfdc)
193
- * @description A really fast deep clone alternative
194
- */
195
- const deepClone = (0, import_rfdc.default)({ circles: true });
196
- //#endregion
197
- //#region ../devtools-kit/src/core/component/utils/index.ts
198
- function getComponentTypeName(options) {
199
- if (typeof options === "function") return options.displayName || options.name || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || "";
200
- const name = options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name;
201
- if (name === "index" && options.__file?.endsWith("index.vue")) return "";
202
- return name;
203
- }
204
- function getComponentFileName(options) {
205
- const file = options.__file;
206
- if (file) return classify(basename(file, ".vue"));
207
- }
208
- function saveComponentGussedName(instance, name) {
209
- instance.type.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ = name;
210
- return name;
211
- }
212
- function getAppRecord(instance) {
213
- if (instance.__VUE_DEVTOOLS_NEXT_APP_RECORD__) return instance.__VUE_DEVTOOLS_NEXT_APP_RECORD__;
214
- else if (instance.root) return instance.appContext.app.__VUE_DEVTOOLS_NEXT_APP_RECORD__;
215
- }
216
- function isFragment(instance) {
217
- const subTreeType = instance.subTree?.type;
218
- const appRecord = getAppRecord(instance);
219
- if (appRecord) return appRecord?.types?.Fragment === subTreeType;
220
- return false;
221
- }
222
- /**
223
- * Get the appropriate display name for an instance.
224
- *
225
- * @param {Vue} instance
226
- * @return {string}
227
- */
228
- function getInstanceName(instance) {
229
- const name = getComponentTypeName(instance?.type || {});
230
- if (name) return name;
231
- if (instance?.root === instance) return "Root";
232
- for (const key in instance.parent?.type?.components) if (instance.parent.type.components[key] === instance?.type) return saveComponentGussedName(instance, key);
233
- for (const key in instance.appContext?.components) if (instance.appContext.components[key] === instance?.type) return saveComponentGussedName(instance, key);
234
- const fileName = getComponentFileName(instance?.type || {});
235
- if (fileName) return fileName;
236
- return "Anonymous Component";
237
- }
238
- /**
239
- * Returns a devtools unique id for instance.
240
- * @param {Vue} instance
241
- */
242
- function getUniqueComponentId(instance) {
243
- return `${instance?.appContext?.app?.__VUE_DEVTOOLS_NEXT_APP_RECORD_ID__ ?? 0}:${instance === instance?.root ? "root" : instance.uid}`;
244
- }
245
- function getComponentInstance(appRecord, instanceId) {
246
- instanceId = instanceId || `${appRecord.id}:root`;
247
- return appRecord.instanceMap.get(instanceId) || appRecord.instanceMap.get(":root");
248
- }
249
- //#endregion
250
- //#region ../devtools-kit/src/core/component/state/bounding-rect.ts
251
- function createRect() {
252
- const rect = {
253
- top: 0,
254
- bottom: 0,
255
- left: 0,
256
- right: 0,
257
- get width() {
258
- return rect.right - rect.left;
259
- },
260
- get height() {
261
- return rect.bottom - rect.top;
262
- }
263
- };
264
- return rect;
265
- }
266
- let range;
267
- function getTextRect(node) {
268
- if (!range) range = document.createRange();
269
- range.selectNode(node);
270
- return range.getBoundingClientRect();
271
- }
272
- function getFragmentRect(vnode) {
273
- const rect = createRect();
274
- if (!vnode.children) return rect;
275
- for (let i = 0, l = vnode.children.length; i < l; i++) {
276
- const childVnode = vnode.children[i];
277
- let childRect;
278
- if (childVnode.component) childRect = getComponentBoundingRect(childVnode.component);
279
- else if (childVnode.el) {
280
- const el = childVnode.el;
281
- if (el.nodeType === 1 || el.getBoundingClientRect) childRect = el.getBoundingClientRect();
282
- else if (el.nodeType === 3 && el.data.trim()) childRect = getTextRect(el);
283
- }
284
- if (childRect) mergeRects(rect, childRect);
285
- }
286
- return rect;
287
- }
288
- function mergeRects(a, b) {
289
- if (!a.top || b.top < a.top) a.top = b.top;
290
- if (!a.bottom || b.bottom > a.bottom) a.bottom = b.bottom;
291
- if (!a.left || b.left < a.left) a.left = b.left;
292
- if (!a.right || b.right > a.right) a.right = b.right;
293
- return a;
294
- }
295
- const DEFAULT_RECT = {
296
- top: 0,
297
- left: 0,
298
- right: 0,
299
- bottom: 0,
300
- width: 0,
301
- height: 0
302
- };
303
- function getComponentBoundingRect(instance) {
304
- const el = instance.subTree.el;
305
- if (typeof window === "undefined") return DEFAULT_RECT;
306
- if (isFragment(instance)) return getFragmentRect(instance.subTree);
307
- else if (el?.nodeType === 1) return el?.getBoundingClientRect();
308
- else if (instance.subTree.component) return getComponentBoundingRect(instance.subTree.component);
309
- else return DEFAULT_RECT;
310
- }
311
- //#endregion
312
- //#region ../devtools-kit/src/core/component/tree/el.ts
313
- function getRootElementsFromComponentInstance(instance) {
314
- if (isFragment(instance)) return getFragmentRootElements(instance.subTree);
315
- if (!instance.subTree) return [];
316
- return [instance.subTree.el];
317
- }
318
- function getFragmentRootElements(vnode) {
319
- if (!vnode.children) return [];
320
- const list = [];
321
- vnode.children.forEach((childVnode) => {
322
- if (childVnode.component) list.push(...getRootElementsFromComponentInstance(childVnode.component));
323
- else if (childVnode?.el) list.push(childVnode.el);
324
- });
325
- return list;
326
- }
327
- //#endregion
328
- //#region ../devtools-kit/src/core/component-highlighter/index.ts
329
- const CONTAINER_ELEMENT_ID = "__vue-devtools-component-inspector__";
330
- const CARD_ELEMENT_ID = "__vue-devtools-component-inspector__card__";
331
- const COMPONENT_NAME_ELEMENT_ID = "__vue-devtools-component-inspector__name__";
332
- const INDICATOR_ELEMENT_ID = "__vue-devtools-component-inspector__indicator__";
333
- const containerStyles = {
334
- display: "block",
335
- zIndex: 2147483640,
336
- position: "fixed",
337
- backgroundColor: "#42b88325",
338
- border: "1px solid #42b88350",
339
- borderRadius: "5px",
340
- transition: "all 0.1s ease-in",
341
- pointerEvents: "none"
342
- };
343
- const cardStyles = {
344
- fontFamily: "Arial, Helvetica, sans-serif",
345
- padding: "5px 8px",
346
- borderRadius: "4px",
347
- textAlign: "left",
348
- position: "absolute",
349
- left: 0,
350
- color: "#e9e9e9",
351
- fontSize: "14px",
352
- fontWeight: 600,
353
- lineHeight: "24px",
354
- backgroundColor: "#42b883",
355
- boxShadow: "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)"
356
- };
357
- const indicatorStyles = {
358
- display: "inline-block",
359
- fontWeight: 400,
360
- fontStyle: "normal",
361
- fontSize: "12px",
362
- opacity: .7
363
- };
364
- function getContainerElement() {
365
- return document.getElementById(CONTAINER_ELEMENT_ID);
366
- }
367
- function getCardElement() {
368
- return document.getElementById(CARD_ELEMENT_ID);
369
- }
370
- function getIndicatorElement() {
371
- return document.getElementById(INDICATOR_ELEMENT_ID);
372
- }
373
- function getNameElement() {
374
- return document.getElementById(COMPONENT_NAME_ELEMENT_ID);
375
- }
376
- function getStyles(bounds) {
377
- return {
378
- left: `${Math.round(bounds.left * 100) / 100}px`,
379
- top: `${Math.round(bounds.top * 100) / 100}px`,
380
- width: `${Math.round(bounds.width * 100) / 100}px`,
381
- height: `${Math.round(bounds.height * 100) / 100}px`
382
- };
383
- }
384
- function create(options) {
385
- const containerEl = document.createElement("div");
386
- containerEl.id = options.elementId ?? CONTAINER_ELEMENT_ID;
387
- Object.assign(containerEl.style, {
388
- ...containerStyles,
389
- ...getStyles(options.bounds),
390
- ...options.style
391
- });
392
- const cardEl = document.createElement("span");
393
- cardEl.id = CARD_ELEMENT_ID;
394
- Object.assign(cardEl.style, {
395
- ...cardStyles,
396
- top: options.bounds.top < 35 ? 0 : "-35px"
397
- });
398
- const nameEl = document.createElement("span");
399
- nameEl.id = COMPONENT_NAME_ELEMENT_ID;
400
- nameEl.innerHTML = `&lt;${options.name}&gt;&nbsp;&nbsp;`;
401
- const indicatorEl = document.createElement("i");
402
- indicatorEl.id = INDICATOR_ELEMENT_ID;
403
- indicatorEl.innerHTML = `${Math.round(options.bounds.width * 100) / 100} x ${Math.round(options.bounds.height * 100) / 100}`;
404
- Object.assign(indicatorEl.style, indicatorStyles);
405
- cardEl.appendChild(nameEl);
406
- cardEl.appendChild(indicatorEl);
407
- containerEl.appendChild(cardEl);
408
- document.body.appendChild(containerEl);
409
- return containerEl;
410
- }
411
- function update(options) {
412
- const containerEl = getContainerElement();
413
- const cardEl = getCardElement();
414
- const nameEl = getNameElement();
415
- const indicatorEl = getIndicatorElement();
416
- if (containerEl) {
417
- Object.assign(containerEl.style, {
418
- ...containerStyles,
419
- ...getStyles(options.bounds)
420
- });
421
- Object.assign(cardEl.style, { top: options.bounds.top < 35 ? 0 : "-35px" });
422
- nameEl.innerHTML = `&lt;${options.name}&gt;&nbsp;&nbsp;`;
423
- indicatorEl.innerHTML = `${Math.round(options.bounds.width * 100) / 100} x ${Math.round(options.bounds.height * 100) / 100}`;
424
- }
425
- }
426
- function highlight(instance) {
427
- const bounds = getComponentBoundingRect(instance);
428
- if (!bounds.width && !bounds.height) return;
429
- const name = getInstanceName(instance);
430
- getContainerElement() ? update({
431
- bounds,
432
- name
433
- }) : create({
434
- bounds,
435
- name
436
- });
437
- }
438
- function unhighlight() {
439
- const el = getContainerElement();
440
- if (el) el.style.display = "none";
441
- }
442
- let inspectInstance = null;
443
- function inspectFn(e) {
444
- const target = e.target;
445
- if (target) {
446
- const instance = target.__vueParentComponent;
447
- if (instance) {
448
- inspectInstance = instance;
449
- if (instance.vnode.el) {
450
- const bounds = getComponentBoundingRect(instance);
451
- const name = getInstanceName(instance);
452
- getContainerElement() ? update({
453
- bounds,
454
- name
455
- }) : create({
456
- bounds,
457
- name
458
- });
459
- }
460
- }
461
- }
462
- }
463
- function selectComponentFn(e, cb) {
464
- e.preventDefault();
465
- e.stopPropagation();
466
- if (inspectInstance) cb(getUniqueComponentId(inspectInstance));
467
- }
468
- let inspectComponentHighLighterSelectFn = null;
469
- function cancelInspectComponentHighLighter() {
470
- unhighlight();
471
- window.removeEventListener("mouseover", inspectFn);
472
- window.removeEventListener("click", inspectComponentHighLighterSelectFn, true);
473
- inspectComponentHighLighterSelectFn = null;
474
- }
475
- function inspectComponentHighLighter() {
476
- window.addEventListener("mouseover", inspectFn);
477
- return new Promise((resolve) => {
478
- function onSelect(e) {
479
- e.preventDefault();
480
- e.stopPropagation();
481
- selectComponentFn(e, (id) => {
482
- window.removeEventListener("click", onSelect, true);
483
- inspectComponentHighLighterSelectFn = null;
484
- window.removeEventListener("mouseover", inspectFn);
485
- const el = getContainerElement();
486
- if (el) el.style.display = "none";
487
- resolve(JSON.stringify({ id }));
488
- });
489
- }
490
- inspectComponentHighLighterSelectFn = onSelect;
491
- window.addEventListener("click", onSelect, true);
492
- });
493
- }
494
- function scrollToComponent(options) {
495
- const instance = getComponentInstance(activeAppRecord.value, options.id);
496
- if (instance) {
497
- const [el] = getRootElementsFromComponentInstance(instance);
498
- if (typeof el.scrollIntoView === "function") el.scrollIntoView({ behavior: "smooth" });
499
- else {
500
- const bounds = getComponentBoundingRect(instance);
501
- const scrollTarget = document.createElement("div");
502
- const styles = {
503
- ...getStyles(bounds),
504
- position: "absolute"
505
- };
506
- Object.assign(scrollTarget.style, styles);
507
- document.body.appendChild(scrollTarget);
508
- scrollTarget.scrollIntoView({ behavior: "smooth" });
509
- setTimeout(() => {
510
- document.body.removeChild(scrollTarget);
511
- }, 2e3);
512
- }
513
- setTimeout(() => {
514
- const bounds = getComponentBoundingRect(instance);
515
- if (bounds.width || bounds.height) {
516
- const name = getInstanceName(instance);
517
- const el = getContainerElement();
518
- el ? update({
519
- ...options,
520
- name,
521
- bounds
522
- }) : create({
523
- ...options,
524
- name,
525
- bounds
526
- });
527
- setTimeout(() => {
528
- if (el) el.style.display = "none";
529
- }, 1500);
530
- }
531
- }, 1200);
532
- }
533
- }
534
- //#endregion
535
- //#region ../devtools-kit/src/core/component-inspector/index.ts
536
- target.__VUE_DEVTOOLS_COMPONENT_INSPECTOR_ENABLED__ ??= true;
537
- function waitForInspectorInit(cb) {
538
- let total = 0;
539
- const timer = setInterval(() => {
540
- if (target.__VUE_INSPECTOR__) {
541
- clearInterval(timer);
542
- total += 30;
543
- cb();
544
- }
545
- if (total >= 5e3) clearInterval(timer);
546
- }, 30);
547
- }
548
- function setupInspector() {
549
- const inspector = target.__VUE_INSPECTOR__;
550
- const _openInEditor = inspector.openInEditor;
551
- inspector.openInEditor = async (...params) => {
552
- inspector.disable();
553
- _openInEditor(...params);
554
- };
555
- }
556
- function getComponentInspector() {
557
- return new Promise((resolve) => {
558
- function setup() {
559
- setupInspector();
560
- resolve(target.__VUE_INSPECTOR__);
561
- }
562
- if (!target.__VUE_INSPECTOR__) waitForInspectorInit(() => {
563
- setup();
564
- });
565
- else setup();
566
- });
567
- }
568
- //#endregion
569
- //#region ../devtools-kit/src/shared/stub-vue.ts
570
- /**
571
- * To prevent include a **HUGE** vue package in the final bundle of chrome ext / electron
572
- * we stub the necessary vue module.
573
- * This implementation is based on the 1c3327a0fa5983aa9078e3f7bb2330f572435425 commit
574
- */
575
- /**
576
- * @from [@vue/reactivity](https://github.com/vuejs/core/blob/1c3327a0fa5983aa9078e3f7bb2330f572435425/packages/reactivity/src/constants.ts#L17-L23)
577
- */
578
- let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags) {
579
- ReactiveFlags["SKIP"] = "__v_skip";
580
- ReactiveFlags["IS_REACTIVE"] = "__v_isReactive";
581
- ReactiveFlags["IS_READONLY"] = "__v_isReadonly";
582
- ReactiveFlags["IS_SHALLOW"] = "__v_isShallow";
583
- ReactiveFlags["RAW"] = "__v_raw";
584
- return ReactiveFlags;
585
- }({});
586
- /**
587
- * @from [@vue/reactivity](https://github.com/vuejs/core/blob/1c3327a0fa5983aa9078e3f7bb2330f572435425/packages/reactivity/src/reactive.ts#L330-L332)
588
- */
589
- function isReadonly(value) {
590
- return !!(value && value[ReactiveFlags.IS_READONLY]);
591
- }
592
- /**
593
- * @from [@vue/reactivity](https://github.com/vuejs/core/blob/1c3327a0fa5983aa9078e3f7bb2330f572435425/packages/reactivity/src/reactive.ts#L312-L317)
594
- */
595
- function isReactive(value) {
596
- if (isReadonly(value)) return isReactive(value[ReactiveFlags.RAW]);
597
- return !!(value && value[ReactiveFlags.IS_REACTIVE]);
598
- }
599
- function isRef(r) {
600
- return !!(r && r.__v_isRef === true);
601
- }
602
- /**
603
- * @from [@vue/reactivity](https://github.com/vuejs/core/blob/1c3327a0fa5983aa9078e3f7bb2330f572435425/packages/reactivity/src/reactive.ts#L372-L375)
604
- */
605
- function toRaw(observed) {
606
- const raw = observed && observed[ReactiveFlags.RAW];
607
- return raw ? toRaw(raw) : observed;
608
- }
609
- //#endregion
610
- //#region ../devtools-kit/src/core/component/state/editor.ts
611
- var StateEditor = class {
612
- constructor() {
613
- this.refEditor = new RefStateEditor();
614
- }
615
- set(object, path, value, cb) {
616
- const sections = Array.isArray(path) ? path : path.split(".");
617
- while (sections.length > 1) {
618
- const section = sections.shift();
619
- if (object instanceof Map) object = object.get(section);
620
- else if (object instanceof Set) object = Array.from(object.values())[section];
621
- else object = object[section];
622
- if (this.refEditor.isRef(object)) object = this.refEditor.get(object);
623
- }
624
- const field = sections[0];
625
- const item = this.refEditor.get(object)[field];
626
- if (cb) cb(object, field, value);
627
- else if (this.refEditor.isRef(item)) this.refEditor.set(item, value);
628
- else object[field] = value;
629
- }
630
- get(object, path) {
631
- const sections = Array.isArray(path) ? path : path.split(".");
632
- for (let i = 0; i < sections.length; i++) {
633
- if (object instanceof Map) object = object.get(sections[i]);
634
- else object = object[sections[i]];
635
- if (this.refEditor.isRef(object)) object = this.refEditor.get(object);
636
- if (!object) return void 0;
637
- }
638
- return object;
639
- }
640
- has(object, path, parent = false) {
641
- if (typeof object === "undefined") return false;
642
- const sections = Array.isArray(path) ? path.slice() : path.split(".");
643
- const size = !parent ? 1 : 2;
644
- while (object && sections.length > size) {
645
- const section = sections.shift();
646
- object = object[section];
647
- if (this.refEditor.isRef(object)) object = this.refEditor.get(object);
648
- }
649
- return object != null && Object.prototype.hasOwnProperty.call(object, sections[0]);
650
- }
651
- createDefaultSetCallback(state) {
652
- return (object, field, value) => {
653
- if (state.remove || state.newKey) if (Array.isArray(object)) object.splice(field, 1);
654
- else if (toRaw(object) instanceof Map) object.delete(field);
655
- else if (toRaw(object) instanceof Set) object.delete(Array.from(object.values())[field]);
656
- else Reflect.deleteProperty(object, field);
657
- if (!state.remove) {
658
- const target = object[state.newKey || field];
659
- if (this.refEditor.isRef(target)) this.refEditor.set(target, value);
660
- else if (toRaw(object) instanceof Map) object.set(state.newKey || field, value);
661
- else if (toRaw(object) instanceof Set) object.add(value);
662
- else object[state.newKey || field] = value;
663
- }
664
- };
665
- }
666
- };
667
- var RefStateEditor = class {
668
- set(ref, value) {
669
- if (isRef(ref)) ref.value = value;
670
- else {
671
- if (ref instanceof Set && Array.isArray(value)) {
672
- ref.clear();
673
- value.forEach((v) => ref.add(v));
674
- return;
675
- }
676
- const currentKeys = Object.keys(value);
677
- if (ref instanceof Map) {
678
- const previousKeysSet = new Set(ref.keys());
679
- currentKeys.forEach((key) => {
680
- ref.set(key, Reflect.get(value, key));
681
- previousKeysSet.delete(key);
682
- });
683
- previousKeysSet.forEach((key) => ref.delete(key));
684
- return;
685
- }
686
- const previousKeysSet = new Set(Object.keys(ref));
687
- currentKeys.forEach((key) => {
688
- Reflect.set(ref, key, Reflect.get(value, key));
689
- previousKeysSet.delete(key);
690
- });
691
- previousKeysSet.forEach((key) => Reflect.deleteProperty(ref, key));
692
- }
693
- }
694
- get(ref) {
695
- return isRef(ref) ? ref.value : ref;
696
- }
697
- isRef(ref) {
698
- return isRef(ref) || isReactive(ref);
699
- }
700
- };
701
- new StateEditor();
702
- //#endregion
703
- //#region ../../node_modules/.pnpm/perfect-debounce@2.0.0/node_modules/perfect-debounce/dist/index.mjs
704
- const DEBOUNCE_DEFAULTS = { trailing: true };
705
- /**
706
- Debounce functions
707
- @param fn - Promise-returning/async function to debounce.
708
- @param wait - Milliseconds to wait before calling `fn`. Default value is 25ms
709
- @returns A function that delays calling `fn` until after `wait` milliseconds have elapsed since the last time it was called.
710
- @example
711
- ```
712
- import { debounce } from 'perfect-debounce';
713
- const expensiveCall = async input => input;
714
- const debouncedFn = debounce(expensiveCall, 200);
715
- for (const number of [1, 2, 3]) {
716
- console.log(await debouncedFn(number));
717
- }
718
- //=> 1
719
- //=> 2
720
- //=> 3
721
- ```
722
- */
723
- function debounce(fn, wait = 25, options = {}) {
724
- options = {
725
- ...DEBOUNCE_DEFAULTS,
726
- ...options
727
- };
728
- if (!Number.isFinite(wait)) throw new TypeError("Expected `wait` to be a finite number");
729
- let leadingValue;
730
- let timeout;
731
- let resolveList = [];
732
- let currentPromise;
733
- let trailingArgs;
734
- const applyFn = (_this, args) => {
735
- currentPromise = _applyPromised(fn, _this, args);
736
- currentPromise.finally(() => {
737
- currentPromise = null;
738
- if (options.trailing && trailingArgs && !timeout) {
739
- const promise = applyFn(_this, trailingArgs);
740
- trailingArgs = null;
741
- return promise;
742
- }
743
- });
744
- return currentPromise;
745
- };
746
- const debounced = function(...args) {
747
- if (options.trailing) trailingArgs = args;
748
- if (currentPromise) return currentPromise;
749
- return new Promise((resolve) => {
750
- const shouldCallNow = !timeout && options.leading;
751
- clearTimeout(timeout);
752
- timeout = setTimeout(() => {
753
- timeout = null;
754
- const promise = options.leading ? leadingValue : applyFn(this, args);
755
- trailingArgs = null;
756
- for (const _resolve of resolveList) _resolve(promise);
757
- resolveList = [];
758
- }, wait);
759
- if (shouldCallNow) {
760
- leadingValue = applyFn(this, args);
761
- resolve(leadingValue);
762
- } else resolveList.push(resolve);
763
- });
764
- };
765
- const _clearTimeout = (timer) => {
766
- if (timer) {
767
- clearTimeout(timer);
768
- timeout = null;
769
- }
770
- };
771
- debounced.isPending = () => !!timeout;
772
- debounced.cancel = () => {
773
- _clearTimeout(timeout);
774
- resolveList = [];
775
- trailingArgs = null;
776
- };
777
- debounced.flush = () => {
778
- _clearTimeout(timeout);
779
- if (!trailingArgs || currentPromise) return;
780
- const args = trailingArgs;
781
- trailingArgs = null;
782
- return applyFn(this, args);
783
- };
784
- return debounced;
785
- }
786
- async function _applyPromised(fn, _this, args) {
787
- return await fn.apply(_this, args);
788
- }
789
- //#endregion
790
- //#region ../devtools-kit/src/core/timeline/storage.ts
791
- const TIMELINE_LAYERS_STATE_STORAGE_ID = "__VUE_DEVTOOLS_KIT_TIMELINE_LAYERS_STATE__";
792
- function getTimelineLayersStateFromStorage() {
793
- if (typeof window === "undefined" || !isBrowser || typeof localStorage === "undefined" || localStorage === null) return {
794
- recordingState: false,
795
- mouseEventEnabled: false,
796
- keyboardEventEnabled: false,
797
- componentEventEnabled: false,
798
- performanceEventEnabled: false,
799
- selected: ""
800
- };
801
- const state = typeof localStorage.getItem !== "undefined" ? localStorage.getItem(TIMELINE_LAYERS_STATE_STORAGE_ID) : null;
802
- return state ? JSON.parse(state) : {
803
- recordingState: false,
804
- mouseEventEnabled: false,
805
- keyboardEventEnabled: false,
806
- componentEventEnabled: false,
807
- performanceEventEnabled: false,
808
- selected: ""
809
- };
810
- }
811
- //#endregion
812
- //#region ../../node_modules/.pnpm/hookable@5.5.3/node_modules/hookable/dist/index.mjs
813
- function flatHooks(configHooks, hooks = {}, parentName) {
814
- for (const key in configHooks) {
815
- const subHook = configHooks[key];
816
- const name = parentName ? `${parentName}:${key}` : key;
817
- if (typeof subHook === "object" && subHook !== null) flatHooks(subHook, hooks, name);
818
- else if (typeof subHook === "function") hooks[name] = subHook;
819
- }
820
- return hooks;
821
- }
822
- const defaultTask = { run: (function_) => function_() };
823
- const _createTask = () => defaultTask;
824
- const createTask = typeof console.createTask !== "undefined" ? console.createTask : _createTask;
825
- function serialTaskCaller(hooks, args) {
826
- const task = createTask(args.shift());
827
- return hooks.reduce((promise, hookFunction) => promise.then(() => task.run(() => hookFunction(...args))), Promise.resolve());
828
- }
829
- function parallelTaskCaller(hooks, args) {
830
- const task = createTask(args.shift());
831
- return Promise.all(hooks.map((hook) => task.run(() => hook(...args))));
832
- }
833
- function callEachWith(callbacks, arg0) {
834
- for (const callback of [...callbacks]) callback(arg0);
835
- }
836
- var Hookable = class {
837
- constructor() {
838
- this._hooks = {};
839
- this._before = void 0;
840
- this._after = void 0;
841
- this._deprecatedMessages = void 0;
842
- this._deprecatedHooks = {};
843
- this.hook = this.hook.bind(this);
844
- this.callHook = this.callHook.bind(this);
845
- this.callHookWith = this.callHookWith.bind(this);
846
- }
847
- hook(name, function_, options = {}) {
848
- if (!name || typeof function_ !== "function") return () => {};
849
- const originalName = name;
850
- let dep;
851
- while (this._deprecatedHooks[name]) {
852
- dep = this._deprecatedHooks[name];
853
- name = dep.to;
854
- }
855
- if (dep && !options.allowDeprecated) {
856
- let message = dep.message;
857
- if (!message) message = `${originalName} hook has been deprecated` + (dep.to ? `, please use ${dep.to}` : "");
858
- if (!this._deprecatedMessages) this._deprecatedMessages = /* @__PURE__ */ new Set();
859
- if (!this._deprecatedMessages.has(message)) {
860
- console.warn(message);
861
- this._deprecatedMessages.add(message);
862
- }
863
- }
864
- if (!function_.name) try {
865
- Object.defineProperty(function_, "name", {
866
- get: () => "_" + name.replace(/\W+/g, "_") + "_hook_cb",
867
- configurable: true
868
- });
869
- } catch {}
870
- this._hooks[name] = this._hooks[name] || [];
871
- this._hooks[name].push(function_);
872
- return () => {
873
- if (function_) {
874
- this.removeHook(name, function_);
875
- function_ = void 0;
876
- }
877
- };
878
- }
879
- hookOnce(name, function_) {
880
- let _unreg;
881
- let _function = (...arguments_) => {
882
- if (typeof _unreg === "function") _unreg();
883
- _unreg = void 0;
884
- _function = void 0;
885
- return function_(...arguments_);
886
- };
887
- _unreg = this.hook(name, _function);
888
- return _unreg;
889
- }
890
- removeHook(name, function_) {
891
- if (this._hooks[name]) {
892
- const index = this._hooks[name].indexOf(function_);
893
- if (index !== -1) this._hooks[name].splice(index, 1);
894
- if (this._hooks[name].length === 0) delete this._hooks[name];
895
- }
896
- }
897
- deprecateHook(name, deprecated) {
898
- this._deprecatedHooks[name] = typeof deprecated === "string" ? { to: deprecated } : deprecated;
899
- const _hooks = this._hooks[name] || [];
900
- delete this._hooks[name];
901
- for (const hook of _hooks) this.hook(name, hook);
902
- }
903
- deprecateHooks(deprecatedHooks) {
904
- Object.assign(this._deprecatedHooks, deprecatedHooks);
905
- for (const name in deprecatedHooks) this.deprecateHook(name, deprecatedHooks[name]);
906
- }
907
- addHooks(configHooks) {
908
- const hooks = flatHooks(configHooks);
909
- const removeFns = Object.keys(hooks).map((key) => this.hook(key, hooks[key]));
910
- return () => {
911
- for (const unreg of removeFns.splice(0, removeFns.length)) unreg();
912
- };
913
- }
914
- removeHooks(configHooks) {
915
- const hooks = flatHooks(configHooks);
916
- for (const key in hooks) this.removeHook(key, hooks[key]);
917
- }
918
- removeAllHooks() {
919
- for (const key in this._hooks) delete this._hooks[key];
920
- }
921
- callHook(name, ...arguments_) {
922
- arguments_.unshift(name);
923
- return this.callHookWith(serialTaskCaller, name, ...arguments_);
924
- }
925
- callHookParallel(name, ...arguments_) {
926
- arguments_.unshift(name);
927
- return this.callHookWith(parallelTaskCaller, name, ...arguments_);
928
- }
929
- callHookWith(caller, name, ...arguments_) {
930
- const event = this._before || this._after ? {
931
- name,
932
- args: arguments_,
933
- context: {}
934
- } : void 0;
935
- if (this._before) callEachWith(this._before, event);
936
- const result = caller(name in this._hooks ? [...this._hooks[name]] : [], arguments_);
937
- if (result instanceof Promise) return result.finally(() => {
938
- if (this._after && event) callEachWith(this._after, event);
939
- });
940
- if (this._after && event) callEachWith(this._after, event);
941
- return result;
942
- }
943
- beforeEach(function_) {
944
- this._before = this._before || [];
945
- this._before.push(function_);
946
- return () => {
947
- if (this._before !== void 0) {
948
- const index = this._before.indexOf(function_);
949
- if (index !== -1) this._before.splice(index, 1);
950
- }
951
- };
952
- }
953
- afterEach(function_) {
954
- this._after = this._after || [];
955
- this._after.push(function_);
956
- return () => {
957
- if (this._after !== void 0) {
958
- const index = this._after.indexOf(function_);
959
- if (index !== -1) this._after.splice(index, 1);
960
- }
961
- };
962
- }
963
- };
964
- function createHooks() {
965
- return new Hookable();
966
- }
967
- //#endregion
968
- //#region ../devtools-kit/src/ctx/timeline.ts
969
- target.__VUE_DEVTOOLS_KIT_TIMELINE_LAYERS ??= [];
970
- const devtoolsTimelineLayers = new Proxy(target.__VUE_DEVTOOLS_KIT_TIMELINE_LAYERS, { get(target, prop, receiver) {
971
- return Reflect.get(target, prop, receiver);
972
- } });
973
- function addTimelineLayer(options, descriptor) {
974
- devtoolsState.timelineLayersState[descriptor.id] = false;
975
- devtoolsTimelineLayers.push({
976
- ...options,
977
- descriptorId: descriptor.id,
978
- appRecord: getAppRecord(descriptor.app)
979
- });
980
- }
981
- //#endregion
982
- //#region ../devtools-kit/src/ctx/inspector.ts
983
- target.__VUE_DEVTOOLS_KIT_INSPECTOR__ ??= [];
984
- const devtoolsInspector = new Proxy(target.__VUE_DEVTOOLS_KIT_INSPECTOR__, { get(target, prop, receiver) {
985
- return Reflect.get(target, prop, receiver);
986
- } });
987
- const callInspectorUpdatedHook = debounce(() => {
988
- devtoolsContext.hooks.callHook(DevToolsMessagingHookKeys.SEND_INSPECTOR_TO_CLIENT, getActiveInspectors());
989
- });
990
- function addInspector(inspector, descriptor) {
991
- devtoolsInspector.push({
992
- options: inspector,
993
- descriptor,
994
- treeFilterPlaceholder: inspector.treeFilterPlaceholder ?? "Search tree...",
995
- stateFilterPlaceholder: inspector.stateFilterPlaceholder ?? "Search state...",
996
- treeFilter: "",
997
- selectedNodeId: "",
998
- appRecord: getAppRecord(descriptor.app)
999
- });
1000
- callInspectorUpdatedHook();
1001
- }
1002
- function getActiveInspectors() {
1003
- return devtoolsInspector.filter((inspector) => inspector.descriptor.app === activeAppRecord.value.app).filter((inspector) => inspector.descriptor.id !== "components").map((inspector) => {
1004
- const descriptor = inspector.descriptor;
1005
- const options = inspector.options;
1006
- return {
1007
- id: options.id,
1008
- label: options.label,
1009
- logo: descriptor.logo,
1010
- icon: `custom-ic-baseline-${options?.icon?.replace(/_/g, "-")}`,
1011
- packageName: descriptor.packageName,
1012
- homepage: descriptor.homepage,
1013
- pluginId: descriptor.id
1014
- };
1015
- });
1016
- }
1017
- function getInspector(id, app) {
1018
- return devtoolsInspector.find((inspector) => inspector.options.id === id && (app ? inspector.descriptor.app === app : true));
1019
- }
1020
- //#endregion
1021
- //#region ../devtools-kit/src/ctx/hook.ts
1022
- let DevToolsV6PluginAPIHookKeys = /* @__PURE__ */ function(DevToolsV6PluginAPIHookKeys) {
1023
- DevToolsV6PluginAPIHookKeys["VISIT_COMPONENT_TREE"] = "visitComponentTree";
1024
- DevToolsV6PluginAPIHookKeys["INSPECT_COMPONENT"] = "inspectComponent";
1025
- DevToolsV6PluginAPIHookKeys["EDIT_COMPONENT_STATE"] = "editComponentState";
1026
- DevToolsV6PluginAPIHookKeys["GET_INSPECTOR_TREE"] = "getInspectorTree";
1027
- DevToolsV6PluginAPIHookKeys["GET_INSPECTOR_STATE"] = "getInspectorState";
1028
- DevToolsV6PluginAPIHookKeys["EDIT_INSPECTOR_STATE"] = "editInspectorState";
1029
- DevToolsV6PluginAPIHookKeys["INSPECT_TIMELINE_EVENT"] = "inspectTimelineEvent";
1030
- DevToolsV6PluginAPIHookKeys["TIMELINE_CLEARED"] = "timelineCleared";
1031
- DevToolsV6PluginAPIHookKeys["SET_PLUGIN_SETTINGS"] = "setPluginSettings";
1032
- return DevToolsV6PluginAPIHookKeys;
1033
- }({});
1034
- let DevToolsContextHookKeys = /* @__PURE__ */ function(DevToolsContextHookKeys) {
1035
- DevToolsContextHookKeys["ADD_INSPECTOR"] = "addInspector";
1036
- DevToolsContextHookKeys["SEND_INSPECTOR_TREE"] = "sendInspectorTree";
1037
- DevToolsContextHookKeys["SEND_INSPECTOR_STATE"] = "sendInspectorState";
1038
- DevToolsContextHookKeys["CUSTOM_INSPECTOR_SELECT_NODE"] = "customInspectorSelectNode";
1039
- DevToolsContextHookKeys["TIMELINE_LAYER_ADDED"] = "timelineLayerAdded";
1040
- DevToolsContextHookKeys["TIMELINE_EVENT_ADDED"] = "timelineEventAdded";
1041
- DevToolsContextHookKeys["GET_COMPONENT_INSTANCES"] = "getComponentInstances";
1042
- DevToolsContextHookKeys["GET_COMPONENT_BOUNDS"] = "getComponentBounds";
1043
- DevToolsContextHookKeys["GET_COMPONENT_NAME"] = "getComponentName";
1044
- DevToolsContextHookKeys["COMPONENT_HIGHLIGHT"] = "componentHighlight";
1045
- DevToolsContextHookKeys["COMPONENT_UNHIGHLIGHT"] = "componentUnhighlight";
1046
- return DevToolsContextHookKeys;
1047
- }({});
1048
- let DevToolsMessagingHookKeys = /* @__PURE__ */ function(DevToolsMessagingHookKeys) {
1049
- DevToolsMessagingHookKeys["SEND_INSPECTOR_TREE_TO_CLIENT"] = "sendInspectorTreeToClient";
1050
- DevToolsMessagingHookKeys["SEND_INSPECTOR_STATE_TO_CLIENT"] = "sendInspectorStateToClient";
1051
- DevToolsMessagingHookKeys["SEND_TIMELINE_EVENT_TO_CLIENT"] = "sendTimelineEventToClient";
1052
- DevToolsMessagingHookKeys["SEND_INSPECTOR_TO_CLIENT"] = "sendInspectorToClient";
1053
- DevToolsMessagingHookKeys["SEND_ACTIVE_APP_UNMOUNTED_TO_CLIENT"] = "sendActiveAppUpdatedToClient";
1054
- DevToolsMessagingHookKeys["DEVTOOLS_STATE_UPDATED"] = "devtoolsStateUpdated";
1055
- DevToolsMessagingHookKeys["DEVTOOLS_CONNECTED_UPDATED"] = "devtoolsConnectedUpdated";
1056
- DevToolsMessagingHookKeys["ROUTER_INFO_UPDATED"] = "routerInfoUpdated";
1057
- return DevToolsMessagingHookKeys;
1058
- }({});
1059
- function createDevToolsCtxHooks() {
1060
- const hooks = createHooks();
1061
- hooks.hook(DevToolsContextHookKeys.ADD_INSPECTOR, ({ inspector, plugin }) => {
1062
- addInspector(inspector, plugin.descriptor);
1063
- });
1064
- const debounceSendInspectorTree = debounce(async ({ inspectorId, plugin }) => {
1065
- if (!inspectorId || !plugin?.descriptor?.app || devtoolsState.highPerfModeEnabled) return;
1066
- const inspector = getInspector(inspectorId, plugin.descriptor.app);
1067
- const _payload = {
1068
- app: plugin.descriptor.app,
1069
- inspectorId,
1070
- filter: inspector?.treeFilter || "",
1071
- rootNodes: []
1072
- };
1073
- await new Promise((resolve) => {
1074
- hooks.callHookWith(async (callbacks) => {
1075
- await Promise.all(callbacks.map((cb) => cb(_payload)));
1076
- resolve();
1077
- }, DevToolsV6PluginAPIHookKeys.GET_INSPECTOR_TREE);
1078
- });
1079
- hooks.callHookWith(async (callbacks) => {
1080
- await Promise.all(callbacks.map((cb) => cb({
1081
- inspectorId,
1082
- rootNodes: _payload.rootNodes
1083
- })));
1084
- }, DevToolsMessagingHookKeys.SEND_INSPECTOR_TREE_TO_CLIENT);
1085
- }, 120);
1086
- hooks.hook(DevToolsContextHookKeys.SEND_INSPECTOR_TREE, debounceSendInspectorTree);
1087
- const debounceSendInspectorState = debounce(async ({ inspectorId, plugin }) => {
1088
- if (!inspectorId || !plugin?.descriptor?.app || devtoolsState.highPerfModeEnabled) return;
1089
- const inspector = getInspector(inspectorId, plugin.descriptor.app);
1090
- const _payload = {
1091
- app: plugin.descriptor.app,
1092
- inspectorId,
1093
- nodeId: inspector?.selectedNodeId || "",
1094
- state: null
1095
- };
1096
- const ctx = { currentTab: `custom-inspector:${inspectorId}` };
1097
- if (_payload.nodeId) await new Promise((resolve) => {
1098
- hooks.callHookWith(async (callbacks) => {
1099
- await Promise.all(callbacks.map((cb) => cb(_payload, ctx)));
1100
- resolve();
1101
- }, DevToolsV6PluginAPIHookKeys.GET_INSPECTOR_STATE);
1102
- });
1103
- hooks.callHookWith(async (callbacks) => {
1104
- await Promise.all(callbacks.map((cb) => cb({
1105
- inspectorId,
1106
- nodeId: _payload.nodeId,
1107
- state: _payload.state
1108
- })));
1109
- }, DevToolsMessagingHookKeys.SEND_INSPECTOR_STATE_TO_CLIENT);
1110
- }, 120);
1111
- hooks.hook(DevToolsContextHookKeys.SEND_INSPECTOR_STATE, debounceSendInspectorState);
1112
- hooks.hook(DevToolsContextHookKeys.CUSTOM_INSPECTOR_SELECT_NODE, ({ inspectorId, nodeId, plugin }) => {
1113
- const inspector = getInspector(inspectorId, plugin.descriptor.app);
1114
- if (!inspector) return;
1115
- inspector.selectedNodeId = nodeId;
1116
- });
1117
- hooks.hook(DevToolsContextHookKeys.TIMELINE_LAYER_ADDED, ({ options, plugin }) => {
1118
- addTimelineLayer(options, plugin.descriptor);
1119
- });
1120
- hooks.hook(DevToolsContextHookKeys.TIMELINE_EVENT_ADDED, ({ options, plugin }) => {
1121
- if (devtoolsState.highPerfModeEnabled || !devtoolsState.timelineLayersState?.[plugin.descriptor.id] && ![
1122
- "performance",
1123
- "component-event",
1124
- "keyboard",
1125
- "mouse"
1126
- ].includes(options.layerId)) return;
1127
- hooks.callHookWith(async (callbacks) => {
1128
- await Promise.all(callbacks.map((cb) => cb(options)));
1129
- }, DevToolsMessagingHookKeys.SEND_TIMELINE_EVENT_TO_CLIENT);
1130
- });
1131
- hooks.hook(DevToolsContextHookKeys.GET_COMPONENT_INSTANCES, async ({ app }) => {
1132
- const appRecord = app.__VUE_DEVTOOLS_NEXT_APP_RECORD__;
1133
- if (!appRecord) return null;
1134
- const appId = appRecord.id.toString();
1135
- return [...appRecord.instanceMap].filter(([key]) => key.split(":")[0] === appId).map(([, instance]) => instance);
1136
- });
1137
- hooks.hook(DevToolsContextHookKeys.GET_COMPONENT_BOUNDS, async ({ instance }) => {
1138
- return getComponentBoundingRect(instance);
1139
- });
1140
- hooks.hook(DevToolsContextHookKeys.GET_COMPONENT_NAME, ({ instance }) => {
1141
- return getInstanceName(instance);
1142
- });
1143
- hooks.hook(DevToolsContextHookKeys.COMPONENT_HIGHLIGHT, ({ uid }) => {
1144
- const instance = activeAppRecord.value.instanceMap.get(uid);
1145
- if (instance) highlight(instance);
1146
- });
1147
- hooks.hook(DevToolsContextHookKeys.COMPONENT_UNHIGHLIGHT, () => {
1148
- unhighlight();
1149
- });
1150
- return hooks;
1151
- }
1152
- //#endregion
1153
- //#region ../devtools-kit/src/ctx/state.ts
1154
- target.__VUE_DEVTOOLS_KIT_APP_RECORDS__ ??= [];
1155
- target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD__ ??= {};
1156
- target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD_ID__ ??= "";
1157
- target.__VUE_DEVTOOLS_KIT_CUSTOM_TABS__ ??= [];
1158
- target.__VUE_DEVTOOLS_KIT_CUSTOM_COMMANDS__ ??= [];
1159
- const STATE_KEY = "__VUE_DEVTOOLS_KIT_GLOBAL_STATE__";
1160
- function initStateFactory() {
1161
- return {
1162
- connected: false,
1163
- clientConnected: false,
1164
- vitePluginDetected: true,
1165
- appRecords: [],
1166
- activeAppRecordId: "",
1167
- tabs: [],
1168
- commands: [],
1169
- highPerfModeEnabled: true,
1170
- devtoolsClientDetected: {},
1171
- perfUniqueGroupId: 0,
1172
- timelineLayersState: getTimelineLayersStateFromStorage()
1173
- };
1174
- }
1175
- target[STATE_KEY] ??= initStateFactory();
1176
- const callStateUpdatedHook = debounce((state) => {
1177
- devtoolsContext.hooks.callHook(DevToolsMessagingHookKeys.DEVTOOLS_STATE_UPDATED, { state });
1178
- });
1179
- debounce((state, oldState) => {
1180
- devtoolsContext.hooks.callHook(DevToolsMessagingHookKeys.DEVTOOLS_CONNECTED_UPDATED, {
1181
- state,
1182
- oldState
1183
- });
1184
- });
1185
- const devtoolsAppRecords = new Proxy(target.__VUE_DEVTOOLS_KIT_APP_RECORDS__, { get(_target, prop, receiver) {
1186
- if (prop === "value") return target.__VUE_DEVTOOLS_KIT_APP_RECORDS__;
1187
- return target.__VUE_DEVTOOLS_KIT_APP_RECORDS__[prop];
1188
- } });
1189
- const activeAppRecord = new Proxy(target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD__, { get(_target, prop, receiver) {
1190
- if (prop === "value") return target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD__;
1191
- else if (prop === "id") return target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD_ID__;
1192
- return target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD__[prop];
1193
- } });
1194
- function updateAllStates() {
1195
- callStateUpdatedHook({
1196
- ...target[STATE_KEY],
1197
- appRecords: devtoolsAppRecords.value,
1198
- activeAppRecordId: activeAppRecord.id,
1199
- tabs: target.__VUE_DEVTOOLS_KIT_CUSTOM_TABS__,
1200
- commands: target.__VUE_DEVTOOLS_KIT_CUSTOM_COMMANDS__
1201
- });
1202
- }
1203
- function setActiveAppRecord(app) {
1204
- target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD__ = app;
1205
- updateAllStates();
1206
- }
1207
- function setActiveAppRecordId(id) {
1208
- target.__VUE_DEVTOOLS_KIT_ACTIVE_APP_RECORD_ID__ = id;
1209
- updateAllStates();
1210
- }
1211
- const devtoolsState = new Proxy(target[STATE_KEY], {
1212
- get(target$3, property) {
1213
- if (property === "appRecords") return devtoolsAppRecords;
1214
- else if (property === "activeAppRecordId") return activeAppRecord.id;
1215
- else if (property === "tabs") return target.__VUE_DEVTOOLS_KIT_CUSTOM_TABS__;
1216
- else if (property === "commands") return target.__VUE_DEVTOOLS_KIT_CUSTOM_COMMANDS__;
1217
- return target[STATE_KEY][property];
1218
- },
1219
- deleteProperty(target, property) {
1220
- delete target[property];
1221
- return true;
1222
- },
1223
- set(target$4, property, value) {
1224
- target$4[property] = value;
1225
- target[STATE_KEY][property] = value;
1226
- return true;
1227
- }
1228
- });
1229
- function onDevToolsConnected(fn) {
1230
- return new Promise((resolve) => {
1231
- if (devtoolsState.connected) {
1232
- fn();
1233
- resolve();
1234
- }
1235
- devtoolsContext.hooks.hook(DevToolsMessagingHookKeys.DEVTOOLS_CONNECTED_UPDATED, ({ state }) => {
1236
- if (state.connected) {
1237
- fn();
1238
- resolve();
1239
- }
1240
- });
1241
- });
1242
- }
1243
- const resolveIcon = (icon) => {
1244
- if (!icon) return;
1245
- if (icon.startsWith("baseline-")) return `custom-ic-${icon}`;
1246
- if (icon.startsWith("i-") || isUrlString(icon)) return icon;
1247
- return `custom-ic-baseline-${icon}`;
1248
- };
1249
- function addCustomTab(tab) {
1250
- const tabs = target.__VUE_DEVTOOLS_KIT_CUSTOM_TABS__;
1251
- if (tabs.some((t) => t.name === tab.name)) return;
1252
- tabs.push({
1253
- ...tab,
1254
- icon: resolveIcon(tab.icon)
1255
- });
1256
- updateAllStates();
1257
- }
1258
- function addCustomCommand(action) {
1259
- const commands = target.__VUE_DEVTOOLS_KIT_CUSTOM_COMMANDS__;
1260
- if (commands.some((t) => t.id === action.id)) return;
1261
- commands.push({
1262
- ...action,
1263
- icon: resolveIcon(action.icon),
1264
- children: action.children ? action.children.map((child) => ({
1265
- ...child,
1266
- icon: resolveIcon(child.icon)
1267
- })) : void 0
1268
- });
1269
- updateAllStates();
1270
- }
1271
- function removeCustomCommand(actionId) {
1272
- const commands = target.__VUE_DEVTOOLS_KIT_CUSTOM_COMMANDS__;
1273
- const index = commands.findIndex((t) => t.id === actionId);
1274
- if (index === -1) return;
1275
- commands.splice(index, 1);
1276
- updateAllStates();
1277
- }
1278
- //#endregion
1279
- //#region ../devtools-kit/src/core/open-in-editor/index.ts
1280
- function openInEditor(options = {}) {
1281
- const { file, host, baseUrl = window.location.origin, line = 0, column = 0 } = options;
1282
- if (file) {
1283
- if (host === "chrome-extension") {
1284
- const fileName = file.replace(/\\/g, "\\\\");
1285
- const _baseUrl = window.VUE_DEVTOOLS_CONFIG?.openInEditorHost ?? "/";
1286
- fetch(`${_baseUrl}__open-in-editor?file=${encodeURI(file)}`).then((response) => {
1287
- if (!response.ok) {
1288
- const msg = `Opening component ${fileName} failed`;
1289
- console.log(`%c${msg}`, "color:red");
1290
- }
1291
- });
1292
- } else if (devtoolsState.vitePluginDetected) {
1293
- const _baseUrl = target.__VUE_DEVTOOLS_OPEN_IN_EDITOR_BASE_URL__ ?? baseUrl;
1294
- target.__VUE_INSPECTOR__.openInEditor(_baseUrl, file, line, column);
1295
- }
1296
- }
1297
- }
1298
- //#endregion
1299
- //#region ../devtools-kit/src/ctx/plugin.ts
1300
- target.__VUE_DEVTOOLS_KIT_PLUGIN_BUFFER__ ??= [];
1301
- const devtoolsPluginBuffer = new Proxy(target.__VUE_DEVTOOLS_KIT_PLUGIN_BUFFER__, { get(target, prop, receiver) {
1302
- return Reflect.get(target, prop, receiver);
1303
- } });
1304
- //#endregion
1305
- //#region ../devtools-kit/src/core/plugin/plugin-settings.ts
1306
- function _getSettings(settings) {
1307
- const _settings = {};
1308
- Object.keys(settings).forEach((key) => {
1309
- _settings[key] = settings[key].defaultValue;
1310
- });
1311
- return _settings;
1312
- }
1313
- function getPluginLocalKey(pluginId) {
1314
- return `__VUE_DEVTOOLS_NEXT_PLUGIN_SETTINGS__${pluginId}__`;
1315
- }
1316
- function getPluginSettingsOptions(pluginId) {
1317
- return (devtoolsPluginBuffer.find((item) => item[0].id === pluginId && !!item[0]?.settings)?.[0] ?? null)?.settings ?? null;
1318
- }
1319
- function getPluginSettings(pluginId, fallbackValue) {
1320
- const localKey = getPluginLocalKey(pluginId);
1321
- if (localKey) {
1322
- const localSettings = localStorage.getItem(localKey);
1323
- if (localSettings) return JSON.parse(localSettings);
1324
- }
1325
- if (pluginId) return _getSettings((devtoolsPluginBuffer.find((item) => item[0].id === pluginId)?.[0] ?? null)?.settings ?? {});
1326
- return _getSettings(fallbackValue);
1327
- }
1328
- function initPluginSettings(pluginId, settings) {
1329
- const localKey = getPluginLocalKey(pluginId);
1330
- if (!localStorage.getItem(localKey)) localStorage.setItem(localKey, JSON.stringify(_getSettings(settings)));
1331
- }
1332
- function setPluginSettings(pluginId, key, value) {
1333
- const localKey = getPluginLocalKey(pluginId);
1334
- const localSettings = localStorage.getItem(localKey);
1335
- const parsedLocalSettings = JSON.parse(localSettings || "{}");
1336
- const updated = {
1337
- ...parsedLocalSettings,
1338
- [key]: value
1339
- };
1340
- localStorage.setItem(localKey, JSON.stringify(updated));
1341
- devtoolsContext.hooks.callHookWith((callbacks) => {
1342
- callbacks.forEach((cb) => cb({
1343
- pluginId,
1344
- key,
1345
- oldValue: parsedLocalSettings[key],
1346
- newValue: value,
1347
- settings: updated
1348
- }));
1349
- }, DevToolsV6PluginAPIHookKeys.SET_PLUGIN_SETTINGS);
1350
- }
1351
- //#endregion
1352
- //#region ../devtools-kit/src/types/hook.ts
1353
- let DevToolsHooks = /* @__PURE__ */ function(DevToolsHooks) {
1354
- DevToolsHooks["APP_INIT"] = "app:init";
1355
- DevToolsHooks["APP_UNMOUNT"] = "app:unmount";
1356
- DevToolsHooks["COMPONENT_UPDATED"] = "component:updated";
1357
- DevToolsHooks["COMPONENT_ADDED"] = "component:added";
1358
- DevToolsHooks["COMPONENT_REMOVED"] = "component:removed";
1359
- DevToolsHooks["COMPONENT_EMIT"] = "component:emit";
1360
- DevToolsHooks["PERFORMANCE_START"] = "perf:start";
1361
- DevToolsHooks["PERFORMANCE_END"] = "perf:end";
1362
- DevToolsHooks["ADD_ROUTE"] = "router:add-route";
1363
- DevToolsHooks["REMOVE_ROUTE"] = "router:remove-route";
1364
- DevToolsHooks["RENDER_TRACKED"] = "render:tracked";
1365
- DevToolsHooks["RENDER_TRIGGERED"] = "render:triggered";
1366
- DevToolsHooks["APP_CONNECTED"] = "app:connected";
1367
- DevToolsHooks["SETUP_DEVTOOLS_PLUGIN"] = "devtools-plugin:setup";
1368
- return DevToolsHooks;
1369
- }({});
1370
- //#endregion
1371
- //#region ../devtools-kit/src/hook/index.ts
1372
- const devtoolsHooks = target.__VUE_DEVTOOLS_HOOK ??= createHooks();
1373
- const hook = {
1374
- on: {
1375
- vueAppInit(fn) {
1376
- devtoolsHooks.hook(DevToolsHooks.APP_INIT, fn);
1377
- },
1378
- vueAppUnmount(fn) {
1379
- devtoolsHooks.hook(DevToolsHooks.APP_UNMOUNT, fn);
1380
- },
1381
- vueAppConnected(fn) {
1382
- devtoolsHooks.hook(DevToolsHooks.APP_CONNECTED, fn);
1383
- },
1384
- componentAdded(fn) {
1385
- return devtoolsHooks.hook(DevToolsHooks.COMPONENT_ADDED, fn);
1386
- },
1387
- componentEmit(fn) {
1388
- return devtoolsHooks.hook(DevToolsHooks.COMPONENT_EMIT, fn);
1389
- },
1390
- componentUpdated(fn) {
1391
- return devtoolsHooks.hook(DevToolsHooks.COMPONENT_UPDATED, fn);
1392
- },
1393
- componentRemoved(fn) {
1394
- return devtoolsHooks.hook(DevToolsHooks.COMPONENT_REMOVED, fn);
1395
- },
1396
- setupDevtoolsPlugin(fn) {
1397
- devtoolsHooks.hook(DevToolsHooks.SETUP_DEVTOOLS_PLUGIN, fn);
1398
- },
1399
- perfStart(fn) {
1400
- return devtoolsHooks.hook(DevToolsHooks.PERFORMANCE_START, fn);
1401
- },
1402
- perfEnd(fn) {
1403
- return devtoolsHooks.hook(DevToolsHooks.PERFORMANCE_END, fn);
1404
- }
1405
- },
1406
- setupDevToolsPlugin(pluginDescriptor, setupFn) {
1407
- return devtoolsHooks.callHook(DevToolsHooks.SETUP_DEVTOOLS_PLUGIN, pluginDescriptor, setupFn);
1408
- }
1409
- };
1410
- //#endregion
1411
- //#region ../devtools-kit/src/api/v6/index.ts
1412
- var DevToolsV6PluginAPI = class {
1413
- constructor({ plugin, ctx }) {
1414
- this.hooks = ctx.hooks;
1415
- this.plugin = plugin;
1416
- }
1417
- get on() {
1418
- return {
1419
- visitComponentTree: (handler) => {
1420
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.VISIT_COMPONENT_TREE, handler);
1421
- },
1422
- inspectComponent: (handler) => {
1423
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.INSPECT_COMPONENT, handler);
1424
- },
1425
- editComponentState: (handler) => {
1426
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.EDIT_COMPONENT_STATE, handler);
1427
- },
1428
- getInspectorTree: (handler) => {
1429
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.GET_INSPECTOR_TREE, handler);
1430
- },
1431
- getInspectorState: (handler) => {
1432
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.GET_INSPECTOR_STATE, handler);
1433
- },
1434
- editInspectorState: (handler) => {
1435
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.EDIT_INSPECTOR_STATE, handler);
1436
- },
1437
- inspectTimelineEvent: (handler) => {
1438
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.INSPECT_TIMELINE_EVENT, handler);
1439
- },
1440
- timelineCleared: (handler) => {
1441
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.TIMELINE_CLEARED, handler);
1442
- },
1443
- setPluginSettings: (handler) => {
1444
- this.hooks.hook(DevToolsV6PluginAPIHookKeys.SET_PLUGIN_SETTINGS, handler);
1445
- }
1446
- };
1447
- }
1448
- notifyComponentUpdate(instance) {
1449
- if (devtoolsState.highPerfModeEnabled) return;
1450
- const inspector = getActiveInspectors().find((i) => i.packageName === this.plugin.descriptor.packageName);
1451
- if (inspector?.id) {
1452
- if (instance) {
1453
- const args = [
1454
- instance.appContext.app,
1455
- instance.uid,
1456
- instance.parent?.uid,
1457
- instance
1458
- ];
1459
- devtoolsHooks.callHook(DevToolsHooks.COMPONENT_UPDATED, ...args);
1460
- } else devtoolsHooks.callHook(DevToolsHooks.COMPONENT_UPDATED);
1461
- this.hooks.callHook(DevToolsContextHookKeys.SEND_INSPECTOR_STATE, {
1462
- inspectorId: inspector.id,
1463
- plugin: this.plugin
1464
- });
1465
- }
1466
- }
1467
- addInspector(options) {
1468
- this.hooks.callHook(DevToolsContextHookKeys.ADD_INSPECTOR, {
1469
- inspector: options,
1470
- plugin: this.plugin
1471
- });
1472
- if (this.plugin.descriptor.settings) initPluginSettings(options.id, this.plugin.descriptor.settings);
1473
- }
1474
- sendInspectorTree(inspectorId) {
1475
- if (devtoolsState.highPerfModeEnabled) return;
1476
- this.hooks.callHook(DevToolsContextHookKeys.SEND_INSPECTOR_TREE, {
1477
- inspectorId,
1478
- plugin: this.plugin
1479
- });
1480
- }
1481
- sendInspectorState(inspectorId) {
1482
- if (devtoolsState.highPerfModeEnabled) return;
1483
- this.hooks.callHook(DevToolsContextHookKeys.SEND_INSPECTOR_STATE, {
1484
- inspectorId,
1485
- plugin: this.plugin
1486
- });
1487
- }
1488
- selectInspectorNode(inspectorId, nodeId) {
1489
- this.hooks.callHook(DevToolsContextHookKeys.CUSTOM_INSPECTOR_SELECT_NODE, {
1490
- inspectorId,
1491
- nodeId,
1492
- plugin: this.plugin
1493
- });
1494
- }
1495
- visitComponentTree(payload) {
1496
- return this.hooks.callHook(DevToolsV6PluginAPIHookKeys.VISIT_COMPONENT_TREE, payload);
1497
- }
1498
- now() {
1499
- if (devtoolsState.highPerfModeEnabled) return 0;
1500
- return Date.now();
1501
- }
1502
- addTimelineLayer(options) {
1503
- this.hooks.callHook(DevToolsContextHookKeys.TIMELINE_LAYER_ADDED, {
1504
- options,
1505
- plugin: this.plugin
1506
- });
1507
- }
1508
- addTimelineEvent(options) {
1509
- if (devtoolsState.highPerfModeEnabled) return;
1510
- this.hooks.callHook(DevToolsContextHookKeys.TIMELINE_EVENT_ADDED, {
1511
- options,
1512
- plugin: this.plugin
1513
- });
1514
- }
1515
- getSettings(pluginId) {
1516
- return getPluginSettings(pluginId ?? this.plugin.descriptor.id, this.plugin.descriptor.settings);
1517
- }
1518
- getComponentInstances(app) {
1519
- return this.hooks.callHook(DevToolsContextHookKeys.GET_COMPONENT_INSTANCES, { app });
1520
- }
1521
- getComponentBounds(instance) {
1522
- return this.hooks.callHook(DevToolsContextHookKeys.GET_COMPONENT_BOUNDS, { instance });
1523
- }
1524
- getComponentName(instance) {
1525
- return this.hooks.callHook(DevToolsContextHookKeys.GET_COMPONENT_NAME, { instance });
1526
- }
1527
- highlightElement(instance) {
1528
- const uid = instance.__VUE_DEVTOOLS_NEXT_UID__;
1529
- return this.hooks.callHook(DevToolsContextHookKeys.COMPONENT_HIGHLIGHT, { uid });
1530
- }
1531
- unhighlightElement() {
1532
- return this.hooks.callHook(DevToolsContextHookKeys.COMPONENT_UNHIGHLIGHT);
1533
- }
1534
- };
1535
- //#endregion
1536
- //#region ../devtools-kit/src/api/index.ts
1537
- const DevToolsPluginAPI = DevToolsV6PluginAPI;
1538
- //#endregion
1539
- //#region ../devtools-kit/src/core/plugin/index.ts
1540
- target.__VUE_DEVTOOLS_KIT__REGISTERED_PLUGIN_APPS__ ??= /* @__PURE__ */ new Set();
1541
- function setupDevToolsPlugin(pluginDescriptor, setupFn) {
1542
- return hook.setupDevToolsPlugin(pluginDescriptor, setupFn);
1543
- }
1544
- function callDevToolsPluginSetupFn(plugin, app) {
1545
- const [pluginDescriptor, setupFn] = plugin;
1546
- if (pluginDescriptor.app !== app) return;
1547
- const api = new DevToolsPluginAPI({
1548
- plugin: {
1549
- setupFn,
1550
- descriptor: pluginDescriptor
1551
- },
1552
- ctx: devtoolsContext
1553
- });
1554
- if (pluginDescriptor.packageName === "vuex") api.on.editInspectorState((payload) => {
1555
- api.sendInspectorState(payload.inspectorId);
1556
- });
1557
- setupFn(api);
1558
- }
1559
- function registerDevToolsPlugin(app, options) {
1560
- if (target.__VUE_DEVTOOLS_KIT__REGISTERED_PLUGIN_APPS__.has(app)) return;
1561
- if (devtoolsState.highPerfModeEnabled && !options?.inspectingComponent) return;
1562
- target.__VUE_DEVTOOLS_KIT__REGISTERED_PLUGIN_APPS__.add(app);
1563
- devtoolsPluginBuffer.forEach((plugin) => {
1564
- callDevToolsPluginSetupFn(plugin, app);
1565
- });
1566
- }
1567
- //#endregion
1568
- //#region ../devtools-kit/src/ctx/router.ts
1569
- const ROUTER_KEY = "__VUE_DEVTOOLS_ROUTER__";
1570
- const ROUTER_INFO_KEY = "__VUE_DEVTOOLS_ROUTER_INFO__";
1571
- target[ROUTER_INFO_KEY] ??= {
1572
- currentRoute: null,
1573
- routes: []
1574
- };
1575
- target[ROUTER_KEY] ??= {};
1576
- new Proxy(target[ROUTER_INFO_KEY], { get(target$1, property) {
1577
- return target[ROUTER_INFO_KEY][property];
1578
- } });
1579
- new Proxy(target[ROUTER_KEY], { get(target$2, property) {
1580
- if (property === "value") return target[ROUTER_KEY];
1581
- } });
1582
- //#endregion
1583
- //#region ../devtools-kit/src/core/router/index.ts
1584
- function getRoutes(router) {
1585
- const routesMap = /* @__PURE__ */ new Map();
1586
- return (router?.getRoutes() || []).filter((i) => !routesMap.has(i.path) && routesMap.set(i.path, 1));
1587
- }
1588
- function filterRoutes(routes) {
1589
- return routes.map((item) => {
1590
- let { path, name, children, meta } = item;
1591
- if (children?.length) children = filterRoutes(children);
1592
- return {
1593
- path,
1594
- name,
1595
- children,
1596
- meta
1597
- };
1598
- });
1599
- }
1600
- function filterCurrentRoute(route) {
1601
- if (route) {
1602
- const { fullPath, hash, href, path, name, matched, params, query } = route;
1603
- return {
1604
- fullPath,
1605
- hash,
1606
- href,
1607
- path,
1608
- name,
1609
- params,
1610
- query,
1611
- matched: filterRoutes(matched)
1612
- };
1613
- }
1614
- return route;
1615
- }
1616
- function normalizeRouterInfo(appRecord, activeAppRecord) {
1617
- function init() {
1618
- const router = appRecord.app?.config.globalProperties.$router;
1619
- const currentRoute = filterCurrentRoute(router?.currentRoute.value);
1620
- const routes = filterRoutes(getRoutes(router));
1621
- const c = console.warn;
1622
- console.warn = () => {};
1623
- target[ROUTER_INFO_KEY] = {
1624
- currentRoute: currentRoute ? deepClone(currentRoute) : {},
1625
- routes: deepClone(routes)
1626
- };
1627
- target[ROUTER_KEY] = router;
1628
- console.warn = c;
1629
- }
1630
- init();
1631
- hook.on.componentUpdated(debounce(() => {
1632
- if (activeAppRecord.value?.app !== appRecord.app) return;
1633
- init();
1634
- if (devtoolsState.highPerfModeEnabled) return;
1635
- devtoolsContext.hooks.callHook(DevToolsMessagingHookKeys.ROUTER_INFO_UPDATED, { state: target[ROUTER_INFO_KEY] });
1636
- }, 200));
1637
- }
1638
- //#endregion
1639
- //#region ../devtools-kit/src/ctx/api.ts
1640
- function createDevToolsApi(hooks) {
1641
- return {
1642
- async getInspectorTree(payload) {
1643
- const _payload = {
1644
- ...payload,
1645
- app: activeAppRecord.value.app,
1646
- rootNodes: []
1647
- };
1648
- await new Promise((resolve) => {
1649
- hooks.callHookWith(async (callbacks) => {
1650
- await Promise.all(callbacks.map((cb) => cb(_payload)));
1651
- resolve();
1652
- }, DevToolsV6PluginAPIHookKeys.GET_INSPECTOR_TREE);
1653
- });
1654
- return _payload.rootNodes;
1655
- },
1656
- async getInspectorState(payload) {
1657
- const _payload = {
1658
- ...payload,
1659
- app: activeAppRecord.value.app,
1660
- state: null
1661
- };
1662
- const ctx = { currentTab: `custom-inspector:${payload.inspectorId}` };
1663
- await new Promise((resolve) => {
1664
- hooks.callHookWith(async (callbacks) => {
1665
- await Promise.all(callbacks.map((cb) => cb(_payload, ctx)));
1666
- resolve();
1667
- }, DevToolsV6PluginAPIHookKeys.GET_INSPECTOR_STATE);
1668
- });
1669
- return _payload.state;
1670
- },
1671
- editInspectorState(payload) {
1672
- const stateEditor = new StateEditor();
1673
- const _payload = {
1674
- ...payload,
1675
- app: activeAppRecord.value.app,
1676
- set: (obj, path = payload.path, value = payload.state.value, cb) => {
1677
- stateEditor.set(obj, path, value, cb || stateEditor.createDefaultSetCallback(payload.state));
1678
- }
1679
- };
1680
- hooks.callHookWith((callbacks) => {
1681
- callbacks.forEach((cb) => cb(_payload));
1682
- }, DevToolsV6PluginAPIHookKeys.EDIT_INSPECTOR_STATE);
1683
- },
1684
- sendInspectorState(inspectorId) {
1685
- const inspector = getInspector(inspectorId);
1686
- hooks.callHook(DevToolsContextHookKeys.SEND_INSPECTOR_STATE, {
1687
- inspectorId,
1688
- plugin: {
1689
- descriptor: inspector.descriptor,
1690
- setupFn: () => ({})
1691
- }
1692
- });
1693
- },
1694
- inspectComponentInspector() {
1695
- return inspectComponentHighLighter();
1696
- },
1697
- cancelInspectComponentInspector() {
1698
- return cancelInspectComponentHighLighter();
1699
- },
1700
- getComponentRenderCode(id) {
1701
- const instance = getComponentInstance(activeAppRecord.value, id);
1702
- if (instance) return !(typeof instance?.type === "function") ? instance.render.toString() : instance.type.toString();
1703
- },
1704
- scrollToComponent(id) {
1705
- return scrollToComponent({ id });
1706
- },
1707
- openInEditor,
1708
- getVueInspector: getComponentInspector,
1709
- toggleApp(id, options) {
1710
- const appRecord = devtoolsAppRecords.value.find((record) => record.id === id);
1711
- if (appRecord) {
1712
- setActiveAppRecordId(id);
1713
- setActiveAppRecord(appRecord);
1714
- normalizeRouterInfo(appRecord, activeAppRecord);
1715
- callInspectorUpdatedHook();
1716
- registerDevToolsPlugin(appRecord.app, options);
1717
- }
1718
- },
1719
- inspectDOM(instanceId) {
1720
- const instance = getComponentInstance(activeAppRecord.value, instanceId);
1721
- if (instance) {
1722
- const [el] = getRootElementsFromComponentInstance(instance);
1723
- if (el) target.__VUE_DEVTOOLS_INSPECT_DOM_TARGET__ = el;
1724
- }
1725
- },
1726
- updatePluginSettings(pluginId, key, value) {
1727
- setPluginSettings(pluginId, key, value);
1728
- },
1729
- getPluginSettings(pluginId) {
1730
- return {
1731
- options: getPluginSettingsOptions(pluginId),
1732
- values: getPluginSettings(pluginId)
1733
- };
1734
- }
1735
- };
1736
- }
1737
- //#endregion
1738
- //#region ../devtools-kit/src/ctx/index.ts
1739
- const hooks = createDevToolsCtxHooks();
1740
- target.__VUE_DEVTOOLS_KIT_CONTEXT__ ??= {
1741
- hooks,
1742
- get state() {
1743
- return {
1744
- ...devtoolsState,
1745
- activeAppRecordId: activeAppRecord.id,
1746
- activeAppRecord: activeAppRecord.value,
1747
- appRecords: devtoolsAppRecords.value
1748
- };
1749
- },
1750
- api: createDevToolsApi(hooks)
1751
- };
1752
- const devtoolsContext = target.__VUE_DEVTOOLS_KIT_CONTEXT__;
1753
- //#endregion
1754
- //#region ../devtools-kit/src/core/index.ts
1755
- function onDevToolsClientConnected(fn) {
1756
- return new Promise((resolve) => {
1757
- if (devtoolsState.connected && devtoolsState.clientConnected) {
1758
- fn();
1759
- resolve();
1760
- return;
1761
- }
1762
- devtoolsContext.hooks.hook(DevToolsMessagingHookKeys.DEVTOOLS_CONNECTED_UPDATED, ({ state }) => {
1763
- if (state.connected && state.clientConnected) {
1764
- fn();
1765
- resolve();
1766
- }
1767
- });
1768
- });
1769
- }
1770
- //#endregion
1771
- export { addCustomCommand, addCustomTab, onDevToolsClientConnected, onDevToolsConnected, removeCustomCommand, setupDevToolsPlugin, setupDevToolsPlugin as setupDevtoolsPlugin };