@playcraft/adsdk 1.0.12 → 1.0.13-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -24,8 +24,7 @@ __export(index_exports, {
24
24
  hideWechatGuide: () => hideWechatGuide,
25
25
  removeWechatGuide: () => removeWechatGuide,
26
26
  sdk: () => sdk,
27
- showWechatGuide: () => showWechatGuide,
28
- tracking: () => tracking
27
+ showWechatGuide: () => showWechatGuide
29
28
  });
30
29
  module.exports = __toCommonJS(index_exports);
31
30
 
@@ -188,275 +187,23 @@ function ensureProtocol() {
188
187
  }
189
188
  }
190
189
 
191
- // src/tracking.ts
192
- function getCurrentAdNetwork(adNetwork) {
193
- const network = adNetwork || (typeof AD_NETWORK !== "undefined" ? AD_NETWORK : "");
194
- const supportedNetworks = ["bigabid", "inmobi", "applovin"];
195
- if (supportedNetworks.includes(network)) {
196
- return network;
197
- }
198
- return null;
199
- }
200
- function trackURL(url) {
201
- if (url) {
202
- const trackingPixel = new Image();
203
- trackingPixel.src = url;
204
- }
205
- }
206
- function trackBigabidEvent(event) {
207
- console.log(" trackBigabidEvent", event);
208
- if (window.BIGABID_BIDTIMEMACROS && window.BIGABID_BIDTIMEMACROS[event]) {
209
- trackURL(window.BIGABID_BIDTIMEMACROS[event]);
210
- }
211
- }
212
- function trackInMobiEvent(event) {
213
- console.log(" trackInMobiEvent", event);
214
- if (window.INMOBI_DSPMACROS && window.INMOBI_DSPMACROS[event]) {
215
- trackURL(window.INMOBI_DSPMACROS[event]);
216
- }
217
- }
218
- function trackApplovinEvent(event) {
219
- console.log(" trackApplovinEvent", event);
220
- if (typeof window.ALPlayableAnalytics !== "undefined") {
221
- window.ALPlayableAnalytics.trackEvent(event);
222
- }
223
- }
224
- var bigabidCompleteTriggered = false;
225
- function trackBigabidComplete() {
226
- if (!bigabidCompleteTriggered) {
227
- trackBigabidEvent("complete");
228
- bigabidCompleteTriggered = true;
229
- }
230
- }
231
- var inmobiTimers = [];
232
- function startInMobiDurationTracking() {
233
- const durations = [5, 10, 15, 20, 25, 30];
234
- for (const sec of durations) {
235
- const timer = setTimeout(() => trackInMobiEvent(`Spent_${sec}_Seconds`), sec * 1e3);
236
- inmobiTimers.push(timer);
237
- }
238
- }
239
- function clearInMobiDurationTracking() {
240
- for (const timer of inmobiTimers) {
241
- clearTimeout(timer);
242
- }
243
- inmobiTimers = [];
244
- }
245
- var totalInteractions = 0;
246
- var progressMilestones = [];
247
- function setTotalInteractions(total) {
248
- totalInteractions = total;
249
- }
250
- function initProgressMilestones(adNetwork) {
251
- if (totalInteractions <= 0) return;
252
- const network = getCurrentAdNetwork(adNetwork);
253
- if (!network) return;
254
- if (network === "applovin") {
255
- progressMilestones = [
256
- { percent: 25, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_25") },
257
- { percent: 50, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_50") },
258
- { percent: 75, triggered: false, callback: () => trackApplovinEvent("CHALLENGE_PASS_75") },
259
- { percent: 100, triggered: false, callback: () => _trackChallengeSuccess(adNetwork) }
260
- ];
261
- } else if (network === "bigabid") {
262
- progressMilestones = [
263
- { percent: 100, triggered: false, callback: () => _trackChallengeSuccess(adNetwork) }
264
- ];
265
- }
266
- }
267
- function checkInteractionProgress(currentInteractions) {
268
- if (totalInteractions <= 0 || progressMilestones.length === 0) return;
269
- const currentPercent = currentInteractions / totalInteractions * 100;
270
- for (const milestone of progressMilestones) {
271
- if (!milestone.triggered && currentPercent >= milestone.percent) {
272
- milestone.triggered = true;
273
- milestone.callback();
274
- }
275
- }
276
- }
277
- function _onInit(adNetwork) {
278
- initProgressMilestones(adNetwork);
279
- const network = getCurrentAdNetwork(adNetwork);
280
- if (!network) return;
281
- if (network === "bigabid") {
282
- trackBigabidEvent("mraid_viewable");
283
- }
284
- if (network === "inmobi") {
285
- trackInMobiEvent("Ad_Load_Start");
286
- }
287
- if (network === "applovin") {
288
- trackApplovinEvent("LOADING");
289
- }
290
- }
291
- function _onStart(adNetwork) {
292
- const network = getCurrentAdNetwork(adNetwork);
293
- if (!network) return;
294
- if (network === "bigabid") {
295
- trackBigabidEvent("game_viewable");
296
- }
297
- if (network === "inmobi") {
298
- trackInMobiEvent("Ad_Viewable");
299
- startInMobiDurationTracking();
300
- }
301
- if (network === "applovin") {
302
- trackApplovinEvent("LOADED");
303
- }
304
- }
305
- function _onInteractive(adNetwork) {
306
- const network = getCurrentAdNetwork(adNetwork);
307
- if (!network) return;
308
- if (network === "applovin") {
309
- trackApplovinEvent("DISPLAYED");
310
- }
311
- }
312
- function _onInteraction(adNetwork) {
313
- const network = getCurrentAdNetwork(adNetwork);
314
- if (!network) return;
315
- if (network === "bigabid") {
316
- trackBigabidEvent("engagement");
317
- }
318
- if (network === "inmobi") {
319
- trackInMobiEvent("First_Engagement");
320
- }
321
- if (network === "applovin") {
322
- trackApplovinEvent("CHALLENGE_STARTED");
323
- }
324
- }
325
- function _onSuccess(successCount) {
326
- checkInteractionProgress(successCount);
327
- }
328
- function _onFinish(adNetwork) {
329
- const network = getCurrentAdNetwork(adNetwork);
330
- if (!network) return;
331
- if (network === "bigabid") {
332
- trackBigabidComplete();
333
- }
334
- if (network === "inmobi") {
335
- trackInMobiEvent("Gameplay_Complete");
336
- clearInMobiDurationTracking();
337
- }
338
- if (network === "applovin") {
339
- trackApplovinEvent("ENDCARD_SHOWN");
340
- }
341
- }
342
- function _onInstall(adNetwork) {
343
- const network = getCurrentAdNetwork(adNetwork);
344
- if (!network) return;
345
- if (network === "bigabid") {
346
- trackBigabidEvent("click");
347
- }
348
- if (network === "inmobi") {
349
- trackInMobiEvent("DSP_Click");
350
- clearInMobiDurationTracking();
351
- }
352
- if (network === "applovin") {
353
- trackApplovinEvent("CTA_CLICKED");
354
- }
355
- }
356
- function _onRetry(adNetwork) {
357
- const network = getCurrentAdNetwork(adNetwork);
358
- if (!network) return;
359
- if (network === "applovin") {
360
- trackApplovinEvent("CHALLENGE_RETRY");
361
- }
362
- }
363
- function _trackChallengeSuccess(adNetwork) {
364
- const network = getCurrentAdNetwork(adNetwork);
365
- if (!network) return;
366
- if (network === "applovin") {
367
- trackApplovinEvent("CHALLENGE_SOLVED");
368
- }
369
- if (network === "bigabid") {
370
- trackBigabidComplete();
371
- }
372
- if (network === "inmobi") {
373
- trackInMobiEvent("Gameplay_Complete");
374
- }
375
- }
376
- function _trackChallengeFailed(adNetwork) {
377
- const network = getCurrentAdNetwork(adNetwork);
378
- if (!network) return;
379
- if (network === "applovin") {
380
- trackApplovinEvent("CHALLENGE_FAILED");
381
- }
382
- }
383
- var tracking = {
384
- /**
385
- * SDK 初始化开始
386
- * @param adNetwork - 可选的广告渠道名称
387
- */
388
- onInit: _onInit,
389
- /**
390
- * 游戏资源加载完成
391
- * @param adNetwork - 可选的广告渠道名称
392
- */
393
- onStart: _onStart,
394
- /**
395
- * 主场景就绪,用户可交互
396
- * @param adNetwork - 可选的广告渠道名称
397
- */
398
- onInteractive: _onInteractive,
399
- /**
400
- * 首次交互
401
- * @param adNetwork - 可选的广告渠道名称
402
- */
403
- onInteraction: _onInteraction,
404
- /**
405
- * 成功计数(用于进度百分比追踪)
406
- * @param successCount - 当前成功次数
407
- */
408
- onSuccess: _onSuccess,
409
- /**
410
- * 游戏结束
411
- * @param adNetwork - 可选的广告渠道名称
412
- */
413
- onFinish: _onFinish,
414
- /**
415
- * 点击安装
416
- * @param adNetwork - 可选的广告渠道名称
417
- */
418
- onInstall: _onInstall,
419
- /**
420
- * 重试游戏
421
- * @param adNetwork - 可选的广告渠道名称
422
- */
423
- onRetry: _onRetry,
424
- /**
425
- * 设置交互总数(用于进度百分比计算)
426
- * @param total - 交互总数
427
- */
428
- setTotalInteractions,
429
- /**
430
- * 检查交互进度
431
- * @param currentInteractions - 当前交互次数
432
- */
433
- checkInteractionProgress,
434
- /**
435
- * 触发游戏成功事件
436
- * @param adNetwork - 可选的广告渠道名称
437
- */
438
- trackChallengeSuccess: _trackChallengeSuccess,
439
- /**
440
- * 触发游戏失败事件
441
- * @param adNetwork - 可选的广告渠道名称
442
- */
443
- trackChallengeFailed: _trackChallengeFailed
444
- };
445
-
446
190
  // src/tracking-init.ts
191
+ var import_ads_tracking = require("@playcraft/ads-tracking");
447
192
  function initTrackingProtocols() {
448
193
  const supportedNetworks = ["bigabid", "inmobi", "applovin"];
449
194
  if (!supportedNetworks.includes(AD_NETWORK)) {
450
195
  return;
451
196
  }
452
- sdk.once("init", tracking.onInit);
453
- sdk.once("start", tracking.onStart);
454
- sdk.once("interactive", tracking.onInteractive);
455
- sdk.once("interaction", tracking.onInteraction);
456
- sdk.on("success", tracking.onSuccess);
457
- sdk.once("finish", tracking.onFinish);
458
- sdk.on("install", tracking.onInstall);
459
- sdk.once("retry", tracking.onRetry);
197
+ sdk.once("playcraftInit", import_ads_tracking.tracking.onPlaycraftTrackingInit);
198
+ sdk.once("playcraftStart", import_ads_tracking.tracking.onPlaycraftTrackingLoading);
199
+ sdk.once("playcraftInteractive", import_ads_tracking.tracking.onPlaycraftTrackingLoaded);
200
+ sdk.on("playcraftChallengeStart", import_ads_tracking.tracking.onPlaycraftChallengeStart);
201
+ sdk.on("playcraftChallengeProgress", import_ads_tracking.tracking.onPlaycraftChallengeProgress);
202
+ sdk.once("playcraftFinish", import_ads_tracking.tracking.onPlaycraftChallengeFinish);
203
+ sdk.on("playcraftInstall", import_ads_tracking.tracking.onPlaycraftInstall);
204
+ sdk.once("playcraftRetry", import_ads_tracking.tracking.onPlaycraftRetry);
205
+ sdk.on("playcraftChallengeSuccess", import_ads_tracking.tracking.onPlaycraftChallengeSuccess);
206
+ sdk.on("playcraftChallengeFailed", import_ads_tracking.tracking.onPlaycraftChallengeFailed);
460
207
  }
461
208
 
462
209
  // src/assets/images.ts
@@ -724,6 +471,73 @@ function removeWechatGuide() {
724
471
  }
725
472
  }
726
473
 
474
+ // src/theme-config.ts
475
+ function extractDefaultsFromSchema(schema) {
476
+ if (!schema || typeof schema !== "object") return void 0;
477
+ if (schema.type === "object" && schema.properties) {
478
+ const result = {};
479
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
480
+ const val = extractDefaultsFromSchema(propSchema);
481
+ if (val !== void 0) {
482
+ result[key] = val;
483
+ }
484
+ }
485
+ return Object.keys(result).length > 0 ? result : void 0;
486
+ }
487
+ if ("default" in schema) {
488
+ return schema.default;
489
+ }
490
+ return void 0;
491
+ }
492
+ function resolveImagePaths(config, assetRecordByPath) {
493
+ if (!assetRecordByPath || !config || typeof config !== "object") return;
494
+ for (const key of Object.keys(config)) {
495
+ const value = config[key];
496
+ if (typeof value === "string") {
497
+ if (assetRecordByPath[value]) {
498
+ config[key] = assetRecordByPath[value];
499
+ }
500
+ } else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
501
+ resolveImagePaths(value, assetRecordByPath);
502
+ }
503
+ }
504
+ }
505
+ var _cachedConfig = null;
506
+ function deepMerge(target, source) {
507
+ for (const key of Object.keys(source)) {
508
+ const srcVal = source[key];
509
+ const tgtVal = target[key];
510
+ if (srcVal !== null && typeof srcVal === "object" && !Array.isArray(srcVal) && tgtVal !== null && typeof tgtVal === "object" && !Array.isArray(tgtVal)) {
511
+ deepMerge(tgtVal, srcVal);
512
+ } else if (srcVal !== void 0) {
513
+ target[key] = srcVal;
514
+ }
515
+ }
516
+ return target;
517
+ }
518
+ function setConfig(configList, config) {
519
+ const { assetRecordByPath } = config;
520
+ const resolvedConfigs = configList.map((item) => {
521
+ var _a;
522
+ if (!item) return {};
523
+ return item.$schema ? (_a = extractDefaultsFromSchema(item)) != null ? _a : {} : item;
524
+ });
525
+ const [first, ...rest] = resolvedConfigs;
526
+ const mergedConfig = JSON.parse(JSON.stringify(first));
527
+ for (const data of rest) {
528
+ deepMerge(mergedConfig, data);
529
+ }
530
+ resolveImagePaths(mergedConfig, assetRecordByPath);
531
+ _cachedConfig = mergedConfig;
532
+ }
533
+ function getConfig() {
534
+ if (!_cachedConfig) {
535
+ console.warn("[PlayableSDK] Theme config not initialized. Call setConfig() first.");
536
+ return {};
537
+ }
538
+ return _cachedConfig;
539
+ }
540
+
727
541
  // src/core.ts
