11import type { KbdKey } from '@solid-primitives/keyboard'
2- import { isWindows } from '@solid-primitives/platform'
32import type { ToDyscriminatedUnion } from '@solid-devtools/shared/utils'
43import { type NodeID , type SourceLocation } from '../main/types.ts'
54
@@ -14,13 +13,13 @@ export type LocatorOptions = {
1413}
1514
1615export type HighlightElementPayload = ToDyscriminatedUnion < {
17- node : { id : NodeID }
16+ node : { id : NodeID }
1817 element : { id : NodeID }
1918} > | null
2019
2120// used by the transform
2221export const WINDOW_PROJECTPATH_PROPERTY = '$sdt_projectPath'
23- export const LOCATION_ATTRIBUTE_NAME = 'data-source-loc'
22+ export const LOCATION_ATTRIBUTE_NAME = 'data-source-loc'
2423
2524export type LocationAttr = `${string } :${number } :${number } `
2625
@@ -32,16 +31,15 @@ export type SourceCodeData = SourceLocation & {
3231
3332export type TargetURLFunction = ( data : SourceCodeData ) => string | void
3433
35- const LOC_ATTR_REGEX_WIN = / ^ ( (?: \\ ? [ ^ \s ] [ ^ / \\ : \" \? \* < > \| ] + ) + ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) $ /
36- const LOC_ATTR_REGEX_UNIX =
37- / ^ ( (?: (?: \. \/ | \. \. \/ | \/ ) ? (?: \. ? \w + \/ ) * ) (?: \. ? \w + \. ? \w + ) ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) $ /
38-
39- export const LOC_ATTR_REGEX = isWindows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
34+ const LOC_ATTR_REGEX_WIN = / ^ ( (?: \\ ? [ ^ \s ] [ ^ / \\ : \" \? \* < > \| ] + ) + ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) $ /
35+ const LOC_ATTR_REGEX_UNIX = / ^ ( (?: (?: \. \/ | \. \. \/ | \/ ) ? (?: \. ? \w + \/ ) * ) (?: \. ? \w + \. ? \w + ) ) : ( [ 0 - 9 ] + ) : ( [ 0 - 9 ] + ) $ /
4036
4137export function getLocationAttr ( element : Element ) : LocationAttr | null {
4238 let attr = element . getAttribute ( LOCATION_ATTRIBUTE_NAME )
43- if ( ! attr || ! LOC_ATTR_REGEX . test ( attr ) ) return null
44- return attr as LocationAttr
39+ if ( ! attr ) return null
40+ let is_windows = / ( w i n 3 2 | w i n 6 4 | w i n d o w s | w i n c e ) / i. test ( navigator . userAgent )
41+ let regex = is_windows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
42+ return regex . test ( attr ) ? attr as LocationAttr : null
4543}
4644
4745const targetIDEMap : Record < TargetIDE , ( data : SourceCodeData ) => string > = {
0 commit comments