@playcraft/adsdk 1.0.18-beta.2 → 1.0.18-beta.3

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/esm/index.js CHANGED
@@ -1,3 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
1
21
  // src/events.ts
2
22
  var registeredEvents = {};
3
23
  function onEvent(event, fn, context, once) {
@@ -652,10 +672,27 @@ function extractDefaultsFromSchema(schema) {
652
672
  return void 0;
653
673
  }
654
674
  function lookupI18nRuntime(runtime, key, langCode) {
655
- var _a, _b;
656
675
  const map = runtime[key];
657
676
  if (!map || typeof map !== "object") return void 0;
658
- return (_b = (_a = map[langCode]) != null ? _a : map["en"]) != null ? _b : Object.values(map)[0];
677
+ const val = map[langCode];
678
+ if (val && val.length > 0) return val;
679
+ const enVal = map["en"];
680
+ if (enVal && enVal.length > 0) return enVal;
681
+ return Object.values(map).find((v) => typeof v === "string" && v.length > 0);
682
+ }
683
+ function mergeI18nRuntimes(runtimes) {
684
+ const merged = {};
685
+ for (const runtime of runtimes) {
686
+ if (!runtime) continue;
687
+ for (const [key, langMap] of Object.entries(runtime)) {
688
+ if (!merged[key]) {
689
+ merged[key] = __spreadValues({}, langMap);
690
+ } else {
691
+ merged[key] = __spreadValues(__spreadValues({}, merged[key]), langMap);
692
+ }
693
+ }
694
+ }
695
+ return merged;
659
696
  }
660
697
  function resolveI18nRefs(config, i18nRecord, langCode) {
661
698
  var _a;
@@ -669,6 +706,9 @@ function resolveI18nRefs(config, i18nRecord, langCode) {
669
706
  const resolved = lookupI18nRuntime(runtime, i18nKey, langCode);
670
707
  if (resolved !== void 0) {
671
708
  config[key] = resolved;
709
+ } else {
710
+ console.warn(`[i18n] Missing translation for key "${i18nKey}" (lang: ${langCode}), using key name as fallback`);
711
+ config[key] = i18nKey;
672
712
  }
673
713
  }
674
714
  } else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
@@ -703,11 +743,12 @@ function deepMerge(target, source) {
703
743
  return target;
704
744
  }
705
745
  function setConfig(configList, config) {
746
+ var _a;
706
747
  const { assetRecordByPath, i18nRecord } = config;
707
748
  const resolvedConfigs = configList.map((item) => {
708
- var _a;
749
+ var _a2;
709
750
  if (!item) return {};
710
- return item.$schema ? (_a = extractDefaultsFromSchema(item)) != null ? _a : {} : item;
751
+ return item.$schema ? (_a2 = extractDefaultsFromSchema(item)) != null ? _a2 : {} : item;
711
752
  });
712
753
  const [first, ...rest] = resolvedConfigs;
713
754
  const mergedConfig = JSON.parse(JSON.stringify(first));
@@ -717,7 +758,8 @@ function setConfig(configList, config) {
717
758
  if (i18nRecord) {
718
759
  const langCode = getLanguageCode();
719
760
  console.log("detect target langCode", langCode);
720
- resolveI18nRefs(mergedConfig, i18nRecord, langCode);
761
+ const runtime = Array.isArray(i18nRecord.runtime) ? mergeI18nRuntimes(i18nRecord.runtime) : (_a = i18nRecord.runtime) != null ? _a : {};
762
+ resolveI18nRefs(mergedConfig, __spreadProps(__spreadValues({}, i18nRecord), { runtime }), langCode);
721
763
  }
722
764
  resolveImagePaths(mergedConfig, assetRecordByPath);
723
765
  _cachedConfig = mergedConfig;
@@ -1609,7 +1651,7 @@ var _sdk = class _sdk {
1609
1651
  }
1610
1652
  };
1611
1653
  /** Current version of the SDK */
1612
- _sdk.version = "1.0.18-beta.2";
1654
+ _sdk.version = "1.0.18-beta.3";
1613
1655
  /** Current maximum width of the playable ad container in pixels */
1614
1656
  _sdk.maxWidth = Math.floor(window.innerWidth);
1615
1657
  /** Current maximum height of the playable ad container in pixels */
@@ -1,5 +1,25 @@
1
1
  "use strict";
2
2
  (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+
3
23
  // src/events.ts
4
24
  var registeredEvents = {};
5
25
  function onEvent(event, fn, context, once) {
@@ -890,10 +910,27 @@
890
910
  return void 0;
891
911
  }
892
912
  function lookupI18nRuntime(runtime, key, langCode) {
893
- var _a, _b;
894
913
  const map = runtime[key];
895
914
  if (!map || typeof map !== "object") return void 0;
896
- return (_b = (_a = map[langCode]) != null ? _a : map["en"]) != null ? _b : Object.values(map)[0];
915
+ const val = map[langCode];
916
+ if (val && val.length > 0) return val;
917
+ const enVal = map["en"];
918
+ if (enVal && enVal.length > 0) return enVal;
919
+ return Object.values(map).find((v) => typeof v === "string" && v.length > 0);
920
+ }
921
+ function mergeI18nRuntimes(runtimes) {
922
+ const merged = {};
923
+ for (const runtime of runtimes) {
924
+ if (!runtime) continue;
925
+ for (const [key, langMap] of Object.entries(runtime)) {
926
+ if (!merged[key]) {
927
+ merged[key] = __spreadValues({}, langMap);
928
+ } else {
929
+ merged[key] = __spreadValues(__spreadValues({}, merged[key]), langMap);
930
+ }
931
+ }
932
+ }
933
+ return merged;
897
934
  }
898
935
  function resolveI18nRefs(config, i18nRecord, langCode) {
899
936
  var _a;
@@ -907,6 +944,9 @@
907
944
  const resolved = lookupI18nRuntime(runtime, i18nKey, langCode);
908
945
  if (resolved !== void 0) {
909
946
  config[key] = resolved;
947
+ } else {
948
+ console.warn(`[i18n] Missing translation for key "${i18nKey}" (lang: ${langCode}), using key name as fallback`);
949
+ config[key] = i18nKey;
910
950
  }
911
951
  }
912
952
  } else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
@@ -941,11 +981,12 @@
941
981
  return target;
942
982
  }
943
983
  function setConfig(configList, config) {
984
+ var _a;
944
985
  const { assetRecordByPath, i18nRecord } = config;
945
986
  const resolvedConfigs = configList.map((item) => {
946
- var _a;
987
+ var _a2;
947
988
  if (!item) return {};
948
- return item.$schema ? (_a = extractDefaultsFromSchema(item)) != null ? _a : {} : item;
989
+ return item.$schema ? (_a2 = extractDefaultsFromSchema(item)) != null ? _a2 : {} : item;
949
990
  });
950
991
  const [first, ...rest] = resolvedConfigs;
951
992
  const mergedConfig = JSON.parse(JSON.stringify(first));
@@ -955,7 +996,8 @@
955
996
  if (i18nRecord) {
956
997
  const langCode = getLanguageCode();
957
998
  console.log("detect target langCode", langCode);
958
- resolveI18nRefs(mergedConfig, i18nRecord, langCode);
999
+ const runtime = Array.isArray(i18nRecord.runtime) ? mergeI18nRuntimes(i18nRecord.runtime) : (_a = i18nRecord.runtime) != null ? _a : {};
1000
+ resolveI18nRefs(mergedConfig, __spreadProps(__spreadValues({}, i18nRecord), { runtime }), langCode);
959
1001
  }
960
1002
  resolveImagePaths(mergedConfig, assetRecordByPath);
961
1003
  _cachedConfig = mergedConfig;
@@ -1847,7 +1889,7 @@
1847
1889
  }
1848
1890
  };
