@cloudcare/cocos-sdk 0.1.1-alpha.1 → 0.1.1-alpha.2

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 (136) hide show
  1. package/README.md +35 -6
  2. package/bin/cli.cjs +42 -5
  3. package/bin/project-configuration.cjs +135 -0
  4. package/bin/web-assets.cjs +32 -0
  5. package/dist/creator2/core/auto-tracking.js.map +1 -1
  6. package/dist/creator2/core/client.d.ts +1 -0
  7. package/dist/creator2/core/client.d.ts.map +1 -1
  8. package/dist/creator2/core/client.js +13 -0
  9. package/dist/creator2/core/client.js.map +1 -1
  10. package/dist/creator2/core/index.js.map +1 -1
  11. package/dist/creator2/core/modules.js.map +1 -1
  12. package/dist/creator2/core/platform-client.d.ts +46 -0
  13. package/dist/creator2/core/platform-client.d.ts.map +1 -0
  14. package/dist/creator2/core/platform-client.js +195 -0
  15. package/dist/creator2/core/platform-client.js.map +1 -0
  16. package/dist/creator2/core/platform-options.d.ts +30 -0
  17. package/dist/creator2/core/platform-options.d.ts.map +1 -0
  18. package/dist/creator2/core/platform-options.js +3 -0
  19. package/dist/creator2/core/platform-options.js.map +1 -0
  20. package/dist/creator2/core/platform-runtime.d.ts +59 -0
  21. package/dist/creator2/core/platform-runtime.d.ts.map +1 -0
  22. package/dist/creator2/core/platform-runtime.js +36 -0
  23. package/dist/creator2/core/platform-runtime.js.map +1 -0
  24. package/dist/creator2/core/plugin-api.d.ts +1 -1
  25. package/dist/creator2/core/plugin-api.d.ts.map +1 -1
  26. package/dist/creator2/core/plugin-api.js.map +1 -1
  27. package/dist/creator2/core/transport.d.ts +1 -1
  28. package/dist/creator2/core/transport.d.ts.map +1 -1
  29. package/dist/creator2/core/transport.js.map +1 -1
  30. package/dist/creator2/core/types.js.map +1 -1
  31. package/dist/creator2/core/validation.js.map +1 -1
  32. package/dist/creator2/core/version.d.ts +1 -1
  33. package/dist/creator2/core/version.js +1 -1
  34. package/dist/creator2/core/version.js.map +1 -1
  35. package/dist/creator2/creator2/auto.js.map +1 -1
  36. package/dist/creator2/creator2/index.d.ts +6 -3
  37. package/dist/creator2/creator2/index.d.ts.map +1 -1
  38. package/dist/creator2/creator2/index.js +12 -8
  39. package/dist/creator2/creator2/index.js.map +1 -1
  40. package/dist/creator2/creator2/transport.js.map +1 -1
  41. package/dist/creator2/native/bootstrap.d.ts +2 -0
  42. package/dist/creator2/native/bootstrap.d.ts.map +1 -0
  43. package/dist/creator2/native/bootstrap.js +34 -0
  44. package/dist/creator2/native/bootstrap.js.map +1 -0
  45. package/dist/creator2/web/bootstrap.d.ts +3 -0
  46. package/dist/creator2/web/bootstrap.d.ts.map +1 -0
  47. package/dist/creator2/web/bootstrap.js +15 -0
  48. package/dist/creator2/web/bootstrap.js.map +1 -0
  49. package/dist/creator2/web/client.d.ts +60 -0
  50. package/dist/creator2/web/client.d.ts.map +1 -0
  51. package/dist/creator2/web/client.js +293 -0
  52. package/dist/creator2/web/client.js.map +1 -0
  53. package/dist/creator2/web/creator2.d.ts +5 -0
  54. package/dist/creator2/web/creator2.d.ts.map +1 -0
  55. package/dist/creator2/web/creator2.js +27 -0
  56. package/dist/creator2/web/creator2.js.map +1 -0
  57. package/dist/creator2/web/privacy.d.ts +3 -0
  58. package/dist/creator2/web/privacy.d.ts.map +1 -0
  59. package/dist/creator2/web/privacy.js +39 -0
  60. package/dist/creator2/web/privacy.js.map +1 -0
  61. package/dist/creator2/web/runtime.d.ts +23 -0
  62. package/dist/creator2/web/runtime.d.ts.map +1 -0
  63. package/dist/creator2/web/runtime.js +265 -0
  64. package/dist/creator2/web/runtime.js.map +1 -0
  65. package/dist/creator2/web/types.d.ts +91 -0
  66. package/dist/creator2/web/types.d.ts.map +1 -0
  67. package/dist/creator2/web/types.js +3 -0
  68. package/dist/creator2/web/types.js.map +1 -0
  69. package/dist/creator3/core/client.d.ts +1 -0
  70. package/dist/creator3/core/client.d.ts.map +1 -1
  71. package/dist/creator3/core/client.js +5 -0
  72. package/dist/creator3/core/client.js.map +1 -1
  73. package/dist/creator3/core/platform-client.d.ts +46 -0
  74. package/dist/creator3/core/platform-client.d.ts.map +1 -0
  75. package/dist/creator3/core/platform-client.js +135 -0
  76. package/dist/creator3/core/platform-client.js.map +1 -0
  77. package/dist/creator3/core/platform-options.d.ts +30 -0
  78. package/dist/creator3/core/platform-options.d.ts.map +1 -0
  79. package/dist/creator3/core/platform-options.js +2 -0
  80. package/dist/creator3/core/platform-options.js.map +1 -0
  81. package/dist/creator3/core/platform-runtime.d.ts +59 -0
  82. package/dist/creator3/core/platform-runtime.d.ts.map +1 -0
  83. package/dist/creator3/core/platform-runtime.js +29 -0
  84. package/dist/creator3/core/platform-runtime.js.map +1 -0
  85. package/dist/creator3/core/plugin-api.d.ts +1 -1
  86. package/dist/creator3/core/plugin-api.d.ts.map +1 -1
  87. package/dist/creator3/core/transport.d.ts +1 -1
  88. package/dist/creator3/core/transport.d.ts.map +1 -1
  89. package/dist/creator3/core/version.d.ts +1 -1
  90. package/dist/creator3/core/version.js +1 -1
  91. package/dist/creator3/creator3/index.d.ts +6 -3
  92. package/dist/creator3/creator3/index.d.ts.map +1 -1
  93. package/dist/creator3/creator3/index.js +13 -8
  94. package/dist/creator3/creator3/index.js.map +1 -1
  95. package/dist/creator3/native/bootstrap.d.ts +2 -0
  96. package/dist/creator3/native/bootstrap.d.ts.map +1 -0
  97. package/dist/creator3/native/bootstrap.js +32 -0
  98. package/dist/creator3/native/bootstrap.js.map +1 -0
  99. package/dist/creator3/web/bootstrap.d.ts +3 -0
  100. package/dist/creator3/web/bootstrap.d.ts.map +1 -0
  101. package/dist/creator3/web/bootstrap.js +11 -0
  102. package/dist/creator3/web/bootstrap.js.map +1 -0
  103. package/dist/creator3/web/client.d.ts +60 -0
  104. package/dist/creator3/web/client.d.ts.map +1 -0
  105. package/dist/creator3/web/client.js +255 -0
  106. package/dist/creator3/web/client.js.map +1 -0
  107. package/dist/creator3/web/creator3.d.ts +5 -0
  108. package/dist/creator3/web/creator3.d.ts.map +1 -0
  109. package/dist/creator3/web/creator3.js +11 -0
  110. package/dist/creator3/web/creator3.js.map +1 -0
  111. package/dist/creator3/web/privacy.d.ts +3 -0
  112. package/dist/creator3/web/privacy.d.ts.map +1 -0
  113. package/dist/creator3/web/privacy.js +26 -0
  114. package/dist/creator3/web/privacy.js.map +1 -0
  115. package/dist/creator3/web/runtime.d.ts +23 -0
  116. package/dist/creator3/web/runtime.d.ts.map +1 -0
  117. package/dist/creator3/web/runtime.js +267 -0
  118. package/dist/creator3/web/runtime.js.map +1 -0
  119. package/dist/creator3/web/types.d.ts +91 -0
  120. package/dist/creator3/web/types.d.ts.map +1 -0
  121. package/dist/creator3/web/types.js +2 -0
  122. package/dist/creator3/web/types.js.map +1 -0
  123. package/extensions/creator2/install-web.cjs +69 -0
  124. package/extensions/creator2/main.js +19 -2
  125. package/extensions/creator2/project-configuration.cjs +135 -0
  126. package/extensions/creator3/dist/hooks.js +13 -0
  127. package/extensions/creator3/install-web.cjs +69 -0
  128. package/extensions/creator3/project-configuration.cjs +135 -0
  129. package/native/ios/FTCocosBridge.podspec +1 -1
  130. package/package.json +19 -3
  131. package/runtime/native.js +1191 -0
  132. package/web/bootstrap/package.json +4 -0
  133. package/web/bootstrap.js +1042 -0
  134. package/web/bootstrap.js.map +7 -0
  135. package/web/creator2/package.json +4 -0
  136. package/web/creator3/package.json +4 -0
