@sveltejs/vite-plugin-svelte 2.1.1 → 2.3.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/dist/index.d.ts +7 -72
- package/dist/index.js +40 -158
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +15 -8
- package/src/utils/compile.ts +0 -3
- package/src/utils/options.ts +27 -100
- package/src/ui/inspector/Inspector.svelte +0 -365
- package/src/ui/inspector/load-inspector.js +0 -15
- package/src/ui/inspector/plugin.ts +0 -115
- package/src/ui/inspector/utils.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/vite-plugin-svelte",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "dominikg",
|
|
6
6
|
"files": [
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.js"
|
|
17
17
|
},
|
|
18
|
-
"./package.json": "./package.json"
|
|
19
|
-
"./src/ui/*": "./src/ui/*"
|
|
18
|
+
"./package.json": "./package.json"
|
|
20
19
|
},
|
|
21
20
|
"engines": {
|
|
22
21
|
"node": "^14.18.0 || >= 16"
|
|
@@ -42,7 +41,8 @@
|
|
|
42
41
|
"kleur": "^4.1.5",
|
|
43
42
|
"magic-string": "^0.30.0",
|
|
44
43
|
"svelte-hmr": "^0.15.1",
|
|
45
|
-
"vitefu": "^0.2.4"
|
|
44
|
+
"vitefu": "^0.2.4",
|
|
45
|
+
"@sveltejs/vite-plugin-svelte-inspector": "^1.0.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"svelte": "^3.54.0",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/debug": "^4.1.7",
|
|
53
|
-
"esbuild": "^0.17.
|
|
54
|
-
"rollup": "^
|
|
55
|
-
"svelte": "^3.
|
|
53
|
+
"esbuild": "^0.17.18",
|
|
54
|
+
"rollup": "^3.21.6",
|
|
55
|
+
"svelte": "^3.59.1",
|
|
56
56
|
"tsup": "^6.7.0",
|
|
57
|
-
"vite": "^4.3.
|
|
57
|
+
"vite": "^4.3.5"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"dev": "pnpm build:ci --sourcemap --watch src",
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
version as viteVersion
|
|
10
10
|
} from 'vite';
|
|
11
11
|
// eslint-disable-next-line node/no-missing-import
|
|
12
|
+
import { svelteInspector } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
13
|
+
// eslint-disable-next-line node/no-missing-import
|
|
12
14
|
import { isDepExcluded } from 'vitefu';
|
|
13
15
|
import { handleHotUpdate } from './handle-hot-update';
|
|
14
16
|
import { log, logCompilerWarnings } from './utils/log';
|
|
@@ -29,7 +31,6 @@ import { resolveViaPackageJsonSvelte } from './utils/resolve';
|
|
|
29
31
|
import { PartialResolvedId } from 'rollup';
|
|
30
32
|
import { toRollupError } from './utils/error';
|
|
31
33
|
import { saveSvelteMetadata } from './utils/optimizer';
|
|
32
|
-
import { svelteInspector } from './ui/inspector/plugin';
|
|
33
34
|
import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache';
|
|
34
35
|
import { loadRaw } from './utils/load-raw';
|
|
35
36
|
import { FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE } from './utils/constants';
|
|
@@ -235,10 +236,16 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
|
|
|
235
236
|
}
|
|
236
237
|
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
237
238
|
cache.update(compileData);
|
|
238
|
-
if (compileData.dependencies?.length
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
if (compileData.dependencies?.length) {
|
|
240
|
+
if (options.server) {
|
|
241
|
+
for (const dep of compileData.dependencies) {
|
|
242
|
+
ensureWatchedFile(options.server.watcher, dep, options.root);
|
|
243
|
+
}
|
|
244
|
+
} else if (options.isBuild && viteConfig.build.watch) {
|
|
245
|
+
for (const dep of compileData.dependencies) {
|
|
246
|
+
this.addWatchFile(dep);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
242
249
|
}
|
|
243
250
|
log.debug(`transform returns compiled js for ${svelteRequest.filename}`);
|
|
244
251
|
return {
|
|
@@ -273,10 +280,10 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin[] {
|
|
|
273
280
|
);
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
|
-
}
|
|
283
|
+
},
|
|
284
|
+
svelteInspector()
|
|
277
285
|
];
|
|
278
|
-
plugins
|
|
279
|
-
return plugins.filter(Boolean);
|
|
286
|
+
return plugins;
|
|
280
287
|
}
|
|
281
288
|
|
|
282
289
|
export { vitePreprocess } from './preprocess';
|
package/src/utils/compile.ts
CHANGED
|
@@ -157,8 +157,6 @@ const _createCompileSvelte = (makeHot: Function) => {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
compiled.js.dependencies = dependencies;
|
|
161
|
-
|
|
162
160
|
return {
|
|
163
161
|
filename,
|
|
164
162
|
normalizedFilename,
|
|
@@ -195,7 +193,6 @@ export function createCompileSvelte(options: ResolvedOptions) {
|
|
|
195
193
|
export interface Code {
|
|
196
194
|
code: string;
|
|
197
195
|
map?: any;
|
|
198
|
-
dependencies?: any[];
|
|
199
196
|
}
|
|
200
197
|
|
|
201
198
|
export interface Compiled {
|
package/src/utils/options.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
|
-
import { ConfigEnv, ResolvedConfig, UserConfig, ViteDevServer
|
|
2
|
+
import { ConfigEnv, normalizePath, ResolvedConfig, UserConfig, ViteDevServer } from 'vite';
|
|
3
3
|
import { isDebugNamespaceEnabled, log } from './log';
|
|
4
4
|
import { loadSvelteConfig } from './load-svelte-config';
|
|
5
5
|
import {
|
|
@@ -18,6 +18,8 @@ import type {
|
|
|
18
18
|
Processed
|
|
19
19
|
// eslint-disable-next-line node/no-missing-import
|
|
20
20
|
} from 'svelte/types/compiler/preprocess';
|
|
21
|
+
// eslint-disable-next-line node/no-missing-import
|
|
22
|
+
import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector';
|
|
21
23
|
|
|
22
24
|
import path from 'path';
|
|
23
25
|
import { esbuildSveltePlugin, facadeEsbuildSveltePluginName } from './esbuild';
|
|
@@ -44,17 +46,13 @@ const allowedPluginOptions = new Set([
|
|
|
44
46
|
'ignorePluginPreprocessors',
|
|
45
47
|
'disableDependencyReinclusion',
|
|
46
48
|
'prebundleSvelteLibraries',
|
|
49
|
+
'inspector',
|
|
47
50
|
'experimental'
|
|
48
51
|
]);
|
|
49
52
|
|
|
50
53
|
const knownRootOptions = new Set(['extensions', 'compilerOptions', 'preprocess', 'onwarn']);
|
|
51
54
|
|
|
52
|
-
const allowedInlineOptions = new Set([
|
|
53
|
-
'configFile',
|
|
54
|
-
'kit', // only for internal use by sveltekit
|
|
55
|
-
...allowedPluginOptions,
|
|
56
|
-
...knownRootOptions
|
|
57
|
-
]);
|
|
55
|
+
const allowedInlineOptions = new Set(['configFile', ...allowedPluginOptions, ...knownRootOptions]);
|
|
58
56
|
|
|
59
57
|
export function validateInlineOptions(inlineOptions?: Partial<Options>) {
|
|
60
58
|
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
@@ -203,7 +201,6 @@ export function resolveOptions(
|
|
|
203
201
|
|
|
204
202
|
removeIgnoredOptions(merged);
|
|
205
203
|
handleDeprecatedOptions(merged);
|
|
206
|
-
addSvelteKitOptions(merged);
|
|
207
204
|
addExtraPreprocessors(merged, viteConfig);
|
|
208
205
|
enforceOptionsForHmr(merged);
|
|
209
206
|
enforceOptionsForProduction(merged);
|
|
@@ -291,24 +288,22 @@ function removeIgnoredOptions(options: ResolvedOptions) {
|
|
|
291
288
|
}
|
|
292
289
|
}
|
|
293
290
|
|
|
294
|
-
// some SvelteKit options need compilerOptions to work, so set them here.
|
|
295
|
-
function addSvelteKitOptions(options: ResolvedOptions) {
|
|
296
|
-
// @ts-expect-error kit is not typed to avoid dependency on sveltekit
|
|
297
|
-
if (options?.kit != null && options.compilerOptions.hydratable == null) {
|
|
298
|
-
log.debug(`Setting compilerOptions.hydratable = true for SvelteKit`);
|
|
299
|
-
options.compilerOptions.hydratable = true;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
291
|
function handleDeprecatedOptions(options: ResolvedOptions) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
292
|
+
const experimental = options.experimental as any;
|
|
293
|
+
if (experimental) {
|
|
294
|
+
for (const promoted of ['prebundleSvelteLibraries', 'inspector']) {
|
|
295
|
+
if (experimental[promoted]) {
|
|
296
|
+
//@ts-expect-error untyped assign
|
|
297
|
+
options[promoted] = experimental[promoted];
|
|
298
|
+
delete experimental[promoted];
|
|
299
|
+
log.warn(
|
|
300
|
+
`Option "vitePlugin.experimental.${promoted}" is no longer experimental and has moved to "vitePlugin.${promoted}". Please update your svelte config.`
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (experimental.generateMissingPreprocessorSourcemaps) {
|
|
305
|
+
log.warn('experimental.generateMissingPreprocessorSourcemaps has been removed.');
|
|
306
|
+
}
|
|
312
307
|
}
|
|
313
308
|
}
|
|
314
309
|
|
|
@@ -643,6 +638,13 @@ export interface PluginOptions {
|
|
|
643
638
|
*/
|
|
644
639
|
prebundleSvelteLibraries?: boolean;
|
|
645
640
|
|
|
641
|
+
/**
|
|
642
|
+
* toggle/configure Svelte Inspector
|
|
643
|
+
*
|
|
644
|
+
* @default true
|
|
645
|
+
*/
|
|
646
|
+
inspector?: InspectorOptions | boolean;
|
|
647
|
+
|
|
646
648
|
/**
|
|
647
649
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
648
650
|
*/
|
|
@@ -713,11 +715,6 @@ export interface ExperimentalOptions {
|
|
|
713
715
|
compileOptions: Partial<CompileOptions>;
|
|
714
716
|
}) => Promise<Partial<CompileOptions> | void> | Partial<CompileOptions> | void;
|
|
715
717
|
|
|
716
|
-
/**
|
|
717
|
-
* enable svelte inspector
|
|
718
|
-
*/
|
|
719
|
-
inspector?: InspectorOptions | boolean;
|
|
720
|
-
|
|
721
718
|
/**
|
|
722
719
|
* send a websocket message with svelte compiler warnings during dev
|
|
723
720
|
*
|
|
@@ -732,76 +729,6 @@ export interface ExperimentalOptions {
|
|
|
732
729
|
disableSvelteResolveWarnings?: boolean;
|
|
733
730
|
}
|
|
734
731
|
|
|
735
|
-
export interface InspectorOptions {
|
|
736
|
-
/**
|
|
737
|
-
* define a key combo to toggle inspector,
|
|
738
|
-
* @default 'control-shift' on windows, 'meta-shift' on other os
|
|
739
|
-
*
|
|
740
|
-
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
|
|
741
|
-
* examples: control-shift, control-o, control-alt-s meta-x control-meta
|
|
742
|
-
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
|
|
743
|
-
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
|
|
744
|
-
*/
|
|
745
|
-
toggleKeyCombo?: string;
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* define keys to select elements with via keyboard
|
|
749
|
-
* @default {parent: 'ArrowUp', child: 'ArrowDown', next: 'ArrowRight', prev: 'ArrowLeft' }
|
|
750
|
-
*
|
|
751
|
-
* improves accessibility and also helps when you want to select elements that do not have a hoverable surface area
|
|
752
|
-
* due to tight wrapping
|
|
753
|
-
*
|
|
754
|
-
* A note for users of screen-readers:
|
|
755
|
-
* If you are using arrow keys to navigate the page itself, change the navKeys to avoid conflicts.
|
|
756
|
-
* e.g. navKeys: {parent: 'w', prev: 'a', child: 's', next: 'd'}
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
* parent: select closest parent
|
|
760
|
-
* child: select first child (or grandchild)
|
|
761
|
-
* next: next sibling (or parent if no next sibling exists)
|
|
762
|
-
* prev: previous sibling (or parent if no prev sibling exists)
|
|
763
|
-
*/
|
|
764
|
-
navKeys?: { parent: string; child: string; next: string; prev: string };
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* define key to open the editor for the currently selected dom node
|
|
768
|
-
*
|
|
769
|
-
* @default 'Enter'
|
|
770
|
-
*/
|
|
771
|
-
openKey?: string;
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
* inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress
|
|
775
|
-
* @default false
|
|
776
|
-
*/
|
|
777
|
-
holdMode?: boolean;
|
|
778
|
-
/**
|
|
779
|
-
* when to show the toggle button
|
|
780
|
-
* @default 'active'
|
|
781
|
-
*/
|
|
782
|
-
showToggleButton?: 'always' | 'active' | 'never';
|
|
783
|
-
|
|
784
|
-
/**
|
|
785
|
-
* where to display the toggle button
|
|
786
|
-
* @default top-right
|
|
787
|
-
*/
|
|
788
|
-
toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* inject custom styles when inspector is active
|
|
792
|
-
*/
|
|
793
|
-
customStyles?: boolean;
|
|
794
|
-
|
|
795
|
-
/**
|
|
796
|
-
* append an import to the module id ending with `appendTo` instead of adding a script into body
|
|
797
|
-
* useful for frameworks that do not support trannsformIndexHtml hook
|
|
798
|
-
*
|
|
799
|
-
* WARNING: only set this if you know exactly what it does.
|
|
800
|
-
* Regular users of vite-plugin-svelte or SvelteKit do not need it
|
|
801
|
-
*/
|
|
802
|
-
appendTo?: string;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
732
|
export interface PreResolvedOptions extends Options {
|
|
806
733
|
// these options are non-nullable after resolve
|
|
807
734
|
compilerOptions: CompileOptions;
|
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
// do not use TS here so that this component works in non-ts projects too
|
|
3
|
-
import { onMount } from 'svelte';
|
|
4
|
-
// eslint-disable-next-line node/no-missing-import
|
|
5
|
-
import options from 'virtual:svelte-inspector-options';
|
|
6
|
-
const toggle_combo = options.toggleKeyCombo?.toLowerCase().split('-');
|
|
7
|
-
const nav_keys = Object.values(options.navKeys).map((k) => k.toLowerCase());
|
|
8
|
-
let enabled = false;
|
|
9
|
-
|
|
10
|
-
const icon = `data:image/svg+xml;base64,${btoa(
|
|
11
|
-
`
|
|
12
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="21" height="25" viewBox="0 0 107 128">
|
|
13
|
-
<title>svelte-inspector-logo</title>
|
|
14
|
-
<path d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157" style="fill:#ff3e00"/><path d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287" style="fill:#fff"/>
|
|
15
|
-
<polygon points="0,0 15,40 40,20" stroke="#ff3e00" fill="#ff3e00"></polygon>
|
|
16
|
-
</svg>
|
|
17
|
-
`
|
|
18
|
-
.replace(/[\n\r\t\s]+/g, ' ')
|
|
19
|
-
.trim()
|
|
20
|
-
)}`;
|
|
21
|
-
|
|
22
|
-
// location of code in file
|
|
23
|
-
let file_loc;
|
|
24
|
-
// cursor pos and width for file_loc overlay positioning
|
|
25
|
-
let x, y, w;
|
|
26
|
-
|
|
27
|
-
let active_el;
|
|
28
|
-
|
|
29
|
-
let enabled_ts;
|
|
30
|
-
|
|
31
|
-
$: show_toggle =
|
|
32
|
-
options.showToggleButton === 'always' || (options.showToggleButton === 'active' && enabled);
|
|
33
|
-
|
|
34
|
-
function mousemove(event) {
|
|
35
|
-
x = event.x;
|
|
36
|
-
y = event.y;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function find_selectable_parent(el, include_self = false) {
|
|
40
|
-
if (!include_self) {
|
|
41
|
-
el = el.parentNode;
|
|
42
|
-
}
|
|
43
|
-
while (el) {
|
|
44
|
-
if (is_selectable(el)) {
|
|
45
|
-
return el;
|
|
46
|
-
}
|
|
47
|
-
el = el.parentNode;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function find_selectable_child(el) {
|
|
52
|
-
return [...el.querySelectorAll('*')].find(is_selectable);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function find_selectable_sibling(el, prev = false) {
|
|
56
|
-
do {
|
|
57
|
-
el = prev ? el.previousElementSibling : el.nextElementSibling;
|
|
58
|
-
if (is_selectable(el)) {
|
|
59
|
-
return el;
|
|
60
|
-
}
|
|
61
|
-
} while (el);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function find_selectable_for_nav(key) {
|
|
65
|
-
const el = active_el;
|
|
66
|
-
if (!el) {
|
|
67
|
-
return find_selectable_child(document?.body);
|
|
68
|
-
}
|
|
69
|
-
switch (key) {
|
|
70
|
-
case options.navKeys.parent:
|
|
71
|
-
return find_selectable_parent(el);
|
|
72
|
-
case options.navKeys.child:
|
|
73
|
-
return find_selectable_child(el);
|
|
74
|
-
case options.navKeys.next:
|
|
75
|
-
return find_selectable_sibling(el) || find_selectable_parent(el);
|
|
76
|
-
case options.navKeys.prev:
|
|
77
|
-
return find_selectable_sibling(el, true) || find_selectable_parent(el);
|
|
78
|
-
default:
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function is_selectable(el) {
|
|
84
|
-
const file = el?.__svelte_meta?.loc?.file;
|
|
85
|
-
if (!file || file.includes('node_modules/')) {
|
|
86
|
-
return false; // no file or 3rd party
|
|
87
|
-
}
|
|
88
|
-
const id = el.getAttribute('id');
|
|
89
|
-
if (id === 'svelte-announcer' || id?.startsWith('svelte-inspector-')) {
|
|
90
|
-
return false; // ignore some elements by id that would be selectable from keyboard nav otherwise
|
|
91
|
-
}
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function mouseover({ target }) {
|
|
96
|
-
const el = find_selectable_parent(target, true);
|
|
97
|
-
activate(el, false);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function activate(el, set_bubble_pos = true) {
|
|
101
|
-
if (options.customStyles && el !== active_el) {
|
|
102
|
-
if (active_el) {
|
|
103
|
-
active_el.classList.remove('svelte-inspector-active-target');
|
|
104
|
-
}
|
|
105
|
-
if (el) {
|
|
106
|
-
el.classList.add('svelte-inspector-active-target');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (el) {
|
|
110
|
-
const { file, line, column } = el.__svelte_meta.loc;
|
|
111
|
-
file_loc = `${file}:${line + 1}:${column + 1}`;
|
|
112
|
-
} else {
|
|
113
|
-
file_loc = null;
|
|
114
|
-
}
|
|
115
|
-
active_el = el;
|
|
116
|
-
if (set_bubble_pos) {
|
|
117
|
-
const pos = el.getBoundingClientRect();
|
|
118
|
-
x = Math.ceil(pos.left);
|
|
119
|
-
y = Math.ceil(pos.bottom - 20);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function open_editor(event) {
|
|
124
|
-
if (file_loc) {
|
|
125
|
-
stop(event);
|
|
126
|
-
fetch(`/__open-in-editor?file=${encodeURIComponent(file_loc)}`);
|
|
127
|
-
if (options.holdMode && is_holding()) {
|
|
128
|
-
disable();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function is_key_active(key, event) {
|
|
134
|
-
switch (key) {
|
|
135
|
-
case 'shift':
|
|
136
|
-
case 'control':
|
|
137
|
-
case 'alt':
|
|
138
|
-
case 'meta':
|
|
139
|
-
return event.getModifierState(key.charAt(0).toUpperCase() + key.slice(1));
|
|
140
|
-
default:
|
|
141
|
-
return key === event.key.toLowerCase();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function is_combo(event) {
|
|
146
|
-
return toggle_combo?.every((key) => is_key_active(key, event));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function is_nav(event) {
|
|
150
|
-
return nav_keys?.some((key) => is_key_active(key, event));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function is_open(event) {
|
|
154
|
-
return options.openKey && options.openKey.toLowerCase() === event.key.toLowerCase();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function is_holding() {
|
|
158
|
-
return enabled_ts && Date.now() - enabled_ts > 250;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function stop(event) {
|
|
162
|
-
event.preventDefault();
|
|
163
|
-
event.stopPropagation();
|
|
164
|
-
event.stopImmediatePropagation();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function keydown(event) {
|
|
168
|
-
if (event.repeat || event.key == null) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (is_combo(event)) {
|
|
173
|
-
toggle();
|
|
174
|
-
if (options.holdMode && enabled) {
|
|
175
|
-
enabled_ts = Date.now();
|
|
176
|
-
}
|
|
177
|
-
} else if (enabled) {
|
|
178
|
-
if (is_nav(event)) {
|
|
179
|
-
const el = find_selectable_for_nav(event.key);
|
|
180
|
-
if (el) {
|
|
181
|
-
activate(el);
|
|
182
|
-
stop(event);
|
|
183
|
-
}
|
|
184
|
-
} else if (is_open(event)) {
|
|
185
|
-
open_editor(event);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function keyup(event) {
|
|
191
|
-
if (event.repeat || event.key == null) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const k = event.key.toLowerCase();
|
|
195
|
-
if (enabled && is_holding() && toggle_combo.includes(k)) {
|
|
196
|
-
disable();
|
|
197
|
-
} else {
|
|
198
|
-
enabled_ts = null;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function toggle() {
|
|
203
|
-
enabled ? disable() : enable();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function listeners(body, enabled) {
|
|
207
|
-
const l = enabled ? body.addEventListener : body.removeEventListener;
|
|
208
|
-
l('mousemove', mousemove);
|
|
209
|
-
l('mouseover', mouseover);
|
|
210
|
-
l('click', open_editor, true);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function enable() {
|
|
214
|
-
enabled = true;
|
|
215
|
-
const b = document.body;
|
|
216
|
-
if (options.customStyles) {
|
|
217
|
-
b.classList.add('svelte-inspector-enabled');
|
|
218
|
-
}
|
|
219
|
-
listeners(b, enabled);
|
|
220
|
-
activate_initial_el();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function activate_initial_el() {
|
|
224
|
-
const hov = innermost_hover_el();
|
|
225
|
-
let el = find_selectable_parent(hov, true);
|
|
226
|
-
if (!el) {
|
|
227
|
-
const act = document.activeElement;
|
|
228
|
-
el = find_selectable_parent(act, true);
|
|
229
|
-
}
|
|
230
|
-
if (!el) {
|
|
231
|
-
el = find_selectable_child(document.body);
|
|
232
|
-
}
|
|
233
|
-
if (el) {
|
|
234
|
-
activate(el);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function innermost_hover_el() {
|
|
239
|
-
let e = document.body.querySelector(':hover');
|
|
240
|
-
let result;
|
|
241
|
-
while (e) {
|
|
242
|
-
result = e;
|
|
243
|
-
e = e.querySelector(':hover');
|
|
244
|
-
}
|
|
245
|
-
return result;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function disable() {
|
|
249
|
-
enabled = false;
|
|
250
|
-
enabled_ts = null;
|
|
251
|
-
const b = document.body;
|
|
252
|
-
listeners(b, enabled);
|
|
253
|
-
if (options.customStyles) {
|
|
254
|
-
b.classList.remove('svelte-inspector-enabled');
|
|
255
|
-
active_el?.classList.remove('svelte-inspector-active-target');
|
|
256
|
-
}
|
|
257
|
-
active_el = null;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
onMount(() => {
|
|
261
|
-
const s = document.createElement('style');
|
|
262
|
-
s.setAttribute('type', 'text/css');
|
|
263
|
-
s.setAttribute('id', 'svelte-inspector-style');
|
|
264
|
-
s.textContent = `:root { --svelte-inspector-icon: url(${icon})};`;
|
|
265
|
-
document.head.append(s);
|
|
266
|
-
if (toggle_combo) {
|
|
267
|
-
document.body.addEventListener('keydown', keydown);
|
|
268
|
-
if (options.holdMode) {
|
|
269
|
-
document.body.addEventListener('keyup', keyup);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return () => {
|
|
273
|
-
// make sure we get rid of everything
|
|
274
|
-
disable();
|
|
275
|
-
const s = document.head.querySelector('#svelte-inspector-style');
|
|
276
|
-
if (s) {
|
|
277
|
-
document.head.removeChild(s);
|
|
278
|
-
}
|
|
279
|
-
if (toggle_combo) {
|
|
280
|
-
document.body.removeEventListener('keydown', keydown);
|
|
281
|
-
if (options.holdMode) {
|
|
282
|
-
document.body.addEventListener('keyup', keyup);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
});
|
|
287
|
-
</script>
|
|
288
|
-
|
|
289
|
-
{#if show_toggle}
|
|
290
|
-
<button
|
|
291
|
-
id="svelte-inspector-toggle"
|
|
292
|
-
class:enabled
|
|
293
|
-
style={`background-image: var(--svelte-inspector-icon);${options.toggleButtonPos
|
|
294
|
-
.split('-')
|
|
295
|
-
.map((p) => `${p}: 8px;`)
|
|
296
|
-
.join('')}`}
|
|
297
|
-
on:click={() => toggle()}
|
|
298
|
-
aria-label={`${enabled ? 'disable' : 'enable'} svelte-inspector`}
|
|
299
|
-
/>
|
|
300
|
-
{/if}
|
|
301
|
-
{#if enabled && active_el && file_loc}
|
|
302
|
-
{@const loc = active_el.__svelte_meta.loc}
|
|
303
|
-
<div
|
|
304
|
-
id="svelte-inspector-overlay"
|
|
305
|
-
style:left="{Math.min(x + 3, document.documentElement.clientWidth - w - 10)}px"
|
|
306
|
-
style:top="{document.documentElement.clientHeight < y + 50 ? y - 30 : y + 30}px"
|
|
307
|
-
bind:offsetWidth={w}
|
|
308
|
-
>
|
|
309
|
-
<{active_el.tagName.toLowerCase()}> {file_loc}
|
|
310
|
-
</div>
|
|
311
|
-
<div id="svelte-inspector-announcer" aria-live="assertive" aria-atomic="true">
|
|
312
|
-
{active_el.tagName.toLowerCase()} in file {loc.file} on line {loc.line} column {loc.column}
|
|
313
|
-
</div>
|
|
314
|
-
{/if}
|
|
315
|
-
|
|
316
|
-
<style>
|
|
317
|
-
:global(body.svelte-inspector-enabled *) {
|
|
318
|
-
cursor: var(--svelte-inspector-icon), crosshair !important;
|
|
319
|
-
}
|
|
320
|
-
:global(.svelte-inspector-active-target) {
|
|
321
|
-
outline: 2px dashed #ff3e00 !important;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
#svelte-inspector-overlay {
|
|
325
|
-
position: fixed;
|
|
326
|
-
background-color: rgba(0, 0, 0, 0.8);
|
|
327
|
-
color: #fff;
|
|
328
|
-
padding: 2px 4px;
|
|
329
|
-
border-radius: 5px;
|
|
330
|
-
z-index: 999999;
|
|
331
|
-
pointer-events: none;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
#svelte-inspector-toggle {
|
|
335
|
-
all: unset;
|
|
336
|
-
border: 1px solid #ff3e00;
|
|
337
|
-
border-radius: 8px;
|
|
338
|
-
position: fixed;
|
|
339
|
-
height: 32px;
|
|
340
|
-
width: 32px;
|
|
341
|
-
background-color: white;
|
|
342
|
-
background-position: center;
|
|
343
|
-
background-repeat: no-repeat;
|
|
344
|
-
cursor: pointer;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
#svelte-inspector-announcer {
|
|
348
|
-
position: absolute;
|
|
349
|
-
left: 0px;
|
|
350
|
-
top: 0px;
|
|
351
|
-
clip: rect(0px, 0px, 0px, 0px);
|
|
352
|
-
clip-path: inset(50%);
|
|
353
|
-
overflow: hidden;
|
|
354
|
-
white-space: nowrap;
|
|
355
|
-
width: 1px;
|
|
356
|
-
height: 1px;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
#svelte-inspector-toggle:not(.enabled) {
|
|
360
|
-
filter: grayscale(1);
|
|
361
|
-
}
|
|
362
|
-
#svelte-inspector-toggle:hover {
|
|
363
|
-
background-color: #facece;
|
|
364
|
-
}
|
|
365
|
-
</style>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line node/no-missing-import
|
|
2
|
-
import Inspector from 'virtual:svelte-inspector-path:Inspector.svelte';
|
|
3
|
-
|
|
4
|
-
function create_inspector_host() {
|
|
5
|
-
const id = 'svelte-inspector-host';
|
|
6
|
-
if (document.getElementById(id) != null) {
|
|
7
|
-
throw new Error('svelte-inspector-host element already exists');
|
|
8
|
-
}
|
|
9
|
-
const el = document.createElement('div');
|
|
10
|
-
el.setAttribute('id', id);
|
|
11
|
-
document.getElementsByTagName('body')[0].appendChild(el);
|
|
12
|
-
return el;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
new Inspector({ target: create_inspector_host() });
|