1849
1891
  /** Current version of the SDK */
1850
- _sdk.version = "1.0.18-beta.2";
1892
+ _sdk.version = "1.0.18-beta.3";
1851
1893
  /** Current maximum width of the playable ad container in pixels */
1852
1894
  _sdk.maxWidth = Math.floor(window.innerWidth);
1853
1895
  /** Current maximum height of the playable ad container in pixels */
package/dist/index.d.mts CHANGED
@@ -1,11 +1,15 @@
1
1
  /**
2
- * i18n 数据结构(仅 runtime,SDK 只处理游戏内运行时多语言):
2
+ * i18n 数据结构(仅 runtime,SDK 只处理游戏内运行时多语言)
3
3
  * runtime: { [key]: { [langCode]: "文案" } }
4
4
  *
5
+ * 当传入数组时,按顺序深度合并(后面的优先级更高),
6
+ * 支持全局 i18n + 主题级 i18n 分文件管理:
7
+ * runtime: [I18nRuntime, themeI18n] // 主题级覆盖全局
8
+ *
5
9
  * xplatform(配置平台 UI 标题)由外部配置平台自行解析,不传入 SDK。
6
10
  */
7
11
  type I18nRecord = {
8
- runtime?: Record<string, Record<string, string>>;
12
+ runtime?: Record<string, Record<string, string>> | Record<string, Record<string, string>>[];
9
13
  };