@@ -0,0 +1,1191 @@
1
+ "use strict";
2
+ (function() {
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __commonJS = function(cb, mod) {
5
+ return function __require() {
6
+ try {
7
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
8
+ } catch (e) {
9
+ throw mod = 0, e;
10
+ }
11
+ };
12
+ };
13
+
14
+ // packages/cocos/dist/creator2/core/auto-tracking.js
15
+ var require_auto_tracking = __commonJS({
16
+ "packages/cocos/dist/creator2/core/auto-tracking.js": function(exports) {
17
+ "use strict";
18
+ var __assign = exports && exports.__assign || function() {
19
+ __assign = Object.assign || function(t) {
20
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
21
+ s = arguments[i];
22
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
23
+ t[p] = s[p];
24
+ }
25
+ return t;
26
+ };
27
+ return __assign.apply(this, arguments);
28
+ };
29
+ var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
30
+ function adopt(value) {
31
+ return value instanceof P ? value : new P(function(resolve) {
32
+ resolve(value);
33
+ });
34
+ }
35
+ return new (P || (P = Promise))(function(resolve, reject) {
36
+ function fulfilled(value) {
37
+ try {
38
+ step(generator.next(value));
39
+ } catch (e) {
40
+ reject(e);
41
+ }
42
+ }
43
+ function rejected(value) {
44
+ try {
45
+ step(generator["throw"](value));
46
+ } catch (e) {
47
+ reject(e);
48
+ }
49
+ }
50
+ function step(result) {
51
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
52
+ }
53
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
54
+ });
55
+ };
56
+ var __generator = exports && exports.__generator || function(thisArg, body) {
57
+ var _ = { label: 0, sent: function() {
58
+ if (t[0] & 1) throw t[1];
59
+ return t[1];
60
+ }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
61
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
62
+ return this;
63
+ }), g;
64
+ function verb(n) {
65
+ return function(v) {
66
+ return step([n, v]);
67
+ };
68
+ }
69
+ function step(op) {
70
+ if (f) throw new TypeError("Generator is already executing.");
71
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
72
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
73
+ if (y = 0, t) op = [op[0] & 2, t.value];
74
+ switch (op[0]) {
75
+ case 0:
76
+ case 1:
77
+ t = op;
78
+ break;
79
+ case 4:
80
+ _.label++;
81
+ return { value: op[1], done: false };
82
+ case 5:
83
+ _.label++;
84
+ y = op[1];
85
+ op = [0];
86
+ continue;
87
+ case 7:
88
+ op = _.ops.pop();
89
+ _.trys.pop();
90
+ continue;
91
+ default:
92
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
93
+ _ = 0;
94
+ continue;
95
+ }
96
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
97
+ _.label = op[1];
98
+ break;
99
+ }
100
+ if (op[0] === 6 && _.label < t[1]) {
101
+ _.label = t[1];
102
+ t = op;
103
+ break;
104
+ }
105
+ if (t && _.label < t[2]) {
106
+ _.label = t[2];
107
+ _.ops.push(op);
108
+ break;
109
+ }
110
+ if (t[2]) _.ops.pop();
111
+ _.trys.pop();
112
+ continue;
113
+ }
114
+ op = body.call(thisArg, _);
115
+ } catch (e) {
116
+ op = [6, e];
117
+ y = 0;
118
+ } finally {
119
+ f = t = 0;
120
+ }
121
+ if (op[0] & 5) throw op[1];
122
+ return { value: op[0] ? op[1] : void 0, done: true };
123
+ }
124
+ };
125
+ var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
126
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
127
+ if (ar || !(i in from)) {
128
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
129
+ ar[i] = from[i];
130
+ }
131
+ }
132
+ return to.concat(ar || Array.prototype.slice.call(from));
133
+ };
134
+ Object.defineProperty(exports, "__esModule", { value: true });
135
+ exports.FTDefaultAutoTracking = void 0;
136
+ var FTDefaultAutoTracking = (
137
+ /** @class */
138
+ (function() {
139
+ function FTDefaultAutoTracking2(rum, logger, trace, hooks, target) {
140
+ if (target === void 0) {
141
+ target = globalThis;
142
+ }
143
+ this.rum = rum;
144
+ this.logger = logger;
145
+ this.trace = trace;
146
+ this.hooks = hooks;
147
+ this.target = target;
148
+ this.stops = [];
149
+ this.networkStops = [];
150
+ }
151
+ FTDefaultAutoTracking2.prototype.start = function(config, viewName, scope) {
152
+ if (scope === void 0) {
153
+ scope = "all";
154
+ }
155
+ this.stop(scope);
156
+ try {
157
+ if (scope !== "network") {
158
+ if (viewName)
159
+ this.switchView(viewName);
160
+ if (config.scenes)
161
+ this.installSceneTracking(viewName === void 0);
162
+ if (config.actions)
163
+ this.installActionTracking();
164
+ if (config.errors)
165
+ this.installErrorTracking();
166
+ if (config.console)
167
+ this.installConsoleTracking();
168
+ }
169
+ if (scope !== "page" && config.network) {
170
+ this.installFetchTracking();
171
+ this.installXhrTracking();
172
+ }
173
+ } catch (error) {
174
+ try {
175
+ this.stop(scope);
176
+ } catch (_a) {
177
+ }
178
+ throw error;
179
+ }
180
+ };
181
+ FTDefaultAutoTracking2.prototype.stop = function(scope) {
182
+ var _this = this;
183
+ if (scope === void 0) {
184
+ scope = "all";
185
+ }
186
+ var failure;
187
+ var cleanup = function(stop) {
188
+ try {
189
+ stop();
190
+ } catch (error) {
191
+ if (failure === void 0)
192
+ failure = error;
193
+ }
194
+ };
195
+ if (scope !== "page")
196
+ this.networkStops.splice(0).reverse().forEach(cleanup);
197
+ if (scope !== "network") {
198
+ this.stops.splice(0).reverse().forEach(cleanup);
199
+ if (this.activeView) {
200
+ cleanup(function() {
201
+ return _this.rum.stopView();
202
+ });
203
+ this.activeView = void 0;
204
+ }
205
+ }
206
+ if (failure !== void 0)
207
+ throw failure;
208
+ };
209
+ FTDefaultAutoTracking2.prototype.installSceneTracking = function(includeCurrent) {
210
+ var _this = this;
211
+ this.stops.push(this.hooks.onSceneChanged(function(name) {
212
+ _this.switchView(name);
213
+ }, includeCurrent));
214
+ };
215
+ FTDefaultAutoTracking2.prototype.switchView = function(name) {
216
+ if (this.activeView)
217
+ this.rum.stopView();
218
+ this.activeView = name;
219
+ this.rum.startView(name);
220
+ };
221
+ FTDefaultAutoTracking2.prototype.installActionTracking = function() {
222
+ var _this = this;
223
+ this.stops.push(this.hooks.onAction(function(name, attributes) {
224
+ return _this.rum.startAction(name, "click", attributes);
225
+ }));
226
+ };
227
+ FTDefaultAutoTracking2.prototype.installErrorTracking = function() {
228
+ var _this = this;
229
+ if (!this.target.addEventListener || !this.target.removeEventListener)
230
+ return;
231
+ var errorListener = function(event) {
232
+ var _a;
233
+ var errorEvent = event;
234
+ _this.rum.addError(errorEvent.message || "Uncaught JavaScript error", ((_a = errorEvent.error) === null || _a === void 0 ? void 0 : _a.stack) || "".concat(errorEvent.filename || "", ":").concat(errorEvent.lineno || 0));
235
+ };
236
+ var rejectionListener = function(event) {
237
+ var reason = event.reason;
238
+ _this.rum.addError(reason instanceof Error ? reason.message : String(reason), reason instanceof Error ? reason.stack || "" : "", "unhandled_promise_rejection");
239
+ };
240
+ this.target.addEventListener("error", errorListener);
241
+ this.target.addEventListener("unhandledrejection", rejectionListener);
242
+ this.stops.push(function() {
243
+ var _a, _b, _c, _d;
244
+ (_b = (_a = _this.target).removeEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, "error", errorListener);
245
+ (_d = (_c = _this.target).removeEventListener) === null || _d === void 0 ? void 0 : _d.call(_c, "unhandledrejection", rejectionListener);
246
+ });
247
+ };
248
+ FTDefaultAutoTracking2.prototype.installConsoleTracking = function() {
249
+ var _this = this;
250
+ var consoleObject = this.target.console;
251
+ if (!consoleObject)
252
+ return;
253
+ var methods = [
254
+ "log",
255
+ "info",
256
+ "warn",
257
+ "error"
258
+ ];
259
+ var originals = /* @__PURE__ */ new Map();
260
+ methods.forEach(function(method) {
261
+ var original = consoleObject[method].bind(consoleObject);
262
+ originals.set(method, original);
263
+ consoleObject[method] = (function() {
264
+ var args = [];
265
+ for (var _i = 0; _i < arguments.length; _i++) {
266
+ args[_i] = arguments[_i];
267
+ }
268
+ original.apply(void 0, args);
269
+ var level = method === "warn" ? "warning" : method === "error" ? "error" : "info";
270
+ _this.logger.log(args.map(stringifyLogValue).join(" "), level);
271
+ });
272
+ });
273
+ this.stops.push(function() {
274
+ methods.forEach(function(method) {
275
+ var original = originals.get(method);
276
+ if (original)
277
+ consoleObject[method] = original;
278
+ });
279
+ });
280
+ };
281
+ FTDefaultAutoTracking2.prototype.installFetchTracking = function() {
282
+ var _this = this;
283
+ var original = this.target.fetch;
284
+ if (!original)
285
+ return;
286
+ var tracked = (function(input, init) {
287
+ return __awaiter(_this, void 0, void 0, function() {
288
+ var inputObject, url, method, key, headers, start, response, end, error_1;
289
+ return __generator(this, function(_a) {
290
+ switch (_a.label) {
291
+ case 0:
292
+ inputObject = typeof input === "object" ? input : void 0;
293
+ url = typeof input === "string" ? input : (inputObject === null || inputObject === void 0 ? void 0 : inputObject.url) || String(input);
294
+ method = (init === null || init === void 0 ? void 0 : init.method) || (inputObject === null || inputObject === void 0 ? void 0 : inputObject.method) || "GET";
295
+ key = resourceKey();
296
+ headers = createHeaders((init === null || init === void 0 ? void 0 : init.headers) || (inputObject === null || inputObject === void 0 ? void 0 : inputObject.headers));
297
+ forEachOwn(this.trace.getHeaders(url, key), function(name, value) {
298
+ return setHeader(headers, name, value);
299
+ });
300
+ this.rum.startResource(key);
301
+ start = nowNs();
302
+ _a.label = 1;
303
+ case 1:
304
+ _a.trys.push([1, 3, , 4]);
305
+ return [4, original(input, __assign(__assign({}, init), { headers: headers }))];
306
+ case 2:
307
+ response = _a.sent();
308
+ end = nowNs();
309
+ this.rum.stopResource(key);
310
+ this.rum.addResource(key, {
311
+ url: url,
312
+ httpMethod: method,
313
+ requestHeaders: headersToObject(headers),
314
+ responseHeaders: headersToObject(response.headers),
315
+ statusCode: response.status
316
+ }, { fetchStartTime: start, responseStartTime: end, responseEndTime: end });
317
+ return [2, response];
318
+ case 3:
319
+ error_1 = _a.sent();
320
+ this.rum.stopResource(key);
321
+ this.rum.addError(String(error_1), error_1 instanceof Error ? error_1.stack || "" : "", "network_error");
322
+ throw error_1;
323
+ case 4:
324
+ return [
325
+ 2
326
+ /*return*/
327
+ ];
328
+ }
329
+ });
330
+ });
331
+ });
332
+ this.networkStops.push(function() {
333
+ _this.target.fetch = original;
334
+ });
335
+ this.target.fetch = tracked;
336
+ };
337
+ FTDefaultAutoTracking2.prototype.installXhrTracking = function() {
338
+ var Xhr = this.target.XMLHttpRequest;
339
+ if (!Xhr)
340
+ return;
341
+ var open = Xhr.prototype.open;
342
+ var send = Xhr.prototype.send;
343
+ var setRequestHeader = Xhr.prototype.setRequestHeader;
344
+ var metadata = /* @__PURE__ */ new WeakMap();
345
+ var rum = this.rum;
346
+ var trace = this.trace;
347
+ this.networkStops.push(function() {
348
+ Xhr.prototype.open = open;
349
+ });
350
+ Xhr.prototype.open = function trackedOpen(method, url) {
351
+ var _a;
352
+ var rest = [];
353
+ for (var _i = 2; _i < arguments.length; _i++) {
354
+ rest[_i - 2] = arguments[_i];
355
+ }
356
+ metadata.set(this, { key: resourceKey(), method: method, url: String(url), headers: {} });
357
+ (_a = open).call.apply(_a, __spreadArray([this, method, url], rest, false));
358
+ };
359
+ this.networkStops.push(function() {
360
+ Xhr.prototype.setRequestHeader = setRequestHeader;
361
+ });
362
+ Xhr.prototype.setRequestHeader = function trackedHeader(name, value) {
363
+ var data = metadata.get(this);
364
+ if (data)
365
+ data.headers[name] = value;
366
+ setRequestHeader.call(this, name, value);
367
+ };
368
+ this.networkStops.push(function() {
369
+ Xhr.prototype.send = send;
370
+ });
371
+ Xhr.prototype.send = function trackedSend(body) {
372
+ var _this = this;
373
+ var data = metadata.get(this);
374
+ if (!data)
375
+ return send.call(this, body);
376
+ forEachOwn(trace.getHeaders(data.url, data.key), function(name, value) {
377
+ data.headers[name] = value;
378
+ setRequestHeader.call(_this, name, value);
379
+ });
380
+ var started = nowNs();
381
+ rum.startResource(data.key);
382
+ var completed = false;
383
+ var report = function() {
384
+ if (completed)
385
+ return;
386
+ completed = true;
387
+ var ended = nowNs();
388
+ rum.stopResource(data.key);
389
+ rum.addResource(data.key, {
390
+ url: data.url,
391
+ httpMethod: data.method,
392
+ requestHeaders: data.headers,
393
+ responseHeaders: parseXhrHeaders(_this.getAllResponseHeaders()),
394
+ statusCode: _this.status
395
+ }, { fetchStartTime: started, responseStartTime: ended, responseEndTime: ended });
396
+ };
397
+ var originalLoadEnd = this.onloadend;
398
+ this.addEventListener("loadend", report, { once: true });
399
+ if (this.onloadend === report) {
400
+ var xhr_1 = this;
401
+ var handler_1 = function(event) {
402
+ if (xhr_1.onloadend === handler_1)
403
+ xhr_1.onloadend = originalLoadEnd;
404
+ try {
405
+ originalLoadEnd === null || originalLoadEnd === void 0 ? void 0 : originalLoadEnd.call(xhr_1, event);
406
+ } finally {
407
+ report();
408
+ }
409
+ };
410
+ this.onloadend = handler_1;
411
+ }
412
+ send.call(this, body);
413
+ };
414
+ };
415
+ return FTDefaultAutoTracking2;
416
+ })()
417
+ );
418
+ exports.FTDefaultAutoTracking = FTDefaultAutoTracking;
419
+ function nowNs() {
420
+ return Date.now() * 1e6;
421
+ }
422
+ var resourceSequence = 0;
423
+ function resourceKey() {
424
+ resourceSequence = (resourceSequence + 1) % Number.MAX_SAFE_INTEGER;
425
+ return "cocos-".concat(Date.now().toString(36), "-").concat(resourceSequence.toString(36));
426
+ }
427
+ function createHeaders(source) {
428
+ var HeadersConstructor = globalThis.Headers;
429
+ if (HeadersConstructor)
430
+ return new HeadersConstructor(source);
431
+ var result = {};
432
+ if (Array.isArray(source)) {
433
+ source.forEach(function(_a) {
434
+ var name = _a[0], value = _a[1];
435
+ result[name] = String(value);
436
+ });
437
+ } else if (source && typeof source.forEach === "function") {
438
+ source.forEach(function(value, name) {
439
+ result[name] = value;
440
+ });
441
+ } else if (source) {
442
+ forEachOwn(source, function(name, value) {
443
+ result[name] = String(value);
444
+ });
445
+ }
446
+ return result;
447
+ }
448
+ function setHeader(headers, name, value) {
449
+ if (typeof headers.set === "function")
450
+ headers.set(name, value);
451
+ else
452
+ headers[name] = value;
453
+ }
454
+ function headersToObject(headers) {
455
+ var result = {};
456
+ if (typeof headers.forEach === "function") {
457
+ headers.forEach(function(value, key) {
458
+ result[key] = value;
459
+ });
460
+ } else {
461
+ forEachOwn(headers, function(key, value) {
462
+ result[key] = value;
463
+ });
464
+ }
465
+ return result;
466
+ }
467
+ function forEachOwn(value, callback) {
468
+ Object.keys(value).forEach(function(key) {
469
+ return callback(key, value[key]);
470
+ });
471
+ }
472
+ function parseXhrHeaders(raw) {
473
+ var result = {};
474
+ raw.trim().split(/[\r\n]+/).forEach(function(line) {
475
+ var index = line.indexOf(":");
476
+ if (index > 0)
477
+ result[line.slice(0, index).trim()] = line.slice(index + 1).trim();
478
+ });
479
+ return result;
480
+ }
481
+ function stringifyLogValue(value) {
482
+ if (typeof value === "string")
483
+ return value;
484
+ if (value instanceof Error)
485
+ return "".concat(value.message, "\n").concat(value.stack || "");
486
+ try {
487
+ return JSON.stringify(value);
488
+ } catch (_a) {
489
+ return String(value);
490
+ }
491
+ }
492
+ }
493
+ });
494
+
495
+ // packages/cocos/dist/creator2/core/validation.js
496
+ var require_validation = __commonJS({
497
+ "packages/cocos/dist/creator2/core/validation.js": function(exports) {
498
+ "use strict";
499
+ var __assign = exports && exports.__assign || function() {
500
+ __assign = Object.assign || function(t) {
501
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
502
+ s = arguments[i];
503
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
504
+ t[p] = s[p];
505
+ }
506
+ return t;
507
+ };
508
+ return __assign.apply(this, arguments);
509
+ };
510
+ Object.defineProperty(exports, "__esModule", { value: true });
511
+ exports.samplingRate = samplingRate;
512
+ exports.samplingPercentage = samplingPercentage;
513
+ exports.validatedSamplingConfig = validatedSamplingConfig;
514
+ exports.requireText = requireText;
515
+ function samplingRate(value, name) {
516
+ if (value === void 0)
517
+ return void 0;
518
+ if (!Number.isFinite(value) || value < 0 || value > 1) {
519
+ throw new RangeError("".concat(name, " must be between 0 and 1"));
520
+ }
521
+ return value;
522
+ }
523
+ function samplingPercentage(value, name) {
524
+ if (value === void 0)
525
+ return void 0;
526
+ if (!Number.isFinite(value) || value < 0 || value > 100) {
527
+ throw new RangeError("".concat(name, " must be between 0 and 100"));
528
+ }
529
+ return value;
530
+ }
531
+ function validatedSamplingConfig(config, scope, fields) {
532
+ var result = __assign({}, config);
533
+ fields.forEach(function(_a) {
534
+ var percentageField = _a[0], legacyField = _a[1];
535
+ var percentage = result[percentageField];
536
+ if (percentage !== void 0) {
537
+ samplingPercentage(percentage, "".concat(scope, ".").concat(percentageField));
538
+ delete result[legacyField];
539
+ return;
540
+ }
541
+ samplingRate(result[legacyField], "".concat(scope, ".").concat(legacyField));
542
+ });
543
+ return result;
544
+ }
545
+ function requireText(value, name) {
546
+ if (!value.trim())
547
+ throw new TypeError("".concat(name, " must not be empty"));
548
+ return value;
549
+ }
550
+ }
551
+ });
552
+
553
+ // packages/cocos/dist/creator2/core/version.js
554
+ var require_version = __commonJS({
555
+ "packages/cocos/dist/creator2/core/version.js": function(exports) {
556
+ "use strict";
557
+ Object.defineProperty(exports, "__esModule", { value: true });
558
+ exports.FT_COCOS_SDK_BRIDGE_INFO = exports.FT_COCOS_SDK_BRIDGE_INFO_KEY = exports.FT_COCOS_SDK_VERSION_KEY = exports.FT_COCOS_SDK_VERSION = void 0;
559
+ exports.FT_COCOS_SDK_VERSION = "0.1.1-alpha.2";
560
+ exports.FT_COCOS_SDK_VERSION_KEY = "sdk_package_cocos";
561
+ exports.FT_COCOS_SDK_BRIDGE_INFO_KEY = "sdk_bridge_info";
562
+ exports.FT_COCOS_SDK_BRIDGE_INFO = JSON.stringify({
563
+ cocos: exports.FT_COCOS_SDK_VERSION
564
+ });
565
+ }
566
+ });
567
+
568
+ // packages/cocos/dist/creator2/core/modules.js
569
+ var require_modules = __commonJS({
570
+ "packages/cocos/dist/creator2/core/modules.js": function(exports) {
571
+ "use strict";
572
+ var __assign = exports && exports.__assign || function() {
573
+ __assign = Object.assign || function(t) {
574
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
575
+ s = arguments[i];
576
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
577
+ t[p] = s[p];
578
+ }
579
+ return t;
580
+ };
581
+ return __assign.apply(this, arguments);
582
+ };
583
+ Object.defineProperty(exports, "__esModule", { value: true });
584
+ exports.FTTrace = exports.FTLogger = exports.FTRUM = exports.FTMobileAgent = exports.FTSDKOwnership = void 0;
585
+ var validation_js_1 = require_validation();
586
+ var version_js_1 = require_version();
587
+ var FTSDKOwnership = (
588
+ /** @class */
589
+ (function() {
590
+ function FTSDKOwnership2() {
591
+ this.mode = "unclaimed";
592
+ }
593
+ FTSDKOwnership2.prototype.claimStandalone = function() {
594
+ if (this.mode === "native-host") {
595
+ throw new Error("The native host owns SDK initialization in Hybrid mode");
596
+ }
597
+ this.mode = "standalone";
598
+ };
599
+ FTSDKOwnership2.prototype.claimNativeHost = function() {
600
+ if (this.mode === "standalone") {
601
+ throw new Error("Standalone initialization and native-host attachment are mutually exclusive");
602
+ }
603
+ this.mode = "native-host";
604
+ };
605
+ FTSDKOwnership2.prototype.releaseNativeHost = function() {
606
+ if (this.mode === "native-host")
607
+ this.mode = "unclaimed";
608
+ };
609
+ FTSDKOwnership2.prototype.releaseStandalone = function() {
610
+ if (this.mode === "standalone")
611
+ this.mode = "unclaimed";
612
+ };
613
+ FTSDKOwnership2.prototype.assertNativeHostDoesNotOwnSDK = function() {
614
+ if (this.mode === "native-host") {
615
+ throw new Error("The native host owns the native SDK in Hybrid mode");
616
+ }
617
+ };
618
+ return FTSDKOwnership2;
619
+ })()
620
+ );
621
+ exports.FTSDKOwnership = FTSDKOwnership;
622
+ function compact(value) {
623
+ var source = value;
624
+ var result = {};
625
+ Object.keys(value).forEach(function(key) {
626
+ if (source[key] !== void 0)
627
+ result[key] = source[key];
628
+ });
629
+ return result;
630
+ }
631
+ function withBridgeInfo(attributes) {
632
+ var _a;
633
+ return __assign((_a = {}, _a[version_js_1.FT_COCOS_SDK_BRIDGE_INFO_KEY] = version_js_1.FT_COCOS_SDK_BRIDGE_INFO, _a), attributes || {});
634
+ }
635
+ var FTMobileAgent = (
636
+ /** @class */
637
+ (function() {
638
+ function FTMobileAgent2(transport, ownership) {
639
+ if (ownership === void 0) {
640
+ ownership = new FTSDKOwnership();
641
+ }
642
+ this.transport = transport;
643
+ this.ownership = ownership;
644
+ }
645
+ FTMobileAgent2.prototype.start = function(config) {
646
+ var _a;
647
+ if (!config.datakitUrl && !(config.datawayUrl && config.clientToken)) {
648
+ throw new TypeError("Configure datakitUrl or datawayUrl with clientToken");
649
+ }
650
+ this.ownership.claimStandalone();
651
+ this.transport.invoke("sdk.configure", compact(__assign(__assign({}, config), { globalContext: __assign(__assign({}, config.globalContext || {}), (_a = {}, _a[version_js_1.FT_COCOS_SDK_VERSION_KEY] = version_js_1.FT_COCOS_SDK_VERSION, _a)) })));
652
+ };
653
+ FTMobileAgent2.prototype.bindUser = function(user) {
654
+ this.transport.invoke("sdk.bindUser", typeof user === "string" ? { userId: (0, validation_js_1.requireText)(user, "userId") } : user);
655
+ };
656
+ FTMobileAgent2.prototype.unbindUser = function() {
657
+ this.transport.invoke("sdk.unbindUser");
658
+ };
659
+ FTMobileAgent2.prototype.shutdown = function() {
660
+ this.ownership.assertNativeHostDoesNotOwnSDK();
661
+ this.transport.invoke("sdk.shutdown");
662
+ this.ownership.releaseStandalone();
663
+ };
664
+ return FTMobileAgent2;
665
+ })()
666
+ );
667
+ exports.FTMobileAgent = FTMobileAgent;
668
+ var FTRUM = (
669
+ /** @class */
670
+ (function() {
671
+ function FTRUM2(transport, ownership) {
672
+ if (ownership === void 0) {
673
+ ownership = new FTSDKOwnership();
674
+ }
675
+ this.transport = transport;
676
+ this.ownership = ownership;
677
+ }
678
+ FTRUM2.prototype.start = function(config) {
679
+ var payload = (0, validation_js_1.validatedSamplingConfig)(config, "rum", [
680
+ ["sessionSamplingRate", "sampleRate"],
681
+ ["sessionOnErrorSamplingRate", "sessionOnErrorSampleRate"]
682
+ ]);
683
+ this.ownership.claimStandalone();
684
+ this.transport.invoke("rum.configure", compact(payload));
685
+ };
686
+ FTRUM2.prototype.startView = function(name, attributes) {
687
+ this.transport.invoke("rum.startView", {
688
+ name: (0, validation_js_1.requireText)(name, "view name"),
689
+ attributes: withBridgeInfo(attributes)
690
+ });
691
+ };
692
+ FTRUM2.prototype.stopView = function(attributes) {
693
+ this.transport.invoke("rum.stopView", { attributes: withBridgeInfo(attributes) });
694
+ };
695
+ FTRUM2.prototype.addAction = function(name, type, attributes) {
696
+ if (type === void 0) {
697
+ type = "click";
698
+ }
699
+ this.transport.invoke("rum.addAction", {
700
+ name: (0, validation_js_1.requireText)(name, "action name"),
701
+ type: (0, validation_js_1.requireText)(type, "action type"),
702
+ attributes: withBridgeInfo(attributes)
703
+ });
704
+ };
705
+ FTRUM2.prototype.startAction = function(name, type, attributes) {
706
+ if (type === void 0) {
707
+ type = "click";
708
+ }
709
+ this.transport.invoke("rum.startAction", {
710
+ name: (0, validation_js_1.requireText)(name, "action name"),
711
+ type: (0, validation_js_1.requireText)(type, "action type"),
712
+ attributes: withBridgeInfo(attributes)
713
+ });
714
+ };
715
+ FTRUM2.prototype.addError = function(message, stack, type, state, attributes) {
716
+ if (type === void 0) {
717
+ type = "cocos_error";
718
+ }
719
+ if (state === void 0) {
720
+ state = "run";
721
+ }
722
+ this.transport.invoke("rum.addError", {
723
+ message: message,
724
+ stack: stack,
725
+ type: type,
726
+ state: state,
727
+ attributes: withBridgeInfo(attributes)
728
+ });
729
+ };
730
+ FTRUM2.prototype.addLongTask = function(stack, durationNs, attributes) {
731
+ this.transport.invoke("rum.addLongTask", {
732
+ stack: stack,
733
+ durationNs: durationNs,
734
+ attributes: withBridgeInfo(attributes)
735
+ });
736
+ };
737
+ FTRUM2.prototype.startResource = function(key, attributes) {
738
+ this.transport.invoke("rum.startResource", {
739
+ key: (0, validation_js_1.requireText)(key, "resource key"),
740
+ attributes: withBridgeInfo(attributes)
741
+ });
742
+ };
743
+ FTRUM2.prototype.stopResource = function(key, attributes) {
744
+ this.transport.invoke("rum.stopResource", {
745
+ key: (0, validation_js_1.requireText)(key, "resource key"),
746
+ attributes: withBridgeInfo(attributes)
747
+ });
748
+ };
749
+ FTRUM2.prototype.addResource = function(key, content, metrics) {
750
+ this.transport.invoke("rum.addResource", {
751
+ key: (0, validation_js_1.requireText)(key, "resource key"),
752
+ content: content,
753
+ metrics: metrics
754
+ });
755
+ };
756
+ return FTRUM2;
757
+ })()
758
+ );
759
+ exports.FTRUM = FTRUM;
760
+ var FTLogger = (
761
+ /** @class */
762
+ (function() {
763
+ function FTLogger2(transport, ownership) {
764
+ if (ownership === void 0) {
765
+ ownership = new FTSDKOwnership();
766
+ }
767
+ this.transport = transport;
768
+ this.ownership = ownership;
769
+ }
770
+ FTLogger2.prototype.start = function(config) {
771
+ var payload = (0, validation_js_1.validatedSamplingConfig)(config, "logger", [
772
+ ["logSamplingRate", "sampleRate"]
773
+ ]);
774
+ this.ownership.claimStandalone();
775
+ this.transport.invoke("logger.configure", compact(payload));
776
+ };
777
+ FTLogger2.prototype.log = function(content, level, attributes) {
778
+ if (level === void 0) {
779
+ level = "info";
780
+ }
781
+ this.transport.invoke("logger.log", {
782
+ content: content,
783
+ level: level,
784
+ attributes: withBridgeInfo(attributes)
785
+ });
786
+ };
787
+ return FTLogger2;
788
+ })()
789
+ );
790
+ exports.FTLogger = FTLogger;
791
+ var FTTrace = (
792
+ /** @class */
793
+ (function() {
794
+ function FTTrace2(transport, ownership) {
795
+ if (ownership === void 0) {
796
+ ownership = new FTSDKOwnership();
797
+ }
798
+ this.transport = transport;
799
+ this.ownership = ownership;
800
+ }
801
+ FTTrace2.prototype.start = function(config) {
802
+ var payload = (0, validation_js_1.validatedSamplingConfig)(config, "trace", [
803
+ ["traceSamplingRate", "sampleRate"]
804
+ ]);
805
+ this.ownership.claimStandalone();
806
+ this.transport.invoke("trace.configure", compact(payload));
807
+ };
808
+ FTTrace2.prototype.getHeaders = function(url, resourceKey) {
809
+ return this.transport.invoke("trace.getHeaders", {
810
+ url: (0, validation_js_1.requireText)(url, "url"),
811
+ resourceKey: resourceKey
812
+ }) || {};
813
+ };
814
+ return FTTrace2;
815
+ })()
816
+ );
817
+ exports.FTTrace = FTTrace;
818
+ }
819
+ });
820
+
821
+ // packages/cocos/dist/creator2/core/client.js
822
+ var require_client = __commonJS({
823
+ "packages/cocos/dist/creator2/core/client.js": function(exports) {
824
+ "use strict";
825
+ var __assign = exports && exports.__assign || function() {
826
+ __assign = Object.assign || function(t) {
827
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
828
+ s = arguments[i];
829
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
830
+ t[p] = s[p];
831
+ }
832
+ return t;
833
+ };
834
+ return __assign.apply(this, arguments);
835
+ };
836
+ Object.defineProperty(exports, "__esModule", { value: true });
837
+ exports.FTCocosSDK = void 0;
838
+ var modules_js_1 = require_modules();
839
+ var version_js_1 = require_version();
840
+ var FTCocosSDK = (
841
+ /** @class */
842
+ (function() {
843
+ function FTCocosSDK2(transport, autoTracking, engine) {
844
+ if (engine === void 0) {
845
+ engine = "creator3";
846
+ }
847
+ this.transport = transport;
848
+ this.autoTracking = autoTracking;
849
+ this.engine = engine;
850
+ this.extensionProtocol = 1;
851
+ this.state = "idle";
852
+ this.hybridAutoTracking = {};
853
+ this.ownership = new modules_js_1.FTSDKOwnership();
854
+ this.mobile = new modules_js_1.FTMobileAgent(transport, this.ownership);
855
+ this.rum = new modules_js_1.FTRUM(transport, this.ownership);
856
+ this.logger = new modules_js_1.FTLogger(transport, this.ownership);
857
+ this.trace = new modules_js_1.FTTrace(transport, this.ownership);
858
+ }
859
+ Object.defineProperty(FTCocosSDK2.prototype, "lifecycleMode", {
860
+ /** @internal Ownership state used by the platform facade. */
861
+ get: function() {
862
+ return this.state === "standalone" ? "standalone" : this.state === "hybrid-attached" || this.state === "hybrid-entered" ? "hybrid" : "idle";
863
+ },
864
+ enumerable: false,
865
+ configurable: true
866
+ });
867
+ Object.defineProperty(FTCocosSDK2.prototype, "isCocosEntered", {
868
+ get: function() {
869
+ return this.state === "standalone" || this.state === "hybrid-entered";
870
+ },
871
+ enumerable: false,
872
+ configurable: true
873
+ });
874
+ FTCocosSDK2.prototype.registerExtension = function(id, version, engine, factory) {
875
+ if (version !== version_js_1.FT_COCOS_SDK_VERSION || engine !== this.engine) {
876
+ throw new Error("SDK extension version or Creator engine does not match the base SDK");
877
+ }
878
+ if (this.extension) {
879
+ if (id !== this.extensionId)
880
+ throw new Error("A different SDK extension is already installed");
881
+ return this.extension.value;
882
+ }
883
+ if (this.state !== "idle")
884
+ throw new Error("Install SDK extensions before start() or attach()");
885
+ var extension = factory();
886
+ this.extension = extension;
887
+ this.extensionId = id;
888
+ return extension.value;
889
+ };
890
+ FTCocosSDK2.prototype.start = function(config) {
891
+ var _a, _b, _c, _d, _e, _f, _g;
892
+ rejectReplayConfig(config);
893
+ if (this.state !== "idle") {
894
+ throw new Error("start() and attach() are mutually exclusive");
895
+ }
896
+ (_c = (_a = this.extension) === null || _a === void 0 ? void 0 : (_b = _a.lifecycle).beforeStart) === null || _c === void 0 ? void 0 : _c.call(_b);
897
+ this.mobile.start(config.sdk);
898
+ this.state = "standalone";
899
+ if (config.rum)
900
+ this.rum.start(config.rum);
901
+ if (config.logger)
902
+ this.logger.start(config.logger);
903
+ if (config.trace)
904
+ this.trace.start(config.trace);
905
+ (_f = (_d = this.extension) === null || _d === void 0 ? void 0 : (_e = _d.lifecycle).afterStart) === null || _f === void 0 ? void 0 : _f.call(_e);
906
+ if (config.autoTrack)
907
+ (_g = this.autoTracking) === null || _g === void 0 ? void 0 : _g.start(config.autoTrack);
908
+ };
909
+ FTCocosSDK2.prototype.attach = function(config) {
910
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
911
+ if (config === void 0) {
912
+ config = {};
913
+ }
914
+ rejectReplayConfig(config);
915
+ if (this.state === "standalone") {
916
+ throw new Error("start() and attach() are mutually exclusive");
917
+ }
918
+ if (this.state === "hybrid-attached" || this.state === "hybrid-entered")
919
+ return;
920
+ this.ownership.claimNativeHost();
921
+ try {
922
+ (_c = (_a = this.extension) === null || _a === void 0 ? void 0 : (_b = _a.lifecycle).beforeAttach) === null || _c === void 0 ? void 0 : _c.call(_b);
923
+ this.transport.invoke("hybrid.attach", {
924
+ sdkVersion: version_js_1.FT_COCOS_SDK_VERSION
925
+ });
926
+ if ((_d = config.autoTrack) === null || _d === void 0 ? void 0 : _d.network) {
927
+ (_e = this.autoTracking) === null || _e === void 0 ? void 0 : _e.start({ network: true }, void 0, "network");
928
+ }
929
+ } catch (error) {
930
+ try {
931
+ (_f = this.autoTracking) === null || _f === void 0 ? void 0 : _f.stop("network");
932
+ } catch (_o) {
933
+ }
934
+ try {
935
+ (_j = (_g = this.extension) === null || _g === void 0 ? void 0 : (_h = _g.lifecycle).rollbackAttach) === null || _j === void 0 ? void 0 : _j.call(_h);
936
+ } catch (_p) {
937
+ }
938
+ if (this.state === "hybrid-detached") {
939
+ try {
940
+ (_m = (_k = this.extension) === null || _k === void 0 ? void 0 : (_l = _k.lifecycle).detach) === null || _m === void 0 ? void 0 : _m.call(_l);
941
+ } catch (_q) {
942
+ }
943
+ } else {
944
+ this.ownership.releaseNativeHost();
945
+ }
946
+ throw error;
947
+ }
948
+ this.hybridAutoTracking = __assign({}, config.autoTrack || {});
949
+ this.state = "hybrid-attached";
950
+ };
951
+ FTCocosSDK2.prototype.enterCocos = function(options) {
952
+ var _a, _b, _c, _d, _e, _f, _g, _h;
953
+ if (options === void 0) {
954
+ options = {};
955
+ }
956
+ if (this.state === "standalone") {
957
+ throw new Error("enterCocos() is only available after attach()");
958
+ }
959
+ if (this.state === "idle" || this.state === "hybrid-detached") {
960
+ throw new Error("Call attach() before enterCocos()");
961
+ }
962
+ if (this.state === "hybrid-entered")
963
+ return;
964
+ var viewName = nonEmptyText(options.viewName);
965
+ if (!this.hybridAutoTracking.scenes && !viewName) {
966
+ throw new TypeError("enterCocos.viewName is required when scene tracking is disabled");
967
+ }
968
+ try {
969
+ (_c = (_a = this.extension) === null || _a === void 0 ? void 0 : (_b = _a.lifecycle).enter) === null || _c === void 0 ? void 0 : _c.call(_b);
970
+ (_d = this.autoTracking) === null || _d === void 0 ? void 0 : _d.start(this.hybridAutoTracking, viewName, "page");
971
+ this.state = "hybrid-entered";
972
+ } catch (error) {
973
+ try {
974
+ (_e = this.autoTracking) === null || _e === void 0 ? void 0 : _e.stop("page");
975
+ } catch (_j) {
976
+ }
977
+ try {
978
+ (_h = (_f = this.extension) === null || _f === void 0 ? void 0 : (_g = _f.lifecycle).leave) === null || _h === void 0 ? void 0 : _h.call(_g);
979
+ } catch (_k) {
980
+ }
981
+ throw error;
982
+ }
983
+ };
984
+ FTCocosSDK2.prototype.leaveCocos = function() {
985
+ var _a, _b, _c, _d;
986
+ if (this.state === "standalone") {
987
+ throw new Error("leaveCocos() is only available after attach()");
988
+ }
989
+ if (this.state !== "hybrid-entered")
990
+ return;
991
+ try {
992
+ (_a = this.autoTracking) === null || _a === void 0 ? void 0 : _a.stop("page");
993
+ } finally {
994
+ (_d = (_b = this.extension) === null || _b === void 0 ? void 0 : (_c = _b.lifecycle).leave) === null || _d === void 0 ? void 0 : _d.call(_c);
995
+ this.state = "hybrid-attached";
996
+ }
997
+ };
998
+ FTCocosSDK2.prototype.detach = function() {
999
+ var _this = this;
1000
+ var _a, _b, _c;
1001
+ if (this.state === "standalone")
1002
+ throw new Error("detach() is only available after attach()");
1003
+ if (this.state === "idle" || this.state === "hybrid-detached")
1004
+ return;
1005
+ var failure;
1006
+ var cleanup = function(operation) {
1007
+ try {
1008
+ operation();
1009
+ } catch (error) {
1010
+ if (failure === void 0)
1011
+ failure = error;
1012
+ }
1013
+ };
1014
+ cleanup(function() {
1015
+ return _this.leaveCocos();
1016
+ });
1017
+ cleanup(function() {
1018
+ var _a2;
1019
+ return (_a2 = _this.autoTracking) === null || _a2 === void 0 ? void 0 : _a2.stop();
1020
+ });
1021
+ if (failure !== void 0)
1022
+ throw failure;
1023
+ (_c = (_a = this.extension) === null || _a === void 0 ? void 0 : (_b = _a.lifecycle).detach) === null || _c === void 0 ? void 0 : _c.call(_b);
1024
+ this.hybridAutoTracking = {};
1025
+ this.state = "hybrid-detached";
1026
+ };
1027
+ FTCocosSDK2.prototype.shutdown = function() {
1028
+ var _this = this;
1029
+ if (this.state === "hybrid-attached" || this.state === "hybrid-entered" || this.state === "hybrid-detached") {
1030
+ throw new Error("The native host owns the native SDK; call leaveCocos() instead of shutdown()");
1031
+ }
1032
+ if (this.state === "idle")
1033
+ return;
1034
+ var failure;
1035
+ var cleanup = function(operation) {
1036
+ try {
1037
+ operation();
1038
+ } catch (error) {
1039
+ if (failure === void 0)
1040
+ failure = error;
1041
+ }
1042
+ };
1043
+ cleanup(function() {
1044
+ var _a;
1045
+ return (_a = _this.autoTracking) === null || _a === void 0 ? void 0 : _a.stop();
1046
+ });
1047
+ cleanup(function() {
1048
+ var _a, _b, _c;
1049
+ return (_c = (_a = _this.extension) === null || _a === void 0 ? void 0 : (_b = _a.lifecycle).shutdown) === null || _c === void 0 ? void 0 : _c.call(_b);
1050
+ });
1051
+ cleanup(function() {
1052
+ _this.mobile.shutdown();
1053
+ _this.state = "idle";
1054
+ });
1055
+ if (failure !== void 0)
1056
+ throw failure;
1057
+ };
1058
+ return FTCocosSDK2;
1059
+ })()
1060
+ );
1061
+ exports.FTCocosSDK = FTCocosSDK;
1062
+ function nonEmptyText(value) {
1063
+ return typeof value === "string" && value.trim().length > 0 ? value : void 0;
1064
+ }
1065
+ function rejectReplayConfig(config) {
1066
+ if ("replay" in config) {
1067
+ throw new Error("Session Replay requires @cloudcare/cocos-session-replay. Install the package and use withSessionReplay() before passing replay configuration.");
1068
+ }
1069
+ }
1070
+ }
1071
+ });
1072
+
1073
+ // packages/cocos/dist/creator2/core/transport.js
1074
+ var require_transport = __commonJS({
1075
+ "packages/cocos/dist/creator2/core/transport.js": function(exports) {
1076
+ "use strict";
1077
+ Object.defineProperty(exports, "__esModule", { value: true });
1078
+ exports.FTNoopTransport = void 0;
1079
+ exports.parseTransportResponse = parseTransportResponse;
1080
+ var FTNoopTransport = (
1081
+ /** @class */
1082
+ (function() {
1083
+ function FTNoopTransport2() {
1084
+ this.platform = "unsupported";
1085
+ }
1086
+ FTNoopTransport2.prototype.invoke = function(_method, _payload) {
1087
+ return void 0;
1088
+ };
1089
+ return FTNoopTransport2;
1090
+ })()
1091
+ );
1092
+ exports.FTNoopTransport = FTNoopTransport;
1093
+ function parseTransportResponse(raw) {
1094
+ if (raw === void 0 || raw === null || raw === "")
1095
+ return void 0;
1096
+ var response = raw;
1097
+ if (typeof raw === "string") {
1098
+ response = JSON.parse(raw);
1099
+ }
1100
+ if (!isResponse(response)) {
1101
+ return response;
1102
+ }
1103
+ if (!response.ok) {
1104
+ throw new Error(response.error || "Native bridge call failed");
1105
+ }
1106
+ return response.value;
1107
+ }
1108
+ function isResponse(value) {
1109
+ return typeof value === "object" && value !== null && "ok" in value;
1110
+ }
1111
+ }
1112
+ });
1113
+
1114
+ // packages/cocos/dist/creator2/core/platform-runtime.js
1115
+ var require_platform_runtime = __commonJS({
1116
+ "packages/cocos/dist/creator2/core/platform-runtime.js": function(exports) {
1117
+ "use strict";
1118
+ Object.defineProperty(exports, "__esModule", { value: true });
1119
+ exports.platformGlobal = platformGlobal;
1120
+ exports.existingPlatformImplementation = existingPlatformImplementation;
1121
+ exports.platformImplementation = platformImplementation;
1122
+ var version_js_1 = require_version();
1123
+ function platformGlobal() {
1124
+ return typeof window !== "undefined" ? window : globalThis;
1125
+ }
1126
+ function existingPlatformImplementation(context, target) {
1127
+ var _a;
1128
+ if (target === void 0) {
1129
+ target = platformGlobal();
1130
+ }
1131
+ var previous = (_a = target.__FT_COCOS_INSTANCES__) === null || _a === void 0 ? void 0 : _a[context.engine + ":" + context.platform];
1132
+ if (previous && previous.version !== version_js_1.FT_COCOS_SDK_VERSION)
1133
+ throw new Error("Cocos SDK versions must match on the same page");
1134
+ return previous === null || previous === void 0 ? void 0 : previous.sdk;
1135
+ }
1136
+ function platformImplementation(context, target, create) {
1137
+ if (target === void 0) {
1138
+ target = platformGlobal();
1139
+ }
1140
+ var key = context.engine + ":" + context.platform;
1141
+ var instances = target.__FT_COCOS_INSTANCES__ || (target.__FT_COCOS_INSTANCES__ = {});
1142
+ var previous = existingPlatformImplementation(context, target);
1143
+ if (previous)
1144
+ return previous;
1145
+ var factory = context.platform === "web" ? target.__FT_COCOS_WEB_FACTORY__ : target.__FT_COCOS_NATIVE_FACTORY__;
1146
+ if (!create && (!factory || factory.protocol !== 1 || factory.version !== version_js_1.FT_COCOS_SDK_VERSION)) {
1147
+ throw new Error(context.platform === "web" ? "Cocos Web runtime is missing or incompatible. Run the installer with --web and rebuild, or load /web/bootstrap before game scripts." : "Cocos native runtime is missing or incompatible. Rerun the SDK installer and rebuild the project.");
1148
+ }
1149
+ var sdk = create ? create() : factory.create(context, target);
1150
+ instances[key] = { version: version_js_1.FT_COCOS_SDK_VERSION, sdk: sdk };
1151
+ return sdk;
1152
+ }
1153
+ }
1154
+ });
1155
+
1156
+ // packages/cocos/dist/creator2/native/bootstrap.js
1157
+ var require_bootstrap = __commonJS({
1158
+ "packages/cocos/dist/creator2/native/bootstrap.js": function(exports) {
1159
+ Object.defineProperty(exports, "__esModule", { value: true });
1160
+ var auto_tracking_js_1 = require_auto_tracking();
1161
+ var client_js_1 = require_client();
1162
+ var modules_js_1 = require_modules();
1163
+ var transport_js_1 = require_transport();
1164
+ var platform_runtime_js_1 = require_platform_runtime();
1165
+ var version_js_1 = require_version();
1166
+ (0, platform_runtime_js_1.platformGlobal)().__FT_COCOS_NATIVE_FACTORY__ = {
1167
+ protocol: 1,
1168
+ version: version_js_1.FT_COCOS_SDK_VERSION,
1169
+ create: function(context) {
1170
+ if (context.platform === "web")
1171
+ throw new Error("Native runtime cannot serve a Web application");
1172
+ var transport = {
1173
+ platform: context.platform,
1174
+ invoke: function(method, payload) {
1175
+ if (context.platform === "unsupported")
1176
+ return void 0;
1177
+ if (!context.reflection)
1178
+ throw new Error("Cocos native reflection is unavailable");
1179
+ var json = payload === void 0 ? "{}" : JSON.stringify(payload);
1180
+ var raw = context.platform === "android" ? context.reflection.callStaticMethod("com/ft/sdk/cocos/FTCocosBridge", "invoke", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", method, json) : context.reflection.callStaticMethod("FTCocosBridge", "invoke:payload:", method, json);
1181
+ return (0, transport_js_1.parseTransportResponse)(raw);
1182
+ }
1183
+ };
1184
+ var tracking = new auto_tracking_js_1.FTDefaultAutoTracking(new modules_js_1.FTRUM(transport), new modules_js_1.FTLogger(transport), new modules_js_1.FTTrace(transport), context.hooks);
1185
+ return new client_js_1.FTCocosSDK(transport, tracking, context.engine);
1186
+ }
1187
+ };
1188
+ }
1189
+ });
1190
+ require_bootstrap();
1191
+ })();