@alibarbar/common 1.0.9 → 1.1.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 (185) hide show
  1. package/dist/{chunk-O3O67R4I.js → algorithm.cjs} +1 -3
  2. package/dist/algorithm.js +130 -44
  3. package/dist/{chunk-LOAZSPGQ.js → array.cjs} +1 -3
  4. package/dist/array.js +135 -84
  5. package/dist/{chunk-Y364QIQH.js → color.cjs} +1 -3
  6. package/dist/color.js +127 -40
  7. package/dist/{chunk-DYBSRI7V.js → crypto.cjs} +109 -3
  8. package/dist/crypto.d.mts +48 -1
  9. package/dist/crypto.d.ts +48 -1
  10. package/dist/crypto.js +274 -60
  11. package/dist/{chunk-BHCRFURU.js → data-structure.cjs} +1 -3
  12. package/dist/data-structure.js +481 -32
  13. package/dist/{chunk-I3L42475.js → date.cjs} +1 -3
  14. package/dist/date.js +125 -72
  15. package/dist/{chunk-JK2SE3I2.js → dom.cjs} +1 -3
  16. package/dist/dom.js +84 -56
  17. package/dist/{chunk-7V5UQXIO.js → file.cjs} +1 -3
  18. package/dist/file.js +79 -32
  19. package/dist/{chunk-OX5PLOWB.js → i18n.cjs} +1 -3
  20. package/dist/i18n.js +78 -40
  21. package/dist/index.cjs +4543 -0
  22. package/dist/index.d.mts +6 -162
  23. package/dist/index.d.ts +6 -162
  24. package/dist/index.js +3712 -17374
  25. package/dist/{chunk-4RGXV4SJ.js → network.cjs} +1 -3
  26. package/dist/network.js +97 -28
  27. package/dist/{chunk-3FRYJPHG.js → number.cjs} +1 -3
  28. package/dist/number.js +77 -56
  29. package/dist/{chunk-27UDDVLZ.js → object.cjs} +1 -3
  30. package/dist/object.js +237 -80
  31. package/dist/{chunk-JQZBPAPO.js → performance.cjs} +1 -3
  32. package/dist/performance.js +145 -40
  33. package/dist/services.cjs +291 -0
  34. package/dist/services.d.mts +161 -0
  35. package/dist/services.d.ts +161 -0
  36. package/dist/services.js +281 -0
  37. package/dist/storage.cjs +943 -0
  38. package/dist/storage.d.mts +46 -1
  39. package/dist/storage.d.ts +46 -1
  40. package/dist/storage.js +930 -32
  41. package/dist/{chunk-D7CS5EKF.js → string.cjs} +1 -3
  42. package/dist/string.js +91 -68
  43. package/dist/{chunk-56W6YECK.js → tracking.cjs} +1 -3
  44. package/dist/tracking.js +359 -52
  45. package/dist/{chunk-ZDMFMUDR.js → transform.cjs} +1 -3
  46. package/dist/transform.js +299 -32
  47. package/dist/{chunk-NJARVI6X.mjs → upload.cjs} +42 -15
  48. package/dist/upload.d.mts +1 -1
  49. package/dist/upload.d.ts +1 -1
  50. package/dist/upload.js +402 -20
  51. package/dist/{chunk-KGFTD255.js → url.cjs} +1 -3
  52. package/dist/url.js +91 -44
  53. package/dist/{chunk-TQN37HIN.js → validation.cjs} +1 -3
  54. package/dist/validation.js +77 -60
  55. package/package.json +7 -2
  56. package/dist/algorithm.js.map +0 -1
  57. package/dist/algorithm.mjs +0 -4
  58. package/dist/algorithm.mjs.map +0 -1
  59. package/dist/array.js.map +0 -1
  60. package/dist/array.mjs +0 -4
  61. package/dist/array.mjs.map +0 -1
  62. package/dist/chunk-27UDDVLZ.js.map +0 -1
  63. package/dist/chunk-2R2QWFJC.mjs +0 -138
  64. package/dist/chunk-2R2QWFJC.mjs.map +0 -1
  65. package/dist/chunk-3FRYJPHG.js.map +0 -1
  66. package/dist/chunk-4RGXV4SJ.js.map +0 -1
  67. package/dist/chunk-56W6YECK.js.map +0 -1
  68. package/dist/chunk-5BGSUGTI.mjs +0 -128
  69. package/dist/chunk-5BGSUGTI.mjs.map +0 -1
  70. package/dist/chunk-7E6GELHJ.mjs +0 -302
  71. package/dist/chunk-7E6GELHJ.mjs.map +0 -1
  72. package/dist/chunk-7V5UQXIO.js.map +0 -1
  73. package/dist/chunk-A4SWQXX7.mjs +0 -484
  74. package/dist/chunk-A4SWQXX7.mjs.map +0 -1
  75. package/dist/chunk-BHCRFURU.js.map +0 -1
  76. package/dist/chunk-CDSGEAOK.mjs +0 -80
  77. package/dist/chunk-CDSGEAOK.mjs.map +0 -1
  78. package/dist/chunk-D7CS5EKF.js.map +0 -1
  79. package/dist/chunk-DYBSRI7V.js.map +0 -1
  80. package/dist/chunk-FEBKPX5A.js +0 -386
  81. package/dist/chunk-FEBKPX5A.js.map +0 -1
  82. package/dist/chunk-FJ6ZGZIA.mjs +0 -39
  83. package/dist/chunk-FJ6ZGZIA.mjs.map +0 -1
  84. package/dist/chunk-HLDFI7R2.mjs +0 -175
  85. package/dist/chunk-HLDFI7R2.mjs.map +0 -1
  86. package/dist/chunk-I3L42475.js.map +0 -1
  87. package/dist/chunk-JBLX27WD.mjs +0 -240
  88. package/dist/chunk-JBLX27WD.mjs.map +0 -1
  89. package/dist/chunk-JHZ7M2MR.mjs +0 -133
  90. package/dist/chunk-JHZ7M2MR.mjs.map +0 -1
  91. package/dist/chunk-JK2SE3I2.js.map +0 -1
  92. package/dist/chunk-JQZBPAPO.js.map +0 -1
  93. package/dist/chunk-JXYGC2C5.mjs +0 -100
  94. package/dist/chunk-JXYGC2C5.mjs.map +0 -1
  95. package/dist/chunk-KGFTD255.js.map +0 -1
  96. package/dist/chunk-LBHBNPNJ.mjs +0 -148
  97. package/dist/chunk-LBHBNPNJ.mjs.map +0 -1
  98. package/dist/chunk-LF4CILQS.mjs +0 -87
  99. package/dist/chunk-LF4CILQS.mjs.map +0 -1
  100. package/dist/chunk-LOAZSPGQ.js.map +0 -1
  101. package/dist/chunk-NJARVI6X.mjs.map +0 -1
  102. package/dist/chunk-NSSDYX2U.mjs +0 -80
  103. package/dist/chunk-NSSDYX2U.mjs.map +0 -1
  104. package/dist/chunk-O3O67R4I.js.map +0 -1
  105. package/dist/chunk-OIXQ3E6W.mjs +0 -354
  106. package/dist/chunk-OIXQ3E6W.mjs.map +0 -1
  107. package/dist/chunk-OX5PLOWB.js.map +0 -1
  108. package/dist/chunk-PJ7UCTX4.mjs +0 -362
  109. package/dist/chunk-PJ7UCTX4.mjs.map +0 -1
  110. package/dist/chunk-PR4QN5HX.js +0 -44
  111. package/dist/chunk-PR4QN5HX.js.map +0 -1
  112. package/dist/chunk-QIBE7GVN.mjs +0 -81
  113. package/dist/chunk-QIBE7GVN.mjs.map +0 -1
  114. package/dist/chunk-QIOC54LQ.mjs +0 -130
  115. package/dist/chunk-QIOC54LQ.mjs.map +0 -1
  116. package/dist/chunk-TQN37HIN.js.map +0 -1
  117. package/dist/chunk-WZDOPUJW.js +0 -361
  118. package/dist/chunk-WZDOPUJW.js.map +0 -1
  119. package/dist/chunk-XJTZDXSR.mjs +0 -94
  120. package/dist/chunk-XJTZDXSR.mjs.map +0 -1
  121. package/dist/chunk-Y364QIQH.js.map +0 -1
  122. package/dist/chunk-YXM6Q4JS.mjs +0 -94
  123. package/dist/chunk-YXM6Q4JS.mjs.map +0 -1
  124. package/dist/chunk-ZDMFMUDR.js.map +0 -1
  125. package/dist/chunk-ZVJ6NQUM.mjs +0 -82
  126. package/dist/chunk-ZVJ6NQUM.mjs.map +0 -1
  127. package/dist/color.js.map +0 -1
  128. package/dist/color.mjs +0 -4
  129. package/dist/color.mjs.map +0 -1
  130. package/dist/crypto.js.map +0 -1
  131. package/dist/crypto.mjs +0 -4
  132. package/dist/crypto.mjs.map +0 -1
  133. package/dist/data-structure.js.map +0 -1
  134. package/dist/data-structure.mjs +0 -4
  135. package/dist/data-structure.mjs.map +0 -1
  136. package/dist/date.js.map +0 -1
  137. package/dist/date.mjs +0 -4
  138. package/dist/date.mjs.map +0 -1
  139. package/dist/dom.js.map +0 -1
  140. package/dist/dom.mjs +0 -4
  141. package/dist/dom.mjs.map +0 -1
  142. package/dist/file.js.map +0 -1
  143. package/dist/file.mjs +0 -4
  144. package/dist/file.mjs.map +0 -1
  145. package/dist/i18n.js.map +0 -1
  146. package/dist/i18n.mjs +0 -4
  147. package/dist/i18n.mjs.map +0 -1
  148. package/dist/index.js.map +0 -1
  149. package/dist/index.mjs +0 -17155
  150. package/dist/index.mjs.map +0 -1
  151. package/dist/network.js.map +0 -1
  152. package/dist/network.mjs +0 -4
  153. package/dist/network.mjs.map +0 -1
  154. package/dist/number.js.map +0 -1
  155. package/dist/number.mjs +0 -4
  156. package/dist/number.mjs.map +0 -1
  157. package/dist/object.js.map +0 -1
  158. package/dist/object.mjs +0 -4
  159. package/dist/object.mjs.map +0 -1
  160. package/dist/performance.js.map +0 -1
  161. package/dist/performance.mjs +0 -4
  162. package/dist/performance.mjs.map +0 -1
  163. package/dist/storage.js.map +0 -1
  164. package/dist/storage.mjs +0 -5
  165. package/dist/storage.mjs.map +0 -1
  166. package/dist/string.js.map +0 -1
  167. package/dist/string.mjs +0 -4
  168. package/dist/string.mjs.map +0 -1
  169. package/dist/tracking.js.map +0 -1
  170. package/dist/tracking.mjs +0 -4
  171. package/dist/tracking.mjs.map +0 -1
  172. package/dist/transform.js.map +0 -1
  173. package/dist/transform.mjs +0 -4
  174. package/dist/transform.mjs.map +0 -1
  175. package/dist/upload.js.map +0 -1
  176. package/dist/upload.mjs +0 -5
  177. package/dist/upload.mjs.map +0 -1
  178. package/dist/url.js.map +0 -1
  179. package/dist/url.mjs +0 -4
  180. package/dist/url.mjs.map +0 -1
  181. package/dist/validation.js.map +0 -1
  182. package/dist/validation.mjs +0 -4
  183. package/dist/validation.mjs.map +0 -1
  184. /package/dist/{upload-DchqyDBQ.d.mts → index-DchqyDBQ.d.mts} +0 -0
  185. /package/dist/{upload-DchqyDBQ.d.ts → index-DchqyDBQ.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/core/string.ts
3
+ // src/core/string/index.ts
4
4
  function capitalize(str) {
5
5
  if (!str) return str;
6
6
  return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
@@ -106,5 +106,3 @@ exports.snakeCase = snakeCase;
106
106
  exports.template = template;
107
107
  exports.truncate = truncate;
108
108
  exports.unescapeHtml = unescapeHtml;
109
- //# sourceMappingURL=chunk-D7CS5EKF.js.map
110
- //# sourceMappingURL=chunk-D7CS5EKF.js.map
package/dist/string.js CHANGED
@@ -1,69 +1,92 @@
1
- 'use strict';
1
+ // src/core/string/index.ts
2
+ function capitalize(str) {
3
+ if (!str) return str;
4
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
5
+ }
6
+ function camelCase(str) {
7
+ if (!str) return str;
8
+ const words = str.replace(/[A-Z]/g, (letter) => ` ${letter.toLowerCase()}`).split(/[\s\-_]+/).filter((word) => word.length > 0);
9
+ if (words.length === 0) return "";
10
+ return words[0].toLowerCase() + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
11
+ }
12
+ function kebabCase(str) {
13
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
14
+ }
15
+ function truncate(str, length, suffix = "...") {
16
+ if (str.length <= length) return str;
17
+ return str.slice(0, length - suffix.length) + suffix;
18
+ }
19
+ function snakeCase(str) {
20
+ if (!str) return str;
21
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`).replace(/[\s-]+/g, "_").replace(/^_+|_+$/g, "").toLowerCase();
22
+ }
23
+ function pascalCase(str) {
24
+ if (!str) return str;
25
+ const camel = camelCase(str);
26
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
27
+ }
28
+ function mask(str, options = {}) {
29
+ if (!str) return str;
30
+ const { start = 0, end = str.length, maskChar = "*" } = options;
31
+ const startIndex = Math.max(0, start);
32
+ const endIndex = Math.min(str.length, end);
33
+ if (startIndex >= endIndex) return str;
34
+ return str.slice(0, startIndex) + maskChar.repeat(endIndex - startIndex) + str.slice(endIndex);
35
+ }
36
+ function maskPhone(phone) {
37
+ if (!phone || phone.length < 7) return phone;
38
+ return mask(phone, { start: 3, end: phone.length - 4 });
39
+ }
40
+ function maskEmail(email) {
41
+ if (!email || !email.includes("@")) return email;
42
+ const [local, domain] = email.split("@");
43
+ if (local.length <= 2) return email;
44
+ return `${local.slice(0, 2)}***@${domain}`;
45
+ }
46
+ function slugify(str) {
47
+ if (!str) return "";
48
+ return str.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
49
+ }
50
+ function removeAccents(str) {
51
+ if (!str) return str;
52
+ return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
53
+ }
54
+ function escapeHtml(str) {
55
+ if (!str) return str;
56
+ const map = {
57
+ "&": "&amp;",
58
+ "<": "&lt;",
59
+ ">": "&gt;",
60
+ '"': "&quot;",
61
+ "'": "&#39;"
62
+ };
63
+ return str.replace(/[&<>"']/g, (char) => map[char]);
64
+ }
65
+ function unescapeHtml(str) {
66
+ if (!str) return str;
67
+ const map = {
68
+ "&amp;": "&",
69
+ "&lt;": "<",
70
+ "&gt;": ">",
71
+ "&quot;": '"',
72
+ "&#39;": "'"
73
+ };
74
+ return str.replace(/&amp;|&lt;|&gt;|&quot;|&#39;/g, (char) => map[char]);
75
+ }
76
+ function template(template2, data) {
77
+ if (!template2) return template2;
78
+ return template2.replace(/\{\{(\w+)\}\}/g, (match, key) => {
79
+ const value = data[key];
80
+ return value !== void 0 && value !== null ? String(value) : match;
81
+ });
82
+ }
83
+ function highlight(text, keyword, tag = "mark") {
84
+ if (!text || !keyword) return text;
85
+ const regex = new RegExp(`(${escapeRegex(keyword)})`, "gi");
86
+ return text.replace(regex, `<${tag}>$1</${tag}>`);
87
+ }
88
+ function escapeRegex(str) {
89
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
90
+ }
2
91
 
3
- var chunkD7CS5EKF_js = require('./chunk-D7CS5EKF.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "camelCase", {
9
- enumerable: true,
10
- get: function () { return chunkD7CS5EKF_js.camelCase; }
11
- });
12
- Object.defineProperty(exports, "capitalize", {
13
- enumerable: true,
14
- get: function () { return chunkD7CS5EKF_js.capitalize; }
15
- });
16
- Object.defineProperty(exports, "escapeHtml", {
17
- enumerable: true,
18
- get: function () { return chunkD7CS5EKF_js.escapeHtml; }
19
- });
20
- Object.defineProperty(exports, "highlight", {
21
- enumerable: true,
22
- get: function () { return chunkD7CS5EKF_js.highlight; }
23
- });
24
- Object.defineProperty(exports, "kebabCase", {
25
- enumerable: true,
26
- get: function () { return chunkD7CS5EKF_js.kebabCase; }
27
- });
28
- Object.defineProperty(exports, "mask", {
29
- enumerable: true,
30
- get: function () { return chunkD7CS5EKF_js.mask; }
31
- });
32
- Object.defineProperty(exports, "maskEmail", {
33
- enumerable: true,
34
- get: function () { return chunkD7CS5EKF_js.maskEmail; }
35
- });
36
- Object.defineProperty(exports, "maskPhone", {
37
- enumerable: true,
38
- get: function () { return chunkD7CS5EKF_js.maskPhone; }
39
- });
40
- Object.defineProperty(exports, "pascalCase", {
41
- enumerable: true,
42
- get: function () { return chunkD7CS5EKF_js.pascalCase; }
43
- });
44
- Object.defineProperty(exports, "removeAccents", {
45
- enumerable: true,
46
- get: function () { return chunkD7CS5EKF_js.removeAccents; }
47
- });
48
- Object.defineProperty(exports, "slugify", {
49
- enumerable: true,
50
- get: function () { return chunkD7CS5EKF_js.slugify; }
51
- });
52
- Object.defineProperty(exports, "snakeCase", {
53
- enumerable: true,
54
- get: function () { return chunkD7CS5EKF_js.snakeCase; }
55
- });
56
- Object.defineProperty(exports, "template", {
57
- enumerable: true,
58
- get: function () { return chunkD7CS5EKF_js.template; }
59
- });
60
- Object.defineProperty(exports, "truncate", {
61
- enumerable: true,
62
- get: function () { return chunkD7CS5EKF_js.truncate; }
63
- });
64
- Object.defineProperty(exports, "unescapeHtml", {
65
- enumerable: true,
66
- get: function () { return chunkD7CS5EKF_js.unescapeHtml; }
67
- });
68
- //# sourceMappingURL=string.js.map
69
- //# sourceMappingURL=string.js.map
92
+ export { camelCase, capitalize, escapeHtml, highlight, kebabCase, mask, maskEmail, maskPhone, pascalCase, removeAccents, slugify, snakeCase, template, truncate, unescapeHtml };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/helper/tracking.ts
3
+ // src/helper/tracking/index.ts
4
4
  var Tracker = class {
5
5
  constructor(options) {
6
6
  this.eventQueue = [];
@@ -370,5 +370,3 @@ exports.trackClick = trackClick;
370
370
  exports.trackEvent = trackEvent;
371
371
  exports.trackExposure = trackExposure;
372
372
  exports.trackPageView = trackPageView;
373
- //# sourceMappingURL=chunk-56W6YECK.js.map
374
- //# sourceMappingURL=chunk-56W6YECK.js.map
package/dist/tracking.js CHANGED
@@ -1,53 +1,360 @@
1
- 'use strict';
1
+ // src/helper/tracking/index.ts
2
+ var Tracker = class {
3
+ constructor(options) {
4
+ this.eventQueue = [];
5
+ this.batchTimer = null;
6
+ this.userInfo = {};
7
+ this.exposureObservers = /* @__PURE__ */ new Map();
8
+ this.exposureTimers = /* @__PURE__ */ new Map();
9
+ this.exposedElements = /* @__PURE__ */ new Set();
10
+ if (!options.endpoint && !options.customSend) {
11
+ throw new Error("Either endpoint or customSend must be provided");
12
+ }
13
+ this.options = {
14
+ endpoint: options.endpoint || "",
15
+ batchSize: options.batchSize ?? 10,
16
+ batchDelay: options.batchDelay ?? 3e3,
17
+ autoTrackPageView: options.autoTrackPageView ?? true,
18
+ autoTrackClick: options.autoTrackClick ?? false,
19
+ commonParams: options.commonParams || {},
20
+ customSend: options.customSend,
21
+ debug: options.debug ?? false
22
+ };
23
+ this.sessionId = this.generateSessionId();
24
+ if (this.options.autoTrackPageView && typeof window !== "undefined") {
25
+ this.trackPageView();
26
+ this.setupPageViewListener();
27
+ }
28
+ if (this.options.autoTrackClick && typeof window !== "undefined") {
29
+ this.setupClickListener();
30
+ }
31
+ }
32
+ /**
33
+ * 生成会话ID
34
+ */
35
+ generateSessionId() {
36
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
37
+ }
38
+ /**
39
+ * 获取公共数据
40
+ */
41
+ getCommonData() {
42
+ const data = {
43
+ timestamp: Date.now(),
44
+ sessionId: this.sessionId,
45
+ ...this.options.commonParams,
46
+ ...this.userInfo
47
+ };
48
+ if (typeof window !== "undefined") {
49
+ data.url = window.location.href;
50
+ data.userAgent = navigator.userAgent;
51
+ }
52
+ return data;
53
+ }
54
+ /**
55
+ * 添加事件到队列
56
+ */
57
+ enqueue(event) {
58
+ this.eventQueue.push(event);
59
+ if (this.options.debug) {
60
+ console.log("[Tracker] Event enqueued:", event);
61
+ }
62
+ if (this.eventQueue.length >= this.options.batchSize) {
63
+ this.flush();
64
+ } else {
65
+ this.scheduleBatch();
66
+ }
67
+ }
68
+ /**
69
+ * 安排批量上报
70
+ */
71
+ scheduleBatch() {
72
+ if (this.batchTimer) {
73
+ clearTimeout(this.batchTimer);
74
+ }
75
+ this.batchTimer = setTimeout(() => {
76
+ this.flush();
77
+ }, this.options.batchDelay);
78
+ }
79
+ /**
80
+ * 上报事件
81
+ */
82
+ async sendEvents(events) {
83
+ if (events.length === 0) return;
84
+ try {
85
+ if (this.options.customSend) {
86
+ await this.options.customSend(events);
87
+ } else if (this.options.endpoint) {
88
+ await this.sendToEndpoint(events);
89
+ }
90
+ if (this.options.debug) {
91
+ console.log("[Tracker] Events sent:", events);
92
+ }
93
+ } catch (error) {
94
+ console.error("[Tracker] Failed to send events:", error);
95
+ this.eventQueue.unshift(...events);
96
+ }
97
+ }
98
+ /**
99
+ * 发送到上报接口
100
+ */
101
+ async sendToEndpoint(events) {
102
+ const response = await fetch(this.options.endpoint, {
103
+ method: "POST",
104
+ headers: {
105
+ "Content-Type": "application/json"
106
+ },
107
+ body: JSON.stringify({ events })
108
+ });
109
+ if (!response.ok) {
110
+ throw new Error(`HTTP error! status: ${response.status}`);
111
+ }
112
+ }
113
+ /**
114
+ * 立即上报所有待上报事件
115
+ */
116
+ async flush() {
117
+ if (this.batchTimer) {
118
+ clearTimeout(this.batchTimer);
119
+ this.batchTimer = null;
120
+ }
121
+ if (this.eventQueue.length === 0) return;
122
+ const events = [...this.eventQueue];
123
+ this.eventQueue = [];
124
+ await this.sendEvents(events);
125
+ }
126
+ /**
127
+ * 追踪事件
128
+ */
129
+ trackEvent(name, params) {
130
+ const event = {
131
+ type: "event",
132
+ name,
133
+ params,
134
+ ...this.getCommonData()
135
+ };
136
+ this.enqueue(event);
137
+ }
138
+ /**
139
+ * 追踪页面浏览
140
+ */
141
+ trackPageView(params) {
142
+ const event = {
143
+ type: "pageview",
144
+ name: "pageview",
145
+ params: {
146
+ path: typeof window !== "undefined" ? window.location.pathname : void 0,
147
+ search: typeof window !== "undefined" ? window.location.search : void 0,
148
+ hash: typeof window !== "undefined" ? window.location.hash : void 0,
149
+ ...params
150
+ },
151
+ ...this.getCommonData()
152
+ };
153
+ this.enqueue(event);
154
+ }
155
+ /**
156
+ * 追踪点击事件
157
+ */
158
+ trackClick(element, params) {
159
+ const el = typeof element === "string" ? document.querySelector(element) : element;
160
+ if (!el) {
161
+ if (this.options.debug) {
162
+ console.warn("[Tracker] Element not found:", element);
163
+ }
164
+ return;
165
+ }
166
+ const event = {
167
+ type: "click",
168
+ name: "click",
169
+ params: {
170
+ element: el.tagName.toLowerCase(),
171
+ id: el.id || void 0,
172
+ className: el.className || void 0,
173
+ text: el.textContent?.trim().substring(0, 100) || void 0,
174
+ ...params
175
+ },
176
+ ...this.getCommonData()
177
+ };
178
+ this.enqueue(event);
179
+ }
180
+ /**
181
+ * 追踪曝光事件
182
+ */
183
+ trackExposure(element, options, params) {
184
+ if (typeof window === "undefined" || !window.IntersectionObserver) {
185
+ if (this.options.debug) {
186
+ console.warn("[Tracker] IntersectionObserver is not supported");
187
+ }
188
+ return;
189
+ }
190
+ const el = typeof element === "string" ? document.querySelector(element) : element;
191
+ if (!el) {
192
+ if (this.options.debug) {
193
+ console.warn("[Tracker] Element not found:", element);
194
+ }
195
+ return;
196
+ }
197
+ const { threshold = 0.5, duration = 1e3, once = true } = options || {};
198
+ const elementId = `${Date.now()}-${Math.random()}`;
199
+ if (once && this.exposedElements.has(el)) {
200
+ return;
201
+ }
202
+ let exposureTimer = null;
203
+ let startTime = null;
204
+ const observer = new IntersectionObserver(
205
+ (entries) => {
206
+ entries.forEach((entry) => {
207
+ if (entry.isIntersecting && entry.intersectionRatio >= threshold) {
208
+ if (!startTime) {
209
+ startTime = Date.now();
210
+ const currentStartTime = startTime;
211
+ exposureTimer = setTimeout(() => {
212
+ const event = {
213
+ type: "exposure",
214
+ name: "exposure",
215
+ params: {
216
+ element: el.tagName.toLowerCase(),
217
+ id: el.id || void 0,
218
+ className: el.className || void 0,
219
+ duration: currentStartTime ? Date.now() - currentStartTime : duration,
220
+ ...params
221
+ },
222
+ ...this.getCommonData()
223
+ };
224
+ this.enqueue(event);
225
+ this.exposedElements.add(el);
226
+ observer.disconnect();
227
+ this.exposureObservers.delete(elementId);
228
+ if (exposureTimer) {
229
+ clearTimeout(exposureTimer);
230
+ this.exposureTimers.delete(elementId);
231
+ }
232
+ }, duration);
233
+ this.exposureTimers.set(elementId, exposureTimer);
234
+ }
235
+ } else {
236
+ if (exposureTimer) {
237
+ clearTimeout(exposureTimer);
238
+ this.exposureTimers.delete(elementId);
239
+ }
240
+ startTime = null;
241
+ }
242
+ });
243
+ },
244
+ {
245
+ threshold: [threshold]
246
+ }
247
+ );
248
+ observer.observe(el);
249
+ this.exposureObservers.set(elementId, observer);
250
+ }
251
+ /**
252
+ * 设置用户信息
253
+ */
254
+ setUserInfo(userInfo) {
255
+ this.userInfo = { ...this.userInfo, ...userInfo };
256
+ }
257
+ /**
258
+ * 设置公共参数
259
+ */
260
+ setCommonParams(params) {
261
+ this.options.commonParams = { ...this.options.commonParams, ...params };
262
+ }
263
+ /**
264
+ * 设置页面浏览监听器(SPA应用)
265
+ */
266
+ setupPageViewListener() {
267
+ if (typeof window === "undefined") return;
268
+ window.addEventListener("popstate", () => {
269
+ this.trackPageView();
270
+ });
271
+ const originalPushState = history.pushState;
272
+ const originalReplaceState = history.replaceState;
273
+ history.pushState = function(...args) {
274
+ originalPushState.apply(history, args);
275
+ window.dispatchEvent(new Event("pushstate"));
276
+ };
277
+ history.replaceState = function(...args) {
278
+ originalReplaceState.apply(history, args);
279
+ window.dispatchEvent(new Event("replacestate"));
280
+ };
281
+ window.addEventListener("pushstate", () => {
282
+ this.trackPageView();
283
+ });
284
+ window.addEventListener("replacestate", () => {
285
+ this.trackPageView();
286
+ });
287
+ }
288
+ /**
289
+ * 设置点击事件监听器
290
+ */
291
+ setupClickListener() {
292
+ if (typeof window === "undefined" || typeof document === "undefined") return;
293
+ document.addEventListener(
294
+ "click",
295
+ (event) => {
296
+ const target = event.target;
297
+ if (target) {
298
+ this.trackClick(target);
299
+ }
300
+ },
301
+ true
302
+ // 使用捕获阶段
303
+ );
304
+ }
305
+ /**
306
+ * 清理资源
307
+ */
308
+ destroy() {
309
+ if (this.batchTimer) {
310
+ clearTimeout(this.batchTimer);
311
+ this.batchTimer = null;
312
+ }
313
+ this.exposureObservers.forEach((observer) => observer.disconnect());
314
+ this.exposureObservers.clear();
315
+ this.exposureTimers.forEach((timer) => clearTimeout(timer));
316
+ this.exposureTimers.clear();
317
+ this.flush().catch(console.error);
318
+ }
319
+ };
320
+ function createTracker(options) {
321
+ return new Tracker(options);
322
+ }
323
+ var defaultTracker = null;
324
+ function initTracker(options) {
325
+ if (defaultTracker) {
326
+ console.warn("[Tracker] Default tracker already initialized");
327
+ return defaultTracker;
328
+ }
329
+ defaultTracker = new Tracker(options);
330
+ return defaultTracker;
331
+ }
332
+ function getTracker() {
333
+ if (!defaultTracker) {
334
+ throw new Error("Tracker not initialized. Call initTracker() first.");
335
+ }
336
+ return defaultTracker;
337
+ }
338
+ function trackEvent(name, params) {
339
+ getTracker().trackEvent(name, params);
340
+ }
341
+ function trackPageView(params) {
342
+ getTracker().trackPageView(params);
343
+ }
344
+ function trackClick(element, params) {
345
+ getTracker().trackClick(element, params);
346
+ }
347
+ function trackExposure(element, options, params) {
348
+ getTracker().trackExposure(element, options, params);
349
+ }
350
+ function setUserInfo(userInfo) {
351
+ getTracker().setUserInfo(userInfo);
352
+ }
353
+ function setCommonParams(params) {
354
+ getTracker().setCommonParams(params);
355
+ }
356
+ async function flush() {
357
+ await getTracker().flush();
358
+ }
2
359
 
3
- var chunk56W6YECK_js = require('./chunk-56W6YECK.js');
4
- require('./chunk-PR4QN5HX.js');
5
-
6
-
7
-
8
- Object.defineProperty(exports, "Tracker", {
9
- enumerable: true,
10
- get: function () { return chunk56W6YECK_js.Tracker; }
11
- });
12
- Object.defineProperty(exports, "createTracker", {
13
- enumerable: true,
14
- get: function () { return chunk56W6YECK_js.createTracker; }
15
- });
16
- Object.defineProperty(exports, "flush", {
17
- enumerable: true,
18
- get: function () { return chunk56W6YECK_js.flush; }
19
- });
20
- Object.defineProperty(exports, "getTracker", {
21
- enumerable: true,
22
- get: function () { return chunk56W6YECK_js.getTracker; }
23
- });
24
- Object.defineProperty(exports, "initTracker", {
25
- enumerable: true,
26
- get: function () { return chunk56W6YECK_js.initTracker; }
27
- });
28
- Object.defineProperty(exports, "setCommonParams", {
29
- enumerable: true,
30
- get: function () { return chunk56W6YECK_js.setCommonParams; }
31
- });
32
- Object.defineProperty(exports, "setUserInfo", {
33
- enumerable: true,
34
- get: function () { return chunk56W6YECK_js.setUserInfo; }
35
- });
36
- Object.defineProperty(exports, "trackClick", {
37
- enumerable: true,
38
- get: function () { return chunk56W6YECK_js.trackClick; }
39
- });
40
- Object.defineProperty(exports, "trackEvent", {
41
- enumerable: true,
42
- get: function () { return chunk56W6YECK_js.trackEvent; }
43
- });
44
- Object.defineProperty(exports, "trackExposure", {
45
- enumerable: true,
46
- get: function () { return chunk56W6YECK_js.trackExposure; }
47
- });
48
- Object.defineProperty(exports, "trackPageView", {
49
- enumerable: true,
50
- get: function () { return chunk56W6YECK_js.trackPageView; }
51
- });
52
- //# sourceMappingURL=tracking.js.map
53
- //# sourceMappingURL=tracking.js.map
360
+ export { Tracker, createTracker, flush, getTracker, initTracker, setCommonParams, setUserInfo, trackClick, trackEvent, trackExposure, trackPageView };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/data/transform.ts
3
+ // src/data/transform/index.ts
4
4
  function csvToJson(csv, options = {}) {
5
5
  const { delimiter = ",", headers, skipEmptyLines = true } = options;
6
6
  const lines = csv.split(/\r?\n/).filter((line) => {
@@ -305,5 +305,3 @@ exports.jsonToXml = jsonToXml;
305
305
  exports.jsonToYaml = jsonToYaml;
306
306
  exports.xmlToJson = xmlToJson;
307
307
  exports.yamlToJson = yamlToJson;
308
- //# sourceMappingURL=chunk-ZDMFMUDR.js.map
309
- //# sourceMappingURL=chunk-ZDMFMUDR.js.map