@posthog/browser-common 0.0.0 → 0.2.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.
Files changed (97) hide show
  1. package/README.md +114 -28
  2. package/dist/client.d.ts +136 -0
  3. package/dist/client.js +18 -0
  4. package/dist/client.mjs +0 -0
  5. package/dist/config.d.ts +9 -0
  6. package/dist/config.js +43 -0
  7. package/dist/config.mjs +9 -0
  8. package/dist/constants.d.ts +3 -0
  9. package/dist/constants.js +44 -0
  10. package/dist/constants.mjs +4 -0
  11. package/dist/disposable.d.ts +13 -0
  12. package/dist/disposable.js +18 -0
  13. package/dist/disposable.mjs +0 -0
  14. package/dist/extension.d.ts +45 -0
  15. package/dist/extension.js +18 -0
  16. package/dist/extension.mjs +0 -0
  17. package/dist/index.d.ts +11 -0
  18. package/dist/index.js +36 -0
  19. package/dist/index.mjs +2 -0
  20. package/dist/persistence.d.ts +24 -0
  21. package/dist/persistence.js +18 -0
  22. package/dist/persistence.mjs +0 -0
  23. package/dist/pubsub.d.ts +28 -0
  24. package/dist/pubsub.js +67 -0
  25. package/dist/pubsub.mjs +33 -0
  26. package/dist/token.d.ts +21 -0
  27. package/dist/token.js +18 -0
  28. package/dist/token.mjs +0 -0
  29. package/dist/utils/array-at-polyfill.d.ts +1 -0
  30. package/dist/utils/array-at-polyfill.js +16 -0
  31. package/dist/utils/array-at-polyfill.mjs +11 -0
  32. package/dist/utils/autocapture-utils.d.ts +23 -0
  33. package/dist/utils/autocapture-utils.js +479 -0
  34. package/dist/utils/autocapture-utils.mjs +385 -0
  35. package/dist/utils/blocked-uas.d.ts +17 -0
  36. package/dist/utils/blocked-uas.js +54 -0
  37. package/dist/utils/blocked-uas.mjs +14 -0
  38. package/dist/utils/cookie-utils.d.ts +1 -0
  39. package/dist/utils/cookie-utils.js +49 -0
  40. package/dist/utils/cookie-utils.mjs +15 -0
  41. package/dist/utils/device-model-utils.d.ts +8 -0
  42. package/dist/utils/device-model-utils.js +52 -0
  43. package/dist/utils/device-model-utils.mjs +18 -0
  44. package/dist/utils/element-utils.d.ts +5 -0
  45. package/dist/utils/element-utils.js +67 -0
  46. package/dist/utils/element-utils.mjs +21 -0
  47. package/dist/utils/elements-chain-utils.d.ts +4 -0
  48. package/dist/utils/elements-chain-utils.js +79 -0
  49. package/dist/utils/elements-chain-utils.mjs +36 -0
  50. package/dist/utils/encode-utils.d.ts +8 -0
  51. package/dist/utils/encode-utils.js +39 -0
  52. package/dist/utils/encode-utils.mjs +5 -0
  53. package/dist/utils/event-utils.d.ts +24 -0
  54. package/dist/utils/event-utils.js +344 -0
  55. package/dist/utils/event-utils.mjs +246 -0
  56. package/dist/utils/general-utils.d.ts +30 -0
  57. package/dist/utils/general-utils.js +191 -0
  58. package/dist/utils/general-utils.mjs +118 -0
  59. package/dist/utils/globals.d.ts +25 -0
  60. package/dist/utils/globals.js +75 -0
  61. package/dist/utils/globals.mjs +14 -0
  62. package/dist/utils/logger.d.ts +16 -0
  63. package/dist/utils/logger.js +83 -0
  64. package/dist/utils/logger.mjs +36 -0
  65. package/dist/utils/matcher-utils.d.ts +3 -0
  66. package/dist/utils/matcher-utils.js +63 -0
  67. package/dist/utils/matcher-utils.mjs +26 -0
  68. package/dist/utils/property-utils.d.ts +23 -0
  69. package/dist/utils/property-utils.js +108 -0
  70. package/dist/utils/property-utils.mjs +65 -0
  71. package/dist/utils/prototype-utils.d.ts +7 -0
  72. package/dist/utils/prototype-utils.js +64 -0
  73. package/dist/utils/prototype-utils.mjs +27 -0
  74. package/dist/utils/regex-utils.d.ts +2 -0
  75. package/dist/utils/regex-utils.js +54 -0
  76. package/dist/utils/regex-utils.mjs +17 -0
  77. package/dist/utils/request-utils.d.ts +15 -0
  78. package/dist/utils/request-utils.js +153 -0
  79. package/dist/utils/request-utils.mjs +95 -0
  80. package/dist/utils/simple-event-emitter.d.ts +5 -0
  81. package/dist/utils/simple-event-emitter.js +51 -0
  82. package/dist/utils/simple-event-emitter.mjs +17 -0
  83. package/dist/utils/stylesheet-loader.d.ts +7 -0
  84. package/dist/utils/stylesheet-loader.js +53 -0
  85. package/dist/utils/stylesheet-loader.mjs +19 -0
  86. package/dist/utils/type-utils.d.ts +2 -0
  87. package/dist/utils/type-utils.js +41 -0
  88. package/dist/utils/type-utils.mjs +4 -0
  89. package/dist/utils/url-targeting-utils.d.ts +28 -0
  90. package/dist/utils/url-targeting-utils.js +56 -0
  91. package/dist/utils/url-targeting-utils.mjs +19 -0
  92. package/dist/utils/uuidv7.d.ts +43 -0
  93. package/dist/utils/uuidv7.js +172 -0
  94. package/dist/utils/uuidv7.js.LICENSE.txt +9 -0
  95. package/dist/utils/uuidv7.mjs +132 -0
  96. package/dist/utils/uuidv7.mjs.LICENSE.txt +9 -0
  97. package/package.json +79 -8