10
14
 
11
15
  type EventName = 'playcraftInit' | 'playcraftReady' | 'playcraftStart' | 'playcraftInteractive' | 'playcraftInteraction' | 'playcraftChallengeStart' | 'playcraftChallengeProgress' | 'playcraftChallengeSuccess' | 'playcraftChallengeFailed' | 'playcraftResize' | 'playcraftPause' | 'playcraftResume' | 'playcraftVolume' | 'playcraftRetry' | 'playcraftFinish' | 'playcraftInstall';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  /**
2
- * i18n 数据结构(仅 runtime,SDK 只处理游戏内运行时多语言):
2
+ * i18n 数据结构(仅 runtime,SDK 只处理游戏内运行时多语言)
3
3
  * runtime: { [key]: { [langCode]: "文案" } }
4
4
  *
5
+ * 当传入数组时,按顺序深度合并(后面的优先级更高),
6
+ * 支持全局 i18n + 主题级 i18n 分文件管理:
7
+ * runtime: [I18nRuntime, themeI18n] // 主题级覆盖全局
8
+ *
5
9
  * xplatform(配置平台 UI 标题)由外部配置平台自行解析,不传入 SDK。
6
10
  */
7
11
  type I18nRecord = {
8
- runtime?: Record<string, Record<string, string>>;
12
+ runtime?: Record<string, Record<string, string>> | Record<string, Record<string, string>>[];
9
13
  };
10
14
 
11
15
  type EventName = 'playcraftInit' | 'playcraftReady' | 'playcraftStart' | 'playcraftInteractive' | 'playcraftInteraction' | 'playcraftChallengeStart' | 'playcraftChallengeProgress' | 'playcraftChallengeSuccess' | 'playcraftChallengeFailed' | 'playcraftResize' | 'playcraftPause' | 'playcraftResume' | 'playcraftVolume' | 'playcraftRetry' | 'playcraftFinish' | 'playcraftInstall';
