@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,1042 @@
1
+ "use strict";
2
+ var CocosWebSDK = (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/validation.js
15
+ var require_validation = __commonJS({
16
+ "packages/cocos/dist/creator2/core/validation.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
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.samplingRate = samplingRate;
31
+ exports.samplingPercentage = samplingPercentage;
32
+ exports.validatedSamplingConfig = validatedSamplingConfig;
33
+ exports.requireText = requireText;
34
+ function samplingRate(value, name) {
35
+ if (value === void 0)
36
+ return void 0;
37
+ if (!Number.isFinite(value) || value < 0 || value > 1) {
38
+ throw new RangeError("".concat(name, " must be between 0 and 1"));
39
+ }
40
+ return value;
41
+ }
42
+ function samplingPercentage(value, name) {
43
+ if (value === void 0)
44
+ return void 0;
45
+ if (!Number.isFinite(value) || value < 0 || value > 100) {
46
+ throw new RangeError("".concat(name, " must be between 0 and 100"));
47
+ }
48
+ return value;
49
+ }
50
+ function validatedSamplingConfig(config, scope, fields) {
51
+ var result = __assign({}, config);
52
+ fields.forEach(function(_a) {
53
+ var percentageField = _a[0], legacyField = _a[1];
54
+ var percentage = result[percentageField];
55
+ if (percentage !== void 0) {
56
+ samplingPercentage(percentage, "".concat(scope, ".").concat(percentageField));
57
+ delete result[legacyField];
58
+ return;
59
+ }
60
+ samplingRate(result[legacyField], "".concat(scope, ".").concat(legacyField));
61
+ });
62
+ return result;
63
+ }
64
+ function requireText(value, name) {
65
+ if (!value.trim())
66
+ throw new TypeError("".concat(name, " must not be empty"));
67
+ return value;
68
+ }
69
+ }
70
+ });
71
+
72
+ // packages/cocos/dist/creator2/core/version.js
73
+ var require_version = __commonJS({
74
+ "packages/cocos/dist/creator2/core/version.js": function(exports) {
75
+ "use strict";
76
+ Object.defineProperty(exports, "__esModule", { value: true });
77
+ 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;
78
+ exports.FT_COCOS_SDK_VERSION = "0.1.1-alpha.2";
79
+ exports.FT_COCOS_SDK_VERSION_KEY = "sdk_package_cocos";
80
+ exports.FT_COCOS_SDK_BRIDGE_INFO_KEY = "sdk_bridge_info";
81
+ exports.FT_COCOS_SDK_BRIDGE_INFO = JSON.stringify({
82
+ cocos: exports.FT_COCOS_SDK_VERSION
83
+ });
84
+ }
85
+ });
86
+
87
+ // packages/cocos/dist/creator2/core/modules.js
88
+ var require_modules = __commonJS({
89
+ "packages/cocos/dist/creator2/core/modules.js": function(exports) {
90
+ "use strict";
91
+ var __assign = exports && exports.__assign || function() {
92
+ __assign = Object.assign || function(t) {
93
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
94
+ s = arguments[i];
95
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
96
+ t[p] = s[p];
97
+ }
98
+ return t;
99
+ };
100
+ return __assign.apply(this, arguments);
101
+ };
102
+ Object.defineProperty(exports, "__esModule", { value: true });
103
+ exports.FTTrace = exports.FTLogger = exports.FTRUM = exports.FTMobileAgent = exports.FTSDKOwnership = void 0;
104
+ var validation_js_1 = require_validation();
105
+ var version_js_1 = require_version();
106
+ var FTSDKOwnership = (
107
+ /** @class */
108
+ (function() {
109
+ function FTSDKOwnership2() {
110
+ this.mode = "unclaimed";
111
+ }
112
+ FTSDKOwnership2.prototype.claimStandalone = function() {
113
+ if (this.mode === "native-host") {
114
+ throw new Error("The native host owns SDK initialization in Hybrid mode");
115
+ }
116
+ this.mode = "standalone";
117
+ };
118
+ FTSDKOwnership2.prototype.claimNativeHost = function() {
119
+ if (this.mode === "standalone") {
120
+ throw new Error("Standalone initialization and native-host attachment are mutually exclusive");
121
+ }
122
+ this.mode = "native-host";
123
+ };
124
+ FTSDKOwnership2.prototype.releaseNativeHost = function() {
125
+ if (this.mode === "native-host")
126
+ this.mode = "unclaimed";
127
+ };
128
+ FTSDKOwnership2.prototype.releaseStandalone = function() {
129
+ if (this.mode === "standalone")
130
+ this.mode = "unclaimed";
131
+ };
132
+ FTSDKOwnership2.prototype.assertNativeHostDoesNotOwnSDK = function() {
133
+ if (this.mode === "native-host") {
134
+ throw new Error("The native host owns the native SDK in Hybrid mode");
135
+ }
136
+ };
137
+ return FTSDKOwnership2;
138
+ })()
139
+ );
140
+ exports.FTSDKOwnership = FTSDKOwnership;
141
+ function compact(value) {
142
+ var source = value;
143
+ var result = {};
144
+ Object.keys(value).forEach(function(key) {
145
+ if (source[key] !== void 0)
146
+ result[key] = source[key];
147
+ });
148
+ return result;
149
+ }
150
+ function withBridgeInfo(attributes) {
151
+ var _a;
152
+ return __assign((_a = {}, _a[version_js_1.FT_COCOS_SDK_BRIDGE_INFO_KEY] = version_js_1.FT_COCOS_SDK_BRIDGE_INFO, _a), attributes || {});
153
+ }
154
+ var FTMobileAgent = (
155
+ /** @class */
156
+ (function() {
157
+ function FTMobileAgent2(transport, ownership) {
158
+ if (ownership === void 0) {
159
+ ownership = new FTSDKOwnership();
160
+ }
161
+ this.transport = transport;
162
+ this.ownership = ownership;
163
+ }
164
+ FTMobileAgent2.prototype.start = function(config) {
165
+ var _a;
166
+ if (!config.datakitUrl && !(config.datawayUrl && config.clientToken)) {
167
+ throw new TypeError("Configure datakitUrl or datawayUrl with clientToken");
168
+ }
169
+ this.ownership.claimStandalone();
170
+ 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)) })));
171
+ };
172
+ FTMobileAgent2.prototype.bindUser = function(user) {
173
+ this.transport.invoke("sdk.bindUser", typeof user === "string" ? { userId: (0, validation_js_1.requireText)(user, "userId") } : user);
174
+ };
175
+ FTMobileAgent2.prototype.unbindUser = function() {
176
+ this.transport.invoke("sdk.unbindUser");
177
+ };
178
+ FTMobileAgent2.prototype.shutdown = function() {
179
+ this.ownership.assertNativeHostDoesNotOwnSDK();
180
+ this.transport.invoke("sdk.shutdown");
181
+ this.ownership.releaseStandalone();
182
+ };
183
+ return FTMobileAgent2;
184
+ })()
185
+ );
186
+ exports.FTMobileAgent = FTMobileAgent;
187
+ var FTRUM = (
188
+ /** @class */
189
+ (function() {
190
+ function FTRUM2(transport, ownership) {
191
+ if (ownership === void 0) {
192
+ ownership = new FTSDKOwnership();
193
+ }
194
+ this.transport = transport;
195
+ this.ownership = ownership;
196
+ }
197
+ FTRUM2.prototype.start = function(config) {
198
+ var payload = (0, validation_js_1.validatedSamplingConfig)(config, "rum", [
199
+ ["sessionSamplingRate", "sampleRate"],
200
+ ["sessionOnErrorSamplingRate", "sessionOnErrorSampleRate"]
201
+ ]);
202
+ this.ownership.claimStandalone();
203
+ this.transport.invoke("rum.configure", compact(payload));
204
+ };
205
+ FTRUM2.prototype.startView = function(name, attributes) {
206
+ this.transport.invoke("rum.startView", {
207
+ name: (0, validation_js_1.requireText)(name, "view name"),
208
+ attributes: withBridgeInfo(attributes)
209
+ });
210
+ };
211
+ FTRUM2.prototype.stopView = function(attributes) {
212
+ this.transport.invoke("rum.stopView", { attributes: withBridgeInfo(attributes) });
213
+ };
214
+ FTRUM2.prototype.addAction = function(name, type, attributes) {
215
+ if (type === void 0) {
216
+ type = "click";
217
+ }
218
+ this.transport.invoke("rum.addAction", {
219
+ name: (0, validation_js_1.requireText)(name, "action name"),
220
+ type: (0, validation_js_1.requireText)(type, "action type"),
221
+ attributes: withBridgeInfo(attributes)
222
+ });
223
+ };
224
+ FTRUM2.prototype.startAction = function(name, type, attributes) {
225
+ if (type === void 0) {
226
+ type = "click";
227
+ }
228
+ this.transport.invoke("rum.startAction", {
229
+ name: (0, validation_js_1.requireText)(name, "action name"),
230
+ type: (0, validation_js_1.requireText)(type, "action type"),
231
+ attributes: withBridgeInfo(attributes)
232
+ });
233
+ };
234
+ FTRUM2.prototype.addError = function(message, stack, type, state, attributes) {
235
+ if (type === void 0) {
236
+ type = "cocos_error";
237
+ }
238
+ if (state === void 0) {
239
+ state = "run";
240
+ }
241
+ this.transport.invoke("rum.addError", {
242
+ message: message,
243
+ stack: stack,
244
+ type: type,
245
+ state: state,
246
+ attributes: withBridgeInfo(attributes)
247
+ });
248
+ };
249
+ FTRUM2.prototype.addLongTask = function(stack, durationNs, attributes) {
250
+ this.transport.invoke("rum.addLongTask", {
251
+ stack: stack,
252
+ durationNs: durationNs,
253
+ attributes: withBridgeInfo(attributes)
254
+ });
255
+ };
256
+ FTRUM2.prototype.startResource = function(key, attributes) {
257
+ this.transport.invoke("rum.startResource", {
258
+ key: (0, validation_js_1.requireText)(key, "resource key"),
259
+ attributes: withBridgeInfo(attributes)
260
+ });
261
+ };
262
+ FTRUM2.prototype.stopResource = function(key, attributes) {
263
+ this.transport.invoke("rum.stopResource", {
264
+ key: (0, validation_js_1.requireText)(key, "resource key"),
265
+ attributes: withBridgeInfo(attributes)
266
+ });
267
+ };
268
+ FTRUM2.prototype.addResource = function(key, content, metrics) {
269
+ this.transport.invoke("rum.addResource", {
270
+ key: (0, validation_js_1.requireText)(key, "resource key"),
271
+ content: content,
272
+ metrics: metrics
273
+ });
274
+ };
275
+ return FTRUM2;
276
+ })()
277
+ );
278
+ exports.FTRUM = FTRUM;
279
+ var FTLogger = (
280
+ /** @class */
281
+ (function() {
282
+ function FTLogger2(transport, ownership) {
283
+ if (ownership === void 0) {
284
+ ownership = new FTSDKOwnership();
285
+ }
286
+ this.transport = transport;
287
+ this.ownership = ownership;
288
+ }
289
+ FTLogger2.prototype.start = function(config) {
290
+ var payload = (0, validation_js_1.validatedSamplingConfig)(config, "logger", [
291
+ ["logSamplingRate", "sampleRate"]
292
+ ]);
293
+ this.ownership.claimStandalone();
294
+ this.transport.invoke("logger.configure", compact(payload));
295
+ };
296
+ FTLogger2.prototype.log = function(content, level, attributes) {
297
+ if (level === void 0) {
298
+ level = "info";
299
+ }
300
+ this.transport.invoke("logger.log", {
301
+ content: content,
302
+ level: level,
303
+ attributes: withBridgeInfo(attributes)
304
+ });
305
+ };
306
+ return FTLogger2;
307
+ })()
308
+ );
309
+ exports.FTLogger = FTLogger;
310
+ var FTTrace = (
311
+ /** @class */
312
+ (function() {
313
+ function FTTrace2(transport, ownership) {
314
+ if (ownership === void 0) {
315
+ ownership = new FTSDKOwnership();
316
+ }
317
+ this.transport = transport;
318
+ this.ownership = ownership;
319
+ }
320
+ FTTrace2.prototype.start = function(config) {
321
+ var payload = (0, validation_js_1.validatedSamplingConfig)(config, "trace", [
322
+ ["traceSamplingRate", "sampleRate"]
323
+ ]);
324
+ this.ownership.claimStandalone();
325
+ this.transport.invoke("trace.configure", compact(payload));
326
+ };
327
+ FTTrace2.prototype.getHeaders = function(url, resourceKey) {
328
+ return this.transport.invoke("trace.getHeaders", {
329
+ url: (0, validation_js_1.requireText)(url, "url"),
330
+ resourceKey: resourceKey
331
+ }) || {};
332
+ };
333
+ return FTTrace2;
334
+ })()
335
+ );
336
+ exports.FTTrace = FTTrace;
337
+ }
338
+ });
339
+
340
+ // packages/cocos/dist/creator2/web/runtime.js
341
+ var require_runtime = __commonJS({
342
+ "packages/cocos/dist/creator2/web/runtime.js": function(exports) {
343
+ "use strict";
344
+ var __assign = exports && exports.__assign || function() {
345
+ __assign = Object.assign || function(t) {
346
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
347
+ s = arguments[i];
348
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
349
+ t[p] = s[p];
350
+ }
351
+ return t;
352
+ };
353
+ return __assign.apply(this, arguments);
354
+ };
355
+ var __spreadArray = exports && exports.__spreadArray || function(to, from, pack) {
356
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
357
+ if (ar || !(i in from)) {
358
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
359
+ ar[i] = from[i];
360
+ }
361
+ }
362
+ return to.concat(ar || Array.prototype.slice.call(from));
363
+ };
364
+ Object.defineProperty(exports, "__esModule", { value: true });
365
+ exports.FTWebRuntime = void 0;
366
+ exports.bootstrapWeb = bootstrapWeb;
367
+ var validation_js_1 = require_validation();
368
+ var version_js_1 = require_version();
369
+ var TRACE_TYPES = {
370
+ ddTrace: "ddtrace",
371
+ zipkinMultiHeader: "zipkin",
372
+ zipkinSingleHeader: "zipkin_single_header",
373
+ traceparent: "w3c_traceparent",
374
+ skywalking: "skywalking_v3",
375
+ jaeger: "jaeger"
376
+ };
377
+ var FTWebRuntime = (
378
+ /** @class */
379
+ (function() {
380
+ function FTWebRuntime2(config, target, beforeEngine) {
381
+ if (beforeEngine === void 0) {
382
+ beforeEngine = false;
383
+ }
384
+ var _this = this;
385
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
386
+ this.config = config;
387
+ this.protocol = 1;
388
+ this.replayStarted = false;
389
+ config = JSON.parse(JSON.stringify(config));
390
+ this.config = config;
391
+ var web = config.web;
392
+ if (!web)
393
+ throw new Error("Configure web explicitly before starting the Web SDK");
394
+ var connection = reportingConnection(web);
395
+ var replay = web.replay;
396
+ if (replay) {
397
+ var keys = ["enabled", "sessionReplaySamplingRate", "sessionReplayOnErrorSamplingRate", "canvasPrivacy", "canvasId", "captureFps", "maxImageDimension", "quality", "maxFrameBytes"];
398
+ for (var _i = 0, _v = Object.keys(replay); _i < _v.length; _i++) {
399
+ var key = _v[_i];
400
+ if (!keys.includes(key))
401
+ throw new Error("Unsupported web.replay.".concat(key));
402
+ }
403
+ }
404
+ if (!config.rum && !config.logger)
405
+ throw new Error("Enable rum or logger for Web collection");
406
+ if (!config.rum && (((_a = config.autoTrack) === null || _a === void 0 ? void 0 : _a.scenes) || ((_b = config.autoTrack) === null || _b === void 0 ? void 0 : _b.actions) || ((_c = config.autoTrack) === null || _c === void 0 ? void 0 : _c.errors) || ((_d = config.autoTrack) === null || _d === void 0 ? void 0 : _d.network)))
407
+ throw new Error("Cocos RUM tracking requires rum configuration");
408
+ if (config.trace && !config.rum)
409
+ throw new Error("Web tracing requires RUM");
410
+ if (((_e = config.autoTrack) === null || _e === void 0 ? void 0 : _e.console) && !config.logger)
411
+ throw new Error("Console tracking requires logger");
412
+ if (replay && (!beforeEngine || !config.rum))
413
+ throw new Error("Web Replay must be configured before engine boot with RUM enabled");
414
+ if (replay && replay.enabled !== true)
415
+ throw new Error("Web Replay requires enabled: true");
416
+ if ((replay === null || replay === void 0 ? void 0 : replay.canvasPrivacy) !== void 0 && !["block", "allow"].includes(replay.canvasPrivacy)) {
417
+ throw new Error("web.replay.canvasPrivacy must be block or allow");
418
+ }
419
+ var fps = integer(replay === null || replay === void 0 ? void 0 : replay.captureFps, 1, 5, 1, "captureFps");
420
+ var dimension = integer(replay === null || replay === void 0 ? void 0 : replay.maxImageDimension, 1, 2048, 720, "maxImageDimension");
421
+ if (web.outsideViewName !== void 0 && !web.outsideViewName.trim())
422
+ throw new Error("outsideViewName must not be empty");
423
+ if ((_f = web.allowedTracingUrls) === null || _f === void 0 ? void 0 : _f.some(function(url) {
424
+ return typeof url !== "string" || !/^https?:\/\//.test(url);
425
+ })) {
426
+ throw new Error("allowedTracingUrls must contain absolute HTTP(S) URL prefixes");
427
+ }
428
+ if ((replay === null || replay === void 0 ? void 0 : replay.quality) !== void 0 && !(typeof replay.quality === "number" ? Number.isFinite(replay.quality) && replay.quality >= 0 && replay.quality <= 1 : ["low", "medium", "high"].includes(replay.quality)))
429
+ throw new Error("web.replay.quality must be low, medium, high, or a number between 0 and 1");
430
+ var quality = (replay === null || replay === void 0 ? void 0 : replay.quality) === "low" ? 0.25 : (replay === null || replay === void 0 ? void 0 : replay.quality) === "medium" ? 0.4 : (replay === null || replay === void 0 ? void 0 : replay.quality) === "high" ? 0.5 : (_g = replay === null || replay === void 0 ? void 0 : replay.quality) !== null && _g !== void 0 ? _g : 0.4;
431
+ var maxBytes = integer(replay === null || replay === void 0 ? void 0 : replay.maxFrameBytes, 1024, 1048576, 4e4, "web.replay.maxFrameBytes");
432
+ var common = __assign(__assign({}, connection), { service: (_h = config.sdk) === null || _h === void 0 ? void 0 : _h.serviceName, env: (_j = config.sdk) === null || _j === void 0 ? void 0 : _j.env, telemetrySampleRate: 0 });
433
+ var rumConfig = config.rum ? __assign(__assign({}, common), {
434
+ applicationId: required(web.applicationId, "web.applicationId"),
435
+ sessionSampleRate: percentage(config.rum.sessionSamplingRate, config.rum.sampleRate, 100, "sessionSamplingRate"),
436
+ sessionOnErrorSampleRate: percentage(config.rum.sessionOnErrorSamplingRate, config.rum.sessionOnErrorSampleRate, 0, "sessionOnErrorSamplingRate"),
437
+ trackViewsManually: true,
438
+ trackUserInteractions: false,
439
+ sessionReplaySampleRate: percentage(replay === null || replay === void 0 ? void 0 : replay.sessionReplaySamplingRate, void 0, replay ? 100 : 0, "sessionReplaySamplingRate"),
440
+ sessionReplayOnErrorSampleRate: percentage(replay === null || replay === void 0 ? void 0 : replay.sessionReplayOnErrorSamplingRate, void 0, 0, "sessionReplayOnErrorSamplingRate"),
441
+ allowedTracingUrls: config.trace ? web.allowedTracingUrls || [] : [],
442
+ tracingSampleRate: percentage((_k = config.trace) === null || _k === void 0 ? void 0 : _k.traceSamplingRate, (_l = config.trace) === null || _l === void 0 ? void 0 : _l.sampleRate, 100, "traceSamplingRate"),
443
+ traceType: TRACE_TYPES[((_m = config.trace) === null || _m === void 0 ? void 0 : _m.traceType) || "ddTrace"],
444
+ replayCanvasEnabled: !!replay,
445
+ replayCanvasMode: "auto",
446
+ replayCanvasSampling: fps,
447
+ replayCanvasAutoInterval: 1e3 / fps,
448
+ // The WebGL plugin otherwise retains a 1000ms cooldown, overriding higher target FPS.
449
+ // One in-flight encode and the capture interval bound load; 1ms is the minimum accepted cooldown.
450
+ replayCanvasAutoCooldown: 1,
451
+ replayCanvasQuality: quality,
452
+ replayCanvasMaxEncodedBytes: maxBytes,
453
+ replayCanvasMaxCanvasSize: dimension,
454
+ replayCanvasMaxConcurrentEncodes: 1,
455
+ replayCanvasAutoMaxPerRun: 1,
456
+ defaultPrivacyLevel: "mask",
457
+ shouldRecordCanvas: function(canvas) {
458
+ var _a2;
459
+ if (!_this.replayStarted || (replay === null || replay === void 0 ? void 0 : replay.canvasPrivacy) !== "allow" || canvas.id !== (replay.canvasId || "GameCanvas"))
460
+ return false;
461
+ try {
462
+ return ((_a2 = _this.privacyCheck) === null || _a2 === void 0 ? void 0 : _a2.call(_this)) === true;
463
+ } catch (_b2) {
464
+ return false;
465
+ }
466
+ },
467
+ beforeSend: function(event) {
468
+ var _a2, _b2, _c2;
469
+ var manual = !!((_a2 = event.context) === null || _a2 === void 0 ? void 0 : _a2[version_js_1.FT_COCOS_SDK_BRIDGE_INFO_KEY]);
470
+ if (event.type === "resource")
471
+ return ((_b2 = config.autoTrack) === null || _b2 === void 0 ? void 0 : _b2.network) === true;
472
+ if (event.type === "error")
473
+ return manual || ((_c2 = config.autoTrack) === null || _c2 === void 0 ? void 0 : _c2.errors) === true;
474
+ if (event.type === "long_task")
475
+ return web.trackLongTasks === true;
476
+ return true;
477
+ }
478
+ }) : void 0;
479
+ var logsConfig = config.logger ? __assign(__assign({}, common), { sessionSampleRate: percentage(config.logger.logSamplingRate, config.logger.sampleRate, 100, "logSamplingRate"), forwardErrorsToLogs: false, forwardConsoleLogs: [], forwardReports: [] }) : void 0;
480
+ this.rum = rumConfig ? target.DATAFLUX_RUM : void 0;
481
+ this.logs = logsConfig ? target.DATAFLUX_LOGS : void 0;
482
+ if (rumConfig && (!this.rum || typeof this.rum.getInitConfiguration !== "function"))
483
+ throw new Error("Load the Browser RUM bundle before Cocos");
484
+ if (logsConfig && (!this.logs || typeof this.logs.getInitConfiguration !== "function"))
485
+ throw new Error("Load the Browser Logs bundle before Cocos");
486
+ if (((_o = this.rum) === null || _o === void 0 ? void 0 : _o.getInitConfiguration()) || ((_p = this.logs) === null || _p === void 0 ? void 0 : _p.getInitConfiguration()))
487
+ throw new Error("Browser SDK already initialized; use the page bootstrap and attach()");
488
+ if (replay && !((_q = target.DATAFLUX_RUM_WEBGL) === null || _q === void 0 ? void 0 : _q.webglReplayPlugin))
489
+ throw new Error("Load the Browser WebGL bundle before Cocos");
490
+ if (rumConfig && this.rum) {
491
+ var accepted_1 = false;
492
+ var ownershipPlugin = { name: "cocos-adapter", onInit: function() {
493
+ accepted_1 = true;
494
+ } };
495
+ this.rum.init(__assign(__assign({}, rumConfig), { plugins: __spreadArray([ownershipPlugin], replay ? [target.DATAFLUX_RUM_WEBGL.webglReplayPlugin()] : [], true) }));
496
+ if (!accepted_1)
497
+ throw new Error("Browser RUM is already initialized or did not accept Cocos initialization");
498
+ this.setContext(this.rum, __assign(__assign({}, (_r = config.sdk) === null || _r === void 0 ? void 0 : _r.globalContext), (_s = config.rum) === null || _s === void 0 ? void 0 : _s.globalContext));
499
+ this.rum.startView({ name: web.outsideViewName || "CocosInactive" });
500
+ if (!this.rum.getInitConfiguration())
501
+ throw new Error("Browser RUM rejected its configuration");
502
+ this.rum.stopSessionReplayRecording();
503
+ }
504
+ if (logsConfig && this.logs) {
505
+ this.logs.init(logsConfig);
506
+ if (!this.logs.getInitConfiguration())
507
+ throw new Error("Browser Logs rejected its configuration");
508
+ this.setContext(this.logs, __assign(__assign({}, (_t = config.sdk) === null || _t === void 0 ? void 0 : _t.globalContext), (_u = config.logger) === null || _u === void 0 ? void 0 : _u.globalContext));
509
+ }
510
+ }
511
+ FTWebRuntime2.prototype.claim = function(owner) {
512
+ if (this.owner && this.owner !== owner)
513
+ throw new Error("Another Cocos facade already owns this page attachment");
514
+ this.owner = owner;
515
+ };
516
+ FTWebRuntime2.prototype.release = function(owner) {
517
+ if (this.owner !== owner)
518
+ return;
519
+ this.stopReplay();
520
+ this.privacyCheck = void 0;
521
+ this.owner = void 0;
522
+ };
523
+ FTWebRuntime2.prototype.setPrivacyCheck = function(owner, check) {
524
+ if (this.owner !== owner)
525
+ throw new Error("Attach the Web SDK before configuring privacy");
526
+ this.privacyCheck = check;
527
+ };
528
+ FTWebRuntime2.prototype.startReplay = function() {
529
+ if (!this.config.web.replay)
530
+ throw new Error("Configure Web Replay in the pre-engine bootstrap");
531
+ this.replayStarted = true;
532
+ this.rum.startSessionReplayRecording();
533
+ };
534
+ FTWebRuntime2.prototype.stopReplay = function() {
535
+ var _a;
536
+ if (!this.replayStarted)
537
+ return;
538
+ this.replayStarted = false;
539
+ (_a = this.rum) === null || _a === void 0 ? void 0 : _a.stopSessionReplayRecording();
540
+ };
541
+ FTWebRuntime2.prototype.isRecording = function() {
542
+ var _a;
543
+ return this.replayStarted && !!((_a = this.rum) === null || _a === void 0 ? void 0 : _a.isRecording());
544
+ };
545
+ FTWebRuntime2.prototype.invoke = function(method, input) {
546
+ var _a, _b, _c, _d;
547
+ var data = input || {};
548
+ switch (method) {
549
+ case "sdk.bindUser": {
550
+ var user = data;
551
+ var identity = __assign(__assign({}, user.extra), { id: required(user.userId, "userId"), name: user.userName, email: user.userEmail });
552
+ (_a = this.rum) === null || _a === void 0 ? void 0 : _a.setUser(identity);
553
+ (_b = this.logs) === null || _b === void 0 ? void 0 : _b.setUser(identity);
554
+ break;
555
+ }
556
+ case "sdk.unbindUser":
557
+ (_c = this.rum) === null || _c === void 0 ? void 0 : _c.clearUser();
558
+ (_d = this.logs) === null || _d === void 0 ? void 0 : _d.clearUser();
559
+ break;
560
+ case "rum.startView":
561
+ this.requireRum().startView({ name: data.name, context: data.attributes });
562
+ break;
563
+ case "rum.stopView":
564
+ this.requireRum().startView({ name: this.config.web.outsideViewName || "CocosInactive", context: data.attributes });
565
+ break;
566
+ case "rum.addAction":
567
+ this.requireRum().addTypeAction(data.name, data.type, data.attributes);
568
+ break;
569
+ case "rum.addError": {
570
+ var error = new Error(data.message);
571
+ error.name = data.type;
572
+ error.stack = data.stack;
573
+ this.requireRum().addError(error, __assign(__assign({}, data.attributes), { cocos_error_state: data.state }));
574
+ break;
575
+ }
576
+ case "logger.log": {
577
+ if (!this.logs)
578
+ throw new Error("Web logging was not enabled");
579
+ var config = this.config.logger;
580
+ if (config.enableCustomLog === false || config.logLevelFilters && config.logLevelFilters.indexOf(data.level) < 0)
581
+ break;
582
+ var status_1 = data.level === "warning" ? "warn" : data.level;
583
+ if (["ok", "debug", "info", "notice", "warn", "error", "critical", "alert", "emerg"].indexOf(status_1) < 0) {
584
+ throw new Error("Unsupported Browser log level: ".concat(data.level));
585
+ }
586
+ this.logs.logger.log(data.content, data.attributes, status_1);
587
+ break;
588
+ }
589
+ default:
590
+ throw new Error("".concat(method, " is not supported on Web. Configure collectors at page bootstrap; use Browser automatic network/trace collection and detach() for Cocos cleanup."));
591
+ }
592
+ return void 0;
593
+ };
594
+ FTWebRuntime2.prototype.requireRum = function() {
595
+ if (!this.rum)
596
+ throw new Error("Web RUM was not enabled");
597
+ return this.rum;
598
+ };
599
+ FTWebRuntime2.prototype.setContext = function(api, context) {
600
+ Object.keys(context).forEach(function(key) {
601
+ return api.setGlobalContextProperty(key, context[key]);
602
+ });
603
+ api.setGlobalContextProperty(version_js_1.FT_COCOS_SDK_VERSION_KEY, version_js_1.FT_COCOS_SDK_VERSION);
604
+ };
605
+ return FTWebRuntime2;
606
+ })()
607
+ );
608
+ exports.FTWebRuntime = FTWebRuntime;
609
+ function bootstrapWeb(config, target) {
610
+ if (target === void 0) {
611
+ target = window;
612
+ }
613
+ if (target.__FT_COCOS_WEB__)
614
+ throw new Error("Cocos Web bootstrap already initialized");
615
+ var runtime = new FTWebRuntime(config, target, true);
616
+ target.__FT_COCOS_WEB__ = runtime;
617
+ return runtime;
618
+ }
619
+ function required(value, name) {
620
+ if (typeof value !== "string" || !value.trim())
621
+ throw new Error("".concat(name, " is required"));
622
+ return value;
623
+ }
624
+ function reportingConnection(web) {
625
+ if (web.datakitOrigin && (web.site || web.clientToken))
626
+ throw new Error("Choose datakitOrigin or site with clientToken");
627
+ var origin = required(web.datakitOrigin || web.site, "web.datakitOrigin or web.site");
628
+ if (!/^https?:\/\/[^/?#@]+\/?$/.test(origin))
629
+ throw new Error("Browser reporting endpoint must be an HTTP(S) origin without a path, credentials, query or fragment");
630
+ return web.datakitOrigin ? { datakitOrigin: origin } : { site: origin, clientToken: required(web.clientToken, "web.clientToken") };
631
+ }
632
+ function percentage(value, legacy, fallback, name) {
633
+ return value !== void 0 ? (0, validation_js_1.samplingPercentage)(value, name) : legacy !== void 0 ? (0, validation_js_1.samplingRate)(legacy, name) * 100 : fallback;
634
+ }
635
+ function integer(value, min, max, fallback, name) {
636
+ if (value === void 0)
637
+ return fallback;
638
+ if (!Number.isInteger(value) || value < min || value > max)
639
+ throw new RangeError("".concat(name, " must be an integer between ").concat(min, " and ").concat(max));
640
+ return value;
641
+ }
642
+ }
643
+ });
644
+
645
+ // packages/cocos/dist/creator2/web/client.js
646
+ var require_client = __commonJS({
647
+ "packages/cocos/dist/creator2/web/client.js": function(exports) {
648
+ "use strict";
649
+ var __assign = exports && exports.__assign || function() {
650
+ __assign = Object.assign || function(t) {
651
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
652
+ s = arguments[i];
653
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
654
+ t[p] = s[p];
655
+ }
656
+ return t;
657
+ };
658
+ return __assign.apply(this, arguments);
659
+ };
660
+ Object.defineProperty(exports, "__esModule", { value: true });
661
+ exports.FTCocosWebSDK = void 0;
662
+ var modules_js_1 = require_modules();
663
+ var runtime_js_1 = require_runtime();
664
+ var FTCocosWebSDK = (
665
+ /** @class */
666
+ (function() {
667
+ function FTCocosWebSDK2(hooks, canvasIsPublic, target, consoleObject) {
668
+ if (target === void 0) {
669
+ target = window;
670
+ }
671
+ if (consoleObject === void 0) {
672
+ consoleObject = console;
673
+ }
674
+ var _this = this;
675
+ this.hooks = hooks;
676
+ this.canvasIsPublic = canvasIsPublic;
677
+ this.target = target;
678
+ this.consoleObject = consoleObject;
679
+ this.platform = "web";
680
+ this.capabilities = {
681
+ timedActions: false,
682
+ manualResourceTiming: false,
683
+ manualLongTasks: false,
684
+ manualTraceHeaders: false,
685
+ shutdown: false,
686
+ nodeReplayMasks: false
687
+ };
688
+ this.tracking = {};
689
+ this.state = "idle";
690
+ this.stops = [];
691
+ this.activeView = false;
692
+ this.privateNodes = /* @__PURE__ */ new Map();
693
+ this.replay = {
694
+ /** Recording settings belong to the pre-engine Web bootstrap. */
695
+ start: function() {
696
+ _this.requireRuntime().startReplay();
697
+ },
698
+ stop: function() {
699
+ _this.requireRuntime().stopReplay();
700
+ },
701
+ isRecording: function() {
702
+ var _a;
703
+ return ((_a = _this.runtime) === null || _a === void 0 ? void 0 : _a.isRecording()) || false;
704
+ },
705
+ /** Any protected node blocks the entire Cocos canvas; Browser Replay cannot render node masks. */
706
+ setPrivacy: function(node, mode) {
707
+ if (!node)
708
+ throw new Error("A Cocos node is required");
709
+ if (mode === "unmask")
710
+ _this.privateNodes.delete(node);
711
+ else if (mode === "mask" || mode === "hide")
712
+ _this.privateNodes.set(node, mode);
713
+ else
714
+ throw new Error("Unknown Replay privacy mode");
715
+ }
716
+ };
717
+ var transport = {
718
+ platform: "web",
719
+ invoke: function(method, payload) {
720
+ return _this.requireRuntime().invoke(method, payload);
721
+ }
722
+ };
723
+ this.mobile = new modules_js_1.FTMobileAgent(transport);
724
+ this.rum = new modules_js_1.FTRUM(transport);
725
+ this.logger = new modules_js_1.FTLogger(transport);
726
+ this.trace = new modules_js_1.FTTrace(transport);
727
+ }
728
+ Object.defineProperty(FTCocosWebSDK2.prototype, "lifecycleMode", {
729
+ get: function() {
730
+ return this.state === "idle" ? "idle" : this.state === "standalone" ? "standalone" : "hybrid";
731
+ },
732
+ enumerable: false,
733
+ configurable: true
734
+ });
735
+ Object.defineProperty(FTCocosWebSDK2.prototype, "isCocosEntered", {
736
+ get: function() {
737
+ return this.state === "standalone" || this.state === "entered";
738
+ },
739
+ enumerable: false,
740
+ configurable: true
741
+ });
742
+ FTCocosWebSDK2.prototype.start = function(config) {
743
+ if (this.state !== "idle")
744
+ throw new Error("Web SDK already started or attached");
745
+ if (config && "replay" in config)
746
+ throw new Error("Configure Web Replay at web.replay before engine boot");
747
+ var runtime = this.target.__FT_COCOS_WEB__;
748
+ if (runtime) {
749
+ if (config)
750
+ assertBootstrapConfiguration(config, runtime.config);
751
+ this.attach({ autoTrack: config === null || config === void 0 ? void 0 : config.autoTrack });
752
+ } else {
753
+ if (!config || !("web" in config))
754
+ throw new Error("Configure web explicitly or install the pre-engine Web bootstrap");
755
+ runtime = new runtime_js_1.FTWebRuntime(config, this.target);
756
+ this.target.__FT_COCOS_WEB__ = runtime;
757
+ this.bind(runtime, config.autoTrack || {});
758
+ }
759
+ this.state = "standalone";
760
+ try {
761
+ this.startPage();
762
+ } catch (error) {
763
+ try {
764
+ this.detach();
765
+ } catch (_a) {
766
+ }
767
+ throw error;
768
+ }
769
+ };
770
+ FTCocosWebSDK2.prototype.attach = function(config) {
771
+ var _a;
772
+ if (config === void 0) {
773
+ config = {};
774
+ }
775
+ if (this.state === "standalone")
776
+ throw new Error("start() and attach() are mutually exclusive");
777
+ if (this.state !== "idle")
778
+ return;
779
+ if ("replay" in config)
780
+ throw new Error("Configure Web Replay at web.replay in the page bootstrap");
781
+ var runtime = this.target.__FT_COCOS_WEB__;
782
+ if (!runtime || runtime.protocol !== 1)
783
+ throw new Error("Run the Cocos Web bootstrap before attach()");
784
+ if (config.applicationId && config.applicationId !== runtime.config.web.applicationId)
785
+ throw new Error("Web applicationId does not match page bootstrap");
786
+ var tracking = __assign(__assign({}, runtime.config.autoTrack), config.autoTrack);
787
+ for (var _i = 0, _b = ["network", "errors"]; _i < _b.length; _i++) {
788
+ var key = _b[_i];
789
+ if (!!tracking[key] !== !!((_a = runtime.config.autoTrack) === null || _a === void 0 ? void 0 : _a[key]))
790
+ throw new Error("Configure autoTrack.".concat(key, " at page bootstrap"));
791
+ }
792
+ this.bind(runtime, tracking);
793
+ this.state = "attached";
794
+ };
795
+ FTCocosWebSDK2.prototype.enterCocos = function(options) {
796
+ var _a;
797
+ if (options === void 0) {
798
+ options = {};
799
+ }
800
+ if (this.state === "idle")
801
+ throw new Error("Call attach() before enterCocos()");
802
+ if (this.state === "standalone")
803
+ throw new Error("enterCocos() requires attach()");
804
+ if (this.state === "entered")
805
+ return;
806
+ if (!this.tracking.scenes && !((_a = options.viewName) === null || _a === void 0 ? void 0 : _a.trim()))
807
+ throw new Error("enterCocos.viewName is required when scene tracking is disabled");
808
+ try {
809
+ this.startPage(options.viewName);
810
+ this.state = "entered";
811
+ } catch (error) {
812
+ try {
813
+ this.stopPage();
814
+ } catch (_b) {
815
+ }
816
+ throw error;
817
+ }
818
+ };
819
+ FTCocosWebSDK2.prototype.leaveCocos = function() {
820
+ if (this.state === "standalone")
821
+ throw new Error("Use detach() to stop standalone Cocos instrumentation on Web");
822
+ if (this.state !== "entered")
823
+ return;
824
+ try {
825
+ this.stopPage();
826
+ } finally {
827
+ this.state = "attached";
828
+ }
829
+ };
830
+ FTCocosWebSDK2.prototype.detach = function() {
831
+ if (this.state === "idle")
832
+ return;
833
+ try {
834
+ this.stopPage();
835
+ } finally {
836
+ this.runtime.release(this);
837
+ this.runtime = void 0;
838
+ this.state = "idle";
839
+ this.privateNodes.clear();
840
+ }
841
+ };
842
+ FTCocosWebSDK2.prototype.stop = function() {
843
+ this.detach();
844
+ };
845
+ FTCocosWebSDK2.prototype.shutdown = function() {
846
+ throw new Error("Browser SDK has no public shutdown API. Use detach() to release Cocos hooks; page collectors continue until unload.");
847
+ };
848
+ FTCocosWebSDK2.prototype.setReplayCamera = function(_camera) {
849
+ throw new Error("Browser Replay captures the configured canvas, not a Cocos camera");
850
+ };
851
+ FTCocosWebSDK2.prototype.bind = function(runtime, tracking) {
852
+ var _this = this;
853
+ if ((tracking.scenes || tracking.actions || tracking.errors || tracking.network) && !runtime.config.rum)
854
+ throw new Error("Cocos RUM tracking requires rum configuration");
855
+ if (tracking.console && !runtime.config.logger)
856
+ throw new Error("Console tracking requires logger");
857
+ runtime.claim(this);
858
+ this.runtime = runtime;
859
+ this.tracking = tracking;
860
+ runtime.setPrivacyCheck(this, function() {
861
+ return _this.privateNodes.size === 0 && _this.canvasIsPublic();
862
+ });
863
+ };
864
+ FTCocosWebSDK2.prototype.startPage = function(viewName) {
865
+ var _this = this;
866
+ var view = function(name) {
867
+ _this.rum.startView(name);
868
+ _this.activeView = true;
869
+ };
870
+ if (viewName)
871
+ view(viewName);
872
+ if (this.tracking.scenes)
873
+ this.stops.push(this.hooks.onSceneChanged(view, !viewName));
874
+ if (this.tracking.actions)
875
+ this.stops.push(this.hooks.onAction(function(name, attributes) {
876
+ return _this.rum.addAction(name, "click", attributes);
877
+ }));
878
+ if (this.tracking.console)
879
+ this.trackConsole();
880
+ if (this.runtime.config.web.replay)
881
+ this.runtime.startReplay();
882
+ };
883
+ FTCocosWebSDK2.prototype.stopPage = function() {
884
+ var _this = this;
885
+ var failure;
886
+ var clean = function(fn) {
887
+ try {
888
+ fn();
889
+ } catch (error) {
890
+ if (!failure)
891
+ failure = error;
892
+ }
893
+ };
894
+ clean(function() {
895
+ var _a;
896
+ return (_a = _this.runtime) === null || _a === void 0 ? void 0 : _a.stopReplay();
897
+ });
898
+ this.stops.splice(0).reverse().forEach(clean);
899
+ if (this.activeView) {
900
+ clean(function() {
901
+ return _this.rum.stopView();
902
+ });
903
+ this.activeView = false;
904
+ }
905
+ if (failure)
906
+ throw failure;
907
+ };
908
+ FTCocosWebSDK2.prototype.requireRuntime = function() {
909
+ if (!this.runtime)
910
+ throw new Error("Start or attach the Cocos Web SDK first");
911
+ return this.runtime;
912
+ };
913
+ FTCocosWebSDK2.prototype.trackConsole = function() {
914
+ var _this = this;
915
+ ["log", "info", "warn", "error"].forEach(function(method) {
916
+ var original = _this.consoleObject[method];
917
+ var wrapped = function() {
918
+ var values = [];
919
+ for (var _i = 0; _i < arguments.length; _i++) {
920
+ values[_i] = arguments[_i];
921
+ }
922
+ original.apply(_this.consoleObject, values);
923
+ _this.logger.log(values.map(function(value) {
924
+ if (typeof value === "string")
925
+ return value;
926
+ try {
927
+ return JSON.stringify(value);
928
+ } catch (_a) {
929
+ return String(value);
930
+ }
931
+ }).join(" "), method === "warn" ? "warning" : method === "error" ? "error" : "info");
932
+ };
933
+ _this.consoleObject[method] = wrapped;
934
+ _this.stops.push(function() {
935
+ if (_this.consoleObject[method] === wrapped)
936
+ _this.consoleObject[method] = original;
937
+ });
938
+ });
939
+ };
940
+ return FTCocosWebSDK2;
941
+ })()
942
+ );
943
+ exports.FTCocosWebSDK = FTCocosWebSDK;
944
+ function assertBootstrapConfiguration(config, installed) {
945
+ var shared = {
946
+ sdk: ["serviceName", "env", "globalContext"],
947
+ rum: ["sessionSamplingRate", "sampleRate", "sessionOnErrorSamplingRate", "sessionOnErrorSampleRate", "globalContext"],
948
+ logger: ["logSamplingRate", "sampleRate", "enableCustomLog", "logLevelFilters", "globalContext"],
949
+ trace: ["traceType", "traceSamplingRate", "sampleRate"],
950
+ web: Object.keys("web" in config && config.web || {})
951
+ };
952
+ Object.keys(shared).forEach(function(group) {
953
+ var requested = config[group];
954
+ if (requested === void 0)
955
+ return;
956
+ var actual = installed[group];
957
+ if (actual === void 0)
958
+ throw new Error("Configure ".concat(group, " in the pre-engine Web bootstrap"));
959
+ shared[group].forEach(function(key) {
960
+ if (requested[key] !== void 0 && stableValue(requested[key]) !== stableValue(actual[key])) {
961
+ throw new Error("Configure ".concat(group, ".").concat(key, " in the pre-engine Web bootstrap; collectors are already initialized"));
962
+ }
963
+ });
964
+ });
965
+ }
966
+ function stableValue(value) {
967
+ return JSON.stringify(value, function(_key, item) {
968
+ return item && typeof item === "object" && !Array.isArray(item) ? Object.keys(item).sort().reduce(function(result, key) {
969
+ result[key] = item[key];
970
+ return result;
971
+ }, {}) : item;
972
+ });
973
+ }
974
+ }
975
+ });
976
+
977
+ // packages/cocos/dist/creator2/core/platform-runtime.js
978
+ var require_platform_runtime = __commonJS({
979
+ "packages/cocos/dist/creator2/core/platform-runtime.js": function(exports) {
980
+ "use strict";
981
+ Object.defineProperty(exports, "__esModule", { value: true });
982
+ exports.platformGlobal = platformGlobal;
983
+ exports.existingPlatformImplementation = existingPlatformImplementation;
984
+ exports.platformImplementation = platformImplementation;
985
+ var version_js_1 = require_version();
986
+ function platformGlobal() {
987
+ return typeof window !== "undefined" ? window : globalThis;
988
+ }
989
+ function existingPlatformImplementation(context, target) {
990
+ var _a;
991
+ if (target === void 0) {
992
+ target = platformGlobal();
993
+ }
994
+ var previous = (_a = target.__FT_COCOS_INSTANCES__) === null || _a === void 0 ? void 0 : _a[context.engine + ":" + context.platform];
995
+ if (previous && previous.version !== version_js_1.FT_COCOS_SDK_VERSION)
996
+ throw new Error("Cocos SDK versions must match on the same page");
997
+ return previous === null || previous === void 0 ? void 0 : previous.sdk;
998
+ }
999
+ function platformImplementation(context, target, create) {
1000
+ if (target === void 0) {
1001
+ target = platformGlobal();
1002
+ }
1003
+ var key = context.engine + ":" + context.platform;
1004
+ var instances = target.__FT_COCOS_INSTANCES__ || (target.__FT_COCOS_INSTANCES__ = {});
1005
+ var previous = existingPlatformImplementation(context, target);
1006
+ if (previous)
1007
+ return previous;
1008
+ var factory = context.platform === "web" ? target.__FT_COCOS_WEB_FACTORY__ : target.__FT_COCOS_NATIVE_FACTORY__;
1009
+ if (!create && (!factory || factory.protocol !== 1 || factory.version !== version_js_1.FT_COCOS_SDK_VERSION)) {
1010
+ 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.");
1011
+ }
1012
+ var sdk = create ? create() : factory.create(context, target);
1013
+ instances[key] = { version: version_js_1.FT_COCOS_SDK_VERSION, sdk: sdk };
1014
+ return sdk;
1015
+ }
1016
+ }
1017
+ });
1018
+
1019
+ // packages/cocos/dist/creator2/web/bootstrap.js
1020
+ var require_bootstrap = __commonJS({
1021
+ "packages/cocos/dist/creator2/web/bootstrap.js": function(exports) {
1022
+ Object.defineProperty(exports, "__esModule", { value: true });
1023
+ exports.bootstrapWeb = void 0;
1024
+ var client_js_1 = require_client();
1025
+ var platform_runtime_js_1 = require_platform_runtime();
1026
+ var version_js_1 = require_version();
1027
+ (0, platform_runtime_js_1.platformGlobal)().__FT_COCOS_WEB_FACTORY__ = {
1028
+ protocol: 1,
1029
+ version: version_js_1.FT_COCOS_SDK_VERSION,
1030
+ create: function(context, target) {
1031
+ return new client_js_1.FTCocosWebSDK(context.hooks, context.canvasIsPublic, target);
1032
+ }
1033
+ };
1034
+ var runtime_js_1 = require_runtime();
1035
+ Object.defineProperty(exports, "bootstrapWeb", { enumerable: true, get: function() {
1036
+ return runtime_js_1.bootstrapWeb;
1037
+ } });
1038
+ }
1039
+ });
1040
+ return require_bootstrap();
1041
+ })();
1042
+ //# sourceMappingURL=bootstrap.js.map