@@ -0,0 +1,28 @@
1
+ import type { Disposable } from './disposable';
2
+ /**
3
+ * Call it with a handler to start listening; dispose the returned
4
+ * {@link Disposable} to stop. There is one `Listener` per event type, so every
5
+ * event carries its own payload type. The handler is called synchronously for
6
+ * each future payload, and the returned disposable unregisters it.
7
+ */
8
+ export type Listener<T> = (handler: (payload: T) => void) => Disposable;
9
+ /**
10
+ * Publish/subscribe helper for client events exposed to extensions. A client
11
+ * owns the publisher, calls {@link Publisher.publish} to fire payloads, and
12
+ * exposes only {@link Publisher.listener} to extensions so they can subscribe
13
+ * without gaining publish access. Calling {@link Publisher.dispose} drops all
14
+ * listeners.
15
+ */
16
+ export declare class Publisher<T> implements Disposable {
17
+ /** Subscriptions currently registered with this publisher. */
18
+ private _subscriptions;
19
+ /**
20
+ * Register a handler for future payloads. The returned disposable
21
+ * subscription unregisters this handler.
22
+ */
23
+ readonly listener: Listener<T>;
24
+ /** Notify every currently registered listener with the provided payload. */
25
+ publish(payload: T): void;
26
+ /** Drop all registered listeners. Safe to call more than once. */
27
+ dispose(): void;
28
+ }
package/dist/pubsub.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ Publisher: ()=>Publisher
28
+ });
29
+ class Publisher {
30
+ publish(payload) {
31
+ const subscriptions = this._subscriptions.slice();
32
+ subscriptions.forEach((subscription)=>{
33
+ if (subscription.isActive) subscription.handler(payload);
34
+ });
35
+ }
36
+ dispose() {
37
+ this._subscriptions.forEach((subscription)=>{
38
+ subscription.isActive = false;
39
+ });
40
+ this._subscriptions = [];
41
+ }
42
+ constructor(){
43
+ this._subscriptions = [];
44
+ this.listener = (handler)=>{
45
+ const subscription = {
46
+ handler,
47
+ isActive: true
48
+ };
49
+ this._subscriptions.push(subscription);
50
+ return {
51
+ dispose: ()=>{
52
+ if (!subscription.isActive) return;
53
+ subscription.isActive = false;
54
+ const index = this._subscriptions.indexOf(subscription);
55
+ if (-1 !== index) this._subscriptions.splice(index, 1);
56
+ }
57
+ };
58
+ };
59
+ }
60
+ }
61
+ exports.Publisher = __webpack_exports__.Publisher;
62
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
63
+ "Publisher"
64
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
65
+ Object.defineProperty(exports, '__esModule', {
66
+ value: true
67
+ });
@@ -0,0 +1,33 @@
1
+ class Publisher {
2
+ publish(payload) {
3
+ const subscriptions = this._subscriptions.slice();
4
+ subscriptions.forEach((subscription)=>{
5
+ if (subscription.isActive) subscription.handler(payload);
6
+ });
7
+ }
8
+ dispose() {
9
+ this._subscriptions.forEach((subscription)=>{
10
+ subscription.isActive = false;
11
+ });
12
+ this._subscriptions = [];
13
+ }
14
+ constructor(){
15
+ this._subscriptions = [];
16
+ this.listener = (handler)=>{
17
+ const subscription = {
18
+ handler,
19
+ isActive: true
20
+ };
21
+ this._subscriptions.push(subscription);
22
+ return {
23
+ dispose: ()=>{
24
+ if (!subscription.isActive) return;
25
+ subscription.isActive = false;
26
+ const index = this._subscriptions.indexOf(subscription);
27
+ if (-1 !== index) this._subscriptions.splice(index, 1);
28
+ }
29
+ };
30
+ };
31
+ }
32
+ }
33
+ export { Publisher };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A typed, implementation-free key for resolving an extension that provides a
3
+ * capability. Declared as a shared `const` next to the providing extension's
4
+ * interface:
5
+ *
6
+ * ```ts
7
+ * export interface FeatureFlagsExtension extends Extension { … }
8
+ * export const FeatureFlags: ExtensionToken<FeatureFlagsExtension> = { name: 'featureFlags' }
9
+ * ```
10
+ *
11
+ * A token holds no implementation, so importing one never pulls the provider's
12
+ * code into the consumer's bundle. The registry is keyed by token identity
13
+ * (the shared object reference), so provider and consumer must import the same
14
+ * exported token; `name` is for diagnostics only.
15
+ */
16
+ export interface ExtensionToken<T> {
17
+ /** Human-readable capability name used only for diagnostics. */
18
+ readonly name: string;
19
+ /** Phantom: carries the provided type for inference; never present at runtime. */
20
+ readonly __provides?: T;
21
+ }
package/dist/token.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
package/dist/token.mjs ADDED
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ var __webpack_exports__ = {};
2
+ if ('function' != typeof Array.prototype.at) Object.defineProperty(Array.prototype, 'at', {
3
+ value: function(index) {
4
+ const len = this.length;
5
+ let relativeIndex = Math.trunc(index) || 0;
6
+ if (relativeIndex < 0) relativeIndex += len;
7
+ return relativeIndex < 0 || relativeIndex >= len ? void 0 : this[relativeIndex];
8
+ },
9
+ writable: true,
10
+ enumerable: false,
11
+ configurable: true
12
+ });
13
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
14
+ Object.defineProperty(exports, '__esModule', {
15
+ value: true
16
+ });
@@ -0,0 +1,11 @@
1
+ if ('function' != typeof Array.prototype.at) Object.defineProperty(Array.prototype, 'at', {
2
+ value: function(index) {
3
+ const len = this.length;
4
+ let relativeIndex = Math.trunc(index) || 0;
5
+ if (relativeIndex < 0) relativeIndex += len;
6
+ return relativeIndex < 0 || relativeIndex >= len ? void 0 : this[relativeIndex];
7
+ },
8
+ writable: true,
9
+ enumerable: false,
10
+ configurable: true
11
+ });
@@ -0,0 +1,23 @@
1
+ import type { AutocaptureConfig, PostHogConfig, Properties } from '@posthog/types';
2
+ import { type UrlTargetingInstance } from './url-targeting-utils';
3
+ export declare const MAX_DOM_ANCESTOR_DEPTH = 1000;
4
+ export declare function splitClassString(s: string): string[];
5
+ export declare function getClassNames(el: Element): string[];
6
+ export declare function makeSafeText(s: string | null | undefined): string | null;
7
+ export declare function getSafeText(el: Element): string;
8
+ export declare function getEventTarget(e: Event): Element | null;
9
+ export declare const autocaptureCompatibleElements: string[];
10
+ export declare function getParentElement(curEl: Element): Element | false;
11
+ export declare const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS: string[];
12
+ export declare function shouldCaptureDeadClick(el: Element | null, _config: PostHogConfig['capture_dead_clicks']): boolean;
13
+ export declare function isTextSelectionTarget(el: Element | null): boolean;
14
+ export declare function shouldCaptureRageclick(el: Element | null, _config: PostHogConfig['rageclick']): boolean;
15
+ export declare function shouldSkipDeadClick(el: Element | null): boolean;
16
+ export declare function shouldCaptureDomEvent(el: Element, event: Event, autocaptureConfig?: AutocaptureConfig | undefined, captureOnAnyElement?: boolean, allowedEventTypes?: string[], instance?: UrlTargetingInstance): boolean;
17
+ export declare function shouldCaptureElement(el: Element): boolean;
18
+ export declare function isSensitiveElement(el: Element): boolean;
19
+ export declare function shouldCaptureValue(value: string, anchorRegexes?: boolean): boolean;
20
+ export declare function isAngularStyleAttr(attributeName: string): boolean;
21
+ export declare function getDirectAndNestedSpanText(target: Element): string;
22
+ export declare function getNestedSpanText(target: Element): string;
23
+ export declare function getElementsChainString(elements: Properties[]): string;