package/dist/index.js CHANGED
@@ -1,8 +1,25 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
6
23
  var __export = (target, all) => {
7
24
  for (var name in all)
8
25
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -686,10 +703,27 @@ function extractDefaultsFromSchema(schema) {
686
703
  return void 0;
687
704
  }
688
705
  function lookupI18nRuntime(runtime, key, langCode) {
689
- var _a, _b;
690
706
  const map = runtime[key];
691
707
  if (!map || typeof map !== "object") return void 0;
692
- return (_b = (_a = map[langCode]) != null ? _a : map["en"]) != null ? _b : Object.values(map)[0];
708
+ const val = map[langCode];
709
+ if (val && val.length > 0) return val;
710
+ const enVal = map["en"];
711
+ if (enVal && enVal.length > 0) return enVal;
712
+ return Object.values(map).find((v) => typeof v === "string" && v.length > 0);
713
+ }
714
+ function mergeI18nRuntimes(runtimes) {
715
+ const merged = {};
716
+ for (const runtime of runtimes) {
717
+ if (!runtime) continue;
718
+ for (const [key, langMap] of Object.entries(runtime)) {
719
+ if (!merged[key]) {
720
+ merged[key] = __spreadValues({}, langMap);
721
+ } else {
722
+ merged[key] = __spreadValues(__spreadValues({}, merged[key]), langMap);
723
+ }
724
+ }
725
+ }
726
+ return merged;
693
727
  }
694
728
  function resolveI18nRefs(config, i18nRecord, langCode) {
695
729
  var _a;
@@ -703,6 +737,9 @@ function resolveI18nRefs(config, i18nRecord, langCode) {
703
737
  const resolved = lookupI18nRuntime(runtime, i18nKey, langCode);
704
738
  if (resolved !== void 0) {
705
739
  config[key] = resolved;
740
+ } else {
741
+ console.warn(`[i18n] Missing translation for key "${i18nKey}" (lang: ${langCode}), using key name as fallback`);
742
+ config[key] = i18nKey;
706
743
  }
707
744
  }
708
745
  } else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
@@ -737,11 +774,12 @@ function deepMerge(target, source) {
737
774
  return target;
738
775
  }
739
776
  function setConfig(configList, config) {
777
+ var _a;
740
778
  const { assetRecordByPath, i18nRecord } = config;
741
779
  const resolvedConfigs = configList.map((item) => {
742
- var _a;
780
+ var _a2;
743
781
  if (!item) return {};
744
- return item.$schema ? (_a = extractDefaultsFromSchema(item)) != null ? _a : {} : item;
782
+ return item.$schema ? (_a2 = extractDefaultsFromSchema(item)) != null ? _a2 : {} : item;
745
783
  });
746
784
  const [first, ...rest] = resolvedConfigs;
747
785
  const mergedConfig = JSON.parse(JSON.stringify(first));
@@ -751,7 +789,8 @@ function setConfig(configList, config) {
751
789
  if (i18nRecord) {
752
790
  const langCode = getLanguageCode();
753
791
  console.log("detect target langCode", langCode);
754
- resolveI18nRefs(mergedConfig, i18nRecord, langCode);
792
+ const runtime = Array.isArray(i18nRecord.runtime) ? mergeI18nRuntimes(i18nRecord.runtime) : (_a = i18nRecord.runtime) != null ? _a : {};
793
+ resolveI18nRefs(mergedConfig, __spreadProps(__spreadValues({}, i18nRecord), { runtime }), langCode);
755
794
  }
756
795
  resolveImagePaths(mergedConfig, assetRecordByPath);
757
796
  _cachedConfig = mergedConfig;
@@ -1643,7 +1682,7 @@ var _sdk = class _sdk {
1643
1682
  }
1644
1683
  };
1645
1684
  /** Current version of the SDK */
1646
- _sdk.version = "1.0.18-beta.2";
1685
+ _sdk.version = "1.0.18-beta.3";
1647
1686
  /** Current maximum width of the playable ad container in pixels */
1648
1687
  _sdk.maxWidth = Math.floor(window.innerWidth);
1649
1688
  /** Current maximum height of the playable ad container in pixels */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/adsdk",
3
- "version": "1.0.18-beta.2",
3
+ "version": "1.0.18-beta.3",
4
4
  "description": "统一的 Playable SDK,支持 MRAID、Google、Facebook、Vungle、BigoAds 等多广告渠道",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",