728
542
  var destinationUrl = "";
729
543
  var isSDKInitialized = false;
@@ -735,16 +549,16 @@ var initCallback = () => {
735
549
  };
736
550
  function bootAd() {
737
551
  if (sdk.isReady) return;
738
- emitEvent("init");
552
+ emitEvent("playcraftInit");
739
553
  document.body.oncontextmenu = function() {
740
554
  return false;
741
555
  };
742
556
  initCallback(sdk.maxWidth, sdk.maxHeight);
743
- emitEvent("ready");
557
+ emitEvent("playcraftReady");
744
558
  sdk.isReady = true;
745
559
  }
746
560
  function fireVolumeChange(value) {
747
- emitEvent("volume", value);
561
+ emitEvent("playcraftVolume", value);
748
562
  }
749
563
  function changeVolume(value) {
750
564
  sdk.volume = value;
@@ -757,13 +571,13 @@ function handleVolumeChange(value) {
757
571
  function handlePause() {
758
572
  changeVolume(0);
759
573
  sdk.isPaused = true;
760
- emitEvent("pause");
574
+ emitEvent("playcraftPause");
761
575
  }
762
576
  function handleResume() {
763
577
  if (isForcePaused) return;
764
578
  changeVolume(actualVolume);
765
579
  sdk.isPaused = false;
766
- emitEvent("resume");
580
+ emitEvent("playcraftResume");
767
581
  }
768
582
  function fireResizeEvent(width, height) {
769
583
  handleResize(width, height);
@@ -946,7 +760,7 @@ function startDefaultProtocol() {
946
760
  const tapjoyApi = {
947
761
  skipAd: function() {
948
762
  try {
949
- sdk.finish();
763
+ sdk.playcraftFinish();
950
764
  } catch (e) {
951
765
  console.warn("Could not skip ad! | " + e);
952
766
  }
@@ -965,7 +779,7 @@ function handleResize(width, height) {
965
779
  sdk.maxWidth = Math.floor(width || window.innerWidth);
966
780
  sdk.maxHeight = Math.floor(height || window.innerHeight);
967
781
  sdk.isLandscape = sdk.maxWidth > sdk.maxHeight;
968
- emitEvent("resize", sdk.maxWidth, sdk.maxHeight);
782
+ emitEvent("playcraftResize", sdk.maxWidth, sdk.maxHeight);
969
783
  }
970
784
  var isListeningToTouchEvents = false;
971
785
  var isTouchEventRegistered = false;
@@ -975,7 +789,7 @@ function onUserInteraction(event) {
975
789
  }
976
790
  if (isListeningToTouchEvents && event instanceof MouseEvent) return;
977
791
  sdk.interactions += 1;
978
- emitEvent("interaction", sdk.interactions);
792
+ emitEvent("playcraftInteraction", sdk.interactions);
979
793
  }
980
794
  function registerTouchHandlers() {
981
795
  if (!isTouchEventRegistered) {
@@ -1059,35 +873,21 @@ var _sdk = class _sdk {
1059
873
  * This must be called as earlier as possible.
1060
874
  *
1061
875
  * @param callback Optional function called when ad container is ready
1062
- * @param options Optional configuration options
1063
- * @param options.totalSuccessCount Total number of successful actions expected for progress tracking.
1064
- * When set, the SDK will track success progress as a percentage and trigger
1065
- * channel-specific milestone events (e.g., AppLovin: CHALLENGE_PASS_25/50/75, CHALLENGE_SOLVED).
1066
- * Different channels monitor different percentage thresholds independently.
1067
- * Set to 0 or omit to disable progress tracking.
1068
876
  * @example
1069
877
  * // Basic initialization
1070
- * sdk.init();
878
+ * sdk.playcraftInit();
1071
879
  *
1072
880
  * // Initialization with callback
1073
- * sdk.init((width, height) => {
881
+ * sdk.playcraftInit((width, height) => {
1074
882
  * new App(width, height)
1075
883
  * });
1076
884
  *
1077
- * // Initialization with success count progress tracking
1078
- * sdk.init((width, height) => {
1079
- * new App(width, height)
1080
- * }, { totalSuccessCount: 20 });
1081
- *
1082
- * @fires loading When SDK initialization starts
1083
- * @fires loaded When game instance is created and ready to load resources
885
+ * @fires playcraftInit When SDK initialization starts
886
+ * @fires playcraftReady When game instance is created and ready to load resources
1084
887
  */
1085
- static init(callback, options) {
888
+ static playcraftInit(callback) {
1086
889
  if (isSDKInitialized) return;
1087
890
  if (callback) initCallback = callback;
1088
- if ((options == null ? void 0 : options.totalSuccessCount) && options.totalSuccessCount > 0) {
1089
- tracking.setTotalInteractions(options.totalSuccessCount);
1090
- }
1091
891
  initTrackingProtocols();
1092
892
  document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
1093
893
  isSDKInitialized = true;
@@ -1097,25 +897,24 @@ var _sdk = class _sdk {
1097
897
  * Should be called after all resources are loaded and first frame is rendered.
1098
898
  *
1099
899
  * @example
1100
- * // Call just after all resources are preloaded and first frame is rendered
1101
- * sdk.start();
900
+ * sdk.playcraftStart();
1102
901
  *
1103
- * @fires start When the playable ad starts
1104
- * @fires resize When the ad container is initially sized
902
+ * @fires playcraftStart When the playable ad starts
903
+ * @fires playcraftResize When the ad container is initially sized
1105
904
  */
1106
- static start() {
905
+ static playcraftStart() {
1107
906
  if (_sdk.isStarted) return;
1108
907
  _sdk.isStarted = true;
1109
- emitEvent("start");
908
+ emitEvent("playcraftStart");
1110
909
  registerTouchHandlers();
1111
910
  if ("mintegral" === AD_NETWORK && isMintegral()) {
1112
- _sdk.resize();
911
+ _sdk.playcraftResize();
1113
912
  handlePause();
1114
913
  window.gameReady && window.gameReady();
1115
914
  } else if ("bigoads" === AD_NETWORK && isBigoAds()) {
1116
915
  window.BGY_MRAID && window.BGY_MRAID.gameReady && window.BGY_MRAID.gameReady();
1117
916
  fireVolumeChange(_sdk.volume);
1118
- _sdk.resize();
917
+ _sdk.playcraftResize();
1119
918
  } else {
1120
919
  if ("tapjoy" === AD_NETWORK && isTapjoy()) {
1121
920
  window.TJ_API.setPlayableBuild({
@@ -1124,7 +923,7 @@ var _sdk = class _sdk {
1124
923
  });
1125
924
  }
1126
925
  fireVolumeChange(_sdk.volume);
1127
- _sdk.resize();
926
+ _sdk.playcraftResize();
1128
927
  }
1129
928
  }
1130
929
  /**
@@ -1132,28 +931,39 @@ var _sdk = class _sdk {
1132
931
  * Should be called at the end of your main game scene's create() method.
1133
932
  *
1134
933
  * @example
1135
- * // In Phaser MainScene.create()
1136
934
  * create() {
1137
935
  * // ... all initialization code ...
1138
- * sdk.interactive();
936
+ * sdk.playcraftInteractive();
937
+ * }
938
+ *
939
+ * @fires playcraftInteractive When the main scene is ready for user interaction
940
+ */
941
+ static playcraftInteractive() {
942
+ emitEvent("playcraftInteractive");
943
+ }
944
+ /**
945
+ * Marks the challenge as started.
946
+ * Should be called by business logic when the user actually starts playing.
947
+ *
948
+ * @example
949
+ * onFirstClick() {
950
+ * sdk.playcraftChallengeStart();
1139
951
  * }
1140
952
  *
1141
- * @fires interactive When the main scene is ready for user interaction
953
+ * @fires playcraftChallengeStart When the challenge starts
1142
954
  */
1143
- static interactive() {
1144
- emitEvent("interactive");
955
+ static playcraftChallengeStart() {
956
+ emitEvent("playcraftChallengeStart");
1145
957
  }
1146
958
  /**
1147
959
  * Marks the playable ad as finished.
1148
- * This triggers network-specific completion handlers.
1149
960
  *
1150
961
  * @example
1151
- * // Call when game/experience is complete
1152
- * sdk.finish();
962
+ * sdk.playcraftFinish();
1153
963
  *
1154
- * @fires finish When the playable ad is marked as finished
964
+ * @fires playcraftFinish When the playable ad is marked as finished
1155
965
  */
1156
- static finish() {
966
+ static playcraftFinish() {
1157
967
  _sdk.isFinished = true;
1158
968
  if ("tapjoy" === AD_NETWORK && isTapjoy()) {
1159
969
  finishTapjoy();
@@ -1173,38 +983,34 @@ var _sdk = class _sdk {
1173
983
  console.warn("Could not call mraid.close():", e);
1174
984
  }
1175
985
  }
1176
- emitEvent("finish");
986
+ emitEvent("playcraftFinish");
1177
987
  }
1178
988
  /**
1179
989
  * Triggers a retry/restart of the playable ad.
1180
- * Behavior varies by ad network.
1181
990
  *
1182
991
  * @example
1183
- * // Allow user to try again
1184
- * retryButton.onclick = () => sdk.retry();
992
+ * retryButton.onclick = () => sdk.playcraftRetry();
1185
993
  *
1186
- * @fires retry When a retry is triggered
994
+ * @fires playcraftRetry When a retry is triggered
1187
995
  */
1188
- static retry() {
996
+ static playcraftRetry() {
1189
997
  if ("mintegral" === AD_NETWORK && isMintegral()) {
1190
998
  } else if ("nucleo" === AD_PROTOCOL && isNucleo()) {
1191
999
  NUC.trigger.tryAgain();
1192
1000
  }
1193
- emitEvent("retry");
1001
+ emitEvent("playcraftRetry");
1194
1002
  }
1195
1003
  /**
1196
1004
  * Triggers the install/download action for the advertised app.
1197
- * Handles different store opening methods across ad networks.
1198
1005
  *
1199
1006
  * @example
1200
- * // Call when user wants to install
1201
- * installButton.onclick = () => sdk.install();
1007
+ * installButton.onclick = () => sdk.playcraftInstall();
1202
1008
  *
1203
- * @fires finish If the ad hasn't been marked as finished
1204
- * @fires install When the install action is triggered
1009
+ * @fires playcraftFinish If the ad hasn't been marked as finished
1010
+ * @fires playcraftInstall When the install action is triggered
1205
1011
  */
1206
- static install(params) {
1207
- console.log("[SDK] install() called, interactions:", _sdk.interactions, "isFinished:", _sdk.isFinished, "isInstallClicked:", isInstallClicked);
1012
+ static playcraftInstall(params) {
1013
+ console.log("[SDK] playcraftInstall() called, interactions:", _sdk.interactions, "isFinished:", _sdk.isFinished, "isInstallClicked:", isInstallClicked);
1208
1014
  if (_sdk.interactions < 1 && isDisableFirstClickToOpenApp()) {
1209
1015
  console.log("[SDK] \u9996\u6B21\u70B9\u51FB\u4FDD\u62A4\uFF0C\u76F4\u63A5\u8FD4\u56DE");
1210
1016
  return;
@@ -1214,23 +1020,23 @@ var _sdk = class _sdk {
1214
1020
  return;
1215
1021
  }
1216
1022
  const timeout = setTimeout(function() {
1217
- _sdk.install();
1023
+ _sdk.playcraftInstall();
1218
1024
  clearTimeout(timeout);
1219
1025
  }, params.timeout || 3e3);
1220
1026
  return;
1221
1027
  }
1222
1028
  if (!_sdk.isFinished) {
1223
- console.log("[SDK] \u9996\u6B21\u6267\u884C install\uFF0C\u89E6\u53D1 finish \u4E8B\u4EF6");
1029
+ console.log("[SDK] \u9996\u6B21\u6267\u884C playcraftInstall\uFF0C\u89E6\u53D1 playcraftFinish \u4E8B\u4EF6");
1224
1030
  _sdk.isFinished = true;
1225
1031
  let timeout = 0;
1226
1032
  if ("tapjoy" === AD_NETWORK && isTapjoy()) {
1227
1033
  finishTapjoy();
1228
1034
  timeout = 300;
1229
1035
  }
1230
- emitEvent("finish");
1036
+ emitEvent("playcraftFinish");
1231
1037
  setTimeout(function() {
1232
- console.log("[SDK] \u5F02\u6B65\u9012\u5F52\u8C03\u7528 install()");
1233
- _sdk.install();
1038
+ console.log("[SDK] \u5F02\u6B65\u9012\u5F52\u8C03\u7528 playcraftInstall()");
1039
+ _sdk.playcraftInstall();
1234
1040
  }, timeout);
1235
1041
  return;
1236
1042
  }
@@ -1243,7 +1049,7 @@ var _sdk = class _sdk {
1243
1049
  isInstallClicked = false;
1244
1050
  console.log("[SDK] \u9632\u6296\u89E3\u9501");
1245
1051
  }, 500);
1246
- emitEvent("install");
1052
+ emitEvent("playcraftInstall");
1247
1053
  console.log("Ad_Protocal: ", AD_PROTOCOL);
1248
1054
  if ("mraid" === AD_PROTOCOL && isMraid()) {
1249
1055
  try {
@@ -1307,39 +1113,30 @@ var _sdk = class _sdk {
1307
1113
  }
1308
1114
  /**
1309
1115
  * Trigger force resize event
1310
- * Useful when container size changes need to be manually propagated.
1311
1116
  *
1312
1117
  * @example
1313
- * sdk.resize();
1118
+ * sdk.playcraftResize();
1314
1119
  *
1315
- * @fires resize With current maxWidth and maxHeight
1120
+ * @fires playcraftResize With current maxWidth and maxHeight
1316
1121
  */
1317
- static resize() {
1122
+ static playcraftResize() {
1318
1123
  handleResize(_sdk.maxWidth, _sdk.maxHeight);
1319
1124
  }
1320
1125
  /**
1321
- * Records successful game actions (e.g., successful match, level clear).
1322
- * This should be called by game logic when a meaningful success occurs.
1323
- * This count is used for progress tracking (e.g., AppLovin milestone events).
1126
+ * Records playable ad challenge progress (0-100).
1127
+ * Triggers channel-specific milestone events based on the progress value.
1128
+ * Milestones are not re-triggered once fired.
1129
+ *
1130
+ * @param percent Progress percentage (0-100)
1324
1131
  *
1325
- * @param count Optional success count to add (default: 1)
1326
- *
1327
1132
  * @example
1328
- * // Record single success when match completes
1329
- * onMatchSuccess() {
1330
- * sdk.recordSuccessCount();
1331
- * }
1332
- *
1333
- * // Record multiple successes at once
1334
- * onComboMatch(comboCount) {
1335
- * sdk.recordSuccessCount(comboCount);
1336
- * }
1133
+ * // Report 50% progress
1134
+ * sdk.recordPlaycraftChallengeProgress(50);
1337
1135
  *
1338
- * @fires success With updated success count (triggers progress tracking)
1136
+ * @fires playcraftChallengeProgress With the progress percentage value
1339
1137
  */
1340
- static recordSuccessCount(count = 1) {
1341
- _sdk.successCount += count;
1342
- emitEvent("success", _sdk.successCount);
1138
+ static recordPlaycraftChallengeProgress(percent) {
1139
+ emitEvent("playcraftChallengeProgress", percent);
1343
1140
  }
1344
1141
  /**
1345
1142
  * Records a game success/completion event.
@@ -1349,13 +1146,12 @@ var _sdk = class _sdk {
1349
1146
  * - InMobi: Gameplay_Complete
1350
1147
  *
1351
1148
  * @example
1352
- * // When player completes the level
1353
1149
  * onLevelComplete() {
1354
- * sdk.recordSuccess();
1150
+ * sdk.playcraftRecordSuccess();
1355
1151
  * }
1356
1152
  */
1357
- static recordSuccess() {
1358
- tracking.trackChallengeSuccess();
1153
+ static playcraftRecordSuccess() {
1154
+ emitEvent("playcraftChallengeSuccess");
1359
1155
  }
1360
1156
  /**
1361
1157
  * Records a game failure event.
@@ -1363,24 +1159,22 @@ var _sdk = class _sdk {
1363
1159
  * - AppLovin: CHALLENGE_FAILED
1364
1160
  *
1365
1161
  * @example
1366
- * // When player fails the level
1367
1162
  * onLevelFailed() {
1368
- * sdk.recordFailed();
1163
+ * sdk.playcraftRecordFailed();
1369
1164
  * }
1370
1165
  */
1371
- static recordFailed() {
1372
- tracking.trackChallengeFailed();
1166
+ static playcraftRecordFailed() {
1167
+ emitEvent("playcraftChallengeFailed");
1373
1168
  }
1374
1169
  /**
1375
1170
  * Forces the playable ad into a paused state.
1376
1171
  *
1377
1172
  * @example
1378
- * // Pause the experience
1379
- * pauseButton.onclick = () => sdk.pause();
1173
+ * pauseButton.onclick = () => sdk.playcraftPause();
1380
1174
  *
1381
- * @fires pause When the ad enters paused state
1175
+ * @fires playcraftPause When the ad enters paused state
1382
1176
  */
1383
- static pause() {
1177
+ static playcraftPause() {
1384
1178
  if (!isForcePaused) {
1385
1179
  isForcePaused = true;
1386
1180
  handlePause();
@@ -1388,15 +1182,13 @@ var _sdk = class _sdk {
1388
1182
  }
1389
1183
  /**
1390
1184
  * Resumes the playable ad from a forced pause state.
1391
- * Only works if the ad was paused via sdk.pause().
1392
1185
  *
1393
1186
  * @example
1394
- * // Resume from pause
1395
- * resumeButton.onclick = () => sdk.resume();
1187
+ * resumeButton.onclick = () => sdk.playcraftResume();
1396
1188
  *
1397
- * @fires resume When the ad resumes from pause
1189
+ * @fires playcraftResume When the ad resumes from pause
1398
1190
  */
1399
- static resume() {
1191
+ static playcraftResume() {
1400
1192
  if (isForcePaused) {
1401
1193
  isForcePaused = false;
1402
1194
  handleResume();
@@ -1410,15 +1202,9 @@ var _sdk = class _sdk {
1410
1202
  * @param context Optional 'this' context for the callback
1411
1203
  *
1412
1204
  * @example
1413
- * // Listen for user interactions
1414
- * sdk.on('interaction', (count) => {
1205
+ * sdk.on('playcraftInteraction', (count) => {
1415
1206
  * console.log(`User interaction #${count}`);
1416
1207
  * });
1417
- *
1418
- * // Listen for resize with context
1419
- * sdk.on('resize', function(width, height) {
1420
- * this.updateLayout(width, height);
1421
- * }, gameInstance);
1422
1208
  */
1423
1209
  static on(event, fn, context) {
1424
1210
  onEvent(event, fn, context);
@@ -1431,8 +1217,7 @@ var _sdk = class _sdk {
1431
1217
  * @param context Optional 'this' context for the callback
1432
1218
  *
1433
1219
  * @example
1434
- * // Listen for first interaction only
1435
- * sdk.once('interaction', () => {
1220
+ * sdk.once('playcraftInteraction', () => {
1436
1221
  * console.log('First user interaction occurred!');
1437
1222
  * });
1438
1223
  */
@@ -1443,22 +1228,16 @@ var _sdk = class _sdk {
1443
1228
  * Removes an event listener.
1444
1229
  *
1445
1230
  * @param event Name of the event to stop listening for
1446
- * @param fn Optional callback function to remove (if not provided, removes all listeners for the event)
1231
+ * @param fn Optional callback function to remove
1447
1232
  * @param context Optional 'this' context to match when removing
1448
1233
  *
1449
1234
  * @example
1450
- * // Remove specific listener
1451
- * const handler = () => console.log('Interaction');
1452
- * sdk.off('interaction', handler);
1453
- *
1454
- * // Remove all listeners for an event
1455
- * sdk.off('interaction');
1235
+ * sdk.off('playcraftInteraction', handler);
1456
1236
  */
1457
1237
  static off(event, fn, context) {
1458
1238
  offEvent(event, fn, context);
1459
1239
  }
1460
1240
  /**
1461
- *
1462
1241
  * @returns 当前渠道
1463
1242
  */
1464
1243
  static getCurChannel() {
@@ -1470,9 +1249,43 @@ var _sdk = class _sdk {
1470
1249
  static isGoogle() {
1471
1250
  return _sdk.getCurChannel() === "google";
1472
1251
  }
1252
+ /**
1253
+ * 设置主题配置,支持传入多份 JSON5 配置。
1254
+ * 每一份配置都可以是 JSON Schema(带 $schema 字段),会自动提取其中的 default 值。
1255
+ * 所有配置按顺序依次深度合并,后面的优先级更高。
1256
+ *
1257
+ * @param configList - 配置数组,每一项可以是:
1258
+ * - JSON Schema(带 $schema 字段):自动提取 default 值后参与合并
1259
+ * - 普通配置对象:直接参与合并
1260
+ * @param config - 额外配置项
1261
+ * - config.assetRecordByPath: 相对路径到已解析 URL 的映射
1262
+ *
1263
+ * @example
1264
+ * sdk.setConfig(
1265
+ * [schemaA, schemaB, themeData],
1266
+ * { assetRecordByPath: imageAssets }
1267
+ * );
1268
+ */
1269
+ static setConfig(configList, config) {
1270
+ setConfig(configList, config);
1271
+ }
1272
+ /**
1273
+ * 获取合并后的主题配置。
1274
+ * 返回 schema 默认值与用户主题数据深度合并后的结果。
1275
+ * 必须先调用 sdk.setConfig() 才能使用此方法。
1276
+ *
1277
+ * @returns 合并后的主题配置对象
1278
+ *
1279
+ * @example
1280
+ * const config = sdk.getConfig();
1281
+ * console.log(config.primaryColor); // '#ff0000'
1282
+ */
1283
+ static getConfig() {
1284
+ return getConfig();
1285
+ }
1473
1286
  };
1474
1287
  /** Current version of the SDK */
1475
- _sdk.version = "1.0.12";
1288
+ _sdk.version = "1.0.13-beta.1";
1476
1289
  /** Current maximum width of the playable ad container in pixels */
1477
1290
  _sdk.maxWidth = Math.floor(window.innerWidth);
1478
1291
  /** Current maximum height of the playable ad container in pixels */
@@ -1491,10 +1304,6 @@ _sdk.isFinished = false;
1491
1304
  _sdk.volume = actualVolume;
1492
1305
  /** Number of user interactions with the playable ad (auto-incremented on each touch/click) */
1493
1306
  _sdk.interactions = 0;
1494
- /** Number of successful game actions (e.g., successful matches, level clears).
1495
- * Controlled by calling sdk.recordSuccessCount(), NOT auto-incremented.
1496
- */
1497
- _sdk.successCount = 0;
1498
1307
  var sdk = _sdk;
1499
1308
  window["console"].log(
1500
1309
  `%c @playcraft/adsdk %c v${sdk.version} `,
@@ -1507,6 +1316,5 @@ window.PlayableSDK = sdk;
1507
1316
  hideWechatGuide,
1508
1317
  removeWechatGuide,
1509
1318
  sdk,
1510
- showWechatGuide,
1511
- tracking
1319
+ showWechatGuide
1512
1320
  });