@amplitude/plugin-autocapture-browser 1.28.0-featelement-selector-v1.0 → 1.28.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/lib/cjs/autocapture-plugin.d.ts.map +1 -1
- package/lib/cjs/autocapture-plugin.js +7 -66
- package/lib/cjs/autocapture-plugin.js.map +1 -1
- package/lib/cjs/data-extractor.d.ts +19 -17
- package/lib/cjs/data-extractor.d.ts.map +1 -1
- package/lib/cjs/data-extractor.js +29 -25
- package/lib/cjs/data-extractor.js.map +1 -1
- package/lib/cjs/element-selector-config.d.ts +21 -0
- package/lib/cjs/element-selector-config.d.ts.map +1 -0
- package/lib/cjs/element-selector-config.js +34 -0
- package/lib/cjs/element-selector-config.js.map +1 -0
- package/lib/cjs/frustration-plugin.d.ts.map +1 -1
- package/lib/cjs/frustration-plugin.js +6 -1
- package/lib/cjs/frustration-plugin.js.map +1 -1
- package/lib/cjs/libs/element-path.d.ts +1 -23
- package/lib/cjs/libs/element-path.d.ts.map +1 -1
- package/lib/cjs/libs/element-path.js +173 -28
- package/lib/cjs/libs/element-path.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.d.ts.map +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/autocapture-plugin.d.ts.map +1 -1
- package/lib/esm/autocapture-plugin.js +7 -66
- package/lib/esm/autocapture-plugin.js.map +1 -1
- package/lib/esm/data-extractor.d.ts +19 -17
- package/lib/esm/data-extractor.d.ts.map +1 -1
- package/lib/esm/data-extractor.js +30 -26
- package/lib/esm/data-extractor.js.map +1 -1
- package/lib/esm/element-selector-config.d.ts +21 -0
- package/lib/esm/element-selector-config.d.ts.map +1 -0
- package/lib/esm/element-selector-config.js +30 -0
- package/lib/esm/element-selector-config.js.map +1 -0
- package/lib/esm/frustration-plugin.d.ts.map +1 -1
- package/lib/esm/frustration-plugin.js +6 -1
- package/lib/esm/frustration-plugin.js.map +1 -1
- package/lib/esm/libs/element-path.d.ts +1 -23
- package/lib/esm/libs/element-path.d.ts.map +1 -1
- package/lib/esm/libs/element-path.js +172 -27
- package/lib/esm/libs/element-path.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.d.ts.map +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/autocapture-plugin.d.ts.map +1 -1
- package/lib/scripts/data-extractor.d.ts +19 -17
- package/lib/scripts/data-extractor.d.ts.map +1 -1
- package/lib/scripts/element-selector-config.d.ts +21 -0
- package/lib/scripts/element-selector-config.d.ts.map +1 -0
- package/lib/scripts/frustration-plugin.d.ts.map +1 -1
- package/lib/scripts/libs/element-path.d.ts +1 -23
- package/lib/scripts/libs/element-path.d.ts.map +1 -1
- package/lib/scripts/version.d.ts +1 -1
- package/lib/scripts/version.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frustration-plugin.js","sourceRoot":"","sources":["../../src/frustration-plugin.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,OAAO,EAKL,6BAA6B,EAC7B,SAAS,EACT,UAAU,EAEV,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAiE,MAAM,WAAW,CAAC;AAClH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAA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P,QAAQ,UAAA;KACT,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport {\n BrowserClient,\n BrowserConfig,\n EnrichmentPlugin,\n FrustrationInteractionsOptions,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n multicast,\n Observable,\n Unsubscribable,\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n} from '@amplitude/analytics-core';\nimport * as constants from './constants';\nimport { createShouldTrackEvent, ElementBasedTimestampedEvent, NavigateEvent, TimestampedEvent } from './helpers';\nimport { trackDeadClick } from './autocapture/track-dead-click';\nimport { trackRageClicks } from './autocapture/track-rage-click';\nimport { ObservablesEnum } from './autocapture-plugin';\nimport {\n BrowserErrorEvent,\n createClickObservable,\n createErrorObservable,\n createMutationObservable,\n createMouseMoveObservable,\n} from './observables';\nimport { DataExtractor } from './data-extractor';\nimport { trackErrorClicks } from './autocapture/track-error-click';\nimport { trackThrashedCursor } from './autocapture/track-thrashed-cursor';\n\nexport interface AllWindowObservables {\n [ObservablesEnum.ClickObservable]: Observable<ElementBasedTimestampedEvent<MouseEvent>>;\n [ObservablesEnum.MutationObservable]: Observable<TimestampedEvent<MutationRecord[]>>;\n [ObservablesEnum.BrowserErrorObservable]: Observable<TimestampedEvent<BrowserErrorEvent>>;\n [ObservablesEnum.NavigateObservable]?: Observable<TimestampedEvent<NavigateEvent>>;\n [ObservablesEnum.SelectionObservable]?: Observable<void>;\n [ObservablesEnum.MouseMoveObservable]: Observable<MouseEvent>;\n}\n\ntype BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\n/**\n * Helper function to extract the css selector allowlist\n * from the frustration interactions options for a specific\n * autocapture feature.\n */\nfunction getCssSelectorAllowlist(\n options: FrustrationInteractionsOptions,\n attribute: keyof FrustrationInteractionsOptions,\n defaultAllowlist: string[],\n enabled: boolean,\n): string[] {\n if (!enabled) {\n return [];\n }\n const config = options[attribute];\n if (\n typeof config === 'object' &&\n config !== null &&\n 'cssSelectorAllowlist' in config &&\n Array.isArray(config.cssSelectorAllowlist)\n ) {\n return config.cssSelectorAllowlist;\n }\n return defaultAllowlist;\n}\n\nconst MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES = 5;\nconst MAXIMUM_THRASHED_CURSOR_THRESHOLD = 4000;\n\nexport const frustrationPlugin = (options: FrustrationInteractionsOptions = {}): BrowserEnrichmentPlugin => {\n const name = constants.FRUSTRATION_PLUGIN_NAME;\n const type = 'enrichment';\n\n const subscriptions: Unsubscribable[] = [];\n\n let isErrorClicksEnabled = options.errorClicks !== false;\n\n // if errorClicks is not defined, disable it\n // change this once it moves out of @experimental\n if (!options.errorClicks) {\n isErrorClicksEnabled = false;\n }\n\n // Check if each feature is enabled\n const deadClicksEnabled = options.deadClicks !== false && options.deadClicks !== null;\n const rageClicksEnabled = options.rageClicks !== false && options.rageClicks !== null;\n\n let thrashedCursorEnabled = options.thrashedCursor !== false && options.thrashedCursor !== null;\n if (!options.thrashedCursor) {\n thrashedCursorEnabled = false;\n }\n\n // Get CSS selectors for enabled features\n const rageCssSelectors = getCssSelectorAllowlist(\n options,\n 'rageClicks',\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n rageClicksEnabled,\n );\n\n const deadCssSelectors = getCssSelectorAllowlist(\n options,\n 'deadClicks',\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n deadClicksEnabled,\n );\n\n const errorCssSelectors = getCssSelectorAllowlist(\n options,\n 'errorClicks',\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n isErrorClicksEnabled,\n );\n\n const dataAttributePrefix = options.dataAttributePrefix ?? DEFAULT_DATA_ATTRIBUTE_PREFIX;\n\n const dataExtractor = new DataExtractor(options);\n\n // combine the selector lists from enabled features to determine which clicked elements should be filtered\n const combinedCssSelectors = [...new Set([...rageCssSelectors, ...deadCssSelectors, ...errorCssSelectors])];\n\n // Create observables on events on the window\n const createObservables = (): AllWindowObservables => {\n const clickObservable = multicast(\n createClickObservable('pointerdown').map((click) => {\n return dataExtractor.addAdditionalEventProperties(\n click,\n 'click',\n combinedCssSelectors,\n dataAttributePrefix,\n true, // capture when cursor is pointer\n );\n }),\n );\n\n const browserErrorObservables = multicast(\n createErrorObservable().map((error) => {\n return dataExtractor.addTypeAndTimestamp(error, 'error');\n }),\n );\n\n const enrichedMutationObservable = multicast<TimestampedEvent<MutationRecord[]>>(\n createMutationObservable().map((mutation) =>\n dataExtractor.addAdditionalEventProperties(mutation, 'mutation', combinedCssSelectors, dataAttributePrefix),\n ),\n );\n\n let enrichedNavigateObservable: Observable<TimestampedEvent<NavigateEvent>> | undefined;\n\n if (window.navigation) {\n const navigateObservable = new Observable<Event>((observer) => {\n const handler = (event: Event): void => {\n observer.next({\n ...event,\n type: 'navigate',\n });\n };\n window.navigation.addEventListener('navigate', handler);\n return () => {\n window.navigation.removeEventListener('navigate', handler);\n };\n });\n enrichedNavigateObservable = multicast<TimestampedEvent<NavigateEvent>>(\n navigateObservable.map<TimestampedEvent<NavigateEvent>>(\n (navigate) =>\n dataExtractor.addAdditionalEventProperties(\n navigate,\n 'navigate',\n combinedCssSelectors,\n dataAttributePrefix,\n ) as TimestampedEvent<NavigateEvent>,\n ),\n );\n }\n\n const selectionObservable = multicast(\n new Observable<void>((observer) => {\n const handler = () => {\n const el: HTMLElement | null = document.activeElement as HTMLElement;\n\n // handle input and textarea\n\n // if the selectionStart and selectionEnd are the same, it means\n // nothing is selected (collapsed) and the cursor position is one point\n if (el && (el.tagName === 'TEXTAREA' || el.tagName === 'INPUT')) {\n let start: number | null | undefined;\n let end: number | null | undefined;\n try {\n start = (el as HTMLInputElement | HTMLTextAreaElement).selectionStart;\n end = (el as HTMLInputElement | HTMLTextAreaElement).selectionEnd;\n if (start === end) return; // collapsed\n } catch (error) {\n // input that doesn't support selectionStart/selectionEnd (like checkbox)\n // do nothing here\n return;\n }\n return observer.next();\n }\n\n // handle non-input elements\n\n // non-input elements have an attribute called \"isCollapsed\" which\n // if true, indicates there \"is currently not any text selected\"\n // (see https://developer.mozilla.org/en-US/docs/Web/API/Selection/isCollapsed)\n const selection = window.getSelection();\n if (!selection || selection.isCollapsed) return;\n return observer.next();\n };\n window.document.addEventListener('selectionchange', handler);\n return () => {\n window.document.removeEventListener('selectionchange', handler);\n };\n }),\n );\n\n const mouseMoveObservable = multicast(createMouseMoveObservable());\n\n return {\n [ObservablesEnum.ClickObservable]: clickObservable as Observable<ElementBasedTimestampedEvent<MouseEvent>>,\n [ObservablesEnum.MutationObservable]: enrichedMutationObservable,\n [ObservablesEnum.NavigateObservable]: enrichedNavigateObservable,\n [ObservablesEnum.BrowserErrorObservable]: browserErrorObservables,\n [ObservablesEnum.SelectionObservable]: selectionObservable,\n [ObservablesEnum.MouseMoveObservable]: mouseMoveObservable,\n };\n };\n\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n /* istanbul ignore if */\n if (typeof document === 'undefined') {\n return;\n }\n\n // Create observables for events on the window\n const allObservables = createObservables();\n\n // Create subscriptions only for enabled features\n if (rageClicksEnabled) {\n const shouldTrackRageClick = createShouldTrackEvent(options, rageCssSelectors);\n const rageClickSubscription = trackRageClicks({\n allObservables,\n amplitude,\n shouldTrackRageClick,\n });\n subscriptions.push(rageClickSubscription);\n }\n\n if (deadClicksEnabled) {\n const shouldTrackDeadClick = createShouldTrackEvent(options, deadCssSelectors);\n const deadClickSubscription = trackDeadClick({\n amplitude,\n allObservables,\n getEventProperties: (actionType, element) =>\n dataExtractor.getEventProperties(actionType, element, dataAttributePrefix),\n shouldTrackDeadClick,\n });\n subscriptions.push(deadClickSubscription);\n }\n\n if (isErrorClicksEnabled) {\n const shouldTrackErrorClick = createShouldTrackEvent(options, errorCssSelectors);\n const errorClickSubscription = trackErrorClicks({\n amplitude,\n allObservables,\n shouldTrackErrorClick,\n });\n subscriptions.push(errorClickSubscription);\n }\n\n if (thrashedCursorEnabled) {\n let directionChanges, thresholdMs;\n if (typeof options.thrashedCursor === 'object') {\n directionChanges = options.thrashedCursor.directionChanges;\n thresholdMs = options.thrashedCursor.threshold;\n\n if (directionChanges && directionChanges < MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES) {\n config.loggerProvider.warn(\n `'thrashedCursor.directionChanges' of ${directionChanges} is below the minimum of ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}, setting to ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}`,\n );\n directionChanges = MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES;\n }\n if (thresholdMs && thresholdMs > MAXIMUM_THRASHED_CURSOR_THRESHOLD) {\n config.loggerProvider.warn(\n `'thrashedCursor.threshold' of ${thresholdMs} is above the maximum of ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}, setting to ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}`,\n );\n thresholdMs = MAXIMUM_THRASHED_CURSOR_THRESHOLD;\n }\n }\n const thrashedCursorSubscription = trackThrashedCursor({\n amplitude,\n options,\n allObservables,\n directionChanges,\n thresholdMs,\n });\n subscriptions.push(thrashedCursorSubscription);\n }\n\n /* istanbul ignore next */\n config?.loggerProvider?.log(`${name} has been successfully added.`);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n for (const subscription of subscriptions) {\n subscription.unsubscribe();\n }\n };\n\n return {\n name,\n type,\n setup,\n execute,\n teardown,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"frustration-plugin.js","sourceRoot":"","sources":["../../src/frustration-plugin.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,OAAO,EAKL,6BAA6B,EAC7B,SAAS,EACT,UAAU,EAEV,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAiE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AE,cAAc,0CAAE,GAAG,CAAC,UAAG,IAAI,kCAA+B,CAAC,CAAC;;;SACrE,CAAC;IAEF,IAAM,OAAO,GAAuC,UAAO,KAAK;;YAC9D,sBAAO,KAAK,EAAC;;SACd,CAAC;IAEF,IAAM,QAAQ,GAAG;;;;;gBACf,KAA2B,kBAAA,SAAA,aAAa,CAAA,mHAAE;oBAA/B,YAAY;oBACrB,YAAY,CAAC,WAAW,EAAE,CAAC;iBAC5B;;;;;;;;;;;SACF,CAAC;IAEF,OAAO;QACL,IAAI,MAAA;QACJ,IAAI,MAAA;QACJ,KAAK,OAAA;QACL,OAAO,SAAA;QACP,QAAQ,UAAA;KACT,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport {\n BrowserClient,\n BrowserConfig,\n EnrichmentPlugin,\n FrustrationInteractionsOptions,\n DEFAULT_DATA_ATTRIBUTE_PREFIX,\n multicast,\n Observable,\n Unsubscribable,\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n} from '@amplitude/analytics-core';\nimport * as constants from './constants';\nimport { createShouldTrackEvent, ElementBasedTimestampedEvent, NavigateEvent, TimestampedEvent } from './helpers';\nimport { trackDeadClick } from './autocapture/track-dead-click';\nimport { trackRageClicks } from './autocapture/track-rage-click';\nimport { ObservablesEnum } from './autocapture-plugin';\nimport {\n BrowserErrorEvent,\n createClickObservable,\n createErrorObservable,\n createMutationObservable,\n createMouseMoveObservable,\n} from './observables';\nimport { DataExtractor } from './data-extractor';\nimport { subscribeToElementSelectorConfig } from './element-selector-config';\nimport { trackErrorClicks } from './autocapture/track-error-click';\nimport { trackThrashedCursor } from './autocapture/track-thrashed-cursor';\n\nexport interface AllWindowObservables {\n [ObservablesEnum.ClickObservable]: Observable<ElementBasedTimestampedEvent<MouseEvent>>;\n [ObservablesEnum.MutationObservable]: Observable<TimestampedEvent<MutationRecord[]>>;\n [ObservablesEnum.BrowserErrorObservable]: Observable<TimestampedEvent<BrowserErrorEvent>>;\n [ObservablesEnum.NavigateObservable]?: Observable<TimestampedEvent<NavigateEvent>>;\n [ObservablesEnum.SelectionObservable]?: Observable<void>;\n [ObservablesEnum.MouseMoveObservable]: Observable<MouseEvent>;\n}\n\ntype BrowserEnrichmentPlugin = EnrichmentPlugin<BrowserClient, BrowserConfig>;\n\n/**\n * Helper function to extract the css selector allowlist\n * from the frustration interactions options for a specific\n * autocapture feature.\n */\nfunction getCssSelectorAllowlist(\n options: FrustrationInteractionsOptions,\n attribute: keyof FrustrationInteractionsOptions,\n defaultAllowlist: string[],\n enabled: boolean,\n): string[] {\n if (!enabled) {\n return [];\n }\n const config = options[attribute];\n if (\n typeof config === 'object' &&\n config !== null &&\n 'cssSelectorAllowlist' in config &&\n Array.isArray(config.cssSelectorAllowlist)\n ) {\n return config.cssSelectorAllowlist;\n }\n return defaultAllowlist;\n}\n\nconst MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES = 5;\nconst MAXIMUM_THRASHED_CURSOR_THRESHOLD = 4000;\n\nexport const frustrationPlugin = (options: FrustrationInteractionsOptions = {}): BrowserEnrichmentPlugin => {\n const name = constants.FRUSTRATION_PLUGIN_NAME;\n const type = 'enrichment';\n\n const subscriptions: Unsubscribable[] = [];\n\n let isErrorClicksEnabled = options.errorClicks !== false;\n\n // if errorClicks is not defined, disable it\n // change this once it moves out of @experimental\n if (!options.errorClicks) {\n isErrorClicksEnabled = false;\n }\n\n // Check if each feature is enabled\n const deadClicksEnabled = options.deadClicks !== false && options.deadClicks !== null;\n const rageClicksEnabled = options.rageClicks !== false && options.rageClicks !== null;\n\n let thrashedCursorEnabled = options.thrashedCursor !== false && options.thrashedCursor !== null;\n if (!options.thrashedCursor) {\n thrashedCursorEnabled = false;\n }\n\n // Get CSS selectors for enabled features\n const rageCssSelectors = getCssSelectorAllowlist(\n options,\n 'rageClicks',\n DEFAULT_RAGE_CLICK_ALLOWLIST,\n rageClicksEnabled,\n );\n\n const deadCssSelectors = getCssSelectorAllowlist(\n options,\n 'deadClicks',\n DEFAULT_DEAD_CLICK_ALLOWLIST,\n deadClicksEnabled,\n );\n\n const errorCssSelectors = getCssSelectorAllowlist(\n options,\n 'errorClicks',\n DEFAULT_ERROR_CLICK_ALLOWLIST,\n isErrorClicksEnabled,\n );\n\n const dataAttributePrefix = options.dataAttributePrefix ?? DEFAULT_DATA_ATTRIBUTE_PREFIX;\n\n const dataExtractor = new DataExtractor(options);\n\n // combine the selector lists from enabled features to determine which clicked elements should be filtered\n const combinedCssSelectors = [...new Set([...rageCssSelectors, ...deadCssSelectors, ...errorCssSelectors])];\n\n // Create observables on events on the window\n const createObservables = (): AllWindowObservables => {\n const clickObservable = multicast(\n createClickObservable('pointerdown').map((click) => {\n return dataExtractor.addAdditionalEventProperties(\n click,\n 'click',\n combinedCssSelectors,\n dataAttributePrefix,\n true, // capture when cursor is pointer\n );\n }),\n );\n\n const browserErrorObservables = multicast(\n createErrorObservable().map((error) => {\n return dataExtractor.addTypeAndTimestamp(error, 'error');\n }),\n );\n\n const enrichedMutationObservable = multicast<TimestampedEvent<MutationRecord[]>>(\n createMutationObservable().map((mutation) =>\n dataExtractor.addAdditionalEventProperties(mutation, 'mutation', combinedCssSelectors, dataAttributePrefix),\n ),\n );\n\n let enrichedNavigateObservable: Observable<TimestampedEvent<NavigateEvent>> | undefined;\n\n if (window.navigation) {\n const navigateObservable = new Observable<Event>((observer) => {\n const handler = (event: Event): void => {\n observer.next({\n ...event,\n type: 'navigate',\n });\n };\n window.navigation.addEventListener('navigate', handler);\n return () => {\n window.navigation.removeEventListener('navigate', handler);\n };\n });\n enrichedNavigateObservable = multicast<TimestampedEvent<NavigateEvent>>(\n navigateObservable.map<TimestampedEvent<NavigateEvent>>(\n (navigate) =>\n dataExtractor.addAdditionalEventProperties(\n navigate,\n 'navigate',\n combinedCssSelectors,\n dataAttributePrefix,\n ) as TimestampedEvent<NavigateEvent>,\n ),\n );\n }\n\n const selectionObservable = multicast(\n new Observable<void>((observer) => {\n const handler = () => {\n const el: HTMLElement | null = document.activeElement as HTMLElement;\n\n // handle input and textarea\n\n // if the selectionStart and selectionEnd are the same, it means\n // nothing is selected (collapsed) and the cursor position is one point\n if (el && (el.tagName === 'TEXTAREA' || el.tagName === 'INPUT')) {\n let start: number | null | undefined;\n let end: number | null | undefined;\n try {\n start = (el as HTMLInputElement | HTMLTextAreaElement).selectionStart;\n end = (el as HTMLInputElement | HTMLTextAreaElement).selectionEnd;\n if (start === end) return; // collapsed\n } catch (error) {\n // input that doesn't support selectionStart/selectionEnd (like checkbox)\n // do nothing here\n return;\n }\n return observer.next();\n }\n\n // handle non-input elements\n\n // non-input elements have an attribute called \"isCollapsed\" which\n // if true, indicates there \"is currently not any text selected\"\n // (see https://developer.mozilla.org/en-US/docs/Web/API/Selection/isCollapsed)\n const selection = window.getSelection();\n if (!selection || selection.isCollapsed) return;\n return observer.next();\n };\n window.document.addEventListener('selectionchange', handler);\n return () => {\n window.document.removeEventListener('selectionchange', handler);\n };\n }),\n );\n\n const mouseMoveObservable = multicast(createMouseMoveObservable());\n\n return {\n [ObservablesEnum.ClickObservable]: clickObservable as Observable<ElementBasedTimestampedEvent<MouseEvent>>,\n [ObservablesEnum.MutationObservable]: enrichedMutationObservable,\n [ObservablesEnum.NavigateObservable]: enrichedNavigateObservable,\n [ObservablesEnum.BrowserErrorObservable]: browserErrorObservables,\n [ObservablesEnum.SelectionObservable]: selectionObservable,\n [ObservablesEnum.MouseMoveObservable]: mouseMoveObservable,\n };\n };\n\n const setup: BrowserEnrichmentPlugin['setup'] = async (config, amplitude) => {\n /* istanbul ignore if */\n if (typeof document === 'undefined') {\n return;\n }\n\n // Create observables for events on the window\n const allObservables = createObservables();\n\n // Keep the data extractor's selector engine in sync with element-selector\n // remote config so frustration events emit the same selectors as the rest\n // of autocapture when an org enables the engine.\n const elementSelectorConfigCleanup = subscribeToElementSelectorConfig(config, dataExtractor);\n if (elementSelectorConfigCleanup) {\n subscriptions.push({ unsubscribe: elementSelectorConfigCleanup });\n }\n\n // Create subscriptions only for enabled features\n if (rageClicksEnabled) {\n const shouldTrackRageClick = createShouldTrackEvent(options, rageCssSelectors);\n const rageClickSubscription = trackRageClicks({\n allObservables,\n amplitude,\n shouldTrackRageClick,\n });\n subscriptions.push(rageClickSubscription);\n }\n\n if (deadClicksEnabled) {\n const shouldTrackDeadClick = createShouldTrackEvent(options, deadCssSelectors);\n const deadClickSubscription = trackDeadClick({\n amplitude,\n allObservables,\n getEventProperties: (actionType, element) =>\n dataExtractor.getEventProperties(actionType, element, dataAttributePrefix),\n shouldTrackDeadClick,\n });\n subscriptions.push(deadClickSubscription);\n }\n\n if (isErrorClicksEnabled) {\n const shouldTrackErrorClick = createShouldTrackEvent(options, errorCssSelectors);\n const errorClickSubscription = trackErrorClicks({\n amplitude,\n allObservables,\n shouldTrackErrorClick,\n });\n subscriptions.push(errorClickSubscription);\n }\n\n if (thrashedCursorEnabled) {\n let directionChanges, thresholdMs;\n if (typeof options.thrashedCursor === 'object') {\n directionChanges = options.thrashedCursor.directionChanges;\n thresholdMs = options.thrashedCursor.threshold;\n\n if (directionChanges && directionChanges < MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES) {\n config.loggerProvider.warn(\n `'thrashedCursor.directionChanges' of ${directionChanges} is below the minimum of ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}, setting to ${MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES}`,\n );\n directionChanges = MINIMUM_THRASHED_CURSOR_DIRECTION_CHANGES;\n }\n if (thresholdMs && thresholdMs > MAXIMUM_THRASHED_CURSOR_THRESHOLD) {\n config.loggerProvider.warn(\n `'thrashedCursor.threshold' of ${thresholdMs} is above the maximum of ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}, setting to ${MAXIMUM_THRASHED_CURSOR_THRESHOLD}`,\n );\n thresholdMs = MAXIMUM_THRASHED_CURSOR_THRESHOLD;\n }\n }\n const thrashedCursorSubscription = trackThrashedCursor({\n amplitude,\n options,\n allObservables,\n directionChanges,\n thresholdMs,\n });\n subscriptions.push(thrashedCursorSubscription);\n }\n\n /* istanbul ignore next */\n config?.loggerProvider?.log(`${name} has been successfully added.`);\n };\n\n const execute: BrowserEnrichmentPlugin['execute'] = async (event) => {\n return event;\n };\n\n const teardown = async () => {\n for (const subscription of subscriptions) {\n subscription.unsubscribe();\n }\n };\n\n return {\n name,\n type,\n setup,\n execute,\n teardown,\n };\n};\n"]}
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Backward-compat re-export.
|
|
3
|
-
*
|
|
4
|
-
* The Chromium-DevTools-derived `cssPath` walker that lived here for years
|
|
5
|
-
* has moved to `@amplitude/element-selector` as `legacyCssPath`. That's now
|
|
6
|
-
* the canonical home — the SDK and the dashboard both import from there,
|
|
7
|
-
* so the two can never drift again.
|
|
8
|
-
*
|
|
9
|
-
* This file stays around as a thin re-export so:
|
|
10
|
-
*
|
|
11
|
-
* - any third-party consumer that historically deep-imported `cssPath` from
|
|
12
|
-
* `@amplitude/plugin-autocapture-browser/src/libs/element-path` continues
|
|
13
|
-
* to work without code changes;
|
|
14
|
-
* - the autocapture plugin's own internals don't have to special-case the
|
|
15
|
-
* rename mid-PR (although `data-extractor` no longer uses it — all
|
|
16
|
-
* routing happens via `generateSelector` from the package).
|
|
17
|
-
*
|
|
18
|
-
* Slated for deletion in a future major once we've audited and confirmed no
|
|
19
|
-
* external imports remain.
|
|
20
|
-
*
|
|
21
|
-
* @deprecated Import `legacyCssPath` from `@amplitude/element-selector` directly.
|
|
22
|
-
*/
|
|
23
|
-
export { legacyCssPath as cssPath } from '@amplitude/element-selector';
|
|
1
|
+
export declare const cssPath: (node: Element, optimized?: boolean) => string;
|
|
24
2
|
//# sourceMappingURL=element-path.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-path.d.ts","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"element-path.d.ts","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":"AAyCA,eAAO,MAAM,OAAO,SAAmB,OAAO,cAAc,OAAO,KAAG,MAuBrE,CAAC"}
|
|
@@ -1,28 +1,173 @@
|
|
|
1
|
-
/* istanbul ignore file
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
import { __values } from "tslib";
|
|
3
|
+
// Code is adapted from The Chromium Authors.
|
|
4
|
+
// Source: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/panels/elements/DOMPath.ts#L14
|
|
5
|
+
// License: BSD-style license
|
|
6
|
+
//
|
|
7
|
+
// Copyright 2014 The Chromium Authors
|
|
8
|
+
//
|
|
9
|
+
// Redistribution and use in source and binary forms, with or without
|
|
10
|
+
// modification, are permitted provided that the following conditions are
|
|
11
|
+
// met:
|
|
12
|
+
//
|
|
13
|
+
// * Redistributions of source code must retain the above copyright
|
|
14
|
+
// notice, this list of conditions and the following disclaimer.
|
|
15
|
+
// * Redistributions in binary form must reproduce the above
|
|
16
|
+
// copyright notice, this list of conditions and the following disclaimer
|
|
17
|
+
// in the documentation and/or other materials provided with the
|
|
18
|
+
// distribution.
|
|
19
|
+
// * Neither the name of Google Inc. nor the names of its
|
|
20
|
+
// contributors may be used to endorse or promote products derived from
|
|
21
|
+
// this software without specific prior written permission.
|
|
22
|
+
//
|
|
23
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
24
|
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
25
|
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
26
|
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
27
|
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
28
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
29
|
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
30
|
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
31
|
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
32
|
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33
|
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34
|
+
var Step = /** @class */ (function () {
|
|
35
|
+
function Step(value, optimized) {
|
|
36
|
+
this.value = value;
|
|
37
|
+
this.optimized = optimized;
|
|
38
|
+
}
|
|
39
|
+
Step.prototype.toString = function () {
|
|
40
|
+
return this.value;
|
|
41
|
+
};
|
|
42
|
+
return Step;
|
|
43
|
+
}());
|
|
44
|
+
export var cssPath = function (node, optimized) {
|
|
45
|
+
// `node` is already an Element; this check is defensive.
|
|
46
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
var steps = [];
|
|
50
|
+
var contextNode = node;
|
|
51
|
+
while (contextNode) {
|
|
52
|
+
var step = cssPathStep(contextNode, Boolean(optimized), contextNode === node);
|
|
53
|
+
if (!step) {
|
|
54
|
+
break;
|
|
55
|
+
} // bail out early
|
|
56
|
+
steps.push(step);
|
|
57
|
+
if (step.optimized) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
contextNode = contextNode.parentElement;
|
|
61
|
+
}
|
|
62
|
+
steps.reverse();
|
|
63
|
+
return steps.join(' > ');
|
|
64
|
+
};
|
|
65
|
+
var cssPathStep = function (node, optimized, isTargetNode) {
|
|
66
|
+
var e_1, _a;
|
|
67
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
var id = node.getAttribute('id');
|
|
71
|
+
if (optimized) {
|
|
72
|
+
if (id) {
|
|
73
|
+
return new Step(idSelector(id), true);
|
|
74
|
+
}
|
|
75
|
+
var nodeNameLower = node.tagName.toLowerCase();
|
|
76
|
+
if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower === 'html') {
|
|
77
|
+
return new Step(nodeNameLower, true);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
var nodeName = node.tagName.toLowerCase();
|
|
81
|
+
if (id) {
|
|
82
|
+
return new Step(nodeName + idSelector(id), true);
|
|
83
|
+
}
|
|
84
|
+
var parent = node.parentNode;
|
|
85
|
+
if (!parent || parent.nodeType === Node.DOCUMENT_NODE) {
|
|
86
|
+
return new Step(nodeName, true);
|
|
87
|
+
}
|
|
88
|
+
function prefixedElementClassNames(el) {
|
|
89
|
+
var classAttribute = el.getAttribute('class');
|
|
90
|
+
if (!classAttribute) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
return classAttribute
|
|
94
|
+
.split(/\s+/g)
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.map(function (name) {
|
|
97
|
+
// The prefix is required to store "__proto__" in a object-based map.
|
|
98
|
+
return '$' + name;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function idSelector(id) {
|
|
102
|
+
return '#' + CSS.escape(id);
|
|
103
|
+
}
|
|
104
|
+
var prefixedOwnClassNamesArray = prefixedElementClassNames(node);
|
|
105
|
+
var needsClassNames = false;
|
|
106
|
+
var needsNthChild = false;
|
|
107
|
+
var ownIndex = -1;
|
|
108
|
+
var elementIndex = -1;
|
|
109
|
+
var siblings = parent.children;
|
|
110
|
+
for (var i = 0; siblings && (ownIndex === -1 || !needsNthChild) && i < siblings.length; ++i) {
|
|
111
|
+
var sibling = siblings[i];
|
|
112
|
+
if (sibling.nodeType !== Node.ELEMENT_NODE) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
elementIndex += 1;
|
|
116
|
+
if (sibling === node) {
|
|
117
|
+
ownIndex = elementIndex;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (needsNthChild) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (sibling.tagName.toLowerCase() !== nodeName) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
needsClassNames = true;
|
|
127
|
+
var ownClassNames = new Set(prefixedOwnClassNamesArray);
|
|
128
|
+
if (!ownClassNames.size) {
|
|
129
|
+
needsNthChild = true;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
var siblingClassNamesArray = prefixedElementClassNames(sibling);
|
|
133
|
+
for (var j = 0; j < siblingClassNamesArray.length; ++j) {
|
|
134
|
+
var siblingClass = siblingClassNamesArray[j];
|
|
135
|
+
if (!ownClassNames.has(siblingClass)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
ownClassNames.delete(siblingClass);
|
|
139
|
+
if (!ownClassNames.size) {
|
|
140
|
+
needsNthChild = true;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
var result = nodeName;
|
|
146
|
+
if (isTargetNode &&
|
|
147
|
+
nodeName.toLowerCase() === 'input' &&
|
|
148
|
+
node.getAttribute('type') &&
|
|
149
|
+
!node.getAttribute('id') &&
|
|
150
|
+
!node.getAttribute('class')) {
|
|
151
|
+
result += '[type=' + CSS.escape(node.getAttribute('type') || '') + ']';
|
|
152
|
+
}
|
|
153
|
+
if (needsNthChild) {
|
|
154
|
+
result += ':nth-child(' + String(ownIndex + 1) + ')';
|
|
155
|
+
}
|
|
156
|
+
else if (needsClassNames) {
|
|
157
|
+
try {
|
|
158
|
+
for (var prefixedOwnClassNamesArray_1 = __values(prefixedOwnClassNamesArray), prefixedOwnClassNamesArray_1_1 = prefixedOwnClassNamesArray_1.next(); !prefixedOwnClassNamesArray_1_1.done; prefixedOwnClassNamesArray_1_1 = prefixedOwnClassNamesArray_1.next()) {
|
|
159
|
+
var prefixedName = prefixedOwnClassNamesArray_1_1.value;
|
|
160
|
+
result += '.' + CSS.escape(prefixedName.slice(1));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
164
|
+
finally {
|
|
165
|
+
try {
|
|
166
|
+
if (prefixedOwnClassNamesArray_1_1 && !prefixedOwnClassNamesArray_1_1.done && (_a = prefixedOwnClassNamesArray_1.return)) _a.call(prefixedOwnClassNamesArray_1);
|
|
167
|
+
}
|
|
168
|
+
finally { if (e_1) throw e_1.error; }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return new Step(result, false);
|
|
172
|
+
};
|
|
28
173
|
//# sourceMappingURL=element-path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-path.js","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":"AAAA;;;kDAGkD;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,MAAM,6BAA6B,CAAC","sourcesContent":["/* istanbul ignore file -- This file is a deprecated thin re-export with no\n runtime behavior of its own. The `legacyCssPath` algorithm is covered\n exhaustively by `@amplitude/element-selector`'s own suite; re-running\n coverage against the re-export adds nothing. */\n\n/**\n * Backward-compat re-export.\n *\n * The Chromium-DevTools-derived `cssPath` walker that lived here for years\n * has moved to `@amplitude/element-selector` as `legacyCssPath`. That's now\n * the canonical home — the SDK and the dashboard both import from there,\n * so the two can never drift again.\n *\n * This file stays around as a thin re-export so:\n *\n * - any third-party consumer that historically deep-imported `cssPath` from\n * `@amplitude/plugin-autocapture-browser/src/libs/element-path` continues\n * to work without code changes;\n * - the autocapture plugin's own internals don't have to special-case the\n * rename mid-PR (although `data-extractor` no longer uses it — all\n * routing happens via `generateSelector` from the package).\n *\n * Slated for deletion in a future major once we've audited and confirmed no\n * external imports remain.\n *\n * @deprecated Import `legacyCssPath` from `@amplitude/element-selector` directly.\n */\n\nexport { legacyCssPath as cssPath } from '@amplitude/element-selector';\n"]}
|
|
1
|
+
{"version":3,"file":"element-path.js","sourceRoot":"","sources":["../../../src/libs/element-path.ts"],"names":[],"mappings":"AAAA,0BAA0B;;AAE1B,6CAA6C;AAC7C,iHAAiH;AACjH,6BAA6B;AAC7B,EAAE;AACF,sCAAsC;AACtC,EAAE;AACF,qEAAqE;AACrE,yEAAyE;AACzE,OAAO;AACP,EAAE;AACF,sEAAsE;AACtE,gEAAgE;AAChE,+DAA+D;AAC/D,yEAAyE;AACzE,gEAAgE;AAChE,gBAAgB;AAChB,4DAA4D;AAC5D,uEAAuE;AACvE,2DAA2D;AAC3D,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,wEAAwE;AACxE,uEAAuE;AACvE,wEAAwE;AACxE,mEAAmE;AACnE,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,wEAAwE;AACxE,uEAAuE;AAEvE;IACE,cAAmB,KAAa,EAAS,SAAkB;QAAxC,UAAK,GAAL,KAAK,CAAQ;QAAS,cAAS,GAAT,SAAS,CAAS;IAAG,CAAC;IAC/D,uBAAQ,GAAR;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IACH,WAAC;AAAD,CAAC,AALD,IAKC;AA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AAY,CAAC,IAAI,CAAC;QACxB,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAC3B;QACA,MAAM,IAAI,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC;KACxE;IACD,IAAI,aAAa,EAAE;QACjB,MAAM,IAAI,aAAa,GAAG,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;KACtD;SAAM,IAAI,eAAe,EAAE;;YAC1B,KAA2B,IAAA,+BAAA,SAAA,0BAA0B,CAAA,sEAAA,8GAAE;gBAAlD,IAAM,YAAY,uCAAA;gBACrB,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aACnD;;;;;;;;;KACF;IAED,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC","sourcesContent":["/* istanbul ignore file */\n\n// Code is adapted from The Chromium Authors.\n// Source: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/panels/elements/DOMPath.ts#L14\n// License: BSD-style license\n//\n// Copyright 2014 The Chromium Authors\n//\n// Redistribution and use in source and binary forms, with or without\n// modification, are permitted provided that the following conditions are\n// met:\n//\n// * Redistributions of source code must retain the above copyright\n// notice, this list of conditions and the following disclaimer.\n// * Redistributions in binary form must reproduce the above\n// copyright notice, this list of conditions and the following disclaimer\n// in the documentation and/or other materials provided with the\n// distribution.\n// * Neither the name of Google Inc. nor the names of its\n// contributors may be used to endorse or promote products derived from\n// this software without specific prior written permission.\n//\n// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nclass Step {\n constructor(public value: string, public optimized: boolean) {}\n toString() {\n return this.value;\n }\n}\n\nexport const cssPath = function (node: Element, optimized?: boolean): string {\n // `node` is already an Element; this check is defensive.\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return '';\n }\n\n const steps: Step[] = [];\n let contextNode: Element | null = node;\n\n while (contextNode) {\n const step = cssPathStep(contextNode, Boolean(optimized), contextNode === node);\n if (!step) {\n break;\n } // bail out early\n steps.push(step);\n if (step.optimized) {\n break;\n }\n contextNode = contextNode.parentElement;\n }\n\n steps.reverse();\n return steps.join(' > ');\n};\n\nconst cssPathStep = function (node: Element, optimized: boolean, isTargetNode: boolean): Step | null {\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return null;\n }\n\n const id = node.getAttribute('id');\n if (optimized) {\n if (id) {\n return new Step(idSelector(id), true);\n }\n\n const nodeNameLower = node.tagName.toLowerCase();\n if (nodeNameLower === 'body' || nodeNameLower === 'head' || nodeNameLower === 'html') {\n return new Step(nodeNameLower, true);\n }\n }\n\n const nodeName = node.tagName.toLowerCase();\n\n if (id) {\n return new Step(nodeName + idSelector(id), true);\n }\n\n const parent = node.parentNode;\n if (!parent || parent.nodeType === Node.DOCUMENT_NODE) {\n return new Step(nodeName, true);\n }\n\n function prefixedElementClassNames(el: Element): string[] {\n const classAttribute = el.getAttribute('class');\n if (!classAttribute) {\n return [];\n }\n return classAttribute\n .split(/\\s+/g)\n .filter(Boolean)\n .map(function (name) {\n // The prefix is required to store \"__proto__\" in a object-based map.\n return '$' + name;\n });\n }\n\n function idSelector(id: string): string {\n return '#' + CSS.escape(id);\n }\n\n const prefixedOwnClassNamesArray = prefixedElementClassNames(node);\n let needsClassNames = false;\n let needsNthChild = false;\n let ownIndex = -1;\n let elementIndex = -1;\n\n const siblings: HTMLCollectionOf<Element> = parent.children;\n\n for (let i = 0; siblings && (ownIndex === -1 || !needsNthChild) && i < siblings.length; ++i) {\n const sibling = siblings[i];\n if (sibling.nodeType !== Node.ELEMENT_NODE) {\n continue;\n }\n\n elementIndex += 1;\n if (sibling === node) {\n ownIndex = elementIndex;\n continue;\n }\n if (needsNthChild) {\n continue;\n }\n\n if (sibling.tagName.toLowerCase() !== nodeName) {\n continue;\n }\n\n needsClassNames = true;\n const ownClassNames = new Set<string>(prefixedOwnClassNamesArray);\n if (!ownClassNames.size) {\n needsNthChild = true;\n continue;\n }\n\n const siblingClassNamesArray = prefixedElementClassNames(sibling);\n for (let j = 0; j < siblingClassNamesArray.length; ++j) {\n const siblingClass = siblingClassNamesArray[j];\n if (!ownClassNames.has(siblingClass)) {\n continue;\n }\n ownClassNames.delete(siblingClass);\n if (!ownClassNames.size) {\n needsNthChild = true;\n break;\n }\n }\n }\n\n let result = nodeName;\n if (\n isTargetNode &&\n nodeName.toLowerCase() === 'input' &&\n node.getAttribute('type') &&\n !node.getAttribute('id') &&\n !node.getAttribute('class')\n ) {\n result += '[type=' + CSS.escape(node.getAttribute('type') || '') + ']';\n }\n if (needsNthChild) {\n result += ':nth-child(' + String(ownIndex + 1) + ')';\n } else if (needsClassNames) {\n for (const prefixedName of prefixedOwnClassNamesArray) {\n result += '.' + CSS.escape(prefixedName.slice(1));\n }\n }\n\n return new Step(result, false);\n};\n"]}
|
package/lib/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.28.0
|
|
1
|
+
export declare const VERSION = "1.28.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/lib/esm/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/lib/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var VERSION = '1.28.0
|
|
1
|
+
export var VERSION = '1.28.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/lib/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.28.0';\n"]}
|